-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsymbol.c
62 lines (56 loc) · 1.06 KB
/
symbol.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "obj.h"
#include "alloc.h"
#include "machine.h"
#include "lisp.h"
#include "symbol.h"
obj_t *find_symbol(name)
char *name;
{
obj_t *entry, *table, *val;
for (table = VM->symbols; nil != table; table = CDR(table)) {
entry = CAR(table);
assert(TSYMBOL == entry->type);
if (0 == strcmp(entry->value.sym.name, name)) {
return entry;
}
}
return NULL;
}
obj_t *alloc_symbol(name)
char *name;
{
obj_t *x;
x = alloc_obj(TSYMBOL);
x->value.sym.name = name;
return x;
}
obj_t *intern(name)
char *name;
{
obj_t *x;
x = find_symbol(name);
if (!x) {
x = alloc_symbol(name);
VM->symbols = alloc_cons(x, VM->symbols);
}
return x;
}
int proper_list_p(o)
obj_t * o;
{
if (nil == o) return 1;
if (TCONS != o->type) return 0;
return proper_list_p(CDR(o));
}
int list_length(o)
obj_t * o;
{
/* assumes that o is a proper list */
obj_t * node;
int len = 0;
for (node = o; node != nil; node = node->value.c.cdr) len++;
return len;
}