-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpureLisp.h
54 lines (48 loc) · 940 Bytes
/
pureLisp.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
#define MAX_TOKEN_LENGTH 256
#define GC_THRESHOLD_BYTES 512000000 // 512MB
typedef enum _objType {
TYPE_PAIR,
TYPE_INTEGER,
TYPE_SYMBOL,
TYPE_STRING,
TYPE_NIL,
TYPE_ENV,
TYPE_PRIMITIVE,
TYPE_T,
TYPE_FUNCTION
} ObjType;
typedef enum _gcmark {
USED,
UNUSED
} GCMark;
// Primitive function type
typedef struct _object *(*Primitive)(struct _object*, struct _object*);
typedef struct _object {
ObjType type;
GCMark gcmark;
struct _object *next;
union {
struct {
struct _object *car;
struct _object *cdr;
} pair;
int integer;
char *symbol;
char *string;
struct {
struct _object *vars;
struct _object *up;
} env;
Primitive primitive;
struct {
struct _object *params;
struct _object *body;
struct _object *applyEnv;
} function;
};
} Object;
extern Object *TopEnv;
void initialize();
Object *read(Object *env, FILE *fp);
Object *eval(Object *env, Object *obj);
void print(Object *obj);