-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathobj.h
82 lines (65 loc) · 1.4 KB
/
obj.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
#include <stdio.h>
/* Both TSOCKET and TSTREAM are handled with the same set of
* primitives STREAM-*, but the type needs to be preserved
* separately.
*/
typedef enum {
/* states */
/* STATE_FORWARDED, */
/* types */
TNIL,
TTRUE,
TINT,
TFLOAT,
TCONS,
TSTRING,
TSYMBOL,
TPRIMITIVE,
TFUNCTION,
TSOCKET, /* INET Socket Stream */
TSTREAM /* FILE stream */
} obj_type_t;
/* function type: (obj **env, obj *args) -> obj *return */
/* args have not been evaluated */
typedef struct obj * (*primitive_t)();
typedef struct obj {
int type;
union {
/* when the object moves during GC, it gets a new location */
/* struct obj *new_location; */
/* TINT and TSOCKET */
int i;
/* TFLOAT */
float f;
/* TSTRING */
char *str;
/* TSTREAM pointer */
FILE *stream;
/* symbols */
struct {
char *name;
} sym;
/* cons cells */
struct {
struct obj *car;
struct obj *cdr;
} c;
/* primitive (C-implemented) functions */
struct {
primitive_t code;
} prim;
/* functions*/
struct {
struct obj *params;
struct obj *body;
struct obj *env;
} fun;
} value;
} obj_t;
#define OBJ_SIZE (sizeof (obj_t))
#define CAR(x) ((x)->value.c.car)
#define CDR(x) ((x)->value.c.cdr)
#define FIRST(x) CAR(x)
#define SECOND(x) CAR(CDR(x))
#define THIRD(x) CAR(CDR(CDR(x)))
#define REST(x) CDR(x)