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?
Afficher les réponses par date