blob: 2bd10d1e2d244bea32b9e46ec038c387125feeb6 [file] [log] [blame]
swissChili8cfb7c42021-04-18 21:17:58 -07001/* -*- mode:c -*- */
2
swissChilica107a02021-04-14 12:07:30 -07003#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;
swissChili8cfb7c42021-04-18 21:17:58 -070015| sub esp, (value_size * nvars);
swissChilica107a02021-04-14 12:07:30 -070016|.endmacro;
17
18|.macro cleanup;
19| mov esp, ebp;
20| pop ebp;
21| ret;
22|.endmacro;
23
24dasm_State *d;
25unsigned int npc = 8;
26
27struct 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
42void 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}