diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index a14a2886..84bd2d07 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -436,7 +436,7 @@ define_var(pic_state *pic, analyze_scope *scope, pic_sym *sym) int ret; if (search_scope(scope, sym)) { - if (scope->depth > 0 || (pic_dict_has(pic, pic->globals, sym) && ! pic_invalid_p(pic_cdr(pic, pic_dict_ref(pic, pic->globals, sym))))) { + if (scope->depth > 0 || (pic_dict_has(pic, pic->globals, sym) && ! pic_invalid_p(pic_box_ptr(pic_dict_ref(pic, pic->globals, sym))->value))) { pic_warnf(pic, "redefining variable: ~s", pic_obj_value(sym)); } return; diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index da2a4885..50737ea3 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -102,14 +102,15 @@ struct pic_state { pic_sym *uDEFINE, *uLAMBDA, *uIF, *uBEGIN, *uQUOTE, *uSETBANG, *uDEFINE_MACRO; pic_sym *uDEFINE_LIBRARY, *uIMPORT, *uEXPORT, *uCOND_EXPAND; + pic_sym *uCONS, *uCAR, *uCDR, *uNILP, *uSYMBOLP, *uPAIRP; pic_sym *uADD, *uSUB, *uMUL, *uDIV, *uEQ, *uLT, *uLE, *uGT, *uGE, *uNOT; pic_value pCONS, pCAR, pCDR, pNILP, pPAIRP, pSYMBOLP, pNOT; pic_value pADD, pSUB, pMUL, pDIV, pEQ, pLT, pLE, pGT, pGE; - pic_value cCONS, cCAR, cCDR, cNILP, cPAIRP, cSYMBOLP, cNOT; - pic_value cADD, cSUB, cMUL, cDIV, cEQ, cLT, cLE, cGT, cGE; + struct pic_box *cCONS, *cCAR, *cCDR, *cNILP, *cPAIRP, *cSYMBOLP, *cNOT; + struct pic_box *cADD, *cSUB, *cMUL, *cDIV, *cEQ, *cLT, *cLE, *cGT, *cGE; struct pic_lib *PICRIN_BASE; struct pic_lib *PICRIN_USER; diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 99127266..86f3d88a 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -127,7 +127,7 @@ static void pic_init_core(pic_state *pic) { void pic_define_syntactic_keyword_(pic_state *, struct pic_env *, pic_sym *, pic_sym *); - pic_value pic_vm_gref_slot(pic_state *, pic_sym *); + struct pic_box *pic_vm_gref_slot(pic_state *, pic_sym *); pic_init_features(pic); @@ -434,22 +434,22 @@ pic_open(pic_allocf allocf, void *userdata) /* turn on GC */ pic->gc_enable = true; - pic->cCONS = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cCAR = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cCDR = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cNILP = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cSYMBOLP = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cPAIRP = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cNOT = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cADD = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cSUB = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cMUL = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cDIV = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cEQ = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cLT = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cLE = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cGT = pic_cons(pic, pic_false_value(), pic_invalid_value()); - pic->cGE = pic_cons(pic, pic_false_value(), pic_invalid_value()); + pic->cCONS = pic_box(pic, pic_invalid_value()); + pic->cCAR = pic_box(pic, pic_invalid_value()); + pic->cCDR = pic_box(pic, pic_invalid_value()); + pic->cNILP = pic_box(pic, pic_invalid_value()); + pic->cSYMBOLP = pic_box(pic, pic_invalid_value()); + pic->cPAIRP = pic_box(pic, pic_invalid_value()); + pic->cNOT = pic_box(pic, pic_invalid_value()); + pic->cADD = pic_box(pic, pic_invalid_value()); + pic->cSUB = pic_box(pic, pic_invalid_value()); + pic->cMUL = pic_box(pic, pic_invalid_value()); + pic->cDIV = pic_box(pic, pic_invalid_value()); + pic->cEQ = pic_box(pic, pic_invalid_value()); + pic->cLT = pic_box(pic, pic_invalid_value()); + pic->cLE = pic_box(pic, pic_invalid_value()); + pic->cGT = pic_box(pic, pic_invalid_value()); + pic->cGE = pic_box(pic, pic_invalid_value()); pic_init_core(pic); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index d586832b..8a7300b8 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -386,32 +386,32 @@ pic_get_args(pic_state *pic, const char *format, ...) return argc; } -pic_value +struct pic_box * pic_vm_gref_slot(pic_state *pic, pic_sym *uid) { - pic_value slot; + struct pic_box *box; if (pic_dict_has(pic, pic->globals, uid)) { - return pic_dict_ref(pic, pic->globals, uid); + return pic_box_ptr(pic_dict_ref(pic, pic->globals, uid)); } - slot = pic_cons(pic, pic_obj_value(uid), pic_invalid_value()); - pic_dict_set(pic, pic->globals, uid, slot); - return slot; + box = pic_box(pic, pic_invalid_value()); + pic_dict_set(pic, pic->globals, uid, pic_obj_value(box)); + return box; } static pic_value -vm_gref(pic_state *pic, pic_value slot) +vm_gref(pic_state *pic, struct pic_box *slot, pic_sym *uid) { - if (pic_invalid_p(pic_cdr(pic, slot))) { - pic_errorf(pic, "uninitialized global variable: ~a", pic_car(pic, slot)); + if (pic_invalid_p(slot->value)) { + pic_errorf(pic, "uninitialized global variable: ~a", uid); } - return pic_cdr(pic, slot); + return slot->value; } static void -vm_gset(pic_state *pic, pic_value slot, pic_value value) +vm_gset(struct pic_box *slot, pic_value value) { - pic_set_cdr(pic, slot, value); + slot->value = value; } static void @@ -630,11 +630,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) NEXT; } CASE(OP_GREF) { - PUSH(vm_gref(pic, pic->ci->irep->pool[c.u.i])); + PUSH(vm_gref(pic, pic_box_ptr(pic->ci->irep->pool[c.u.i]), pic_intern(pic, "unknown"))); /* FIXME */ NEXT; } CASE(OP_GSET) { - vm_gset(pic, pic->ci->irep->pool[c.u.i], POP()); + vm_gset(pic_box_ptr(pic->ci->irep->pool[c.u.i]), POP()); PUSH(pic_undef_value()); NEXT; } @@ -847,7 +847,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) } #define check_condition(name, n) do { \ - if (! pic_eq_p(pic->p##name, pic_cdr(pic, pic->c##name))) \ + if (! pic_eq_p(pic->p##name, pic->c##name->value)) \ goto L_CALL; \ if (c.u.i != n + 1) \ goto L_CALL; \ @@ -1161,7 +1161,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name) pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); } - return vm_gref(pic, pic_vm_gref_slot(pic, uid)); + return vm_gref(pic, pic_vm_gref_slot(pic, uid), uid); } void @@ -1175,7 +1175,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val) pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name); } - vm_gset(pic, pic_vm_gref_slot(pic, uid), val); + vm_gset(pic_vm_gref_slot(pic, uid), val); } pic_value