|
Hi
I'm currently teaching the ObjVlisp reflective kernel and the
students have to implement it in VW.
Now I realized that I have a bug for the error (equivalent of DNU).
And I wanted to know
how the squeak VM does it.
My bug is the following one:
when a message is not understood, the message error is raised. By
default on Object error raises an Error.
Now when I redefine the method error on a class, I do not cancel the
application of the
method that was not found. So I end up applying (value: self in the
unarySend: method below)
the old arguments of the not-found message to the result of the
redefined error method and this should not
happen.
I have the impression that the solution is to cancel the application
of the found method when there is an error.
And I wanted to know what the Squeak VM does?
Here how I did it in my ObjVlisp implementation:
Obj is a subclass of Array I use to represent objects and block to
represent methods
Obj>>lookup: selector for: anObjObject
^(self doesUnderstand: selector)
ifTrue: [ self bodyOfMethod: selector]
ifFalse: [self objName = #ObjObject
ifFalse: [ (Obj giveClassNamed: self objSuperclassId) lookup:
selector for: anObjObject.]
ifTrue: [ anObjObject binarySend: #error with: selector
"this should be escaping the flow"]].
Obj>>unarySend: selector
| ans |
"should do something different to deal with the fact that error can
be redefined"
ans := (self objClass lookup: selector for: self) value: self.
^ ans
The method error is defined as follow.
(objectClass at: objectClass offsetForMethodDict) at: #error
put:
[:object :selector |
Transcript show: 'Error: selector ' , selector printString , 'not
understood';
cr.
object error].
So the following code work well when I do not redefine error but not
when I redefine it.
|