2 c734c0e9 2021-08-03 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 c734c0e9 2021-08-03 op * Permission to use, copy, modify, and distribute this software for any
5 c734c0e9 2021-08-03 op * purpose with or without fee is hereby granted, provided that the above
6 c734c0e9 2021-08-03 op * copyright notice and this permission notice appear in all copies.
8 c734c0e9 2021-08-03 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 c734c0e9 2021-08-03 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 c734c0e9 2021-08-03 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 c734c0e9 2021-08-03 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 c734c0e9 2021-08-03 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 c734c0e9 2021-08-03 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 c734c0e9 2021-08-03 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c734c0e9 2021-08-03 op #ifndef SCRIPT_H
18 c734c0e9 2021-08-03 op #define SCRIPT_H
20 da4de0c1 2021-08-04 op #include "compat.h"
22 da4de0c1 2021-08-04 op #include <stdio.h>
24 c734c0e9 2021-08-03 op #include "kamid.h"
27 c734c0e9 2021-08-03 op /* literals */
42 c734c0e9 2021-08-03 op struct value {
54 c734c0e9 2021-08-03 op uint8_t qid[QIDSIZE];
74 c734c0e9 2021-08-03 op struct op *next;
79 c734c0e9 2021-08-03 op struct op *expr;
81 c734c0e9 2021-08-03 op struct op *assert;
83 c734c0e9 2021-08-03 op struct proc *proc;
84 c734c0e9 2021-08-03 op struct op *argv;
87 c734c0e9 2021-08-03 op struct value literal;
90 c734c0e9 2021-08-03 op struct op *expr;
98 acf1403a 2021-08-05 op struct op *expr;
103 8250ab19 2021-08-07 op struct op *expr;
108 f9cd3e06 2021-08-04 op TAILQ_HEAD(bindings, binding);
109 f9cd3e06 2021-08-04 op struct binding {
110 bc298316 2021-08-05 op TAILQ_ENTRY(binding) entry;
112 f9cd3e06 2021-08-04 op struct value val;
115 bc298316 2021-08-05 op * Hack to support varargs. We set a special variable named
116 bc298316 2021-08-05 op * "..." that contains the list of ops that will evaluate to
117 bc298316 2021-08-05 op * the arguments.
119 bc298316 2021-08-05 op struct op *raw;
122 f9cd3e06 2021-08-04 op TAILQ_HEAD(envs, env);
124 f9cd3e06 2021-08-04 op TAILQ_ENTRY(env) entry;
125 f9cd3e06 2021-08-04 op struct bindings bindings;
128 d9d02161 2021-08-04 op TAILQ_HEAD(opstacks, opstack);
129 d9d02161 2021-08-04 op struct opstack {
130 d9d02161 2021-08-04 op TAILQ_ENTRY(opstack) entry;
131 d9d02161 2021-08-04 op struct op base;
132 d9d02161 2021-08-04 op struct op *last;
136 c734c0e9 2021-08-03 op TAILQ_HEAD(procs, proc);
137 c734c0e9 2021-08-03 op struct proc {
138 c734c0e9 2021-08-03 op TAILQ_ENTRY(proc) entry;
142 c734c0e9 2021-08-03 op char *args[MAXWELEM];
143 c734c0e9 2021-08-03 op struct op *body;
144 c734c0e9 2021-08-03 op int (*nativefn)(int);
147 c734c0e9 2021-08-03 op TAILQ_HEAD(tests, test);
148 c734c0e9 2021-08-03 op struct test {
149 c734c0e9 2021-08-03 op TAILQ_ENTRY(test) entry;
150 0b453b63 2021-08-07 op int shouldfail;
153 d9d02161 2021-08-04 op struct op *body;
162 f9cd3e06 2021-08-04 op int global_set(char *, struct op *);
164 c734c0e9 2021-08-03 op struct op *newop(int);
165 c734c0e9 2021-08-03 op void free_op(struct op *);
166 0e62706a 2021-08-04 op struct op *op_rest(void);
167 c734c0e9 2021-08-03 op struct op *op_assign(char *, struct op *);
168 c734c0e9 2021-08-03 op struct op *op_assert(struct op *);
169 c734c0e9 2021-08-03 op struct op *op_var(char *);
170 c734c0e9 2021-08-03 op struct op *op_lit_str(char *);
171 c734c0e9 2021-08-03 op struct op *op_lit_num(uint64_t);
172 c734c0e9 2021-08-03 op struct op *op_cmp_eq(struct op *, struct op *);
173 c734c0e9 2021-08-03 op struct op *op_cast(struct op *, int);
174 acf1403a 2021-08-05 op struct op *op_faccess(struct op *, char *);
175 8250ab19 2021-08-07 op struct op *op_sfail(struct op *, char *);
177 da4de0c1 2021-08-04 op void ppf_val(FILE *, struct value *);
178 c734c0e9 2021-08-03 op void pp_val(struct value *);
179 c734c0e9 2021-08-03 op int val_trueish(struct value *);
180 c734c0e9 2021-08-03 op int val_eq(struct value *, struct value *);
181 da4de0c1 2021-08-04 op int val_cast(struct value *, int);
182 acf1403a 2021-08-05 op int val_faccess(struct value *, const char *, struct value *);
183 c734c0e9 2021-08-03 op void pp_op(struct op *);
184 c734c0e9 2021-08-03 op void pp_block(struct op *);
185 c734c0e9 2021-08-03 op int eval(struct op *);
187 c734c0e9 2021-08-03 op /* funcall */
188 d9d02161 2021-08-04 op void prepare_funcall(void);
189 c734c0e9 2021-08-03 op void push_arg(struct op *);
190 d9d02161 2021-08-04 op struct op *op_funcall(struct proc *);
193 54736a95 2021-08-04 op void add_builtin_proc(const char *name, int (*)(int), int, int);
194 d9d02161 2021-08-04 op void prepare_proc(void);
195 c734c0e9 2021-08-03 op /* push_arg works on procs too */
196 d9d02161 2021-08-04 op int proc_setup_body(void);
197 d9d02161 2021-08-04 op void proc_done(char *name);
198 c734c0e9 2021-08-03 op void block_push(struct op *);
199 c734c0e9 2021-08-03 op struct proc *proc_by_name(const char *);
201 c734c0e9 2021-08-03 op /* testing */
202 d9d02161 2021-08-04 op void prepare_test(void);
203 0b453b63 2021-08-07 op void test_done(int, char *, char *);
206 c734c0e9 2021-08-03 op void loadfile(const char *);