Nasty VM stuff

jim benson jb at speed.net
Tue Apr 14 22:49:03 UTC 1998


Thanks Stephen :

Stephen Travis Pope wrote:

> Introduction: primitives written in C are essentially in a different
> world
> altogether than the Smalltalk object space.

The problem that I have is that there is no "Bridge" between
ObjectMemory and the primitive machine.  Most of the commercial
Smalltalks have some sort of C interface for this VM <-> ObjectMemory.
Typically they have calls such as GlobalLookup(SymbolHash("Rectangle"))
and Send(0,"new")) ( where 0 is the topmost stack item ).

There are two cases that I am currently working on. An example of the
first:

I call this example Internal Message.
Within C specific code on the Mac, the MenuBar handling is processed.
Because this code is static, there is no way to respond to anything
outside of the preconfigured bar. My first thought was just to throw an
action message from the C MenuBar handler out to Smalltalk , have some
clever Smalltalk class figure out what the MenuBar was trying to do, and

act accordingly.

Pseudocode within the C platform specific code:

    item := menu item selected.
    id := menu id.
    CleverMenuBarClass := GlobalLookup("CleverMenuBarClass").
    SendSmalltalkMessage(CleverMenuBarClass id: id item: item).

Using this strategy, I could have a MenuBar with a little more
flexibility. In my first month with Squeak, I don't know how many times
I bypassed the save image dialog that happens when you select quit from
the Squeak desktop by selecting 'Quit' from the File Menu.

The second case:

I want to have DLL calls. (These are called CodeFragments on the Mac ).
I am sort of partial to the syntax of VisualWorks DLL & C connect. So I
went and changed the Parser around to accept things like:
    < pascal Rect *NewRect ( void ) >
This is in addition to primitives of the form: < primitive: 367 >

I built my new little primitive, loaded up the stacks, merrily ran my
DLL call got ready to return to Squeak and ....

Based on the C type that I was returning,  an object  should be returned

such as  ExternalPointer, ExternalHandle, Rectangle etc. (In this case
ExternalPointer ).
Deep within the bowels of the VM with my new primitive, I realized I
wanted to instantiate an object that I knew the class name of  at
compile time, but not the physical class OOP at run time.

Thus my interest in the stack and the garbage collector. Don't mess with

Mr. GC ! This is pretty nasty stuff,  although I think it is also
"standard". After all, the VM is running the machine, and should be able

to talk to its objects somehow.

Thanks again,

Jim

Smalltalk vendors come and go, but with Squeak at least I have the code.

 
 
 
 
 
 





More information about the Squeak-dev mailing list