Doc for writing Pluggable Prims?

David T. Lewis lewis at mail.msen.com
Wed Jul 21 02:59:50 UTC 1999


On Tue, Jul 20, 1999 at 08:24:32AM -0700, Stephen Travis Pope wrote:
> 
> Hello all,
> 
> I'm about to port the Siren MIDI primitives to be a DLL-style loadable
> library and was hoping that some kind soul could point me to a simple
> how-to swiki page about porting old-fashioned primitives to the
> pluggable API -- does such a thing exist?

Shucks, I figured out how to write a few pluggable primitives by reading
your own excellent tutorial at:
   http://www.create.ucsb.edu/squeak/DIYSqPrims.html

.... and by plagiarizing some source in the image.

I suppose the least I could do is try to return the favor by documenting
some differences for pluggable primitives. I'm afraid I won't have
time for a while, but I can safely predict that you'll have no big
troubles.

In any case, I think that the only real difference is that when you are
doing a pluggable primitive in a loadable module, you are using an
InterpreterProxy (instance variable interpreterProxy in InterpreterPlugin,
which is what you subclass your plugin from) to map function pointers in
the generated C code. This is in contrast to old fashioned primitives,
which just translate down into straight C functions.

This means you'll be sending messages to interpreterProxy in your
Smalltalk code, and these messages will get transmogrified into function
pointers which point to interpreter functions in the VM. The available
function pointers are in sqVirtualMachine.h, and many of the corresponding
functions are generated from Smalltalk code in Interpreter class.

Modules are loaded when you call a method that contains code such as:
  <primitive: 'primitiveMyNewPrim' module: 'MyNewPrims'>

The function pointers all get fixed up when the loadable module is loaded,
and everything magically starts working from that point on.





More information about the Squeak-dev mailing list