pluggable primitive(S)?

Stephen Pair spair at advantive.com
Thu May 13 17:55:47 UTC 1999


Actually, you can create one pluggable primitive to call any external
module.  I did a little work in this area a while back, but due to time
constraints, I haven't pushed it far enough to be comfortable making it
available.  The trick is to make a framework that can handle any type of
calling convention on any type of hardware (abstrations for the machine code
for thunking on various hardware platforms is needed here).  I prefer to do
that type of abstraction in the image (not down in the VM).

Also, you'll want to create a framework that can handle the marshalling of
objects to any sort of external data type (not just the basic C types and
structures).  This is the more time consuming part, and the part you want to
make sure is very well architected.  Living with a bad implementation will
be real headache in this area.

As a pre-req, you also need a mechanism for putting bytes into a fixed place
in memory.  I did a little bit of work with that too (under NT, not the
mac...incidentally, I would love to have one of those sexy G3s for doing
Squeak stuff) and pretty much completed it, but I couldn't get anyone to
port it to other platforms (any takers?...Tim R. did do a little code review
of it and gave me some tips though...thanks).

Also, once all of that is done, you could then bolt on a C header parser to
automatically create function prototype descriptors (and similar tools for
other languages), and then spit that out into a handy "sub-image" that only
gets loaded if the particular external module is needed.

Of course, the danger here is that people will be tempted to simply
interface external code rather than re-write the code in Squeak.  In some
situations the external interface is warranted, but in others, the extra
work to port it would be preferable.  But, I'd rather have the rope than the
executioner!

- Stephen

> -----Original Message-----
> From: daanth at wnt.sas.com [mailto:daanth at wnt.sas.com]
> Sent: Thursday, May 13, 1999 11:58 AM
> To: squeak at cs.uiuc.edu
> Subject: Re: pluggable primitive(S)?
>
>
> I am suggesting this with zero actual experience writing pluggable
> primitives, but, couldnt you
> write just ONE pluggable primitive like so:
>
> JasmineDLL methods
>
>
> call: functionName with: argumentArray
>
> ^self call: functionName with: argumentArray size: argumentArray size
>
>
> call: functionName with: argumentArray size: argumentCount
>
> "This primitive calls any of the functions in the Jasmine DLL.  Put the
> arguments into
> the argumentArray in the correct order"
>
> <primitive syntax I don't know>
>
> Then the C primitive would have code something like:
>
> void * jasmineDLL_genericPrimitive (char * fname, void **argV, int argc)
> {  if argc = 0 then return (void) & jasmineDLL_zeroArgFunction(fname);
>    if argc = 1 then return (void) & jasmineDLL_oneArgFunction(fname,
> argV);
> .... etc to the maximum number of arguments in the library functions you
> are stubbing to
> }
>
> .....
> void * jasmineDLL_twoArgFunction (char * fname, void **argV)
> {   if strcmp(fname, "firstfunction") then return (void) &
> firstfunction((int) *argv[0], (char *) argv[1]);
> .... etc for each differnt 2 variable function
> }
>
> course with all the casting and stuff it'd be slower but it would work?
> the idea I mean,
> not the exact code :)
>
> Lex Spoon wrote:
> >
> > Linking in system libraries is one thing pluggable primitives
> are really good at.  You have to write a separate C "plug" for
> each function you want to link out of the library, though, which
> can be a pain.
> >
> > Lex
> >
> > "Eric Ulevik" <eau at fast.fujitsu.com.au> wrote:
> > > From: Roxie Rochat <rrochat at vline.net>
> > > >I need to connect to a Jasmine database from Squeak.
> > > >Jasmine doesn't have a Smalltalk API yet, but I have located
> > > >an ODBC wrapper.  Has anyone written or is working on
> > > >an ODBC interface for Squeak?  Or are there better alternatives?
> > >
> > > The Jasmine C-API is a lot simpler and better than ODBC. This is a DLL
> > > interface.
> > >
> > > The problem then becomes how to get from Squeak to C methods
> in a DLL..
> > >
> > > One idea, which may be sensible depending upon your
> application, is to write
> > > a separate Windows executable that makes all the Jasmine
> calls, and talks
> > > TCP/IP to Squeak.
> > >
> > > Regards,
> > >
> > > Eric Ulevik
>
> --
> Dana Lynne Goldblatt Anthony
> Internet Publications Technology at SAS Institute
> World Headquarters Cary, NC, USA
>
>





More information about the Squeak-dev mailing list