Merge branch 'issue-140'. close #140

This commit is contained in:
Yuichi Nishiwaki 2014-06-23 00:57:56 +09:00
commit 88a4943148
1 changed files with 12 additions and 15 deletions

View File

@ -747,7 +747,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
/* invoke! */ /* invoke! */
pic->sp[0] = proc->u.func.f(pic); pic->sp[0] = proc->u.func.f(pic);
pic->sp += ci->retc; pic->sp += pic->ci->retc;
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
goto L_RET; goto L_RET;
@ -994,29 +994,26 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
} VM_LOOP_END; } VM_LOOP_END;
} }
static pic_code trampoline_iseq[] = {
{ OP_NOP, {0} },
{ OP_TAILCALL, {0} },
};
pic_value pic_value
pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args) pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
{ {
pic_value v, call_list, *fp = pic->ci->fp; static const pic_code iseq = { OP_TAILCALL, { .i = -1 } };
pic_value v, *sp;
pic_callinfo *ci; pic_callinfo *ci;
call_list = pic_cons(pic, pic_obj_value(proc), args); *pic->sp++ = pic_obj_value(proc);
pic_for_each (v, call_list) { sp = pic->sp;
*fp++ = v; pic_for_each (v, args) {
*sp++ = v;
} }
trampoline_iseq[1].u.i = pic_length(pic, call_list);
ci = PUSHCI(); ci = PUSHCI();
ci->ip = trampoline_iseq; ci->ip = (pic_code *)&iseq - 1;
ci->fp = fp - 1; /* the last argument is pushed by the VM */ ci->fp = pic->sp;
return v; ci->retc = pic_length(pic, args);
return pic_obj_value(proc);
} }
pic_value pic_value