diff --git a/include/cyclone/runtime-main.h b/include/cyclone/runtime-main.h index 43193da3..da0c5b86 100644 --- a/include/cyclone/runtime-main.h +++ b/include/cyclone/runtime-main.h @@ -15,37 +15,28 @@ 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,long heap_size,char *stack_base); +static void Cyc_main(long stack_size, char *stack_base); +static void Cyc_heap_init(long heap_size); -static void Cyc_main (stack_size,heap_size,stack_base) - long stack_size,heap_size; char *stack_base; -{char in_my_frame; - mclosure0(clos_halt,&Cyc_halt); /* Halt program if final closure is reached */ - - /* Initialize stack trace table */ - Cyc_st_init(); - - { - /* Setup first function to execute */ - mclosure0(entry_pt,&c_entry_pt); +static void Cyc_heap_init(long heap_size) +{ + /* Initialize stack trace table + TODO: will eventually be relocated to a per-thread operation */ + Cyc_st_init(); /* Allocate heap area for second generation. */ - /* Use calloc instead of malloc to assure pages are in main memory. */ #if DEBUG_SHOW_DIAG printf("main: Allocating and initializing heap...\n"); #endif - Cyc_heap = gc_heap_create(heap_size / 2, 0, 0); - Cyc_num_mutators = 1; // 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: from here, break this out into a separate function that -// could spin up additional threads -// would need mutator_num, stack args. -// don't want to waste stack space though, so maybe inits above -// get moved to the caller of Cyc_main, and Cyc_main becomes -// that separate function -// int mutator_num = 0; +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); @@ -55,6 +46,8 @@ static void Cyc_main (stack_size,heap_size,stack_base) /* 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 @@ -66,6 +59,7 @@ static void Cyc_main (stack_size,heap_size,stack_base) 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);}} + printf("Internal error: should never have reached this line\n"); exit(0); +} #endif /* CYCLONE_RUNTIME_MAIN_H */ diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 4fcc5ba3..7fac33dd 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -78,7 +78,8 @@ long heap_size = global_heap_size = HEAP_SIZE; _cyc_argc = argc; _cyc_argv = argv; - Cyc_main(stack_size,heap_size,(char *) &stack_size); + Cyc_heap_init(heap_size); + Cyc_main(stack_size, (char *) &stack_size); return 0;}") ;;; Auto-generation of C macros