unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* scm_c_catch question
@ 2014-08-15 22:13 Ian Grant
  2014-08-16 13:24 ` Neil Jerram
  2014-08-18  1:14 ` Ian Grant
  0 siblings, 2 replies; 6+ messages in thread
From: Ian Grant @ 2014-08-15 22:13 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2271 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: scm_c_catch question
@ 2014-09-15 21:17 Ian Grant
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Grant @ 2014-09-15 21:17 UTC (permalink / raw)
  To: Ian Grant, guile-devel

[-- Attachment #1: Type: text/plain, Size: 1295 bytes --]

A while ago I posted this patch:

   http://lists.gnu.org/archive/html/guile-devel/2014-08/msg00058.html

No-one had anything to say about it. But I would like to know what to do if
I want my code to work with the next release of Guile.

I think in retrospect this patch is too much. A better patch would leave
the API alone, and just remove the existing check for the current throw
handlers, and make the documentation clearer about exactly what "the
dynamic context of the throw" really means.

If the catcher wants to 'fall through' to the main handler from the
pre-unwind-handler, then she can just return from the pre-unwind-handler.
So what is the function this check provides?

If we remove the check, then the dynamic context of the throw, in which the
pre-unwind-handler is called, includes the throw-handlers in effect at the
time of the throw., So if you throw the same exception from within the
pre-unwind-handler, you re-enter it.

What I am proposing is a change to the actual semantics implemented, but it
is arguably not a change to the semantics documented. Or have I missed the
clearer definition somewhere else in the manual of what "the dynamic
context of the throw" means, and which makes it clear that this is
everything but the throw handlers in effect at the time?!

Ian

[-- Attachment #2: Type: text/html, Size: 1550 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-15 21:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-15 22:13 scm_c_catch question Ian Grant
2014-08-16 13:24 ` Neil Jerram
2014-08-18  1:14 ` Ian Grant
2014-08-20 18:02   ` Neil Jerram
2014-08-24  1:09     ` Ian Grant
  -- strict thread matches above, loose matches on Subject: below --
2014-09-15 21:17 Ian Grant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).