From 87c266a44ae6acd86c65ca9e02ebfd167f174134 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 12 Jan 2016 03:21:36 -0500 Subject: [PATCH] Adding exception stack to thread data --- gc.c | 1 + include/cyclone/runtime.h | 1 + include/cyclone/types.h | 2 ++ runtime.c | 11 +++++++---- scheme/cyclone/cgen.sld | 5 +++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gc.c b/gc.c index ede7cf46..1cfc8ba2 100644 --- a/gc.c +++ b/gc.c @@ -1200,6 +1200,7 @@ void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, lon thd->stack_trace_idx = 0; thd->stack_prev_frame = NULL; thd->mutations = NULL; + thd->exception_handler_stack = NULL; // thd->thread = NULL; thd->thread_state = CYC_THREAD_STATE_NEW; //thd->mutator_num = mut_num; diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 4d0dbf69..909b25fe 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -369,6 +369,7 @@ extern object Cyc_exception_handler_stack; object Cyc_default_exception_handler(void *data, int argc, closure _, object err); object Cyc_current_exception_handler(); +object Cyc_current_exception_handler2(void *data); // TODO: this is temporary, will consolidate with above function void Cyc_rt_raise(void *data, object err); void Cyc_rt_raise2(void *data, const char *msg, object err); void Cyc_rt_raise_msg(void *data, const char *err); diff --git a/include/cyclone/types.h b/include/cyclone/types.h index eec9df4b..1d9558cc 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -91,6 +91,8 @@ struct gc_thread_data_t { char **stack_traces; int stack_trace_idx; char *stack_prev_frame; + // Exception handler stack + object exception_handler_stack; }; /* GC data structures */ diff --git a/runtime.c b/runtime.c index 39935119..9eaab32e 100644 --- a/runtime.c +++ b/runtime.c @@ -371,6 +371,9 @@ object Cyc_default_exception_handler(void *data, int argc, closure _, object err return nil; } +object Cyc_current_exception_handler2(void *data) { + return Cyc_current_exception_handler(); +} object Cyc_current_exception_handler() { if (nullp(Cyc_exception_handler_stack)) { return primitive_Cyc_91default_91exception_91handler; @@ -384,7 +387,7 @@ void Cyc_rt_raise(void *data, object err) { make_cons(c2, err, nil); make_cons(c1, boolean_f, &c2); make_cons(c0, &c1, nil); - apply(data, nil, Cyc_current_exception_handler(), &c0); + apply(data, nil, Cyc_current_exception_handler2(data), &c0); // Should never get here fprintf(stderr, "Internal error in Cyc_rt_raise\n"); exit(1); @@ -395,7 +398,7 @@ void Cyc_rt_raise2(void *data, const char *msg, object err) { make_cons(c2, &s, &c3); make_cons(c1, boolean_f, &c2); make_cons(c0, &c1, nil); - apply(data, nil, Cyc_current_exception_handler(), &c0); + apply(data, nil, Cyc_current_exception_handler2(data), &c0); // Should never get here fprintf(stderr, "Internal error in Cyc_rt_raise2\n"); exit(1); @@ -1958,7 +1961,7 @@ void _cyc_system(void *data, object cont, object args) { // integer_type argc = Cyc_length(args); // dispatch_va(data, argc.value, dispatch_error, cont, cont, args); } void _Cyc_91current_91exception_91handler(void *data, object cont, object args) { - object handler = Cyc_current_exception_handler(); + object handler = Cyc_current_exception_handler2(data); return_closcall1(data, cont, handler); } void _Cyc_91default_91exception_91handler(void *data, object cont, object args) { // TODO: this is a quick-and-dirty implementation, may be a better way to write this @@ -2627,7 +2630,7 @@ static primitive_type _121_123_primitive = {{0}, primitive_tag, "<=", &__121_123 static primitive_type apply_primitive = {{0}, primitive_tag, "apply", &_apply}; static primitive_type _75halt_primitive = {{0}, primitive_tag, "%halt", &__75halt}; static primitive_type exit_primitive = {{0}, primitive_tag, "exit", &_cyc_exit}; -static primitive_type Cyc_91current_91exception_91handler_primitive = {{0}, primitive_tag, "Cyc_current_exception_handler", &_Cyc_91current_91exception_91handler}; +static primitive_type Cyc_91current_91exception_91handler_primitive = {{0}, primitive_tag, "Cyc_current_exception_handler2", &_Cyc_91current_91exception_91handler}; static primitive_type Cyc_91default_91exception_91handler_primitive = {{0}, primitive_tag, "Cyc_default_exception_handler", &_Cyc_91default_91exception_91handler}; static primitive_type cons_primitive = {{0}, primitive_tag, "cons", &_cons}; static primitive_type cell_91get_primitive = {{0}, primitive_tag, "cell-get", &_cell_91get}; diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 51430409..972148ea 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -472,7 +472,7 @@ ((eq? p '%halt) "__halt") ((eq? p 'exit) "__halt") ((eq? p 'Cyc-default-exception-handler) "Cyc_default_exception_handler") - ((eq? p 'Cyc-current-exception-handler) "Cyc_current_exception_handler") + ((eq? p 'Cyc-current-exception-handler) "Cyc_current_exception_handler2") ((eq? p 'open-input-file) "Cyc_io_open_input_file") ((eq? p 'open-output-file) "Cyc_io_open_output_file") ((eq? p 'close-port) "Cyc_io_close_port") @@ -591,6 +591,7 @@ <= apply Cyc-default-exception-handler + Cyc-current-exception-handler Cyc-end-thread! thread-sleep! open-input-file @@ -716,7 +717,7 @@ ;; Primitive functions that pass a continuation or thread data but have no other arguments (define (prim:cont/no-args? exp) (and (prim? exp) - (member exp '(command-line-arguments make-mutex Cyc-minor-gc)))) + (member exp '(command-line-arguments make-mutex Cyc-minor-gc Cyc-current-exception-handler)))) ;; Pass an integer arg count as the function's first parameter? (define (prim:arg-count? exp)