[TECH] Pb with primtive definition
Tim Rowledge
tim at sumeru.stanford.edu
Thu Jan 10 18:56:27 UTC 2002
Bergel Alexandre <bergel at iam.unibe.ch> is widely believed to have written:
> Hello,
>
> I have tried to set up a primtive as it was explain in Andrew C. Greenberg article ("Extending the Squeak Virtual Machine").
> So I define a method foo in a class TestPlugin derived from InterpreterPlugin.
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> TestPlugin >> foo
> self export: true.
> interpreterProxy
> pop: 1
> thenPush: (interpreterProxy booleanValueOf: true).
The problem here is a simple wrong-message; booleanValueOf: extracts a
_C_ value from a Smallalk Boolean. So, your code is putting on the stack
a 32bit word that has the bits of C's 'true' - #defined in sq.h as 1.
This is not an acceptable OOP to Squeak and so when you (for example)
have any garbage collection it will go boom.
If you try
TestPlugin>>foo
self export: true.
interpreterProxy pop:1;
pushBool: true
you should be okay.
If you made your plugin a subclass of TestInterpreterPlugin you would be
able to use the extended capabilities and do something like
TestPlugin>>foo
self primitive: 'foo'.
^myCfunctionBooleanAnswer asBoolean
tim
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Life would be much easier if I had the source code.
More information about the Squeak-dev
mailing list
|