[gambit-list] Continuations and C callbacks

Jeremie Lasalle Ratelle pouexmachinax at gmail.com
Fri Oct 15 16:46:24 EDT 2010


In the windows gui code of Jazzscheme we have to use callbacks from c
to dispatch events to do event dispatching. This is a requirement of
windows.

The event loop : http://pastebin.com/iBT85Yev

It calls DispatchMessage which ultimately calls our callback.

The callback must either handle the message and return 0 or call
DefWindowProc which is the default handler.

The Jedi debugger allows the message loop to be restarted when an
error occurs. For that, it uses continuations. Those continuations
jump over the c code causing problems because the c frames are not
cleared and the handler does not return.

To fix that, I developped a new version of dynamic-wind that I call
with-continuation-checkpoints.

Instead of being thunks, the before and after functions take two
arguments, the exit and the restart.

The exit is simply the continuation of the
with-continuation-checkpoints call which allows to stop the
continuation invocation.
The restart is a thunk that make the original continuation invokation
call. It might be a continuation-return or a continuation-graft.
This allows resuming the continuation invocation at a different point
in the code.

An example similar to the windows event loop : http://pastebin.com/xn2EaYYZ

This example shows how we can use with-continuations-checkpoints to
unwind the c-stack and correctly return from the handler.

Any suggestions? Comments?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-with-continuation-checkpoints.patch
Type: application/octet-stream
Size: 10071 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20101015/298fdfd8/attachment.obj>


More information about the Gambit-list mailing list