Proposal for Extensible Primitives (was: FFI)

Lukas Renggli renggli at gmail.com
Mon Aug 14 08:07:10 UTC 2006


I propose the following changes:

Problem: FFI is hardcoded into the Squeak parser and uses a special
parsing method. While parsing pragmas the implementation has to check
for special conditions (Parser>>pragmaStatement) to trigger special
handling of FFI functions (Parser>>externalFunctionDeclaration). This
adds unnecessary code requirements to the base image and violates the
extensibility of the system.

Current State: Squeak primitives in 3.9 are already parsed using the
pragma parser, they fully comply the new syntax. As a post operation
the parser checks for these primitive pragmas and modifies the
compiled method to call the primitive instead of the fallback code.
FFI primitives have a slightly different syntax than the pragmas
therefor are handled differently.

Solution: Unify parsing of pragmas and FFI primitives. Make the
primitive parsing extensible using pragmas.

Proceeding: As a first step I would remove all the hardcoded code to
parse Squeak and FFI primitives. Then I would tag the already
implemented methods #primitive: and #primitive:module: using the newly
introduced pragma #primitive, so that the parser is able to
automatically detect these methods and postprocess the compiled method
after the parsing.

Proceeding FFI: The FFI package would add two extension methods to the
parser, in the example below these would be #cdecel:module: and
#apicall:module:. The implementation would look similar as the current
implementation in #externalFunctionDeclaration, the parsing however
(except for the C declaration) would have been done by the pragma
parser already. The syntax of FFI primitives would need to be changed
from

	XSetBackground: xDisplay with: xGC with: bg
		<cdecl: void 'XSetBackground' (X11Display* X11GC long) module: 'X11'>
		^self externalCallFailed

to something like

	XSetBackground: xDisplay with: xGC with: bg
		<cdecl: 'void XSetBackground(X11Display* X11GC long)' module: 'X11'>
		^self externalCallFailed

As a free goodie, we could now look for all FFI calls by simply
looking at the senders of #cdecel:module: and #apicall:module:.

I can do the proposed changes. We can also discuss about the
implementation, though I won't go into any discussion if pragmas are
good or evil ;-)

Cheers,
Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list