[Fun][Weird][VM] Objects as compiled methods
andreas.raab at gmx.de
Sat May 17 18:42:31 UTC 2003
For some experimentation I wanted to have the ability to have *any* object
act as a compiled method, so that it can be 'invoked' as if it were a
function. I've just published a package for this at SqueakMap.
>From the description:
Nothing for the faint-hearted. This package is a VM modification which
arbitrary objects to 'act' like CompiledMethods. In other words, if you want
to have some object to act like a method you merely add it to the
method dictionary, like in:
Object addSelector: #foo:bar: withMethod: FooBarAlgorithm.
When you now say something like:
someObject foo: 42 bar: 'mumble'.
the special message #run:with:in: will be sent to FooBarAlgorithm so you
handle it like this:
FooBarAlgorithm class>>run: originalSelector with: argsArray in: aReceiver
"Run the FooBarAlgorithm when invoked via originalSelector from
argsArray contains the arguments passed along with the original invokation."
Pretty cool, eh? Needless to say, the package requires a new VM. Without it,
the supplied tests will horribly crash your system.
More information about the Squeak-dev