-
Notifications
You must be signed in to change notification settings - Fork 0
/
evalstate.cpp
53 lines (46 loc) · 1.56 KB
/
evalstate.cpp
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
/**
* File: evalstate.cpp
* -------------------
*/
#include "evalstate.h"
#include "specialforms.h"
void EvalState::addBuiltins() {
setExpression("car", new CarSpecialForm());
setExpression("cdr", new CdrSpecialForm());
setExpression("list", new ListSpecialForm());
setExpression("cons", new ConsSpecialForm());
setExpression("if", new IfSpecialForm());
setExpression("quit", new QuitSpecialForm());
setExpression("define", new DefineSpecialForm());
setExpression("null", new NullSpecialForm());
setExpression("lambda", new LambdaSpecialForm());
setExpression("add", new AddSpecialForm());
setExpression("subtract", new SubtractSpecialForm());
setExpression("multiply", new MultiplySpecialForm());
setExpression("equal", new EqualSpecialForm());
setExpression("less", new LessSpecialForm());
setExpression("and", new AndSpecialForm());
setExpression("or", new OrSpecialForm());
setExpression("not", new NotSpecialForm());
setExpression("apply", new ApplySpecialForm());
setExpression("load", new LoadSpecialForm());
}
bool EvalState::containsSymbol(string symbol) {
return entries.containsKey(symbol);
}
Expression *EvalState::getExpression(string symbol) {
if (!containsSymbol(symbol)) {
Error(symbol + " is not defined.");
}
return entries[symbol];
}
void EvalState::setExpression(string symbol, Expression *value) {
entries[symbol] = value;
}
void EvalState::add(EvalState *other) {
Map<Expression *>::Iterator iter = other->entries.iterator();
while (iter.hasNext()) {
string symbol = iter.next();
this->entries[symbol] = other->entries[symbol];
}
}