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 our compiler will compute the difference between the number of required
args and the number of provided ones, and pass the difference as 'count' args and the number of provided ones, and pass the difference as 'count'
*/ */
#define load_varargs(var, arg_var, count) \ #define load_varargs(var, args_var, start, count) \
list var = (count > 0) ? alloca(sizeof(pair_type)*count) : NULL; \ list var = ((count) > 0) ? alloca(sizeof(pair_type)*(count)) : NULL; \
{ \ { \
int i; \ int i; \
object tmp; \ object tmp; \
va_list va; \ if ((count) > 0) { \
if (count > 0) { \ for (i = 0; i < (count); i++) { \
va_start(va, arg_var); \ tmp = arg[start + i]; \
for (i = 0; i < count; i++) { \
if (i) { \
tmp = va_arg(va, object); \
} else { \
tmp = arg_var; \
} \
var[i].hdr.mark = gc_color_red; \ var[i].hdr.mark = gc_color_red; \
var[i].hdr.grayed = 0; \ var[i].hdr.grayed = 0; \
var[i].hdr.immutable = 0; \ var[i].hdr.immutable = 0; \
var[i].tag = pair_tag; \ var[i].tag = pair_tag; \
var[i].pair_car = tmp; \ 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. */ /* Prototypes for primitive functions. */

View file

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