guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scm_c_catch question


From: Ian Grant
Subject: scm_c_catch question
Date: Fri, 15 Aug 2014 18:13:48 -0400

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:

debug: main_trampoline: calling scm_c_catch(main_call,main_handler,main_pre_unwind_handler)
debug: main_call: calling caml_main
Moscow ML [Red October] 2.10
Type `quit();' to quit.
- scm_repl();
Moscow ML Guile REPL
Type `(quit)' to exit.
> (+ "ab")
debug: main_pre_unwind_handler called
! Uncaught exception:
! FailĀ  "Uncaught scheme exception"
- scm_repl();
Moscow ML Guile REPL
Type `(quit)' to exit.
> (+ "ab")
debug: main_handler called
debug: main_trampoline: scm_c_catch returned!

Process mosml finished


reply via email to

[Prev in Thread] Current Thread [Next in Thread]