summaryrefslogtreecommitdiff
path: root/lisp_api.h
blob: 70d317b8c62a79797728bb6bbe64f036e987910e (plain)
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
#ifndef LISP_API_H
#define LISP_API_H

typedef struct value value;
typedef struct env env;

typedef enum {
	VT_INT,
	VT_DOUBLE,
	VT_SYMBOL,
	VT_STRING,
	VT_NIL,
	VT_PAIR,
	VT_LAMBDA,
	VT_BUILTIN
} val_type;

struct value {
	val_type type;
	union {
		int i;
		double d;
		const char *sym;
		const char *str;
		struct {
			value *car;
			value *cdr;
		} pair;
		struct {
			value *params;
			value *body;
			env *env;
		} lambda;
		struct {
			value *(*fn) (env *, value *);
		} builtin;
	} as;
};

value *make_int(int i);
value *make_double(double d);
value *make_symbol(const char *sym);
value *make_string(const char *str);
value *make_nil();
value *make_lambda(env *e, value *params, value *body);
value *make_builtin(value *(*fn) (env *, value *));
value *cons(value *car, value *cdr);
value *car(value *cons);
value *cdr(value *cons);
value *reverse(value *list);

#endif