From 976a44185d4c28f5994e3be83fef348985ba5d86 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 7 Jul 2015 14:57:44 +0900 Subject: [PATCH] cache slot objects --- extlib/benz/include/picrin.h | 3 +++ extlib/benz/state.c | 38 ++++++++++++++++++++++++++++++++++++ extlib/benz/vm.c | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 02d0eaa4..f543aeeb 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -108,6 +108,9 @@ struct pic_state { 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_lib *PICRIN_BASE; struct pic_lib *PICRIN_USER; diff --git a/extlib/benz/state.c b/extlib/benz/state.c index e29c4304..2fb447a3 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -118,6 +118,9 @@ pic_features(pic_state *pic) #define VM(uid, name) \ pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern_cstr(pic, name), uid) +#define VM3(name) \ + pic->c##name = pic_vm_gref_slot(pic, pic->u##name); + #define VM2(proc, name) \ proc = pic_ref(pic, pic->lib, name) @@ -125,6 +128,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 *); pic_init_features(pic); @@ -182,6 +186,23 @@ pic_init_core(pic_state *pic) pic_init_attr(pic); DONE; pic_init_reg(pic); DONE; + VM3(CONS); + VM3(CAR); + VM3(CDR); + VM3(NILP); + VM3(SYMBOLP); + VM3(PAIRP); + VM3(NOT); + VM3(ADD); + VM3(SUB); + VM3(MUL); + VM3(DIV); + VM3(EQ); + VM3(LT); + VM3(LE); + VM3(GT); + VM3(GE); + VM2(pic->pCONS, "cons"); VM2(pic->pCAR, "car"); VM2(pic->pCDR, "cdr"); @@ -420,6 +441,23 @@ 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_init_core(pic); pic_gc_arena_restore(pic, ai); diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 10fdaac5..ec63da8b 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -856,7 +856,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, vm_gref(pic, pic_vm_gref_slot(pic, pic->u##name)))) \ + if (! pic_eq_p(pic->p##name, pic_cdr(pic, pic->c##name))) \ goto L_CALL; \ if (c.u.i != n + 1) \ goto L_CALL; \