From a315f518d277c1fe448b1ee49cfed9524fbcc591 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 18 Jan 2014 22:56:43 +0900 Subject: [PATCH] auto-extend constant pool array --- include/config.h | 2 +- src/codegen.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/config.h b/include/config.h index d89ccc82..6bf3818c 100644 --- a/include/config.h +++ b/include/config.h @@ -22,10 +22,10 @@ #define PIC_HEAP_PAGE_SIZE (10000) #define PIC_STACK_SIZE 1024 #define PIC_RESCUE_SIZE 30 -#define PIC_IREP_SIZE 256 #define PIC_GLOBALS_SIZE 1024 #define PIC_MACROS_SIZE 1024 #define PIC_SYM_POOL_SIZE 128 +#define PIC_IREP_SIZE 256 #define PIC_POOL_SIZE 1024 #define PIC_ISEQ_SIZE 1024 diff --git a/src/codegen.c b/src/codegen.c index 266798fd..bc5cdbdc 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -457,10 +457,11 @@ codegen(codegen_state *state, pic_value obj, bool tailpos) pic_error(pic, "syntax error"); } - pidx = scope->plen++; - if (pidx >= scope->pcapa) { - pic_abort(pic, "constant pool overflow"); + if (scope->plen >= scope->pcapa) { + scope->pool = (pic_value *)pic_realloc(pic, scope->pool, scope->pcapa * 2); + scope->pcapa *= 2; } + pidx = scope->plen++; scope->pool[pidx] = pic_car(pic, pic_cdr(pic, obj)); scope->code[scope->clen].insn = OP_PUSHCONST; scope->code[scope->clen].u.i = pidx; @@ -693,10 +694,11 @@ codegen(codegen_state *state, pic_value obj, bool tailpos) case PIC_TT_VECTOR: case PIC_TT_BLOB: { int pidx; - pidx = scope->plen++; - if (pidx >= scope->pcapa) { - pic_abort(pic, "constant pool overflow"); + if (scope->plen >= scope->pcapa) { + scope->pool = (pic_value *)pic_realloc(pic, scope->pool, scope->pcapa * 2); + scope->pcapa *= 2; } + pidx = scope->plen++; scope->pool[pidx] = obj; scope->code[scope->clen].insn = OP_PUSHCONST; scope->code[scope->clen].u.i = pidx;