acid.h 4.3 KB

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