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 c734c0e9 2021-08-03 op #include "kamid.h"
23 c734c0e9 2021-08-03 op /* literals */
37 c734c0e9 2021-08-03 op struct value {
42 c734c0e9 2021-08-03 op uint8_t qid[QIDSIZE];
59 c734c0e9 2021-08-03 op struct op *next;
64 c734c0e9 2021-08-03 op struct op *expr;
66 c734c0e9 2021-08-03 op struct op *assert;
68 c734c0e9 2021-08-03 op struct proc *proc;
69 c734c0e9 2021-08-03 op struct op *argv;
72 c734c0e9 2021-08-03 op struct value literal;
75 c734c0e9 2021-08-03 op struct op *expr;
85 d9d02161 2021-08-04 op TAILQ_HEAD(opstacks, opstack);
86 d9d02161 2021-08-04 op struct opstack {
87 d9d02161 2021-08-04 op TAILQ_ENTRY(opstack) entry;
88 d9d02161 2021-08-04 op struct op base;
89 d9d02161 2021-08-04 op struct op *last;
93 c734c0e9 2021-08-03 op TAILQ_HEAD(procs, proc);
95 c734c0e9 2021-08-03 op TAILQ_ENTRY(proc) entry;
99 c734c0e9 2021-08-03 op char *args[MAXWELEM];
100 c734c0e9 2021-08-03 op struct op *body;
101 c734c0e9 2021-08-03 op int (*nativefn)(int);
104 c734c0e9 2021-08-03 op TAILQ_HEAD(tests, test);
105 c734c0e9 2021-08-03 op struct test {
106 c734c0e9 2021-08-03 op TAILQ_ENTRY(test) entry;
109 d9d02161 2021-08-04 op struct op *body;
118 c734c0e9 2021-08-03 op void global_set(char *, struct op *);
120 c734c0e9 2021-08-03 op struct op *newop(int);
121 c734c0e9 2021-08-03 op void free_op(struct op *);
122 c734c0e9 2021-08-03 op struct op *op_assign(char *, struct op *);
123 c734c0e9 2021-08-03 op struct op *op_assert(struct op *);
124 c734c0e9 2021-08-03 op struct op *op_var(char *);
125 c734c0e9 2021-08-03 op struct op *op_lit_str(char *);
126 c734c0e9 2021-08-03 op struct op *op_lit_num(uint64_t);
127 c734c0e9 2021-08-03 op struct op *op_cmp_eq(struct op *, struct op *);
128 c734c0e9 2021-08-03 op struct op *op_cast(struct op *, int);
130 c734c0e9 2021-08-03 op void pp_val(struct value *);
131 c734c0e9 2021-08-03 op int val_trueish(struct value *);
132 c734c0e9 2021-08-03 op int val_eq(struct value *, struct value *);
133 c734c0e9 2021-08-03 op void pp_op(struct op *);
134 c734c0e9 2021-08-03 op void pp_block(struct op *);
135 c734c0e9 2021-08-03 op int eval(struct op *);
137 c734c0e9 2021-08-03 op /* funcall */
138 d9d02161 2021-08-04 op void prepare_funcall(void);
139 c734c0e9 2021-08-03 op void push_arg(struct op *);
140 d9d02161 2021-08-04 op struct op *op_funcall(struct proc *);
143 c734c0e9 2021-08-03 op void add_builtin_proc(const char *name, int (*)(int));
144 d9d02161 2021-08-04 op void prepare_proc(void);
145 c734c0e9 2021-08-03 op /* push_arg works on procs too */
146 d9d02161 2021-08-04 op int proc_setup_body(void);
147 d9d02161 2021-08-04 op void proc_done(char *name);
148 c734c0e9 2021-08-03 op void block_push(struct op *);
149 c734c0e9 2021-08-03 op struct proc *proc_by_name(const char *);
151 c734c0e9 2021-08-03 op /* testing */
152 d9d02161 2021-08-04 op void prepare_test(void);
153 d9d02161 2021-08-04 op void test_done(char *, char *);
156 c734c0e9 2021-08-03 op void loadfile(const char *);