Return a value from the image to the VM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Return a value from the image to the VM

Rob Rothwell
 
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.

Thanks!

Rob
Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Bert Freudenberg

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.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
In reply to this post by Rob Rothwell
 

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
Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

johnmci

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 <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
 
Thanks, John!

I DID manage to build a new VM from the C source code that is available; I have never yet GENERATED the source from VMMaker.
I guess once I figure that out I'll have a place to start now.

(I was poking around in the primitive table directly and recompiling!)

I did find ioExit() in the C-Code, but when I loaded VMMaker, I only found it in InterpreterSimulator.

What a lot to learn!

Thanks again for pointing me towards and example,

Rob



On Mon, Nov 23, 2009 at 12:19 AM, John M McIntosh <[hidden email]> wrote:

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 <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

johnmci

Well the interpreter is written in a subset of smalltalk (called slang).
In order to host on a platform you need to supply the basic hosting api routines.

some documentation at
http://isqueak.org/PlatformVMAPI
like
http://isqueak.org/ioExit

then most of the old docs on
primitive writting
http://wiki.squeak.org/squeak/407
http://bike-nomad.com/squeak/writingPlugins.html


On 2009-11-23, at 3:33 AM, Rob Rothwell wrote:

> Thanks, John!
>
> I DID manage to build a new VM from the C source code that is available; I have never yet GENERATED the source from VMMaker.
> I guess once I figure that out I'll have a place to start now.
>
> (I was poking around in the primitive table directly and recompiling!)
>
> I did find ioExit() in the C-Code, but when I loaded VMMaker, I only found it in InterpreterSimulator.
>
> What a lot to learn!
>
> Thanks again for pointing me towards and example,
>
> Rob
>

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
In reply to this post by johnmci
 
I miraculously managed to somehow load VMMaker in Pharo on Windows XP.

Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.

I was even able to use that primitive without the VM crashing!

But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...

Any tips?  Is there something special you have to do to create the instance variables?

Thanks again for pointing me in the right direction...

Rob

On Mon, Nov 23, 2009 at 12:19 AM, John M McIntosh <[hidden email]> wrote:

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 <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

johnmci

How about pasting your smalltalk code for primitiveSetOSErrorCode

On 2009-11-25, at 7:06 PM, Rob Rothwell wrote:

> I miraculously managed to somehow load VMMaker in Pharo on Windows XP.
>
> Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.
>
> I was even able to use that primitive without the VM crashing!
>
> But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...
>
> Any tips?  Is there something special you have to do to create the instance variables?
>
> Thanks again for pointing me in the right direction...
>
> Rob
--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
 
Oh...I just did:

Interpreter>>primitiveSetOSErrorCode
| value |
self export: true.
value := self stackIntegerValue: 0.
successFlag ifTrue:[
osErrorCode  := value.
self pop: argumentCount.
].

where 

osErrorCode is an instvar in Interpreter...

(I found the variable declarations in interp.c, including gcBiasToGrowGCLimit like you pointed out, but I don't see how it ended up there!)

Rob

On Wed, Nov 25, 2009 at 11:08 PM, John M McIntosh <[hidden email]> wrote:
How about pasting your smalltalk code for primitiveSetOSErrorCode

On 2009-11-25, at 7:06 PM, Rob Rothwell wrote:

> I miraculously managed to somehow load VMMaker in Pharo on Windows XP.
>
> Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.
>
> I was even able to use that primitive without the VM crashing!
>
> But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...
>
> Any tips?  Is there something special you have to do to create the instance variables?
>
> Thanks again for pointing me in the right direction...
>
> Rob
--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
In reply to this post by johnmci
 
Then, of course, all I want to do is something like:

int ioExit(void)
{
  inCleanExit = 1;
  exit(osErrorCode);
  /* avoid the warnings here */
  return 0;

in sqWin32Window.c...

Take care,

Rob

On Mon, Nov 23, 2009 at 12:19 AM, John M McIntosh <[hidden email]> wrote:

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 <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

johnmci
In reply to this post by Rob Rothwell

Well let's see likely you should have in
ObjectMemory>>initializeObjectMemory:
osErrorCode := 0 ;

just for completeness to ensure it has a explicit value you set, versus a supposed zero value.

Now you need an accessor.

So on
Interpreter>>getOsErrorCode
        ^osErrorCode;

and likely you need to add
getOsErrorCode as a required method to the requiredList in
Interpreter (class)>>requiredMethodNames.

Otherwise the Slang logic will delete the method getOsErrorCode as not being used and it
won't generate the expected "C" code.

Then in your platform ioExit()  you need to add
extern sqInt getOsErrorCode(void);

sqInt myReturnErrorCode = getOsErrorCode();


To answer your other question, if an instance variable is declared in the ObjectMemory or Interpreter class it ends up
as a static variable in interp.c (or in the global Foo structure), unless a unique condition is met.

The Slang generator inlines methods so methods not in requiredMethodNames could be folded into the caller.
This historically has generated better code than what compiler in-line optimization can do.
If a method can be folded into the caller, then based on  requiredMethodNames it might not exist as a standalone method anymore.

Now a special further optimization which greatly improved GC behaviour on register rich machines was to
consider changing a instance variable from a static global to a procedure local variable if after code inlining it was discovered
that all references to the variable are within a single method.  

In this case because you have two method primitiveSetOSErrorCode, and getOsErrorCode it will remain a global var,
and change to requiredMethodNames ensures the getOsErrorCode procedure gets created.


On 2009-11-25, at 8:49 PM, Rob Rothwell wrote:

> Oh...I just did:
>
> Interpreter>>primitiveSetOSErrorCode
> | value |
> self export: true.
> value := self stackIntegerValue: 0.
> successFlag ifTrue:[
> osErrorCode  := value.
> self pop: argumentCount.
> ].
>
> where
>
> osErrorCode is an instvar in Interpreter...
>
> (I found the variable declarations in interp.c, including gcBiasToGrowGCLimit like you pointed out, but I don't see how it ended up there!)
>
> Rob
>
> On Wed, Nov 25, 2009 at 11:08 PM, John M McIntosh <[hidden email]> wrote:
> How about pasting your smalltalk code for primitiveSetOSErrorCode
>
> On 2009-11-25, at 7:06 PM, Rob Rothwell wrote:
>
> > I miraculously managed to somehow load VMMaker in Pharo on Windows XP.
> >
> > Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.
> >
> > I was even able to use that primitive without the VM crashing!
> >
> > But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...
> >
> > Any tips?  Is there something special you have to do to create the instance variables?
> >
> > Thanks again for pointing me in the right direction...
> >
> > Rob
> --
> ===========================================================================
> John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
>
>
>
>
>

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

johnmci
In reply to this post by Rob Rothwell

PS, in general I don't recommend doing the cross file reference to osErrorCode and have the
linker do the right thing, because.

(a) some platforms make better memory references if globals are static.
(b) some platforms use the global VM Foo memory structure so you can't refer to osErrorCode directly it's  foo->osErrorCode

So by having getOsErrorCode()  hides where the value really comes from.

However technically if one was wanting to ensure there is no external references to interp.c you would
alter sqVirtualMachine.h and add a set/get api for the Error code then use interpreterProxy-> to access
the data.  However that's a bit more work than required for a one-off solution.


On 2009-11-25, at 9:01 PM, Rob Rothwell wrote:

> Then, of course, all I want to do is something like:
>
> int ioExit(void)
> {
>   inCleanExit = 1;
>   exit(osErrorCode);
>   /* avoid the warnings here */
>   return 0;
>
> in sqWin32Window.c...

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
In reply to this post by johnmci
 
Wow!  Thanks for all the useful information.  Very hard to glean from the various wiki's out there...

I can't wait to give this a try...but I have promised to cook for my in-laws in the morning!

Take care,

Rob

On Thu, Nov 26, 2009 at 12:13 AM, John M McIntosh <[hidden email]> wrote:
Well let's see likely you should have in
ObjectMemory>>initializeObjectMemory:
osErrorCode := 0 ;

just for completeness to ensure it has a explicit value you set, versus a supposed zero value.

Now you need an accessor.

So on
Interpreter>>getOsErrorCode
       ^osErrorCode;

and likely you need to add
getOsErrorCode as a required method to the requiredList in
Interpreter (class)>>requiredMethodNames.

Otherwise the Slang logic will delete the method getOsErrorCode as not being used and it
won't generate the expected "C" code.

Then in your platform ioExit()  you need to add
extern sqInt getOsErrorCode(void);

sqInt myReturnErrorCode = getOsErrorCode();


To answer your other question, if an instance variable is declared in the ObjectMemory or Interpreter class it ends up
as a static variable in interp.c (or in the global Foo structure), unless a unique condition is met.

The Slang generator inlines methods so methods not in requiredMethodNames could be folded into the caller.
This historically has generated better code than what compiler in-line optimization can do.
If a method can be folded into the caller, then based on  requiredMethodNames it might not exist as a standalone method anymore.

Now a special further optimization which greatly improved GC behaviour on register rich machines was to
consider changing a instance variable from a static global to a procedure local variable if after code inlining it was discovered
that all references to the variable are within a single method.

In this case because you have two method primitiveSetOSErrorCode, and getOsErrorCode it will remain a global var,
and change to requiredMethodNames ensures the getOsErrorCode procedure gets created.


On 2009-11-25, at 8:49 PM, Rob Rothwell wrote:

> Oh...I just did:
>
> Interpreter>>primitiveSetOSErrorCode
>       | value |
>       self export: true.
>       value := self stackIntegerValue: 0.
>       successFlag ifTrue:[
>               osErrorCode  := value.
>               self pop: argumentCount.
>       ].
>
> where
>
> osErrorCode is an instvar in Interpreter...
>
> (I found the variable declarations in interp.c, including gcBiasToGrowGCLimit like you pointed out, but I don't see how it ended up there!)
>
> Rob
>
> On Wed, Nov 25, 2009 at 11:08 PM, John M McIntosh <[hidden email]> wrote:
> How about pasting your smalltalk code for primitiveSetOSErrorCode
>
> On 2009-11-25, at 7:06 PM, Rob Rothwell wrote:
>
> > I miraculously managed to somehow load VMMaker in Pharo on Windows XP.
> >
> > Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.
> >
> > I was even able to use that primitive without the VM crashing!
> >
> > But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...
> >
> > Any tips?  Is there something special you have to do to create the instance variables?
> >
> > Thanks again for pointing me in the right direction...
> >
> > Rob
> --
> ===========================================================================
> John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
>
>
>
>
>

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
In reply to this post by johnmci
 
On Thu, Nov 26, 2009 at 12:18 AM, John M McIntosh <[hidden email]> wrote:
PS, in general I don't recommend doing the cross file reference to osErrorCode and have the
linker do the right thing, because.

(a) some platforms make better memory references if globals are static.
(b) some platforms use the global VM Foo memory structure so you can't refer to osErrorCode directly it's  foo->osErrorCode

So by having getOsErrorCode()  hides where the value really comes from.

However technically if one was wanting to ensure there is no external references to interp.c you would
alter sqVirtualMachine.h and add a set/get api for the Error code then use interpreterProxy-> to access
the data.  However that's a bit more work than required for a one-off solution.

I think I might have to figure this out for this "one-off" solution!

My setOSErrorCode "works" when I start the image up by dragging the image onto the executable in Windows XP, or at least the primitive appears to execute!

However, when I test the whole point of the exercise by running a batch file with something like:

start /wait squeak.exe working.image
echo %errorlevel%

Interpreter>>setOSErrorCode (my new primitive) fails!

So...starting from Windows works; starting from a DOS-box fails.  Seems like a memory management thing to me?

It's been a long time, but does anyone try to debug this sort of thing with an actual debugger?  Throw an INT 9 in there and watch what happens?  I might have an old copy of Turbo Debugger somewhere...

Thanks again.  I'll try to figure out how to use interpreterProxy and see what happens...

Rob

 


On 2009-11-25, at 9:01 PM, Rob Rothwell wrote:

> Then, of course, all I want to do is something like:
>
> int ioExit(void)
> {
>   inCleanExit = 1;
>   exit(osErrorCode);
>   /* avoid the warnings here */
>   return 0;
>
> in sqWin32Window.c...

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





Reply | Threaded
Open this post in threaded view
|

Re: Return a value from the image to the VM

Rob Rothwell
 
Never mind!

I had an error in my batch file!  I wasn't running my newly created VM!

It works.

Now just need to work on improving the command line parsing...

Rob

On Thu, Nov 26, 2009 at 8:18 AM, Rob Rothwell <[hidden email]> wrote:
On Thu, Nov 26, 2009 at 12:18 AM, John M McIntosh <[hidden email]> wrote:
PS, in general I don't recommend doing the cross file reference to osErrorCode and have the
linker do the right thing, because.

(a) some platforms make better memory references if globals are static.
(b) some platforms use the global VM Foo memory structure so you can't refer to osErrorCode directly it's  foo->osErrorCode

So by having getOsErrorCode()  hides where the value really comes from.

However technically if one was wanting to ensure there is no external references to interp.c you would
alter sqVirtualMachine.h and add a set/get api for the Error code then use interpreterProxy-> to access
the data.  However that's a bit more work than required for a one-off solution.

I think I might have to figure this out for this "one-off" solution!

My setOSErrorCode "works" when I start the image up by dragging the image onto the executable in Windows XP, or at least the primitive appears to execute!

However, when I test the whole point of the exercise by running a batch file with something like:

start /wait squeak.exe working.image
echo %errorlevel%

Interpreter>>setOSErrorCode (my new primitive) fails!

So...starting from Windows works; starting from a DOS-box fails.  Seems like a memory management thing to me?

It's been a long time, but does anyone try to debug this sort of thing with an actual debugger?  Throw an INT 9 in there and watch what happens?  I might have an old copy of Turbo Debugger somewhere...

Thanks again.  I'll try to figure out how to use interpreterProxy and see what happens...

Rob

 


On 2009-11-25, at 9:01 PM, Rob Rothwell wrote:

> Then, of course, all I want to do is something like:
>
> int ioExit(void)
> {
>   inCleanExit = 1;
>   exit(osErrorCode);
>   /* avoid the warnings here */
>   return 0;
>
> in sqWin32Window.c...

--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================