From 78fe64cb5633fa285213f2301213d3627d2ba466 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 31 Mar 2015 21:45:10 -0400 Subject: [PATCH] Replaced AFTER_LONGJMP, and misc fixes --- cyclone.h | 2 ++ runtime.c | 56 +++++++++++++++++++++++++++++-------------------------- runtime.h | 20 ++++++++++---------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/cyclone.h b/cyclone.h index bd59dc61..1a764db2 100644 --- a/cyclone.h +++ b/cyclone.h @@ -266,5 +266,7 @@ static const object primitive_##name = &name##_primitive void dispatch(int argc, function_type func, object clo, object cont, object args); void dispatch_va(int argc, function_type_va func, object clo, object cont, object args); +void do_dispatch(int argc, function_type func, object clo, object *buffer); + #endif /* CYCLONE_H */ diff --git a/runtime.c b/runtime.c index dbfee666..02fdb1b8 100644 --- a/runtime.c +++ b/runtime.c @@ -8,29 +8,42 @@ */ // TODO: get VA args function below to work -// TODO: need a way of consolidating AFTER_LONGJMP with code below. -// may be able to do this by creating a function that wraps -// an array of objs into a scheme list (at least initially), -// and calling apply on it. In this case, would want a flag -// to indicate that the cont parameter should be skipped, -// since it is not explicitly used by the AFTER_LONGJMP code. /** * Receive a list of arguments and apply them to the given function */ void dispatch(int argc, function_type func, object clo, object cont, object args) { - // TODO: is this portable? may be better to have a dedicated memory area and -// just copy to it as needed - object b[argc + 1]; // OK to do this? - int i; - // Assume there is always a cont. but could parametize this later - argc++; - b[0] = cont; - for (i = 1; i < argc; i++){ - b[i] = car(args); - args = cdr(args); - } + object b[argc + 1]; // OK to do this? Is this portable? + int i; + argc++; + b[0] = cont; + for (i = 1; i < argc; i++){ + b[i] = car(args); + args = cdr(args); + } + + do_dispatch(argc, func, clo, b); +} + +/** + * Same as above but for a varargs C function + */ +void dispatch_va(int argc, function_type_va func, object clo, object cont, object args) { + object b[argc + 1]; // OK to do this? Is this portable? + int i; + + argc++; + b[0] = cont; + for (i = 1; i < argc; i++){ + b[i] = car(args); + args = cdr(args); + } + + do_dispatch(argc, func, clo, b); +} + +void do_dispatch(int argc, function_type func, object clo, object *b) { /* The following is based on the macro expansion code from CHICKEN's do_apply */ /* PTR_O_p

_(o): list of COUNT = ((2 ** P) * B) '*(b+I)' arguments, @@ -109,12 +122,3 @@ PTR_O_p0_##p0(((n0-2)&0xFE)+0)); } } -/** - * Same as above but for a varargs C function - */ -void dispatch_va(int argc, function_type_va func, object clo, object cont, object args) { -// TODO: DISPATCH_RETURN_CALL_FUNC - printf("TODO: implement\n"); - exit(1); -} - diff --git a/runtime.h b/runtime.h index 6b29520a..370e93ed 100644 --- a/runtime.h +++ b/runtime.h @@ -103,9 +103,6 @@ static void GC(closure,object*,int) never_returns; static void main_main(long stack_size,long heap_size,char *stack_base) never_returns; static long long_arg(int argc,char **argv,char *name,long dval); -void dispatch(int argc, function_type func, object clo, object cont, object args); -void dispatch_va(int argc, function_type_va func, object clo, object cont, object args); - /* Symbol Table */ /* Notes for the symbol table @@ -224,9 +221,9 @@ static char *dhalloc_end; static long no_gcs = 0; /* Count the number of GC's. */ static long no_major_gcs = 0; /* Count the number of GC's. */ -static volatile object gc_cont; /* GC continuation closure. */ -static volatile object gc_ans[NUM_GC_ANS]; /* argument for GC continuation closure. */ -static volatile int gc_num_ans; +static object gc_cont; /* GC continuation closure. */ +static object gc_ans[NUM_GC_ANS]; /* argument for GC continuation closure. */ +static int gc_num_ans; static jmp_buf jmp_main; /* Where to jump to. */ //static object test_exp1, test_exp2; /* Expressions used within test. */ @@ -700,9 +697,11 @@ static string_type Cyc_string_append_va_list(int argc, object str1, va_list ap) char *buffer, *bufferp, **str = alloca(sizeof(char *) * argc); object tmp; - str[i] = ((string_type *)str1)->str; - len[i] = strlen(str[i]); - total_len += len[i]; + if (argc > 0) { + str[i] = ((string_type *)str1)->str; + len[i] = strlen(str[i]); + total_len += len[i]; + } for (i = 1; i < argc; i++) { tmp = va_arg(ap, object); @@ -1588,7 +1587,8 @@ static void main_main (stack_size,heap_size,stack_base) /* Tank, load the jump program... */ setjmp(jmp_main); - AFTER_LONGJMP + do_dispatch(gc_num_ans, ((closure)gc_cont)->fn, gc_cont, gc_ans); + /* */ printf("main: your setjmp and/or longjmp are broken.\n"); exit(0);}}