Hi javier
I suggest you to read this paper:
http://www.iam.unibe.ch/~scg/Archive/Papers/Duca99aMsgPassingControl.pdf
stef
On Lundi, déc 1, 2003, at 00:15 Europe/Zurich, Javier Lanatta wrote:
Hi everybody, I'm doing a research work for my OOD class at university and I'm a little lost... So I come here looking for your help :) I'm sorry to tell you that this email is gonna be kinda long, anyway I will try to write only the most relevant things.
For this research work I have to write a set of tools that allows the user to define what should be done when a given object receives a given message. These are examples of what the tools must do:
- When a given instance of RectangleMorph receives #addMorph: this
should be logged and then the instance finally receives the #addMorph:
- When any instance of Array receives #add: this message should be
sent to the instance only if the add's argument belongs to a given class.
I have most of the model finished. But I have problems intercepting the messages.
By now I'm only trying to redirect every message to an object of a fixed class to another fixed object. Both the class of the first object and the second object are stored in the Special Objects Array. Later I will replace the receiver with a fixed object that will act as an entry point and it will redirect the message inside the "object's world" to other objects that will do all the work.
I have tried two approaches without luck.
1.- Replace the receiver @ Interpreter>>internalActivateNewMethod
I overwrote the receiver after the real receiver and its arguments are stored: ... ... "Copy the reciever and arguments..." argCount2 _ argumentCount. 0 to: argCount2 do: [:i | self storePointerUnchecked: ReceiverIndex+i ofObject: newContext withValue: (self internalStackValue: argCount2-i)].
"here comes my code" rcvr _ self internalStackValue: argumentCount. self assertClassOf: rcvr is: (self splObj: MRFAux1). successFlag ifTrue: [ self print: 'Intercepting...';cr. self storePointerUnchecked: ReceiverIndex+argumentCount ofObject: newContext withValue: (self splObj: MRFAux2). ]. "and here it ends" ... ...
MRFAux1: Contains the class of the object I want to intercept. MRFAux2: Contains the receiver.
I guess I'm storing it in the wrong position... I have tried several indexes without any good result.
2.- Send the message the same way a #doesNotUnderstand is sent @ Interpreter>>lookupMethodInClass: class
When the method is found in the dictionary I just send the message to the other object creating a message in the doesNotUnderstand fashion:
.... .... found _ self lookupMethodInDictionary: dictionary. found ifTrue: [ rcvr _ self internalStackValue: argumentCount. self assertClassOf: rcvr is: (self splObj: MRFAux1). successFlag ifTrue: self print: 'Intercepting @ lookupMethodInClass...';cr. self pushRemappableOop: (self splObj: MRFEntryPoint). self createActualMessageTo: (self splObj: MRFEntryPoint). rclass _ self popRemappableOop. messageSelector _ self splObj: MRFAux2. ^ self lookupMethodInClass: rclass ] ifFalse: [ ^ methodClass _ currentClass ]. ]. .... .... MRFAux1: Contains the class of the object I want to intercept. MRFEntryPoint: Contains the receiver. MRFAux2: Contains the selector I want to send to the new receiver.
In this case I cant compile the generated code :/
./release/gnu-interp.o: In function `findNewMethodInClass': //D/J4V13R/SqueakImages/TP/src/3.5.1/win32/gnu-interp.c:3388: undefined reference to `lookupMethodInClass' ./release/gnu-interp.o: In function `interpret': //D/J4V13R/SqueakImages/TP/src/3.5.1/win32/gnu-interp.c:6756: undefined reference to `lookupMethodInClass'
I browse the gnu-interp.c file and the function lookupMethodInClass is missiong, if I remove the lines I added the code is ok... I have no clue of what's going on.
Is there a better way to do this? Where any of my ideas right? What was wrong in their implementation?
Thanks in advance, Javier
Some background information: Squeak Version: 3.6 Virtual Machine: 3.5.1/Tea 1.9 VM (release) from June 21 2003 I've been using Squeak for about 9 months.
squeak-dev@lists.squeakfoundation.org