Debugging ex handler integration with icyc

This commit is contained in:
Justin Ethier 2015-03-20 23:25:50 -04:00
parent 15094f6d03
commit a46b5f18f8
2 changed files with 15 additions and 3 deletions

View file

@ -468,22 +468,27 @@ notes:
*/ */
list exception_handler_stack = nil; list exception_handler_stack = nil;
static void default_exception_handler(int argc, closure _, object k, object err) { static void default_exception_handler(int argc, closure _, /*object k,*/ object err) {
printf("Error: "); printf("Error: ");
Cyc_display(err); Cyc_display(err);
printf("\n"); printf("\n");
exit(1); exit(1);
} }
// TODO: does this cause GC problems? for example, what if handler is on the stack??
// putting all of this in the scheme code could help solve that problem
//
// TODO: not sure this is the best approach, may be able to do this in // TODO: not sure this is the best approach, may be able to do this in
// Scheme code, but for now do add/remove this way: // Scheme code, but for now do add/remove this way:
static object Cyc_add_exception_handler(object handler) { static object Cyc_add_exception_handler(object handler) {
printf("DEBUG: add ex handler\n");
// TODO: error checking on handler? // TODO: error checking on handler?
exception_handler_stack = mcons(handler, exception_handler_stack); exception_handler_stack = mcons(handler, exception_handler_stack);
return handler; return handler;
} }
static object Cyc_remove_exception_handler(){ static object Cyc_remove_exception_handler(){
object old_cons = exception_handler_stack; object old_cons = exception_handler_stack;
printf("DEBUG: remove ex handler\n");
if (nullp(exception_handler_stack)) { if (nullp(exception_handler_stack)) {
printf("Internal error, no exception handler to remove\n"); printf("Internal error, no exception handler to remove\n");
@ -1018,6 +1023,7 @@ static object Cyc_error(int count, object obj1, ...) {
} }
static object Cyc_error_va(int count, object obj1, va_list ap) { static object Cyc_error_va(int count, object obj1, va_list ap) {
closure ex = (closure)car(Cyc_current_exception_handler());
object tmp; object tmp;
int i; int i;
@ -1031,8 +1037,10 @@ static object Cyc_error_va(int count, object obj1, va_list ap) {
printf("\n"); printf("\n");
} }
exit(1); //exit(1);
// TODO: Cyc_raise(obj1); //// TODO: Cyc_raise(obj1);
// TODO: make closure
(ex->fn)(1, ex, obj1);
return boolean_f; return boolean_f;
} }

View file

@ -77,6 +77,7 @@
(let ((result #f) (let ((result #f)
(my-handler (my-handler
(lambda (obj) (lambda (obj)
(write "entered my-handler")
(let ((result #f) (let ((result #f)
(continuable? (and (pair? obj) (continuable? (and (pair? obj)
(equal? (car obj) 'continuable)))) (equal? (car obj) 'continuable))))
@ -89,8 +90,11 @@
(error "exception handler returned")))))) (error "exception handler returned"))))))
;; TODO: cond-expand below, since it uses Cyc functions? ;; TODO: cond-expand below, since it uses Cyc functions?
;; probably no need since this is part of internal lib ;; probably no need since this is part of internal lib
(write "before add ex handler")
(Cyc-add-exception-handler my-handler) (Cyc-add-exception-handler my-handler)
(write "before thunk")
(set! result (thunk)) (set! result (thunk))
(write (list "after thunk" result))
;; Only reached if no ex raised ;; Only reached if no ex raised
(Cyc-remove-exception-handler) (Cyc-remove-exception-handler)
result)) result))