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