primitive objects (was: Image format proposals...)

Jecel Assumpcao Jr jecel at merlintec.com
Sat Feb 9 23:24:10 UTC 2002


I have a proposal for a radical change in the image format/VM that I 
might have posted here before, though I don't think so.

I like objects and messages and it seems a shame to me to abandon them 
when we get to the primitives. An alternative design would be to have 
"primitive objects" implemented in machine language (C or whatever) so 
that messages sent to them (using the regular send bytecodes) would be 
directly executed without further message sends. Something like

               IntegerALU add: 3 and: 4

This would be even better if integrated into the exception mechanism.

   SmallInteger>>+ aNumber
    "primitive addition between two SmallIntegers"

    [ IntegerALU add: self and: aNumber ] ifError:
                    [:err :rcvr | ^ super + aNumber]

Better still, this could be integrated with the plugin system so that 
some of these global objects could actually be written in Smalltalk and 
the code would work slowly. By loading a pluging, the Smalltalk object 
would be overlaid with the primitive equivalent and everything would 
run much faster.

It would be a simple alternative to numbered primitives, named 
primitives and plugins. Backward compatibility would be possible by 
extending the compiler so it could generate the above code when reading 
in

   SmallInteger>>+ aNumber
    "primitive addition between two SmallIntegers"

    <primitive 1>
    ^ super + aNumber

The two problems with my idea are memory and performance. In the 
example I gave we would trade a few bits in the method object header 
for several additional literals and bytecodes. And of course, a naive 
execution of all the extra bytecodes (specially block creation ones) 
would make things run much slower than the current scheme (though it 
might make things simpler and faster for Jitter 3....).

-- Jecel



More information about the Squeak-dev mailing list