hoc.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef void (*Inst)(void);
  10. #define STOP (Inst) 0ULL
  11. typedef struct Symbol Symbol;
  12. typedef union Datum Datum;
  13. typedef struct Formal Formal;
  14. typedef struct Saveval Saveval;
  15. typedef struct Fndefn Fndefn;
  16. typedef union Symval Symval;
  17. union Symval { /* value of a symbol */
  18. double val; /* VAR */
  19. double (*ptr)(double); /* BLTIN */
  20. Fndefn *defn; /* FUNCTION, PROCEDURE */
  21. char *str; /* STRING */
  22. };
  23. struct Symbol { /* symbol table entry */
  24. char *name;
  25. long type;
  26. Symval u;
  27. struct Symbol *next; /* to link to another */
  28. };
  29. Symbol *install(char*, int, double), *lookup(char*);
  30. union Datum { /* interpreter stack type */
  31. double val;
  32. Symbol *sym;
  33. };
  34. struct Saveval { /* saved value of variable */
  35. Symval val;
  36. long type;
  37. Saveval *next;
  38. };
  39. struct Formal { /* formal parameter */
  40. Symbol *sym;
  41. Saveval *save;
  42. Formal *next;
  43. };
  44. struct Fndefn { /* formal parameter */
  45. Inst *code;
  46. Formal *formals;
  47. int nargs;
  48. };
  49. extern int indef;
  50. extern Formal *formallist(Symbol*, Formal*);
  51. extern double Fgetd(int);
  52. extern int moreinput(void);
  53. extern void restore(Symbol*);
  54. extern void restoreall(void);
  55. extern void execerror(char*, char*);
  56. extern void define(Symbol*, Formal*), verify(Symbol*);
  57. extern Datum pop(void);
  58. extern void initcode(void), push(Datum), xpop(void), constpush(void);
  59. extern void varpush(void);
  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. extern Inst *progp, *progbase, prog[], *code(Inst);
  64. extern void assign(void), bltin(void), varread(void);
  65. extern void prexpr(void), prstr(void);
  66. extern void gt(void), lt(void), eq(void), ge(void), le(void), ne(void);
  67. extern void and(void), or(void), not(void);
  68. extern void ifcode(void), whilecode(void), forcode(void);
  69. extern void call(void), arg(void), argassign(void);
  70. extern void funcret(void), procret(void);
  71. extern void preinc(void), predec(void), postinc(void), postdec(void);
  72. extern void execute(Inst*);
  73. extern void printtop(void);
  74. extern double Log(double), Log10(double), Gamma(double), Sqrt(double), Exp(double);
  75. extern double Asin(double), Acos(double), Sinh(double), Cosh(double), integer(double);
  76. extern double Pow(double, double);
  77. extern void init(void);
  78. extern int yyparse(void);
  79. extern void execerror(char*, char*);
  80. extern void *emalloc(unsigned);