diff --git a/gc.c b/gc.c index 1e116677..4fd5bdd0 100644 --- a/gc.c +++ b/gc.c @@ -675,7 +675,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon (1 - STACK_GROWS_DOWNWARD)); exit(1); } - thd->mutator_num = mut_num; + //thd->mutator_num = mut_num; thd->jmp_start = malloc(sizeof(jmp_buf)); thd->gc_args = malloc(sizeof(object) * NUM_GC_ANS); thd->gc_num_args = 0; diff --git a/include/cyclone/runtime-main.h b/include/cyclone/runtime-main.h index 5bd1d7ed..bdc098e9 100644 --- a/include/cyclone/runtime-main.h +++ b/include/cyclone/runtime-main.h @@ -15,7 +15,6 @@ long global_stack_size = 0; long global_heap_size = 0; static void c_entry_pt(void *,int,closure,closure); -static void Cyc_main(long stack_size, char *stack_base); static void Cyc_heap_init(long heap_size); static void Cyc_heap_init(long heap_size) @@ -29,40 +28,8 @@ static void Cyc_heap_init(long heap_size) printf("main: Allocating and initializing heap...\n"); #endif Cyc_heap = gc_heap_create(heap_size / 2, 0, 0); + Cyc_num_mutators = 10; // TODO: alloca this using a vpbuffer, or maybe another type of data structure Cyc_mutators = malloc(sizeof(gc_thread_data *) * Cyc_num_mutators); - Cyc_num_mutators = 1; // TODO: alloca this using a vpbuffer, or maybe another type of data structure -} - -TODO: relocate this to a runtime function (that accepts gc_thread_data and does the setjmp/dispatch, and -to cgen (to setup a new gc_thread_data and call to the new function) - -static void Cyc_main (long stack_size, char *stack_base) -{ - mclosure0(clos_halt,&Cyc_halt); // Halt if final closure is reached - mclosure0(entry_pt,&c_entry_pt); // First function to execute - Cyc_mutators[0] = malloc(sizeof(gc_thread_data)); - gc_thread_data_init(Cyc_mutators[0], 0, stack_base, stack_size); - - Cyc_mutators[0]->gc_cont = &entry_pt; - Cyc_mutators[0]->gc_args[0] = &clos_halt; - Cyc_mutators[0]->gc_num_args = 1; - - /* Tank, load the jump program... */ - setjmp(*(Cyc_mutators[0]->jmp_start)); -// TODO: note, if longjmp is passed 0 it will return 1. need to -// account for that there (add one to mut_num) and here (subtract 1 unless 0) -#if DEBUG_GC - printf("Done with GC\n"); -#endif - -// JAE - note for the general case, setjmp will return the data pointer's addy - if (type_of(Cyc_mutators[0]->gc_cont) == cons_tag || prim(Cyc_mutators[0]->gc_cont)) { - Cyc_apply_from_buf(Cyc_mutators[0], Cyc_mutators[0]->gc_num_args, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_args); - } else { - do_dispatch(Cyc_mutators[0], Cyc_mutators[0]->gc_num_args, ((closure)(Cyc_mutators[0]->gc_cont))->fn, Cyc_mutators[0]->gc_cont, Cyc_mutators[0]->gc_args); - } - - printf("Internal error: should never have reached this line\n"); exit(0); } #endif /* CYCLONE_RUNTIME_MAIN_H */ diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 3b2533f6..45968c1a 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -181,7 +181,8 @@ object get(object,object); object equalp(object,object); object memberp(void *,object,list); object memqp(void *,object,list); -char *transport(char *,int); + +void Cyc_start_thread(gc_thread_data *thd); void GC(void *,closure,object*,int); void Cyc_st_init(); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 6cbdfde4..2432cd11 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -45,7 +45,7 @@ struct gc_thread_data_t { void **moveBuf; int moveBufLen; // Need the following to perform longjmp's - int mutator_num; + //int mutator_num; jmp_buf *jmp_start; // After longjmp, pick up execution using continuation/arguments object gc_cont; diff --git a/runtime.c b/runtime.c index eb2f2b15..6df073cf 100644 --- a/runtime.c +++ b/runtime.c @@ -2343,6 +2343,25 @@ void Cyc_apply_from_buf(void *data, int argc, object prim, object *buf) { // longjmp(jmp_main,1); /* Return globals gc_cont, gc_ans. */ //} +void Cyc_start_thread(gc_thread_data *thd) +{ + /* Tank, load the jump program... */ + setjmp(*(thd->jmp_start)); + +#if DEBUG_GC + printf("Done with GC\n"); +#endif + + if (type_of(thd->gc_cont) == cons_tag || prim(thd->gc_cont)) { + Cyc_apply_from_buf(thd, thd->gc_num_args, thd->gc_cont, thd->gc_args); + } else { + do_dispatch(thd, thd->gc_num_args, ((closure)(thd->gc_cont))->fn, thd->gc_cont, thd->gc_args); + } + + printf("Internal error: should never have reached this line\n"); + exit(0); +} + // Collect garbage using mark&sweep algorithm // Note non-global roots should be marked prior to calling this function. size_t gc_collect(gc_heap *h, size_t *sum_freed) @@ -2727,8 +2746,7 @@ void GC(void *data, closure cont, object *args, int num_args) } /* Let it all go, Neo... */ - longjmp(*(((gc_thread_data *)data)->jmp_start), - (((gc_thread_data *)data)->mutator_num)); + longjmp(*(((gc_thread_data *)data)->jmp_start), 1); } diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 7fac33dd..00e936f9 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -76,10 +76,17 @@ "main(int argc,char **argv) {long stack_size = global_stack_size = STACK_SIZE; long heap_size = global_heap_size = HEAP_SIZE; + mclosure0(clos_halt,&Cyc_halt); // Halt if final closure is reached + mclosure0(entry_pt,&c_entry_pt); // First function to execute _cyc_argc = argc; _cyc_argv = argv; Cyc_heap_init(heap_size); - Cyc_main(stack_size, (char *) &stack_size); + Cyc_mutators[0] = malloc(sizeof(gc_thread_data)); + gc_thread_data_init(Cyc_mutators[0], 0, (char *) &stack_size, stack_size); + Cyc_mutators[0]->gc_cont = &entry_pt; + Cyc_mutators[0]->gc_args[0] = &clos_halt; + Cyc_mutators[0]->gc_num_args = 1; + Cyc_start_thread(Cyc_mutators[0]); return 0;}") ;;; Auto-generation of C macros