unpack varargs

This commit is contained in:
Justin Ethier 2021-02-10 22:28:21 -05:00
parent 95f8a17124
commit c77cfcd6f7
2 changed files with 19 additions and 26 deletions

View file

@ -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. */

View file

@ -1868,19 +1868,19 @@
;; here if at all possible
;;
;; Load varargs from C stack into Scheme list
(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))
", "
(mangle (ast:lambda-varargs-var exp))
"_raw, argc - " (number->string
(- (length (ast:lambda-formals->list exp))
1
(if has-closure? 1 0)))
");\n");
", args"
", " (number->string num-fixargs)
", argc - " (number->string num-fixargs)
");\n"))
"") ; No varargs, skip
(c:serialize
(c:append