mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 14:00:21 +02:00
Implement scm_call_varargs and scm_call_{7,8,9}
* libguile/eval.c (scm_call_7, scm_call_8, scm_call_9, scm_call_varargs): New functions. * libguile/eval.h: Add prototypes. * doc/ref/api-evaluation.texi: Add documentation. * test-suite/standalone/test-loose-ends.c: Add tests. * NEWS: Add news entry.
This commit is contained in:
parent
adb8054c6d
commit
741b8a2300
5 changed files with 86 additions and 0 deletions
1
NEWS
1
NEWS
|
@ -136,6 +136,7 @@ Reflection", "Syntax Transformer Helpers", and "Local Inclusion".
|
|||
** New print option: `escape-newlines', defaults to #t.
|
||||
** (ice-9 ftw): `file-system-fold', `file-system-tree', `scandir'
|
||||
** `scm_c_value_ref': access to multiple returned values from C
|
||||
** scm_call_7, scm_call_8, scm_call_9, and scm_call_varargs
|
||||
** Some new syntax helpers in (system syntax)
|
||||
|
||||
Search the manual for these identifiers and modules, for more.
|
||||
|
|
|
@ -533,9 +533,24 @@ then there's no @var{arg1}@dots{}@var{argN} and @var{arg} is the
|
|||
@deffnx {C Function} scm_call_4 (proc, arg1, arg2, arg3, arg4)
|
||||
@deffnx {C Function} scm_call_5 (proc, arg1, arg2, arg3, arg4, arg5)
|
||||
@deffnx {C Function} scm_call_6 (proc, arg1, arg2, arg3, arg4, arg5, arg6)
|
||||
@deffnx {C Function} scm_call_7 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
||||
@deffnx {C Function} scm_call_8 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
||||
@deffnx {C Function} scm_call_9 (proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
|
||||
Call @var{proc} with the given arguments.
|
||||
@end deffn
|
||||
|
||||
@deffn {C Function} scm_call_varargs (proc, ...)
|
||||
Call @var{proc} with any number of arguments. The argument list must be
|
||||
terminated by @code{SCM_UNDEFINED}. For example:
|
||||
|
||||
@example
|
||||
scm_call_varargs (scm_c_public_ref ("guile", "+"),
|
||||
scm_from_int (1),
|
||||
scm_from_int (2),
|
||||
SCM_UNDEFINED);
|
||||
@end example
|
||||
@end deffn
|
||||
|
||||
@deffn {C Function} scm_call_n (proc, argv, nargs)
|
||||
Call @var{proc} with the array of arguments @var{argv}, as a
|
||||
@code{SCM*}. The length of the arguments should be passed in
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#endif
|
||||
|
||||
#include <alloca.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "libguile/__scm.h"
|
||||
|
||||
|
@ -521,12 +522,57 @@ scm_call_6 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5,
|
|||
return scm_c_vm_run (scm_the_vm (), proc, args, 6);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_call_7 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5,
|
||||
SCM arg6, SCM arg7)
|
||||
{
|
||||
SCM args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
|
||||
return scm_c_vm_run (scm_the_vm (), proc, args, 7);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_call_8 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5,
|
||||
SCM arg6, SCM arg7, SCM arg8)
|
||||
{
|
||||
SCM args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
|
||||
return scm_c_vm_run (scm_the_vm (), proc, args, 8);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_call_9 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5,
|
||||
SCM arg6, SCM arg7, SCM arg8, SCM arg9)
|
||||
{
|
||||
SCM args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 };
|
||||
return scm_c_vm_run (scm_the_vm (), proc, args, 9);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_call_n (SCM proc, SCM *argv, size_t nargs)
|
||||
{
|
||||
return scm_c_vm_run (scm_the_vm (), proc, argv, nargs);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_call_varargs (SCM proc, ...)
|
||||
{
|
||||
va_list argp;
|
||||
SCM *argv = NULL;
|
||||
size_t i, nargs = 0;
|
||||
|
||||
va_start (argp, proc);
|
||||
while (!SCM_UNBNDP (va_arg (argp, SCM)))
|
||||
nargs++;
|
||||
va_end (argp);
|
||||
|
||||
argv = alloca (nargs * sizeof (SCM));
|
||||
va_start (argp, proc);
|
||||
for (i = 0; i < nargs; i++)
|
||||
argv[i] = va_arg (argp, SCM);
|
||||
va_end (argp);
|
||||
|
||||
return scm_c_vm_run (scm_the_vm (), proc, argv, nargs);
|
||||
}
|
||||
|
||||
/* Simple procedure applies
|
||||
*/
|
||||
|
||||
|
|
|
@ -72,7 +72,14 @@ SCM_API SCM scm_call_5 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
|
|||
SCM arg5);
|
||||
SCM_API SCM scm_call_6 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
|
||||
SCM arg5, SCM arg6);
|
||||
SCM_API SCM scm_call_7 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
|
||||
SCM arg5, SCM arg6, SCM arg7);
|
||||
SCM_API SCM scm_call_8 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
|
||||
SCM arg5, SCM arg6, SCM arg7, SCM arg8);
|
||||
SCM_API SCM scm_call_9 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
|
||||
SCM arg5, SCM arg6, SCM arg7, SCM arg8, SCM arg9);
|
||||
SCM_API SCM scm_call_n (SCM proc, SCM *argv, size_t nargs);
|
||||
SCM_API SCM scm_call_varargs (SCM proc, ...);
|
||||
SCM_API SCM scm_apply_0 (SCM proc, SCM args);
|
||||
SCM_API SCM scm_apply_1 (SCM proc, SCM arg1, SCM args);
|
||||
SCM_API SCM scm_apply_2 (SCM proc, SCM arg1, SCM arg2, SCM args);
|
||||
|
|
|
@ -58,11 +58,28 @@ test_scm_local_eval ()
|
|||
scm_from_signed_integer (3))));
|
||||
}
|
||||
|
||||
static void
|
||||
test_scm_call_varargs ()
|
||||
{
|
||||
SCM result;
|
||||
|
||||
result = scm_call_varargs (scm_c_public_ref ("guile", "+"),
|
||||
scm_from_int (1),
|
||||
scm_from_int (2),
|
||||
SCM_UNDEFINED);
|
||||
assert (scm_is_true (scm_equal_p (result, scm_from_int (3))));
|
||||
|
||||
result = scm_call_varargs (scm_c_public_ref ("guile", "list"),
|
||||
SCM_UNDEFINED);
|
||||
assert (scm_is_eq (result, SCM_EOL));
|
||||
}
|
||||
|
||||
static void
|
||||
tests (void *data, int argc, char **argv)
|
||||
{
|
||||
test_scm_from_locale_keywordn ();
|
||||
test_scm_local_eval ();
|
||||
test_scm_call_varargs ();
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue