-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLispEnv.h
79 lines (51 loc) · 1.81 KB
/
LispEnv.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef LISPENV_H
#define LISPENV_H
#include <string>
#include <boost/tr1/memory.hpp>
#include <boost/unordered_map.hpp>
#include "LispObj.h"
namespace Lisp {
class LispEnv;
typedef boost::shared_ptr<LispEnv> LispEnvRef;
class LispEnv {
public:
typedef boost::unordered_map<std::string, LispObjRef> EnvironmentT;
/** construct root environment */
LispEnv();
/** construct child environment from parent */
LispEnv(LispEnvRef parentEnv);
/** fetch var in environment */
LispObjRef ref(std::string var);
/** Set a var in the environment */
LispObjRef set(std::string var, LispObjRef ref);
/** define a var in the environment */
LispObjRef define(std::string var, LispObjRef ref);
/** fetch function in environment */
LispObjRef fref(std::string var);
/** Set a function in the environment */
LispObjRef fset(std::string var, LispObjRef ref);
/** Set function primitive */
static LispObjRef set_fn(LispObjRef cons, LispEnvRef env);
/** Set function primitive */
static LispObjRef define_fn(LispObjRef cons, LispEnvRef env);
/** Set function primitive */
static LispObjRef defun_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef car_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef cdr_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef print_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef apply_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef lambda_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef if_fn(LispObjRef cons, LispEnvRef env);
static LispObjRef prog_fn(LispObjRef cons, LispEnvRef env);
/** Global environment */
static LispEnvRef globalEnv;
private:
/** Our environemnt. */
EnvironmentT env_;
/** Our function environment (yes, it's a Lisp-2) */
EnvironmentT fEnv_;
/** Pointer back up to parent environment */
LispEnvRef parent_;
};
}
#endif