-
Notifications
You must be signed in to change notification settings - Fork 6
/
base.h
69 lines (56 loc) · 1.49 KB
/
base.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
#ifndef __TINYLISP_H
#define __TINYLISP_H
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
typedef int atom;
#define nil NULL
typedef struct _cons_cell cons_cell;
typedef struct _object object;
struct _object {
bool atom_p;
bool function_p;
cons_cell * data;
int symbol_index;
};
struct _cons_cell {
object * car;
object * cdr;
};
extern object * globals;
extern object * globals_end;
object * car(object * o);
object * cdr(object * o);
object * quote(object * o);
object * atom_p(object * o);
object * eq(object * o1, object * o2);
object * cons(object * o1, object * o2);
object * print(object * o);
object * reader();
object * sym(const char * name);
object * list(int len, ...);
object * null(object * o);
object * and(object * x, object * y);
object * not(object * o);
object * cadr(object * o);
object * caddr(object * o);
object * cadar(object * o);
object * caar(object * o);
object * caddar(object * o);
object * append(object * x, object * y);
object * pair(object * x, object * y);
object * assoc(object * x, object * y);
object * eval(object * e, object * a);
#ifdef DEBUG
#define LOG(fmt, ...) fprintf(stderr, "%s: " fmt "\n", __PRETTY_FUNCTION__, ##__VA_ARGS__);
#else
#define LOG(fmt, ...)
#endif
#define check(cond, error_fmt, ...) {\
if (!(cond)) {\
fprintf(stderr, "%s: (%s) == false. " error_fmt "\n", __PRETTY_FUNCTION__, #cond, ##__VA_ARGS__);\
exit(EXIT_FAILURE);\
}\
}
#define check_not_nil(p, error_fmt, ...) (check(p!=nil, error_fmt, ##__VA_ARGS__))
#endif