blob: ae660011db5e59926b2e1bb35c54b04f023ec08c [file] [log] [blame]
swissChilica107a02021-04-14 12:07:30 -07001#pragma once
2
3#include "lisp.h"
swissChilif3e7f182021-04-20 13:57:22 -07004#include <dasm_proto.h>
swissChilica107a02021-04-14 12:07:30 -07005#include <stdbool.h>
swissChilib3ca4fb2021-04-20 10:33:00 -07006#include <stdint.h>
swissChilica107a02021-04-14 12:07:30 -07007
8struct function
9{
10 char *name;
11 int nargs; // number of arguments
12
13 union {
swissChili53472e82021-05-08 16:06:32 -070014 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);
swissChilica107a02021-04-14 12:07:30 -070018 void *code_ptr;
swissChilif3e7f182021-04-20 13:57:22 -070019 uintptr_t code_addr;
swissChilica107a02021-04-14 12:07:30 -070020 };
21
22 struct function *prev;
23};
24
25struct environment
26{
27 struct function *first;
28};
29
30struct variable
31{
32 char *name;
33 int number;
34 struct variable *prev;
35};
36
37// local environment
38struct local
39{
swissChilica107a02021-04-14 12:07:30 -070040 int num_vars;
41 struct variable *first;
swissChili53472e82021-05-08 16:06:32 -070042 int npc;
43 int nextpc;
swissChilica107a02021-04-14 12:07:30 -070044};
45
swissChili53472e82021-05-08 16:06:32 -070046void compile_expression(struct environment *env, struct local *local,
47 value_t val, dasm_State **Dst);
48void compile_expr_to_func(struct environment *env, char *name, value_t val,
49 dasm_State **Dst);
50int nextpc(struct local *local, dasm_State **Dst);
swissChili8fc5e2f2021-04-22 13:45:10 -070051// Compile top-level declaration
swissChili53472e82021-05-08 16:06:32 -070052void compile_tl(value_t val, struct environment *env);
53struct environment compile_all(struct istream *is);
54struct function *find_function(struct environment *env, char *name);