-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.h
63 lines (51 loc) · 1.73 KB
/
value.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
#ifndef _VALUE
#define _VALUE
typedef enum {
INT_TYPE, DOUBLE_TYPE, STR_TYPE, CONS_TYPE, NULL_TYPE, PTR_TYPE,
OPEN_TYPE, CLOSE_TYPE, BOOL_TYPE, SYMBOL_TYPE,
// Types below are only for bonus work
OPENBRACKET_TYPE, CLOSEBRACKET_TYPE, DOT_TYPE, SINGLEQUOTE_TYPE,
// Types below are new for define/lambda portion
VOID_TYPE, CLOSURE_TYPE,
// Type below is new for primitive portion
PRIMITIVE_TYPE,
// Type below is new for final portion
UNSPECIFIED_TYPE
} valueType;
struct Value {
valueType type;
union {
int i;
double d;
char *s;
void *p;
struct ConsCell {
struct Value *car;
struct Value *cdr;
} c;
// For purposes of this project a closure is just another type of value,
// containing everything needed to execute a user-defined function: (1)
// a list of formal parameter names; (2) a pointer to the function body;
// (3) a pointer to the environment frame in which the function was
// created.
struct Closure {
struct Value *paramNames;
struct Value *functionCode;
struct Frame *frame;
} cl;
// A primitive style function; just a pointer to it, with the right
// signature (pf = primitive function)
struct Value *(*pf)(struct Value *);
};
};
typedef struct Value Value;
// A frame is a linked list of bindings, and a pointer to another frame. A
// binding is a variable name (represented as a string), and a pointer to the
// Value it is bound to. Specifically how you implement the list of bindings is
// up to you.
struct Frame {
Value *bindings;
struct Frame *parent;
};
typedef struct Frame Frame;
#endif