From 55d1072441582936d119ed04fd8c532c2760b9d4 Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 12 Aug 2013 20:37:38 +0800 Subject: ... --- types.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'types.cpp') diff --git a/types.cpp b/types.cpp index e3a7542..1548805 100644 --- a/types.cpp +++ b/types.cpp @@ -12,16 +12,24 @@ const double EPS = 1e-16; const int PREC = 16; -EmptyList *empty_list = new EmptyList(); -UnspecObj *unspec_obj = new UnspecObj(); +extern EmptyList *empty_list; +extern UnspecObj *unspec_obj; -Pair::Pair(EvalObj *_car, EvalObj *_cdr) : - EvalObj(CLS_PAIR_OBJ), car(_car), cdr(_cdr), - next(NULL) {} +Pair::Pair(EvalObj *_car, EvalObj *_cdr) : EvalObj(CLS_PAIR_OBJ), + car(_car), cdr(_cdr), next(NULL) { - ReprCons *Pair::get_repr_cons() { - return new PairReprCons(this, this); - } + gc.attach(car); + gc.attach(cdr); +} + +Pair::~Pair() { + gc.expose(car); + gc.expose(cdr); +} + +ReprCons *Pair::get_repr_cons() { + return new PairReprCons(this, this); +} ParseBracket::ParseBracket(unsigned char _btype) : @@ -49,6 +57,12 @@ ProcObj::ProcObj(Pair *_body, Environment *_envt, EvalObj *_params) : gc.attach(envt); } +ProcObj::~ProcObj() { + gc.expose(body); + gc.expose(params); + gc.expose(envt); +} + Pair *ProcObj::call(Pair *args, Environment * &genvt, Continuation * &cont, FrameObj ** &top_ptr) { // Create a new continuation @@ -77,6 +91,7 @@ Pair *ProcObj::call(Pair *args, Environment * &genvt, genvt = _envt; cont = _cont; *top_ptr++ = new RetAddr(NULL); // Mark the entrance of a cont + gc.expose(args); return body; // Move pc to the proc entry point } @@ -208,6 +223,7 @@ BuiltinProcObj::BuiltinProcObj(BuiltinProc f, string _name) : Pair *ret_addr = static_cast(*top_ptr)->addr; *top_ptr++ = handler(TO_PAIR(args->cdr), name); + gc.expose(args); return ret_addr->next; // Move to the next instruction } -- cgit v1.2.3