1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 01:00:20 +02:00

Small subr-call refactor

* libguile/gsubr.c (scm_apply_subr): New internal helper.
* libguile/vm-engine.c (subr-call): Call out to scm_apply_subr.
* doc/ref/vm.texi (subr-call): Don't specify how the foreign pointer is
  obtained.
This commit is contained in:
Andy Wingo 2015-10-22 12:13:37 +00:00
parent 9144f50c31
commit 8832e8b68c
4 changed files with 58 additions and 72 deletions

View file

@ -781,77 +781,19 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Specialized call stubs
*/
/* subr-call ptr-idx:24
/* subr-call _:24
*
* Call a subr, passing all locals in this frame as arguments. Fetch
* the foreign pointer from PTR-IDX, a free variable. Return from the
* calling frame. This instruction is part of the trampolines
* created in gsubr.c, and is not generated by the compiler.
* Call a subr, passing all locals in this frame as arguments. Return
* from the calling frame. This instruction is part of the
* trampolines created in gsubr.c, and is not generated by the
* compiler.
*/
VM_DEFINE_OP (10, subr_call, "subr-call", OP1 (X8_C24))
VM_DEFINE_OP (10, subr_call, "subr-call", OP1 (X32))
{
scm_t_uint32 ptr_idx;
SCM pointer, ret;
SCM (*subr)();
UNPACK_24 (op, ptr_idx);
pointer = SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), ptr_idx);
subr = SCM_POINTER_VALUE (pointer);
SCM ret;
SYNC_IP ();
switch (FRAME_LOCALS_COUNT_FROM (1))
{
case 0:
ret = subr ();
break;
case 1:
ret = subr (SP_REF (0));
break;
case 2:
ret = subr (SP_REF (1), SP_REF (0));
break;
case 3:
ret = subr (SP_REF (2), SP_REF (1), SP_REF (0));
break;
case 4:
ret = subr (SP_REF (3), SP_REF (2), SP_REF (1),
SP_REF (0));
break;
case 5:
ret = subr (SP_REF (4), SP_REF (3), SP_REF (2),
SP_REF (1), SP_REF (0));
break;
case 6:
ret = subr (SP_REF (5), SP_REF (4), SP_REF (3),
SP_REF (2), SP_REF (1), SP_REF (0));
break;
case 7:
ret = subr (SP_REF (6), SP_REF (5), SP_REF (4),
SP_REF (3), SP_REF (2), SP_REF (1),
SP_REF (0));
break;
case 8:
ret = subr (SP_REF (7), SP_REF (6), SP_REF (5),
SP_REF (4), SP_REF (3), SP_REF (2),
SP_REF (1), SP_REF (0));
break;
case 9:
ret = subr (SP_REF (8), SP_REF (7), SP_REF (6),
SP_REF (5), SP_REF (4), SP_REF (3),
SP_REF (2), SP_REF (1), SP_REF (0));
break;
case 10:
ret = subr (SP_REF (9), SP_REF (8), SP_REF (7),
SP_REF (6), SP_REF (5), SP_REF (4),
SP_REF (3), SP_REF (2), SP_REF (1),
SP_REF (0));
break;
default:
abort ();
}
ret = scm_apply_subr (sp, FRAME_LOCALS_COUNT ());
CACHE_SP ();
if (SCM_UNLIKELY (SCM_VALUESP (ret)))