From f6eddbc6d3f4e1a3c38d3eb83b5bbbbdb4fa6a58 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 16 Oct 2013 11:53:25 +0900 Subject: [PATCH] save all ireps into pic_state in order to decrease the stress GC will get, restore irep structures under pic_state instead of under each procs and making it collectable object --- include/picconf.h | 1 + include/picrin.h | 3 +++ include/picrin/irep.h | 3 --- src/state.c | 5 +++++ src/vm.c | 23 +++++++++-------------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/picconf.h b/include/picconf.h index a609439d..ae8f8869 100644 --- a/include/picconf.h +++ b/include/picconf.h @@ -4,6 +4,7 @@ #define PIC_ARENA_SIZE 100 #define PIC_HEAP_SIZE 8192 #define PIC_STACK_SIZE 1024 +#define PIC_IREP_SIZE 256 #define DEBUG 1 diff --git a/include/picrin.h b/include/picrin.h index 87137359..77761db1 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -23,6 +23,9 @@ typedef struct { pic_value sADD, sSUB, sMUL, sDIV; struct pic_env *global_env; + struct pic_irep **irep; + size_t ilen, icapa; + struct heap_page *heap; struct pic_object *arena[PIC_ARENA_SIZE]; int arena_idx; diff --git a/include/picrin/irep.h b/include/picrin/irep.h index 0ca5d3db..f8b62885 100644 --- a/include/picrin/irep.h +++ b/include/picrin/irep.h @@ -30,9 +30,6 @@ struct pic_code { struct pic_irep { struct pic_code *code; size_t clen, ccapa; - - struct pic_irep **proto; - size_t plen, pcapa; }; #endif diff --git a/src/state.c b/src/state.c index c069757b..fe21d27b 100644 --- a/src/state.c +++ b/src/state.c @@ -37,6 +37,11 @@ pic_open() pic->heap = (struct heap_page *)malloc(sizeof(struct heap_page)); init_heap_page(pic->heap); + /* irep */ + pic->irep = (struct pic_irep **)malloc(sizeof(struct pic_irep *) * PIC_IREP_SIZE); + pic->ilen = 0; + pic->icapa = PIC_IREP_SIZE; + /* GC arena */ pic->arena_idx = 0; diff --git a/src/vm.c b/src/vm.c index ddddcf2f..46215a6c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -165,9 +165,6 @@ new_irep(pic_state *pic) irep->code = (struct pic_code *)pic_alloc(pic, sizeof(struct pic_code) * 1024); irep->clen = 0; irep->ccapa = 1024; - irep->proto = NULL; - irep->plen = irep->pcapa = 0; - return irep; } @@ -218,19 +215,11 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en break; } else if (pic_eq_p(pic, proc, sLAMBDA)) { - if (irep->proto == NULL) { - irep->proto = (struct pic_irep **)pic_alloc(pic, sizeof(struct pic_irep **) * 5); - irep->pcapa = 5; - } - if (irep->plen >= irep->pcapa) { - irep->proto = (struct pic_irep **)pic_realloc(pic, irep->proto, irep->pcapa * 2); - irep->pcapa *= 2; - } irep->code[irep->clen].insn = OP_LAMBDA; - irep->code[irep->clen].u.i = irep->plen; + irep->code[irep->clen].u.i = pic->ilen; irep->clen++; - irep->proto[irep->plen++] = pic_gen_lambda(pic, obj, env); + pic->irep[pic->ilen++] = pic_gen_lambda(pic, obj, env); break; } else if (pic_eq_p(pic, proc, sCONS)) { @@ -334,6 +323,12 @@ pic_gen_lambda(pic_state *pic, pic_value obj, struct pic_env *env) irep->code[irep->clen].insn = OP_RET; irep->clen++; +#if VM_DEBUG + printf("LAMBDA_%d:\n", pic->ilen); + print_irep(pic, irep); + puts(""); +#endif + return irep; } @@ -430,7 +425,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args) proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC); proc->cfunc_p = false; - proc->u.irep = ci->proc->u.irep->proto[pc->u.i]; + proc->u.irep = pic->irep[pc->u.i]; PUSH(pic_obj_value(proc)); pic_gc_arena_restore(pic, ai); NEXT;