[Vm-dev] Return a value from the image to the VM

John M McIntosh johnmci at smalltalkconsulting.com
Mon Nov 23 05:19:24 UTC 2009


Well yes you need to use VMMaker
Look at the gcBiasToGrowGCLimit setup. 
gcBiasToGrowGCLimit is an instance var on Interpreter
Then you need 

Interpreter>>primitiveSetGCBiasToGrowGCLimit
	"Primitive. If the GC logic has  bias to grow, set growth limit"
	| value |
	self export: true.
	value := self stackIntegerValue: 0.
	successFlag ifTrue:[
		gcBiasToGrowGCLimit := value.
		//Other clutter here which is not important to the example
		self pop: argumentCount.
	].

Then an example to call it. 

SystemDictionary>>setGCBiasToGrowGCLimit: aNumber
	"Primitive. Indicate that the bias to grow logic should do a GC after aNumber Bytes"
	<primitive: 'primitiveSetGCBiasToGrowGCLimit'>
	^self primitiveFailed
"Example:
	Smalltalk setGCBiasToGrowGCLimit: 16*1024*1024.
"

Squeak calls the routine ioExit() to exit, which is platform dependent, in that routine you 
would need to load the return code and do something interesting with it. 


On 2009-11-22, at 5:12 AM, Rob Rothwell wrote:

> 
> On 22.11.2009, at 05:07, Rob Rothwell wrote:
> > Hello...
> >
> > For scripting purposes, I just want to be able to do something like:
> >
> > SmalltalkImage current quit: errorCode.
> >
> > So that in the VM I can essentially do:
> >
> > return errorCode.
> >
> > at the end of sqMain?
> >
> > Any pointers on how to push a value BACK to the VM?  I have only barely dabbled with adding some custom menu commands to the VM long ago, and have no idea where to start.
> 
> You would need to add a primitive to set the errorCode. This would be stored in an interpreter variable. Then the VM's exit code would be modified to retrieve that value.
> 
> So, unlike all the other examples out there, this would probably be best if it were NOT an external plugin?  Would you be able to use VMMaker to do this (I've never done that before), or just go hand code some stuff?
> 
> Do you think this seems like a generically pretty useful think to add to the VM?  If so, I suppose I would like to do it right!
> 
> I hacked a temporary solution together with batch files and unique file names, but it feels a little sloppy.
> 
> Thanks,
> 
> Rob

--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================






More information about the Vm-dev mailing list