Callbacks, simplified.

Andreas Raab andreas.raab at gmx.de
Tue Jun 6 01:17:58 UTC 2006


Folks -

Another one of the issues I really need a solution for is simple 
callback support into the interpreter. For me, the simplest thing to do 
that can potentially support all the relevant use cases is to merely 
provide an interface that (via setjmp/longjmp) ensures that the C 
callstack remains in order, e.g., prevents returns "through" other 
callback frames.

I'm thinking about an interface like here:

int interpretEnter(int *cbID);
     - (Re-)Enters the interpreter. Different from interpret() in such 
that it creates an environment (via setjmp) to return to. Fills in the 
cbID with an ID that is used in the return call.

int interpretExit(int cbID);
     - Returns from a previous call to interpretEnter() with the 
provided callback ID.

Both of the above functions may fail - interpretEnter() would fail if 
for some reason the interpreter cannot be entered (no setjmp/longjmp 
support, or failure to allocate jmpbuf). interpretExit() would fail if 
the callback ID is not the last "matching" ID.

Note that the above does NOT make any assumptions on the means by which 
the VM gets notified about the occurrence of the callback itself nor any 
arguments etc. It is up to the plugin to provide that information by its 
idiosyncratic means.

Question: Does anyone have a problem with the above? I'm trying to 
design "just enough" so that projects like wxSqueak or others can 
cooperate without knowing too much about each other.

Cheers,
   - Andreas




More information about the Vm-dev mailing list