[Vm-dev] Re: Method invocation in Slang

Andreas Raab andreas.raab at gmx.de
Wed Feb 6 18:21:19 UTC 2008


Robert Krahn wrote:
> 
>> What are you actually trying to accomplish? Possibly Andreas' callback 
>> support is what you need.
> 
> We are actually trying to find an easy way to use callbacks. The method 
> invocation would be triggered from outside the VM. But since the 
> callbacks are probably synchronous we don't have to use callbacks into 
> the VM at all. If that will not work, we will follow Andreas' proposal 
> and use semaphores. One thing I am interested in concerning this is how 
> are parameters normally passed to the callbacks when using semaphores? 
> By manipulating the stack?

No, by writing primitives which pick them up. For exampe:

runCallbackProcess
	"Run the callback process"
	[true] whileTrue:[
		CallbackSema wait.
		[self handleCallback] ensure:[self callbackReturn].
	].

handleCallback
	"Handle a callback from Python"
	| nArgs rcvr selector args result |
	nArgs := self callbackGetArgCount.
	nArgs < 2 ifTrue:[^nil].
	rcvr := self resolveReceiver: (self callbackGetArg: 1).
	selector := self callbackGetArg: 2.
	selector isString ifFalse:[^nil].
	args := (3 to: nArgs) collect:[:i| self callbackGetArg: i].
	"Transcript cr; show: selector; space; show: args."
	result := [rcvr pyCallback: selector asSymbol args: args] on: Error 
do:[:ex|
		Transcript cr; show: ex description.
		Transcript cr; show: ex signalerContext longStack.
		ex return: nil.
	].
	"Transcript show:' ==> '; show: result."
	self callbackResult: result.


callbackGetArgCount
	"Primitive. Answer the number of args for the current callback."
	<primitive: 'primitivePyCallbackGetArgCount' module: 'PyBridge'>
	^self primitiveFailed

callbackGetArg: index
	"Primitive. Answer the n-th argument of the current callback"
	<primitive: 'primitivePyCallbackGetArg' module: 'PyBridge'>
	^self primitiveFailed

callbackResult: result
	"Primitive. Set the return value from the callback."
	<primitive: 'primitivePyCallbackSetResult' module: 'PyBridge'>
	^self primitiveFailed

callbackReturn
	"Primitive. Return from the callback."
	<primitive: 'primitivePyCallbackReturn' module: 'PyBridge'>
	^self primitiveFailed


More information about the Vm-dev mailing list