How difficult is multiple inheritance?
Stefan Matthias Aust
sma at kiel.netsurf.de
Sat Jan 2 21:23:38 UTC 1999
Hi!
I wondered how easy (or difficult) it would be to add support for multiple
superclasses (aka parents) to Squeak. I think, there's just one method
Interpreter>>lookupMethodInClass: which would be affected by the change.
Let's say, I create a new subclass of Behavior (called MapClass) which has
an additional instance variable called "parents" that can contain nil or an
(possible empty) array of other Behavior instances.
Then I'd modify the first part of the lookup method as follows
currentClass := class.
[currentClass ~= nilObj] whileTrue: [
"{ new/replaced code"
mapClass := self lookupWithParentMaps: currentClass.
mapClass ~= nilObj ifTrue: [^ mapClass].
"}"
currentClass := self superclassOf: currentClass].
and write a new method (things in {{}} are pseudo code)
lookupWithParentMaps: aClass
| dictionary found parents mapClass dictionary |
self inline: true.
"{ copied from old method"
dictionary := self
fetchPointer: MessageDictionaryIndex
ofObject: currentClass.
found := self lookupMethodInDictionary: dictionary.
found ifTrue: [^ currentClass].
"}"
(self isMapClass: aClass) ifFalse: [^ nilObj].
parents := self
fetchPointer: {{indexOf('parents')}}
ofObject: aClass.
parents ~= nilObj ifTrue: [
1 to: {{parents size}} do: [:index |
mapClass := {{parents at: index}}.
mapClass := self lookupParentMaps: mapClass.
mapClass ~= nilObj ifTrue: [^ mapClass]]].
^ nilObj
and finally invent some solution for the #isMapClass: method (are there any
format bits left?! Does anybody know?) then, well, then would this already
add multiple inheritance?
I'd like to hear your comments before I'll actually start some VM hacking.
I'd even gracefully accept a patched and newly compiled Windows VM :-)
bye
--
Stefan Matthias Aust // Are you ready to discover the twilight zone?
More information about the Squeak-dev
mailing list
|