Hi All,
I find myself using something like this to copy methods across
hierarchies:
[:s| | class |
self halt.
class := CogVMSimulator whichClassIncludesSelector: s.
StackInterpreterSimulator recompile: s from: class.
StackInterpreterSimulator organization classify: s under: (class
whichCategoryIncludesSelector: s)] value: #printStringOf:on:.
because if one simply does recompile:from: and the selector doesn't exist
in the target then one ends up with a hidden selector; it's in the method
dictionary but because it isn't in the organization it doesn't show in the
browser or in Monticello etc.
The rationale for not having recompile:from: check the organization is a
good one; when recompiling a class that has changed shape (had inst vars
added or removed) we don't want to waste cycles checking something
redundant. So how about having ClassDescription>>recompile:from: doing the
check if the receiver doesn't equal the argument class, e.g.:
ClassDescription>>recompile: selector from: oldClass
"Preserve the originalTraitMethod (if any) after recompiling a selector"
| oldMethod |
oldMethod := oldClass compiledMethodAt: selector.
super recompile: selector from: oldClass.
oldMethod originalTraitMethod ifNotNil:
[:traitMethod|
(self compiledMethodAt: selector) originalTraitMethod: traitMethod].
(self ~~ oldClass
and: [(organization numberOfCategoryOfElement: selector) = 0]) ifTrue:
[organization classify: selector under: (oldClass
whichCategoryIncludesSelector: oldClass)]
_,,,^..^,,,_
best, Eliot