9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

hoc.h (2377B)


      1 typedef void (*Inst)(void);
      2 #define	STOP	(Inst) 0
      3 
      4 typedef struct Symbol	Symbol;
      5 typedef union Datum 	Datum;
      6 typedef struct Formal	Formal;
      7 typedef struct Saveval	Saveval;
      8 typedef struct Fndefn	Fndefn;
      9 typedef union Symval	Symval;
     10 
     11 union Symval { /* value of a symbol */
     12 	double	val;		/* VAR */
     13 	double	(*ptr)(double);	/* BLTIN */
     14 	Fndefn	*defn;		/* FUNCTION, PROCEDURE */
     15 	char	*str;		/* STRING */
     16 };
     17 
     18 struct Symbol {	/* symbol table entry */
     19 	char	*name;
     20 	long	type;
     21 	Symval u;
     22 	struct Symbol	*next;	/* to link to another */
     23 };
     24 Symbol	*install(char*, int, double), *lookup(char*);
     25 
     26 union Datum {	/* interpreter stack type */
     27 	double	val;
     28 	Symbol	*sym;
     29 };
     30 
     31 struct Saveval {	/* saved value of variable */
     32 	Symval	val;
     33 	long		type;
     34 	Saveval	*next;
     35 };
     36 
     37 struct Formal {	/* formal parameter */
     38 	Symbol	*sym;
     39 	Saveval	*save;
     40 	Formal	*next;
     41 };
     42 
     43 struct Fndefn {	/* formal parameter */
     44 	Inst	*code;
     45 	Formal	*formals;
     46 	int	nargs;
     47 };
     48 
     49 extern	Formal *formallist(Symbol*, Formal*);
     50 extern	double Fgetd(int);
     51 extern	int moreinput(void);
     52 extern	void restore(Symbol*);
     53 extern	void restoreall(void);
     54 extern	void execerror(char*, char*);
     55 extern	void define(Symbol*, Formal*), verify(Symbol*);
     56 extern	Datum pop(void);
     57 extern	void initcode(void), push(Datum), xpop(void), constpush(void);
     58 extern	void varpush(void);
     59 #define div hocdiv
     60 extern	void eval(void), add(void), sub(void), mul(void), div(void), mod(void);
     61 extern	void negate(void), power(void);
     62 extern	void addeq(void), subeq(void), muleq(void), diveq(void), modeq(void);
     63 
     64 extern	Inst *progp, *progbase, prog[], *code(Inst);
     65 extern	void assign(void), bltin(void), varread(void);
     66 extern	void prexpr(void), prstr(void);
     67 extern	void gt(void), lt(void), eq(void), ge(void), le(void), ne(void);
     68 extern	void and(void), or(void), not(void);
     69 extern	void ifcode(void), whilecode(void), forcode(void);
     70 extern	void call(void), arg(void), argassign(void);
     71 extern	void funcret(void), procret(void);
     72 extern	void preinc(void), predec(void), postinc(void), postdec(void);
     73 extern	void execute(Inst*);
     74 extern	void printtop(void);
     75 
     76 extern double	Log(double), Log10(double), Gamma(double), Sqrt(double), Exp(double);
     77 extern double	Asin(double), Acos(double), Sinh(double), Cosh(double), integer(double);
     78 extern double	Pow(double, double);
     79 
     80 extern	void init(void);
     81 extern	int yyparse(void);
     82 extern	void execerror(char*, char*);
     83 extern	void *emalloc(unsigned);