acid.h 4.6 KB

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