mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Replaced AFTER_LONGJMP, and misc fixes
This commit is contained in:
parent
716d0e0b7f
commit
78fe64cb56
3 changed files with 42 additions and 36 deletions
|
@ -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 */
|
||||
|
|
56
runtime.c
56
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<P>_<B>(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);
|
||||
}
|
||||
|
||||
|
|
20
runtime.h
20
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);}}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue