From c77cfcd6f7501bdd22879ac83d943842047451d5 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 10 Feb 2021 22:28:21 -0500 Subject: [PATCH] unpack varargs --- include/cyclone/runtime.h | 19 ++++++------------- scheme/cyclone/cgen.sld | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index f718d2c2..88fe774e 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -148,28 +148,21 @@ object Cyc_global_set_cps(void *thd, object cont, object sym, object * glo, obje our compiler will compute the difference between the number of required args and the number of provided ones, and pass the difference as 'count' */ -#define load_varargs(var, arg_var, count) \ - list var = (count > 0) ? alloca(sizeof(pair_type)*count) : NULL; \ +#define load_varargs(var, args_var, start, count) \ + list var = ((count) > 0) ? alloca(sizeof(pair_type)*(count)) : NULL; \ { \ int i; \ object tmp; \ - va_list va; \ - if (count > 0) { \ - va_start(va, arg_var); \ - for (i = 0; i < count; i++) { \ - if (i) { \ - tmp = va_arg(va, object); \ - } else { \ - tmp = arg_var; \ - } \ + if ((count) > 0) { \ + for (i = 0; i < (count); i++) { \ + tmp = arg[start + i]; \ var[i].hdr.mark = gc_color_red; \ var[i].hdr.grayed = 0; \ var[i].hdr.immutable = 0; \ var[i].tag = pair_tag; \ var[i].pair_car = tmp; \ - var[i].pair_cdr = (i == (count-1)) ? NULL : &var[i + 1]; \ + var[i].pair_cdr = (i == ((count)-1)) ? NULL : &var[i + 1]; \ } \ - va_end(va); \ } \ } /* Prototypes for primitive functions. */ diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 84df0e2a..a8f834c3 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -1868,19 +1868,19 @@ ;; here if at all possible ;; ;; Load varargs from C stack into Scheme list - (string-append - ;; DEBUGGING: - ;; "printf(\"%d %d\\n\", argc, " - ;; (number->string (length (ast:lambda-formals->list exp))) ");" - "load_varargs(" - (mangle (ast:lambda-varargs-var exp)) - ", " - (mangle (ast:lambda-varargs-var exp)) - "_raw, argc - " (number->string - (- (length (ast:lambda-formals->list exp)) - 1 - (if has-closure? 1 0))) - ");\n"); + (let ((num-fixargs (- (length (ast:lambda-formals->list exp)) + 2 ;; include raw and "..." + (if has-closure? 1 0)))) + (string-append + ;; DEBUGGING: + ;; "printf(\"%d %d\\n\", argc, " + ;; (number->string (length (ast:lambda-formals->list exp))) ");" + "load_varargs(" + (mangle (ast:lambda-varargs-var exp)) + ", args" + ", " (number->string num-fixargs) + ", argc - " (number->string num-fixargs) + ");\n")) "") ; No varargs, skip (c:serialize (c:append