don't use static non-const local variable

This commit is contained in:
Yuichi Nishiwaki 2015-06-09 19:19:27 +09:00
parent 5b87706af1
commit 6af60c9e2b
4 changed files with 21 additions and 9 deletions

View File

@ -760,9 +760,9 @@ static void
gc_sweep_page(pic_state *pic, struct heap_page *page)
{
#if GC_DEBUG
static union header *NIL = (union header *)0xdeadbeef;
static union header * const NIL = (union header *)0xdeadbeef;
#else
static union header *NIL = NULL;
static union header * const NIL = NULL;
#endif
union header *bp, *p, *s = NIL, *t = NIL;

View File

@ -144,6 +144,8 @@ typedef struct {
pic_value err;
pic_code *iseq; /* for pic_apply_trampoline */
char *native_stack_start;
} pic_state;

View File

@ -204,6 +204,13 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
goto EXIT_ARENA;
}
/* trampoline iseq */
pic->iseq = allocf(NULL, 2 * sizeof(pic_code));
if (! pic->iseq) {
goto EXIT_ISEQ;
}
/* memory heap */
pic->heap = pic_heap_open(pic);
@ -373,6 +380,8 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
return pic;
EXIT_ISEQ:
allocf(pic->arena, 0);
EXIT_ARENA:
allocf(pic->xp, 0);
EXIT_XP:
@ -431,6 +440,9 @@ pic_close(pic_state *pic)
allocf(pic->cibase, 0);
allocf(pic->xpbase, 0);
/* free trampoline iseq */
allocf(pic->iseq, 0);
/* free global stacks */
xh_destroy(&pic->syms);

View File

@ -76,7 +76,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
}
/* '|' should be followed by at least 1 char */
assert(opt <= optc);
assert((opt ? 1 : 0) <= optc);
/* '*' should not be followed by any char */
assert(format[paramc + opt + optc + rest] == '\0');
@ -681,7 +681,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_code boot[2];
#if PIC_DIRECT_THREADED_VM
static void *oplabels[] = {
static const void *oplabels[] = {
&&L_OP_NOP, &&L_OP_POP, &&L_OP_PUSHUNDEF, &&L_OP_PUSHNIL, &&L_OP_PUSHTRUE,
&&L_OP_PUSHFALSE, &&L_OP_PUSHINT, &&L_OP_PUSHCHAR, &&L_OP_PUSHCONST,
&&L_OP_GREF, &&L_OP_GSET, &&L_OP_LREF, &&L_OP_LSET, &&L_OP_CREF, &&L_OP_CSET,
@ -1180,13 +1180,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args)
pic_value
pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
{
static pic_code iseq[2];
pic_value v, it, *sp;
pic_callinfo *ci;
PIC_INIT_CODE_I(iseq[0], OP_NOP, 0);
PIC_INIT_CODE_I(iseq[1], OP_TAILCALL, -1);
PIC_INIT_CODE_I(pic->iseq[0], OP_NOP, 0);
PIC_INIT_CODE_I(pic->iseq[1], OP_TAILCALL, -1);
*pic->sp++ = pic_obj_value(proc);
@ -1196,7 +1194,7 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
}
ci = PUSHCI();
ci->ip = (pic_code *)iseq;
ci->ip = pic->iseq;
ci->fp = pic->sp;
ci->retc = (int)pic_length(pic, args);