[GOODIE] named primitives without dynamic loading

Tim Rowledge rowledge at interval.com
Thu Dec 9 23:50:45 UTC 1999


On Thu 09 Dec, ohshima at is.titech.ac.jp wrote:

>   I wrote a snippet of code to make the named primitive
> mechanism works on the platform where the dynamic loading
> (by name) is not supported.
> 
>   The idea is to generate a C data something like:
> 
> int (*namedPrimitivesAddr[])() =
>   {setInterpreter, gePrimitiveAddLine,
>    gePrimitiveAddRect, gePrimitiveSetDepth,
>    gePrimitiveSetOffset, gePrimitiveGetTimes, ...};
> 
> whose entries are the exported C functions, and lookup the
> address of the called primitive at runtime.

I have a similar problem with the Acorn, the named prims that are compiled into
the VM are tricky to find reliably. Luckily, I found a utility to do the
external plugins calling!
I'd like to sugest a much simpler solution, based on the observation that
finding the address does not need to be fast since it is done only one and the
result is recorded in the method literals. This avoids the need to worry about
hashing, and I claim that simple strcmp() searching would be ok.
If we change the codegen to produce a structure with the function name strings
and addresses, we can just run through it in a linear fashion.
The good news is that it is completely known how many entries are needed and
how many characters each function name uses so it should be simple to make the
structure - an array of {(char *)name; *addr()} like structs would do, with the
strings off in some long char array.

tim

-- 
Useful Latin Phrases:- Nullo metro compositum est.
It doesn't rhyme.
Tim Rowledge:  rowledge at interval.com (w)  +1 (650) 842-6110 (w)
 tim at sumeru.stanford.edu (h)  <http://sumeru.stanford.edu/tim>





More information about the Squeak-dev mailing list