-
Notifications
You must be signed in to change notification settings - Fork 1
/
object.h
78 lines (68 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef OBJECT_H
#define OBJECT_H
struct object;
typedef struct object * pobject;
typedef pobject (*pcfunc)(pobject env, pobject params);
/*
* flags: 0000|0000
* ^^^^|^^^^
* GC|Type
* |
*/
struct object {
char flags;
union {
int character;
double number;
pcfunc cfunc;
struct {
int length;
char *value;
} symbol;
struct {
pobject car;
pobject cdr;
} cons;
struct {
pobject env;
pobject code;
} closure;
} data;
};
#define NIL 0
#define T_SYMBOL 0x01
#define T_CHARACTER 0x02
#define T_NUMBER 0x03
#define T_CFUNC 0x04
#define T_CONS 0x05
#define T_CLOSURE 0x06
#define T_MACRO 0x07
extern int object_new_count;
extern int object_free_count;
extern pobject object_true;
extern pobject symbol_parent_env;
extern pobject symbol_quote;
static inline int object_type(pobject o)
{ return o ? (o->flags & 0x0f) : NIL; }
static inline int is_nil(pobject o) { return !o; }
static inline pobject object_bool(int b)
{ return b ? object_true : NIL; }
static inline int is_symbol(pobject o)
{ return object_type(o) == T_SYMBOL; }
static inline int is_character(pobject o)
{ return object_type(o) == T_CHARACTER; }
static inline int is_number(pobject o)
{ return object_type(o) == T_NUMBER; }
static inline int is_cfunc(pobject o)
{ return object_type(o) == T_CFUNC; }
static inline int is_cons(pobject o)
{ return object_type(o) == T_CONS; }
static inline int is_closure(pobject o)
{ return object_type(o) == T_CLOSURE; }
static inline int is_macro(pobject o)
{ return object_type(o) == T_MACRO; }
extern pobject object_new(char type);
extern void object_free(pobject o);
extern int object_equal(pobject o1, pobject o2);
extern pobject object_prepend_begin(pobject o);
#endif