-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcons.c
42 lines (35 loc) · 884 Bytes
/
cons.c
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
#include "lilscheme.h"
// Conses
Handle CreateCons(Handle car, Handle cdr) {
Handle hnd = CreateObject(TYPE_CONS,0);
DATA_AREA(CONS,hnd)->car = car;
DATA_AREA(CONS,hnd)->cdr = cdr;
return hnd;
}
Handle Car(Handle cons) {
if (DEREF(cons)->type != TYPE_CONS) {
panic("can't Car that type");
}
return DATA_AREA(CONS,cons)->car;
}
Handle Cdr(Handle cons) {
if (DEREF(cons)->type != TYPE_CONS) {
panic("can't Cdr that type");
}
return DATA_AREA(CONS,cons)->cdr;
}
void SetCar(Handle cons, Handle car) {
if (DEREF(cons)->type != TYPE_CONS) {
panic("can't SetCar that type");
}
DATA_AREA(CONS,cons)->car = car;
}
void SetCdr(Handle cons, Handle cdr) {
if (DEREF(cons)->type != TYPE_CONS) {
panic("can't SetCdr that type");
}
DATA_AREA(CONS,cons)->cdr = cdr;
}
Handle Cadr(Handle cons) {
return Car(Cdr(cons));
}