unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Implement scm_call_varargs and scm_call_{7,8,9}
@ 2012-01-30  1:04 Mark H Weaver
  2012-01-30 10:59 ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2012-01-30  1:04 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 95 bytes --]

Andy suggested that we should add these, so here's a patch to do so.
Okay to push?

    Mark



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Implement scm_call_varargs and scm_call_{7,8,9} --]
[-- Type: text/x-patch, Size: 6359 bytes --]

From 08376ad8f67f8c268d78d4f25bd59ca8affe5585 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Sun, 29 Jan 2012 20:00:21 -0500
Subject: [PATCH] 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.
---
 NEWS                                    |    1 +
 doc/ref/api-evaluation.texi             |   15 ++++++++++
 libguile/eval.c                         |   46 +++++++++++++++++++++++++++++++
 libguile/eval.h                         |    7 +++++
 test-suite/standalone/test-loose-ends.c |   17 +++++++++++
 5 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 02b824d..df5a4f8 100644
--- a/NEWS
+++ b/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.
diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi
index 90cae45..de54194 100644
--- a/doc/ref/api-evaluation.texi
+++ b/doc/ref/api-evaluation.texi
@@ -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
diff --git a/libguile/eval.c b/libguile/eval.c
index e008b3a..70e303a 100644
--- a/libguile/eval.c
+++ b/libguile/eval.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <alloca.h>
+#include <stdarg.h>
 
 #include "libguile/__scm.h"
 
@@ -522,11 +523,56 @@ scm_call_6 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5,
 }
 
 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
  */
 
diff --git a/libguile/eval.h b/libguile/eval.h
index f193ad6..dca0b41 100644
--- a/libguile/eval.h
+++ b/libguile/eval.h
@@ -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);
diff --git a/test-suite/standalone/test-loose-ends.c b/test-suite/standalone/test-loose-ends.c
index d1d6831..253c9a6 100644
--- a/test-suite/standalone/test-loose-ends.c
+++ b/test-suite/standalone/test-loose-ends.c
@@ -59,10 +59,27 @@ test_scm_local_eval ()
 }
 
 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
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement scm_call_varargs and scm_call_{7,8,9}
  2012-01-30  1:04 [PATCH] Implement scm_call_varargs and scm_call_{7,8,9} Mark H Weaver
@ 2012-01-30 10:59 ` Andy Wingo
  2012-01-30 15:20   ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2012-01-30 10:59 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-devel

On Mon 30 Jan 2012 02:04, Mark H Weaver <mhw@netris.org> writes:

> Andy suggested that we should add these, so here's a patch to do so.
> Okay to push?

Looks great to me, thanks.  Please push.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement scm_call_varargs and scm_call_{7,8,9}
  2012-01-30 10:59 ` Andy Wingo
@ 2012-01-30 15:20   ` Ludovic Courtès
  2012-01-30 16:20     ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2012-01-30 15:20 UTC (permalink / raw)
  To: guile-devel

Andy Wingo <wingo@pobox.com> skribis:

> On Mon 30 Jan 2012 02:04, Mark H Weaver <mhw@netris.org> writes:
>
>> Andy suggested that we should add these, so here's a patch to do so.
>> Okay to push?
>
> Looks great to me, thanks.  Please push.

Can we s/scm_call_varargs/scm_call/ instead?  (For consistency with
scm_list_n, it would be ‘scm_call_n’, but that one is already taken for
something else.)

Other than that, OK!

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement scm_call_varargs and scm_call_{7,8,9}
  2012-01-30 15:20   ` Ludovic Courtès
@ 2012-01-30 16:20     ` Mark H Weaver
  0 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2012-01-30 16:20 UTC (permalink / raw)
  To: guile-devel

ludo@gnu.org (Ludovic Courtès) writes:
> Can we s/scm_call_varargs/scm_call/ instead?  (For consistency with
> scm_list_n, it would be ‘scm_call_n’, but that one is already taken for
> something else.)

Excellent suggestion!  'scm_call' it is :)

    Thanks,
      Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-30 16:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30  1:04 [PATCH] Implement scm_call_varargs and scm_call_{7,8,9} Mark H Weaver
2012-01-30 10:59 ` Andy Wingo
2012-01-30 15:20   ` Ludovic Courtès
2012-01-30 16:20     ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).