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