Plug in primitive help

agree at agree at
Thu Feb 11 20:42:10 UTC 1999

Right -- the loop is basically eating up the execution stack.

After execution of the primitive, you need to have PRECISELY ONE value left on 
the stack as a return value.  In the case of a parameterless prim, leaving the 
rcvr on the stack without removing is the equivalent of ending with the squeak 
code "^self."  

The sole exception to this is when the primitive fails.  In this case, you 
DON'T want to have messed with the stack, since the Smalltalk code will want 
to access the parameters, etc.  Accordingly, you should only do the popping of 
parameters and rcvr, followed by a push of the return value at the end before 
returning, so that failures are handled properly.

However, if you want to return something other than self, you should pop the 
receiver as well and then push back the thing you want to return.

-----Original Message-----
From:	MIME :jb at 
Sent:	Thursday, February 11, 1999 3:08 PM
To:	squeak at
Subject:	Plug in primitive help


I am confused. I am writing a primitive plug in, but I am unsure of if I need
to pop the receiver and the end of the primitive.

For example:

Tester plug in code:

    self export: true.
    self inline: false
    interpreterProxy pop: 1.  " pop the receiver "

Tester code:
    <primitive: 'primTest' module: 'TestPlug'>
    ^ self primitiveFailed.

If I place this puppy into a while loop:

    tester := Tester new.
    [ false ] ifFalse: [ tester testPop ].

The machine dies a horrible death. If I don't pop the receiver, it appears to
work fine.

Please tell me the errors of my ways. I am under the delusion that I need to
pop the receiver off the stack in a primitive call.


 << File: FILE0001.HTM >>  << File: ENVELOPE.TXT >> 

More information about the Squeak-dev mailing list