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 */
43 c734c0e9 2021-08-03 op struct value {
56 983e73a6 2021-08-08 op uint8_t *start;
59 c734c0e9 2021-08-03 op uint8_t qid[QIDSIZE];
81 c734c0e9 2021-08-03 op struct op *next;
86 c734c0e9 2021-08-03 op struct op *expr;
88 c734c0e9 2021-08-03 op struct op *assert;
90 c734c0e9 2021-08-03 op struct proc *proc;
91 c734c0e9 2021-08-03 op struct op *argv;
94 c734c0e9 2021-08-03 op struct value literal;
97 c734c0e9 2021-08-03 op struct op *expr;
101 c734c0e9 2021-08-03 op struct op *a;
102 c734c0e9 2021-08-03 op struct op *b;
105 acf1403a 2021-08-05 op struct op *expr;
110 8250ab19 2021-08-07 op struct op *expr;
115 f9cd3e06 2021-08-04 op TAILQ_HEAD(bindings, binding);
116 f9cd3e06 2021-08-04 op struct binding {
117 bc298316 2021-08-05 op TAILQ_ENTRY(binding) entry;
119 f9cd3e06 2021-08-04 op struct value val;
122 bc298316 2021-08-05 op * Hack to support varargs. We set a special variable named
123 bc298316 2021-08-05 op * "..." that contains the list of ops that will evaluate to
124 bc298316 2021-08-05 op * the arguments.
126 bc298316 2021-08-05 op struct op *raw;
129 f9cd3e06 2021-08-04 op TAILQ_HEAD(envs, env);
131 f9cd3e06 2021-08-04 op TAILQ_ENTRY(env) entry;
132 f9cd3e06 2021-08-04 op struct bindings bindings;
135 d9d02161 2021-08-04 op TAILQ_HEAD(opstacks, opstack);
136 d9d02161 2021-08-04 op struct opstack {
137 d9d02161 2021-08-04 op TAILQ_ENTRY(opstack) entry;
138 d9d02161 2021-08-04 op struct op base;
139 d9d02161 2021-08-04 op struct op *last;
143 c734c0e9 2021-08-03 op TAILQ_HEAD(procs, proc);
144 c734c0e9 2021-08-03 op struct proc {
145 c734c0e9 2021-08-03 op TAILQ_ENTRY(proc) entry;
149 c734c0e9 2021-08-03 op char *args[MAXWELEM];
150 c734c0e9 2021-08-03 op struct op *body;
151 c734c0e9 2021-08-03 op int (*nativefn)(int);
154 c734c0e9 2021-08-03 op TAILQ_HEAD(tests, test);
155 c734c0e9 2021-08-03 op struct test {
156 c734c0e9 2021-08-03 op TAILQ_ENTRY(test) entry;
157 0b453b63 2021-08-07 op int shouldfail;
160 d9d02161 2021-08-04 op struct op *body;
169 f9cd3e06 2021-08-04 op int global_set(char *, struct op *);
171 c734c0e9 2021-08-03 op struct op *newop(int);
172 7c459187 2021-08-12 op void free_op_rec(struct op *);
173 c734c0e9 2021-08-03 op void free_op(struct op *);
174 0e62706a 2021-08-04 op struct op *op_rest(void);
175 c734c0e9 2021-08-03 op struct op *op_assign(char *, struct op *);
176 c734c0e9 2021-08-03 op struct op *op_assert(struct op *);
177 c734c0e9 2021-08-03 op struct op *op_var(char *);
178 c734c0e9 2021-08-03 op struct op *op_lit_str(char *);
179 c734c0e9 2021-08-03 op struct op *op_lit_num(uint64_t);
180 c734c0e9 2021-08-03 op struct op *op_cmp_eq(struct op *, struct op *);
181 423f02f5 2021-12-28 cage struct op *op_cmp_leq(struct op *, struct op *);
182 c734c0e9 2021-08-03 op struct op *op_cast(struct op *, int);
183 acf1403a 2021-08-05 op struct op *op_faccess(struct op *, char *);
184 8250ab19 2021-08-07 op struct op *op_sfail(struct op *, char *);
185 983e73a6 2021-08-08 op struct op *op_vargs(void);
187 da4de0c1 2021-08-04 op void ppf_val(FILE *, struct value *);
188 c734c0e9 2021-08-03 op void pp_val(struct value *);
189 7a495cc0 2021-12-02 op void pp_val(struct value *);
190 7c459187 2021-08-12 op const char *val_type(struct value *);
191 c734c0e9 2021-08-03 op int val_trueish(struct value *);
192 7a495cc0 2021-12-02 op int val_isnum(struct value *);
193 7a495cc0 2021-12-02 op int64_t val_tonum(struct value *);
194 c734c0e9 2021-08-03 op int val_eq(struct value *, struct value *);
195 423f02f5 2021-12-28 cage int val_leq(struct value *, struct value *);
196 da4de0c1 2021-08-04 op int val_cast(struct value *, int);
197 acf1403a 2021-08-05 op int val_faccess(struct value *, const char *, struct value *);
198 c734c0e9 2021-08-03 op void pp_op(struct op *);
199 c734c0e9 2021-08-03 op void pp_block(struct op *);
200 c734c0e9 2021-08-03 op int eval(struct op *);
202 c734c0e9 2021-08-03 op /* funcall */
203 d9d02161 2021-08-04 op void prepare_funcall(void);
204 c734c0e9 2021-08-03 op void push_arg(struct op *);
205 d9d02161 2021-08-04 op struct op *op_funcall(struct proc *);
208 54736a95 2021-08-04 op void add_builtin_proc(const char *name, int (*)(int), int, int);
209 d9d02161 2021-08-04 op void prepare_proc(void);
210 c734c0e9 2021-08-03 op /* push_arg works on procs too */
211 d9d02161 2021-08-04 op int proc_setup_body(void);
212 d9d02161 2021-08-04 op void proc_done(char *name);
213 c734c0e9 2021-08-03 op void block_push(struct op *);
214 c734c0e9 2021-08-03 op struct proc *proc_by_name(const char *);
216 c734c0e9 2021-08-03 op /* testing */
217 d9d02161 2021-08-04 op void prepare_test(void);
218 0b453b63 2021-08-07 op void test_done(int, char *, char *);
221 c734c0e9 2021-08-03 op void loadfile(const char *);