-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandor.h
87 lines (71 loc) · 1.65 KB
/
candor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef CANDOR_H
#define CANDOR_H
struct cval;
struct cenv;
typedef struct cval cval;
typedef struct cenv cenv;
struct cenv {
cenv* par;
int count;
int capacity;
char** keys;
cval** vals;
};
typedef cval* (*cbuiltin)(cenv*, cval*);
typedef struct {
cenv* env;
cval* params;
cval* body;
} user_function;
typedef struct {
int count;
int capacity;
struct cval** cell;
} sexpr;
struct cval {
int type;
union {
long num;
char* str;
char* kywd;
char* err;
cbuiltin builtin;
user_function* function;
struct cval* quot;
sexpr* sexpr;
};
};
typedef enum {
CVAL_NUM,
CVAL_STR,
CVAL_ERR,
CVAL_KYWD,
CVAL_SEXPR,
CVAL_QUOT,
CVAL_QQUOT,
CVAL_FUN,
CVAL_BFUN,
CVAL_MCR,
CVAL_BMCR,
} CvalType;
static char* cval_type_str[]
= { [CVAL_NUM] = "number", [CVAL_STR] = "string",
[CVAL_ERR] = "error", [CVAL_KYWD] = "keyword",
[CVAL_SEXPR] = "sexpr", [CVAL_QUOT] = "quot",
[CVAL_QQUOT] = "quasiquot", [CVAL_FUN] = "function",
[CVAL_BFUN] = "builtin", [CVAL_MCR] = "macro",
[CVAL_BMCR] = "builtin-macro" };
void candor_init(void);
void candor_deinit(void);
cval* candor_load(const char* filename, const char* str);
cval* candor_load_file(const char* filename);
/// Print val
void cval_print(cval* val);
/// Print val followed by a newline
void cval_println(cval* val);
/// Free cval and all assoc values
void cval_del(cval* val);
/* Adding Builtins */
/// Add a new builtin procedure to the global scope
void candor_add_builtin(char* name, cbuiltin proc);
#endif /* CANDOR_H */