acid.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* acid.h */
  2. enum
  3. {
  4. Eof = -1,
  5. Strsize = 4096,
  6. Hashsize = 128,
  7. Maxarg = 512,
  8. NFD = 100,
  9. Maxproc = 50,
  10. Maxval = 10,
  11. Mempergc = 1024*1024,
  12. };
  13. #pragma varargck type "L" void
  14. typedef struct Node Node;
  15. typedef struct String String;
  16. typedef struct Lsym Lsym;
  17. typedef struct List List;
  18. typedef struct Store Store;
  19. typedef struct Gc Gc;
  20. typedef struct Strc Strc;
  21. typedef struct Rplace Rplace;
  22. typedef struct Ptab Ptab;
  23. typedef struct Value Value;
  24. typedef struct Type Type;
  25. typedef struct Frtype Frtype;
  26. Extern int kernel;
  27. Extern int remote;
  28. Extern int text;
  29. Extern int silent;
  30. Extern Fhdr fhdr;
  31. Extern int line;
  32. Extern Biobuf* bout;
  33. Extern Biobuf* io[32];
  34. Extern int iop;
  35. Extern char symbol[Strsize];
  36. Extern int interactive;
  37. Extern int na;
  38. Extern int wtflag;
  39. Extern Map* cormap;
  40. Extern Map* symmap;
  41. Extern Lsym* hash[Hashsize];
  42. Extern long dogc;
  43. Extern Rplace* ret;
  44. Extern char* aout;
  45. Extern int gotint;
  46. Extern Gc* gcl;
  47. Extern int stacked;
  48. Extern jmp_buf err;
  49. Extern Node* prnt;
  50. Extern List* tracelist;
  51. Extern int initialising;
  52. Extern int quiet;
  53. extern void (*expop[])(Node*, Node*);
  54. #define expr(n, r) (r)->comt=0; (*expop[(n)->op])(n, r);
  55. enum
  56. {
  57. TINT,
  58. TFLOAT,
  59. TSTRING,
  60. TLIST,
  61. TCODE,
  62. };
  63. struct Type
  64. {
  65. Type* next;
  66. int offset;
  67. char fmt;
  68. char depth;
  69. Lsym* type;
  70. Lsym* tag;
  71. Lsym* base;
  72. };
  73. struct Frtype
  74. {
  75. Lsym* var;
  76. Type* type;
  77. Frtype* next;
  78. };
  79. struct Ptab
  80. {
  81. int pid;
  82. int ctl;
  83. };
  84. Extern Ptab ptab[Maxproc];
  85. struct Rplace
  86. {
  87. jmp_buf rlab;
  88. Node* stak;
  89. Node* val;
  90. Lsym* local;
  91. Lsym** tail;
  92. };
  93. struct Gc
  94. {
  95. char gcmark;
  96. Gc* gclink;
  97. };
  98. struct Store
  99. {
  100. char fmt;
  101. Type* comt;
  102. union {
  103. vlong ival;
  104. double fval;
  105. String* string;
  106. List* l;
  107. Node* cc;
  108. };
  109. };
  110. struct List
  111. {
  112. Gc;
  113. List* next;
  114. char type;
  115. Store;
  116. };
  117. struct Value
  118. {
  119. char set;
  120. char type;
  121. Store;
  122. Value* pop;
  123. Lsym* scope;
  124. Rplace* ret;
  125. };
  126. struct Lsym
  127. {
  128. char* name;
  129. int lexval;
  130. Lsym* hash;
  131. Value* v;
  132. Type* lt;
  133. Node* proc;
  134. Frtype* local;
  135. void (*builtin)(Node*, Node*);
  136. };
  137. struct Node
  138. {
  139. Gc;
  140. char op;
  141. char type;
  142. Node* left;
  143. Node* right;
  144. Lsym* sym;
  145. int builtin;
  146. Store;
  147. };
  148. #define ZN (Node*)0
  149. struct String
  150. {
  151. Gc;
  152. char *string;
  153. int len;
  154. };
  155. List* addlist(List*, List*);
  156. List* al(int);
  157. Node* an(int, Node*, Node*);
  158. void append(Node*, Node*, Node*);
  159. int bool(Node*);
  160. void build(Node*);
  161. void call(char*, Node*, Node*, Node*, Node*);
  162. void catcher(void*, char*);
  163. void checkqid(int, int);
  164. void cmd(void);
  165. Node* con(vlong);
  166. List* construct(Node*);
  167. void ctrace(int);
  168. void decl(Node*);
  169. void defcomplex(Node*, Node*);
  170. void deinstall(int);
  171. void delete(List*, int n, Node*);
  172. void dostop(int);
  173. Lsym* enter(char*, int);
  174. void error(char*, ...);
  175. void execute(Node*);
  176. void fatal(char*, ...);
  177. void flatten(Node**, Node*);
  178. void gc(void);
  179. char* getstatus(int);
  180. void* gmalloc(long);
  181. void indir(Map*, uvlong, char, Node*);
  182. void installbuiltin(void);
  183. void kinit(void);
  184. int Lfmt(Fmt*);
  185. int listcmp(List*, List*);
  186. int listlen(List*);
  187. List* listvar(char*, vlong);
  188. void loadmodule(char*);
  189. void loadvars(void);
  190. Lsym* look(char*);
  191. void ltag(char*);
  192. void marklist(List*);
  193. Lsym* mkvar(char*);
  194. void msg(int, char*);
  195. void notes(int);
  196. int nproc(char**);
  197. void nthelem(List*, int, Node*);
  198. int numsym(char);
  199. void odot(Node*, Node*);
  200. void pcode(Node*, int);
  201. void pexpr(Node*);
  202. int popio(void);
  203. void pstr(String*);
  204. void pushfile(char*);
  205. void pushstr(Node*);
  206. void readtext(char*);
  207. void restartio(void);
  208. uvlong rget(Map*, char*);
  209. String *runenode(Rune*);
  210. int scmp(String*, String*);
  211. void sproc(int);
  212. String* stradd(String*, String*);
  213. String* straddrune(String*, Rune);
  214. String* strnode(char*);
  215. String* strnodlen(char*, int);
  216. char* system(void);
  217. void trlist(Map*, uvlong, uvlong, Symbol*);
  218. void unwind(void);
  219. void userinit(void);
  220. void varreg(void);
  221. void varsym(void);
  222. Waitmsg* waitfor(int);
  223. void whatis(Lsym*);
  224. void windir(Map*, Node*, Node*, Node*);
  225. void yyerror(char*, ...);
  226. int yylex(void);
  227. int yyparse(void);
  228. enum
  229. {
  230. ONAME,
  231. OCONST,
  232. OMUL,
  233. ODIV,
  234. OMOD,
  235. OADD,
  236. OSUB,
  237. ORSH,
  238. OLSH,
  239. OLT,
  240. OGT,
  241. OLEQ,
  242. OGEQ,
  243. OEQ,
  244. ONEQ,
  245. OLAND,
  246. OXOR,
  247. OLOR,
  248. OCAND,
  249. OCOR,
  250. OASGN,
  251. OINDM,
  252. OEDEC,
  253. OEINC,
  254. OPINC,
  255. OPDEC,
  256. ONOT,
  257. OIF,
  258. ODO,
  259. OLIST,
  260. OCALL,
  261. OCTRUCT,
  262. OWHILE,
  263. OELSE,
  264. OHEAD,
  265. OTAIL,
  266. OAPPEND,
  267. ORET,
  268. OINDEX,
  269. OINDC,
  270. ODOT,
  271. OLOCAL,
  272. OFRAME,
  273. OCOMPLEX,
  274. ODELETE,
  275. OCAST,
  276. OFMT,
  277. OEVAL,
  278. OWHAT,
  279. };