Hello Guile types,
I have been experimenting with using libguile from within another byte-code interpreter: Moscow ML. I have a version of Moscow ML with an GNU lightning interface in which I JIT compile primitives to give access to libguile functions from Standard ML.
Moscow ML uses an old version of the CAML light runtime which is a byte-code interpreter implemented in C. The CAML runtime provides exceptions implemented using a longjmp buffer.
The Moscow ML top-level REPL is implemented as a byte-code compiled ML function which is invoked by main(). What I would like to do would be to catch any unhandled Guile exceptions and re-throw them as ML exceptions so that the toplevel isn't exit'ed by an un-handled scheme exception. To this end I call the CAML main from the scm_boot_guile callback, under a scm_c_catch. This code is in the guilert.c file
https://github.com/IanANGrant/red-october/blob/master/src/runtime/guilert.c The only CAML'ism here is the call to failwith("message"). This does a longjump 'into the CAML exception bucket'
The problem is that after the first successful catch by the pre-unwind handler, the next Guile exception is handled by the main_handler. This is not what I expected. The manual seems to say that it is only after the main_handler is invoked, that the catch is cancelled. Is this not the right understanding? The output of the example shows this isn't what happens: