Missed env.h
[lispp.git] / lisp.h
blob53fe457e393c8d4ad958af4dfc7456ecb7c663f8
1 #ifndef LISP_H_INCLUDED
2 #define LISP_H_INCLUDED
4 namespace lisp {
6 /* We begin by defining four types of objects we will be
7 * using. CONS is what we use to hold lists, ATOMs are letters or
8 * digits anything that is not used by LISP, a FUNC holds a
9 * reference to a C function and a LAMBDA holds a lambda
10 * expression. */
12 struct object;
14 // TO DO : ADD SYMBOL, FIXNUM, FLOATNUM
15 enum kind {
16 e_ATOM = 0,
17 e_CONS,
18 e_FUNC,
19 e_LAMBDA,
20 e_SYMBOL
23 struct atom {
24 std::string name;
26 atom(const std::string& n) : name(n) {
30 struct cons {
31 boost::shared_ptr<object> car;
32 boost::shared_ptr<object> cdr;
34 cons(boost::shared_ptr<object> first, boost::shared_ptr<object> second) : car(first), cdr(second) {
39 typedef boost::function< boost::shared_ptr<object> (boost::shared_ptr<object>,boost::shared_ptr<object>) > lisp_func;
41 struct func {
42 lisp_func fn;
44 func(const lisp_func& f) : fn(f) {
49 struct lambda {
50 boost::shared_ptr<object> args;
51 boost::shared_ptr<object> sexp;
53 lambda(boost::shared_ptr<object> a, boost::shared_ptr<object> s) : args(a), sexp(s) {
58 struct symbol {
59 boost::shared_ptr<object> value;
61 symbol(boost::shared_ptr<object> v) : value(v) {
65 typedef boost::variant< atom, cons, func, lambda, symbol > base_object;
67 struct object : public base_object {
69 object(const base_object&b) : base_object(b) {
73 object(const std::string&s) : base_object(atom(s)) {
79 extern boost::shared_ptr<object> tee;
80 extern boost::shared_ptr<object> nil;
84 #endif