static Cons *copyCons(Cons *cons) { if(cons == NULL) return NULL; Cons *c = new Cons(cons->type); switch(cons->type) { case CONS_INT: c->i = cons->i; break; case CONS_STR: c->str = newStr(cons->str); break; case CONS_FLOAT: c->f = cons->f; break; case CONS_CAR: c->car = copyCons(cons->car); break; default: abort(); } if(cons->cdr != NULL) c->cdr = copyCons(cons->cdr); return c; }
void fun_sub () { VAR_ rval = *copyCons(top()); /* make a copy */ pop(); /* remove the r-operand */ subtract(top(), &rval); /* subtract the rval to the top */ destructor(&rval); /* remove the local var */ }
static ValueType genDefun(Func *, Cons *cons, CodeBuilder *cb, int sp) { Cons *c = copyCons(cons); cb->createConsIns(INS_DEFUN, c); cb->getCtx()->code_cons.add(c); return VT_VOID; }