blob: b3bd89ce6257064ed9fcccbdd0ad3896fe6a8f79 [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 {
swissChilib3ca4fb2021-04-20 10:33:00 -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;
42};
43
swissChilib3ca4fb2021-04-20 10:33:00 -070044void compile_expression (struct environment *env, struct local *local,
45 value_t val, dasm_State **Dst);
swissChilif3e7f182021-04-20 13:57:22 -070046void compile_expr_to_func (struct environment *env, char *name, value_t val,
47 dasm_State **Dst);
swissChili8fc5e2f2021-04-22 13:45:10 -070048// Compile top-level declaration
49void compile_tl (value_t val, struct environment *env);
50struct environment compile_all (struct istream *is);
swissChilica107a02021-04-14 12:07:30 -070051struct function *find_function (struct environment *env, char *name);