swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "lisp.h" |
swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame] | 4 | #include <dasm_proto.h> |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 5 | #include <stdbool.h> |
swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 6 | #include <stdint.h> |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 7 | |
| 8 | struct function |
| 9 | { |
| 10 | char *name; |
| 11 | int nargs; // number of arguments |
| 12 | |
| 13 | union { |
swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 14 | value_t (*def0) (); |
| 15 | value_t (*def1) (value_t); |
| 16 | value_t (*def2) (value_t, value_t); |
| 17 | value_t (*def3) (value_t, value_t, value_t); |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 18 | void *code_ptr; |
swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame] | 19 | uintptr_t code_addr; |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | struct function *prev; |
| 23 | }; |
| 24 | |
| 25 | struct environment |
| 26 | { |
| 27 | struct function *first; |
| 28 | }; |
| 29 | |
| 30 | struct variable |
| 31 | { |
| 32 | char *name; |
| 33 | int number; |
| 34 | struct variable *prev; |
| 35 | }; |
| 36 | |
| 37 | // local environment |
| 38 | struct local |
| 39 | { |
| 40 | // temps are accessed at ebp - 8 * (num_vars + temp) |
| 41 | bool temps[ 64 ]; |
| 42 | int num_vars; |
| 43 | struct variable *first; |
| 44 | }; |
| 45 | |
swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 46 | void compile_expression (struct environment *env, struct local *local, |
| 47 | value_t val, dasm_State **Dst); |
swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame] | 48 | void compile_expr_to_func (struct environment *env, char *name, value_t val, |
| 49 | dasm_State **Dst); |
| 50 | void compile (value_t val); |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 51 | struct function *find_function (struct environment *env, char *name); |