[Newbies] AbstractObjectsAsMethod
stes@PANDORA.BE
stes at telenet.be
Thu Mar 11 11:15:56 UTC 2021
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
It seems the runtime (VM) defines a special selector
#define SelectorRunWithIn 49
for a message with:run:in:
I don't know the details of the purpose of this selector,
but I think the VM supports it so that subclasses of AbstractObjectsAsMethod,
not just subclasses of CompiledMethod, can be used as methods.
As a test (this could be documented somewhere, for example on wiki.squeak.org)
consider 2 classes 'Foo' and 'Bar' :
AbstractObjectsAsMethod subclass: #Foo
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'ObjectAsMethodTrivial'!
!Foo methodsFor: 'RuntimeSupport'!
run:aSelector with:arguments in:aReceiver
""
Transcript show:'in Foo run:with:in:'.
Transcript cr.
^ self! !
Object subclass: #Bar
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'ObjectAsMethodTrivial'!
!Bar class methodsFor: 'class initialization'!
addFooBar
""
self addSelector:#foobar withMethod:(Foo new).
^ self! !
Now after fileIn of the above Foo and Bar classes,
if I open a Transcript and run in a Workspace :
|p|
p _ Bar new.
Bar addFooBar.
p foobar.
will print in an open Transcript
in Foo run:with:in:
Again, I think this could/or should be documented on wiki.squeak.org,
but what happens is, I think, that if I dynamically add a message (method)
implementation to class Bar, using addFooBar, which is installing
a method #foobar using addSelector:withMethod:, then the VM dispatched
a run:with:in message to the 'method' object, which need not be a actually,
a subclass of CompiledMethod.
Also some other selectors flushCache, selector: and methodClass: seem
necessary for this feature to work.
By subclassing AbstractObjectsAsMethod, on the other hand, it is not required
to implement flushCache, selector: and methodClass: as AbstractObjectsAsMethod
is doing that, so perhaps the intented usage is to subclass
AbstractObjectsAsMethod
That is why in the above example I do:
AbstractObjectsAsMethod subclass: #Foo
If this is a standard Squeak feature, it could be on the wiki.squeak.org;
I was not able to find info on it.
David Stes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBCAAGBQJgSfvAAAoJEAwpOKXMq1MaaGkIAKlXT+qfJcTVjMXRZwABdhFP
nTYk+yxSVCarXcoNZSDM6P6dC3xurEECF2Ypkr4zN7QvogFU/4hpe90AXWNPP26E
kmX5fJy59bxld1OlNYOX3DjTx69cL8/0QKcBHdRS6Ka012WY0Af415r9bLca6kOc
b19FsWDZe9FcXJUaHqiQRBvyhQBt3NcVwYUIXlRwHEiTPfLIXqkjPlOOTlTtezRE
B9m3u0GI0ycUcj4hMb7HpSZQOlb6ADfyz4pYXr+0js3EKxiFC6VSThPB0cJpcOTl
o7dGjS2kFwX333JJfpyztETqWjmUR6s9PLGGZe9Ki2H7LsKKi4Gy35yWs33n0tI=
=tvmw
-----END PGP SIGNATURE-----
More information about the Beginners
mailing list