swissChili | 8cfb7c4 | 2021-04-18 21:17:58 -0700 | [diff] [blame] | 1 | /* -*- mode:c -*- */ |
| 2 | |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 3 | #include "compiler.h" |
| 4 | |
| 5 | #include <dasm_proto.h> |
| 6 | #include <dasm_x86.h> |
| 7 | |
| 8 | #define value_size sizeof (struct value) |
| 9 | |
| 10 | |.arch x86; |
| 11 | |
| 12 | |.macro setup, nvars; |
| 13 | | push ebp; |
| 14 | | mov ebp, esp; |
swissChili | 8cfb7c4 | 2021-04-18 21:17:58 -0700 | [diff] [blame] | 15 | | sub esp, (value_size * nvars); |
swissChili | ca107a0 | 2021-04-14 12:07:30 -0700 | [diff] [blame] | 16 | |.endmacro; |
| 17 | |
| 18 | |.macro cleanup; |
| 19 | | mov esp, ebp; |
| 20 | | pop ebp; |
| 21 | | ret; |
| 22 | |.endmacro; |
| 23 | |
| 24 | dasm_State *d; |
| 25 | unsigned int npc = 8; |
| 26 | |
| 27 | struct function *find_function (struct environment *env, char *name) |
| 28 | { |
| 29 | struct function *f = env->first; |
| 30 | |
| 31 | while ( strcmp (f->name, name) != 0 ) |
| 32 | { |
| 33 | if ( f->prev ) |
| 34 | f = f->prev; |
| 35 | else |
| 36 | return NULL; |
| 37 | } |
| 38 | |
| 39 | return f; |
| 40 | } |
| 41 | |
| 42 | void compile (struct istream *is) |
| 43 | { |
| 44 | |.section code; |
| 45 | dasm_init (&d, DASM_MAXSECTION); |
| 46 | |
| 47 | |.globals lbl_; |
| 48 | void *labels[ lbl__MAX ]; |
| 49 | dasm_setupglobal (&d, labels, lbl__MAX); |
| 50 | |
| 51 | |.actionlist lisp_actions; |
| 52 | dasm_setup (&d, lisp_actions); |
| 53 | |
| 54 | dasm_growpc (&d, npc); |
| 55 | } |