add trampoline helper

This commit is contained in:
Yuichi Nishiwaki 2014-02-06 14:22:29 +09:00
parent 845961e7f9
commit 2ef426d90b
2 changed files with 25 additions and 0 deletions

View File

@ -173,6 +173,7 @@ pic_value pic_load(pic_state *, const char *);
pic_value pic_apply(pic_state *pic, struct pic_proc *, pic_value);
pic_value pic_apply_argv(pic_state *pic, struct pic_proc *, size_t, ...);
pic_value pic_trampoline(pic_state *, struct pic_proc *, pic_value);
struct pic_proc *pic_compile(pic_state *, pic_value);
pic_value pic_macroexpand(pic_state *, pic_value);

View File

@ -814,3 +814,27 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
}
} VM_LOOP_END;
}
struct pic_code trampoline_iseq[] = {
{ OP_NOP, {0} },
{ OP_CALL, {0} },
{ OP_RET, {0} },
};
pic_value
pic_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args)
{
pic_value v, call_list;
call_list = pic_cons(pic, pic_obj_value(proc), args);
pic_for_each (v, call_list) {
*pic->ci->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 */
return v;
}