From b951e3dee0487e11e243159504872296dcc3ecd1 Mon Sep 17 00:00:00 2001 From: John Connors Date: Mon, 4 Oct 2010 00:18:50 +0100 Subject: [PATCH] Adding quick SConstruct --- lisp.cpp | 18 ++++---- lisp.h | 148 ++++++++++++++++++++++++++++++--------------------------------- 2 files changed, 79 insertions(+), 87 deletions(-) diff --git a/lisp.cpp b/lisp.cpp index 506e720..595c808 100644 --- a/lisp.cpp +++ b/lisp.cpp @@ -287,31 +287,31 @@ boost::shared_ptr init_env() { boost::shared_ptr nul; boost::shared_ptr a_quote(new lisp::object(std::string("QUOTE"))); - boost::shared_ptr f_quote(new lisp::object(fn_quote)); + boost::shared_ptr f_quote(new lisp::object(lisp::func(fn_quote))); boost::shared_ptr a_car(new lisp::object(std::string("CAR"))); - boost::shared_ptr f_car(new lisp::object(fn_car)); + boost::shared_ptr f_car(new lisp::object(lisp::func(fn_car))); boost::shared_ptr a_cdr(new lisp::object(std::string("CDR"))); - boost::shared_ptr f_cdr(new lisp::object(fn_cdr)); + boost::shared_ptr f_cdr(new lisp::object(lisp::func(fn_cdr))); boost::shared_ptr a_cons(new lisp::object(std::string("CONS"))); - boost::shared_ptr f_cons(new lisp::object(fn_cons)); + boost::shared_ptr f_cons(new lisp::object(lisp::func(fn_cons))); boost::shared_ptr a_equal(new lisp::object(std::string("EQUAL"))); - boost::shared_ptr f_equal(new lisp::object(fn_equal)); + boost::shared_ptr f_equal(new lisp::object(lisp::func(fn_equal))); boost::shared_ptr a_atom(new lisp::object(std::string("ATOM"))); - boost::shared_ptr f_atom(new lisp::object(fn_atom)); + boost::shared_ptr f_atom(new lisp::object(lisp::func(fn_atom))); boost::shared_ptr a_cond(new lisp::object(std::string("COND"))); - boost::shared_ptr f_cond(new lisp::object(fn_cond)); + boost::shared_ptr f_cond(new lisp::object(lisp::func(fn_cond))); boost::shared_ptr a_lambda(new lisp::object(std::string("LAMBDA"))); - boost::shared_ptr f_lambda(new lisp::object(fn_lambda)); + boost::shared_ptr f_lambda(new lisp::object(lisp::func(fn_lambda))); boost::shared_ptr a_label(new lisp::object(std::string("LABEL"))); - boost::shared_ptr f_label(new lisp::object(fn_label)); + boost::shared_ptr f_label(new lisp::object(lisp::func(fn_label))); boost::shared_ptr env = make_cons(make_cons(a_quote,make_cons(f_quote,nul)),nul); diff --git a/lisp.h b/lisp.h index 6f776d6..466300f 100644 --- a/lisp.h +++ b/lisp.h @@ -1,78 +1,70 @@ -#ifndef LISP_H_INCLUDED -#define LISP_H_INCLUDED - -namespace lisp { - - /* We begin by defining four types of objects we will be - * using. CONS is what we use to hold lists, ATOMs are letters or - * digits anything that is not used by LISP, a FUNC holds a - * reference to a C function and a LAMBDA holds a lambda - * expression. */ - - struct object; - - enum kind { - e_ATOM = 0, - e_CONS, - e_FUNC, - e_LAMBDA - }; - - struct atom { - std::string name; - - atom(const std::string& n) : name(n) { - } - }; - - struct cons { - boost::shared_ptr car; - boost::shared_ptr cdr; - - cons(boost::shared_ptr first, boost::shared_ptr second) : car(first), cdr(second) { - - } - }; - - typedef boost::function< boost::shared_ptr (boost::shared_ptr,boost::shared_ptr) > lisp_func; - - struct func { - lisp_func fn; - - func(const lisp_func& f) : fn(f) { - - } - }; - - struct lambda { - boost::shared_ptr args; - boost::shared_ptr sexp; - - lambda(boost::shared_ptr a, boost::shared_ptr s) : args(a), sexp(s) { - - } - }; - - typedef boost::variant< atom, cons, func, lambda > base_object; - - struct object : public base_object { - object(base_object&b) : base_object(b) { - - } - object(const std::string&s) : base_object(atom(s)) { - - } - object(const lisp::cons& c) : base_object(c) { - - } - object(const lisp::lambda& l) : base_object(l) { - - } - object(const lisp::lisp_func& f) : base_object(f) { - - } - }; - -}; - -#endif +#ifndef LISP_H_INCLUDED +#define LISP_H_INCLUDED + +namespace lisp { + + /* We begin by defining four types of objects we will be + * using. CONS is what we use to hold lists, ATOMs are letters or + * digits anything that is not used by LISP, a FUNC holds a + * reference to a C function and a LAMBDA holds a lambda + * expression. */ + + struct object; + + enum kind { + e_ATOM = 0, + e_CONS, + e_FUNC, + e_LAMBDA + }; + + struct atom { + std::string name; + + atom(const std::string& n) : name(n) { + } + }; + + struct cons { + boost::shared_ptr car; + boost::shared_ptr cdr; + + cons(boost::shared_ptr first, boost::shared_ptr second) : car(first), cdr(second) { + + } + }; + + typedef boost::function< boost::shared_ptr (boost::shared_ptr,boost::shared_ptr) > lisp_func; + + struct func { + lisp_func fn; + + func(const lisp_func& f) : fn(f) { + + } + }; + + struct lambda { + boost::shared_ptr args; + boost::shared_ptr sexp; + + lambda(boost::shared_ptr a, boost::shared_ptr s) : args(a), sexp(s) { + + } + }; + + typedef boost::variant< atom, cons, func, lambda > base_object; + + struct object : public base_object { + object(const base_object&b) : base_object(b) { + + } + object(const std::string&s) : base_object(atom(s)) { + + } + + }; + +}; + +#endif -- 2.11.4.GIT