Proposal for Extensible Primitives (was: FFI)

stéphane ducasse ducasse at iam.unibe.ch
Tue Aug 15 08:26:00 UTC 2006


It seems to me that the parser is patched to deal with ffi while it  
could be made modular and in addition
the pragmas would be consistent, but I will wait for lukas answer's.

For the non breaking point we can have both approaches coexisting for  
a while.


On 15 août 06, at 02:04, Andreas Raab wrote:

> Hi Lukas -
>
> What problem exactly are you trying to solve? The way I understand  
> it the problem we have is a dependency problem - how can the FFI  
> cleanly interact with the parser. To do this, I would simply add a  
> class variable that points to some FFI support class handling the  
> parsing requests. If the FFI is loaded it registers the appropriate  
> entry point and it unregisters it when unloading. As far as I can  
> see, no further changes are needed, in particular none that break  
> compatibility.
>
> Cheers,
>   - Andreas
>
> Lukas Renggli wrote:
>> 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
>
>




More information about the Squeak-dev mailing list