From e462669c3c3cc04ea29420e14dbb589899d201ec Mon Sep 17 00:00:00 2001 From: Teddy Date: Sat, 3 Aug 2013 12:10:09 +0800 Subject: AST parser can now work! --- model.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'model.cpp') diff --git a/model.cpp b/model.cpp index 11c7a63..6f49871 100644 --- a/model.cpp +++ b/model.cpp @@ -1,3 +1,4 @@ +#include #include "model.h" EmptyList *empty_list = new EmptyList(); @@ -17,18 +18,26 @@ void EvalObj::prepare(Cons *pc) {} bool EvalObj::is_simple_obj() { return otype == CLS_SIM_OBJ; } +void EvalObj::_debug_print() { + printf("mem: 0x%llX\n%s\n\n", (unsigned long long)this, + _debug_repr().c_str()); +} bool EvalObj::is_true() { return true; } -Cons::Cons(EvalObj *_car, Cons *_cdr) : EvalObj(), car(_car), cdr(_cdr), skip(false), next(NULL) {} +Cons::Cons(EvalObj *_car, Cons *_cdr) : + EvalObj(), car(_car), cdr(_cdr), skip(false), next(cdr) {} string Cons::ext_repr() { return string("#"); } #ifdef DEBUG string Cons::_debug_repr() { return ext_repr(); } -Cons::_debug_print() { - printf("%s", +void Cons::_debug_print() { + printf("mem: 0x%llX 0x%llX 0x%llX\n%s\n", + (unsigned long long)this, + (unsigned long long)car, + (unsigned long long)cdr, ("car: " + car -> ext_repr() + "\n" + \ "cdr: " + cdr -> ext_repr() + "\n").c_str()); } @@ -37,6 +46,9 @@ Cons::_debug_print() { RetAddr::RetAddr(Cons *_addr) : FrameObj(), addr(_addr) { ftype = CLS_RET_ADDR; } +#ifdef DEBUG +string RetAddr::_debug_repr() { return string("#"); } +#endif UnspecObj::UnspecObj() : EvalObj() {} string UnspecObj::ext_repr() { return string("#"); } @@ -44,7 +56,7 @@ string UnspecObj::ext_repr() { return string("#"); } string UnspecObj::_debug_repr() { return ext_repr(); } #endif -SymObj::SymObj(string str) : EvalObj(), val(str) {} +SymObj::SymObj(const string &str) : EvalObj(), val(str) {} string SymObj::ext_repr() { return "#"; } #ifdef DEBUG string SymObj::_debug_repr() { return ext_repr(); } @@ -81,7 +93,7 @@ SpecialOptObj::SpecialOptObj() : OptObj() {} NumberObj::NumberObj() : EvalObj() {} -BuiltinProcObj::BuiltinProcObj(BuiltinProc f, string _name) : +BuiltinProcObj::BuiltinProcObj(BuiltinProc f, const string &_name) : OptObj(), handler(f), name(_name) {} Cons *BuiltinProcObj::call(ArgList *arg_list, Environment * &envt, -- cgit v1.2.3