diff --git a/src/vm.c b/src/vm.c index 18e88bae..f87e5053 100644 --- a/src/vm.c +++ b/src/vm.c @@ -816,25 +816,26 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) } struct pic_code trampoline_iseq[] = { - { OP_NOP, {0} }, - { OP_CALL, {0} }, - { OP_RET, {0} }, + { OP_NOP, {0} }, + { OP_TAILCALL, {0} }, }; pic_value pic_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args) { - pic_value v, call_list; + pic_value v, call_list, *fp = pic->ci->fp; + pic_callinfo *ci; call_list = pic_cons(pic, pic_obj_value(proc), args); pic_for_each (v, call_list) { - *pic->ci->fp++ = v; + *fp++ = v; } trampoline_iseq[1].u.i = pic_length(pic, call_list); - pic->ci->ip = trampoline_iseq; - pic->ci->fp--; /* the last argument is pushed by the VM */ + ci = PUSHCI(); + ci->ip = trampoline_iseq; + ci->fp = fp - 1; /* the last argument is pushed by the VM */ return v; }