(Apologies for nagging folks again, but I never received answers to any of my plugin questions. While creating plugins may not be nearly as exciting as discussing licensing issues, it is far more important to my current project. :) )
Here is a re-post of my latest plugin question:
I have a trivial plugin:
TestInterpreterPlugin subclass: #MyPlugin instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Eric-Test'
With a "primitive" method I intend to compile to C:
innerLoopX: x y: y limit: escape | | self primitive: 'primGuy' parameters: #(SmallInteger SmallInteger SmallInteger) receiver: #Oop. ^ (escape + x + y) asOop: SmallInteger
(Note, simplified to do nothing useful, but illustrates the problem)
If I execute:
MyPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments #(1 1 1)
I would expect to get 3. Instead, I get a walkback:
Error: attempt to index non-existent element in an ordered collection
OrderedCollection(Object)>>error: OrderedCollection>>errorNoSuchElement OrderedCollection>>at: InterpreterProxy>>stackValue: InterpreterProxy>>stackIntegerValue: MyPlugin>>DoItIn: Compiler>>evaluate:in:to:notifying:ifFail: [] in TestTMethod>>simulatePrologInContext: Array(SequenceableCollection)>>keysAndValuesDo: TestTMethod>>simulatePrologInContext: MyPlugin(Object)>>primitive:parameters:receiver: MyPlugin>>innerLoopX:y:limit: MyPlugin class(TestInterpreterPlugin class)>>doPrimitive:withArguments:
What am I doing wrong?
-Eric
Hi,
This is a bug. Attached is a version which fixes these problems. If you are running pre-3.6 you'll have to substitute TestInterpreterPlugin for SmartSyntaxInterpreterPlugin as it is named in 3.6.
Cheers, - Andreas
-----Original Message----- From: squeak-dev-bounces@lists.squeakfoundation.org [mailto:squeak-dev-bounces@lists.squeakfoundation.org] On Behalf Of Eric Scharff Sent: Tuesday, September 02, 2003 10:59 PM To: squeak-dev@lists.squeakfoundation.org Subject: HELP! with plugins
(Apologies for nagging folks again, but I never received answers to any of my plugin questions. While creating plugins may not be nearly as exciting as discussing licensing issues, it is far more important to my current project. :) )
Here is a re-post of my latest plugin question:
I have a trivial plugin:
TestInterpreterPlugin subclass: #MyPlugin instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Eric-Test'
With a "primitive" method I intend to compile to C:
innerLoopX: x y: y limit: escape | | self primitive: 'primGuy' parameters: #(SmallInteger SmallInteger SmallInteger) receiver: #Oop. ^ (escape + x + y) asOop: SmallInteger
(Note, simplified to do nothing useful, but illustrates the problem)
If I execute:
MyPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments #(1 1 1)
I would expect to get 3. Instead, I get a walkback:
Error: attempt to index non-existent element in an ordered collection
OrderedCollection(Object)>>error: OrderedCollection>>errorNoSuchElement OrderedCollection>>at: InterpreterProxy>>stackValue: InterpreterProxy>>stackIntegerValue: MyPlugin>>DoItIn: Compiler>>evaluate:in:to:notifying:ifFail: [] in TestTMethod>>simulatePrologInContext: Array(SequenceableCollection)>>keysAndValuesDo: TestTMethod>>simulatePrologInContext: MyPlugin(Object)>>primitive:parameters:receiver: MyPlugin>>innerLoopX:y:limit: MyPlugin class(TestInterpreterPlugin class)>>doPrimitive:withArguments:
What am I doing wrong?
-Eric
First problem is that Eric's original example is wrong - with a prim named 'primGuy' he should have been doing not:-
MyPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments #(1 1 1)
but MyPlugin doPrimitive: #primGuy withArguments #(1 1 1)
The problem with the proposed fix is that there is no trivial mapping fr mthe name the primitive is given in the #primitive:parameters:.... message and the actual method name! Some variety of looking at all the methods in the relevant class, seeing if they send #primitive: or #primitive:parameters: (etc) and the working ou the argument for the primitive name will be needed. Ugly.....
On Tuesday 02 September 2003 01:58 pm, Eric Scharff wrote:
MyPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments #(1 1 1)
I would expect to get 3. Instead, I get a walkback:
#doPrimitive:withArguments: isn't called in the usual way. The idiom is that it is called from a method that tried to call a primitive:
Object subclass: #EricsPluginUser instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Test'
Then in EricsPluginUser, define:
innerLoopX: x y: y limit: escape
<primitive: 'primGuy' module: 'EricsPlugin'> ^EricsPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments: { x. y. escape }
Then try to use it:
u _ EricsPluginUser new. u innerLoopX: 1 y: 1 limit: 1
Which returns 3, as expected.
innerLoopX: x y: y limit: escape
<primitive: 'primGuy' module: 'EricsPlugin'> ^EricsPlugin doPrimitive: 'innerLoopX:y:limit:' withArguments: { x. y. escape }
Thanks Ned and Bob! Both this (and the class method version) worked great. I didn't realize that the InterpreterProxy was so sensitive to method contexts coming from method calls (and not plain doits from a workspace).
Now I can test my plugin code without translating it *again* and *again*. :)
Thanks again,
-Eric
squeak-dev@lists.squeakfoundation.org