forked from splatspace/wombat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.h
70 lines (55 loc) · 1.37 KB
/
types.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
#ifndef _UBERLISP_TYPES_H
#define _UBERLISP_TYPES_H
/* Lisp Types *******************************/
enum types { SPECIAL, FUNCTION, SYMBOL, CONS, INT };
typedef struct {
enum types type;
} Type;
typedef struct {
enum types type;
unsigned long hashcode;
union Value {
char *sval;
int ival;
} v;
} Atom;
typedef struct special {
enum types type;
char *name;
void *(*fn)(void **env, void *expr);
} Special;
typedef struct function {
enum types type;
char *name;
void *fn;
} Function;
typedef struct cons {
enum types type;
void *car;
void *cdr;
} Cons;
/* Booleans **********************************/
extern void *TRUE;
extern void *FALSE;
extern void *NIL;
/* Type Helpers ******************************/
enum types type(void* expr);
Cons* cons(void* car, void* cdr);
Cons* empty();
Atom* integer(int ival);
Atom* sym(char *s);
int truthy(void* x);
void* equal(void* x, void* y);
void rfree(void* x);
/* Type Macros *******************************/
#define CONS(x) ((Cons*)x)
#define CAR(x) ((Cons*)x)->car
#define CDR(x) ((Cons*)x)->cdr
#define ATOM(x) ((Atom*)x)
#define SPECIAL(x) ((Special*)x)
#define IVAL(x) ((Atom*)x)->v.ival
#define SVAL(x) ((Atom*)x)->v.sval
#define HASHCODE(x) ((Atom*)x)->hashcode
#define PRINT_TYPE(x) printf("type: %s\n", type(x) == CONS ? "CONS" : type(x) == INT ? "INT" : "SYMBOL");
unsigned long hash(char *str);
#endif