do not create pic_env object when not needed
This commit is contained in:
parent
86458359e3
commit
fb66791216
|
@ -571,6 +571,29 @@ valid_formal(pic_state *pic, pic_value formal)
|
|||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
lift_cv(pic_state *pic, struct pic_irep *irep)
|
||||
{
|
||||
int i;
|
||||
struct pic_code c;
|
||||
|
||||
for (i = 0; i < irep->clen; ++i) {
|
||||
c = irep->code[i];
|
||||
switch (c.insn) {
|
||||
default:
|
||||
/* pass */
|
||||
break;
|
||||
case OP_LAMBDA:
|
||||
lift_cv(pic, pic->irep[c.u.i]);
|
||||
break;
|
||||
case OP_CREF:
|
||||
case OP_CSET:
|
||||
irep->code[i].u.c.depth--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
slide_cv(pic_state *pic, unsigned *cv_tbl, unsigned cv_num, struct pic_irep *irep, int d)
|
||||
{
|
||||
|
@ -584,7 +607,12 @@ slide_cv(pic_state *pic, unsigned *cv_tbl, unsigned cv_num, struct pic_irep *ire
|
|||
/* pass */
|
||||
break;
|
||||
case OP_LAMBDA:
|
||||
if (pic->irep[c.u.i]->cv_num == 0) {
|
||||
slide_cv(pic, cv_tbl, cv_num, pic->irep[c.u.i], d);
|
||||
}
|
||||
else {
|
||||
slide_cv(pic, cv_tbl, cv_num, pic->irep[c.u.i], d + 1);
|
||||
}
|
||||
break;
|
||||
case OP_CREF:
|
||||
case OP_CSET:
|
||||
|
@ -672,6 +700,12 @@ codegen_lambda(codegen_state *state, pic_value obj)
|
|||
if (state->scope->dirty_flags[i])
|
||||
++c;
|
||||
}
|
||||
if (c == 0) {
|
||||
lift_cv(pic, irep);
|
||||
irep->cv_tbl = NULL;
|
||||
irep->cv_num = 0;
|
||||
}
|
||||
else {
|
||||
irep->cv_tbl = (unsigned *)pic_calloc(pic, c, sizeof(unsigned));
|
||||
k = 0;
|
||||
for (i = 0; i < irep->argc + irep->localc; ++i) {
|
||||
|
@ -683,6 +717,7 @@ codegen_lambda(codegen_state *state, pic_value obj)
|
|||
irep->cv_num = c;
|
||||
slide_cv(pic, irep->cv_tbl, irep->cv_num, irep, 0);
|
||||
}
|
||||
}
|
||||
destroy_scope(pic, state->scope);
|
||||
|
||||
state->irep = prev_irep;
|
||||
|
|
5
src/vm.c
5
src/vm.c
|
@ -368,6 +368,10 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
}
|
||||
|
||||
/* prepare env */
|
||||
if (proc->u.irep->cv_num == 0) {
|
||||
ci->env = proc->env;
|
||||
}
|
||||
else {
|
||||
ci->env = (struct pic_env *)pic_obj_alloc(pic, sizeof(struct pic_env), PIC_TT_ENV);
|
||||
ci->env->up = proc->env;
|
||||
ci->env->valuec = proc->u.irep->cv_num;
|
||||
|
@ -375,6 +379,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
for (i = 0; i < ci->env->valuec; ++i) {
|
||||
ci->env->values[i] = ci->fp[proc->u.irep->cv_tbl[i]];
|
||||
}
|
||||
}
|
||||
|
||||
pc = proc->u.irep->code;
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
|
|
Loading…
Reference in New Issue