-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.h
57 lines (50 loc) · 1.47 KB
/
object.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
#define LISP_OBJECT_TYPE_INTEGER 1
#define LISP_OBJECT_TYPE_SYMBOL 2
#define LISP_OBJECT_TYPE_CONS 3
#define LISP_OBJECT_TYPE_STRING 4
#define LISP_OBJECT_TYPE_PROCEDURE 5
#define LISP_OBJECT_TYPE_BIT_USER (1 << 31)
// This is just pseudocode to describe the structure of the lisp objects in memory
struct lisp_cons {
struct lisp_object *head; // NULL = nil
struct lisp_object *tail; // NULL = nil
};
struct lisp_symbol {
char *buf;
unsigned long len; // cap = len for symbols (they must be allocated with exact size)
struct lisp_object *global_value; // for lookup in global context
};
struct lisp_string {
char *buf;
unsigned long len; // the length of the string
unsigned long cap; // the actual size of the allocated buffer
};
struct lisp_procedure {
struct lisp_return (*ptr)(
struct lisp_object *args,
struct lisp_object *local_words,
struct lisp_object *data
);
struct lisp_object *data; // passed on call, can be nil
};
struct lisp_return {
long status;
struct lisp_object *return_value;
};
struct lisp_user_obj {
void (*destructor)(struct lisp_object *obj);
long data1;
long data2;
};
struct lisp_object {
int type; // negative values are user types
int refcount; // should be >= 1, or else destroy
union {
long as_integer;
struct lisp_symbol as_symbol;
struct lisp_cons as_cons;
struct lisp_string as_string;
struct lisp_procedure as_procedure;
struct lisp_user_obj as_user_obj;
} value;
};