[Newbies] Questions about primitives - how to avoid one ?
David T. Lewis
lewis at mail.msen.com
Sun Feb 17 23:23:02 UTC 2008
On Sun, Feb 17, 2008 at 11:30:18PM +0100, cdrick wrote:
> For whatever reasons, I want sometimes to experiment some smalltalk
> code by avoiding a primitive call, like in Float>>=, which start by
> <primitive:47>. Only commenting doesn't work. So, is it possible ? and
> if the primitive fail, is the smalltalk code evaluated ?
If you comment out the primitive like this is should definitely work:
"Primitive. Compare the receiver with the argument and return true
if the receiver is greater than the argument. Otherwise return false.
Fail if the argument is not a Float. Essential. See Object documentation
^ aNumber adaptToFloat: self andSend: #>
And yes, if the primitive fails, the alternative Smalltalk (after the
"<primitive: 44>" is evaluated.
> Out of curiosity, where can we find the "primitive 47" code ? I
> imagine in the source of the VM... but if someone can give me some
> insights :)
Load the VMMaker package to see the source code. Look at
Interpreter class>>initializePrimitiveTable to find the method that
implements primitive 47, which is #primitiveFloatEqual. Find implementers
of #primitiveFloatEqual, and you will have the Smalltalk source code.
This will be translated from Smalltalk to C when you generate the VM,
and the resulting C is what implements the primitive.
More information about the Beginners