[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ffi helper

From: Matt Wette
Subject: Re: ffi helper
Date: Mon, 13 Mar 2017 17:53:59 -0700

> On Mar 8, 2017, at 6:06 PM, Matt Wette <address@hidden> wrote:
> I’m now working on a FFI helper based on the nyacc C99 parser.   

So, like, I think what might be useful is something that will convert a dot-h 
file to a spec file, with certain assumptions about function signatures (e.g., 
if passing a pointer to int, then the scheme implementation is a (system 
foreign) int*, or maybe a boxed integer).  

Then the spec is compiled, in a machine-dependent manner to deal with type 
sizes and alignment, to a .go file which provides scheme-callable functions.  
I’m not sure the output of the dot-H reader can be machine independent, given 
all the spaghetti code that typically exists in /usr/include.  It may be worth 
a try, later.

Also, the module should support structures.  The bytestructures package looks 
promising here.

Enums should be provided also.

CPP constants (aka #define’s) should be supported.

Do CPP macros with arguments need to be supported?   This is not just 
converting to functions, because CPP macros do not recurse (e.g., `#define 
sqrt(F) sqrt(fabs(F))’ is perfectly legal C).

Some other tidbits: 

The nyacc c99 module provides a few neat functions to support this.  One is 
expand-typerefs (was expand-decl-typerefs).  This will convert an sxml 
representation of 

  typedef const int (*foo_t)(int a, double b);
  extern foo_t fctns[2];

into one of 

  extern const int (*fctns[2])(int a, double b);

Another function, udecl->mspec, helps with the conversion as follows.  Consider

  double x[10]; /* state vector */

The c99 parser, followed by tree->udict, followed by cadr will turn the above 

  (udecl (decl-spec-list
          (type-spec (float-type "double")))
          (array-of (ident "x") (p-expr (fixed "10"))))
        (comment " state vector “))

And “udecl->mspec/comm” will convert the above into

   " state vector "
   (array-of "10")
   (float-type "double”))

I am in the process of cleaning up the above in order to convert some function 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]