From: Matt Wette <matt.wette@gmail.com>
To: guile-user@gnu.org
Subject: Re: ffi helper
Date: Mon, 13 Mar 2017 17:53:59 -0700 [thread overview]
Message-ID: <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com> (raw)
In-Reply-To: <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@gmail.com>
> On Mar 8, 2017, at 6:06 PM, Matt Wette <matt.wette@gmail.com> 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 into
(udecl (decl-spec-list
(type-spec (float-type "double")))
(init-declr
(array-of (ident "x") (p-expr (fixed "10"))))
(comment " state vector “))
And “udecl->mspec/comm” will convert the above into
("x"
" state vector "
(array-of "10")
(float-type "double”))
I am in the process of cleaning up the above in order to convert some function signatures.
Matt
next prev parent reply other threads:[~2017-03-14 0:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 2:06 ffi helper Matt Wette
2017-03-11 11:38 ` Taylan Ulrich Bayırlı/Kammer
2017-03-11 19:55 ` David Pirotte
2017-03-14 0:53 ` Matt Wette [this message]
2017-03-19 17:23 ` Matt Wette
2017-03-20 14:49 ` Taylan Ulrich Bayırlı/Kammer
2017-03-21 22:40 ` Matt Wette
2017-04-18 2:26 ` Matt Wette
2017-05-13 16:19 ` Matt Wette
2017-03-23 17:43 ` Amirouche
2017-03-24 1:43 ` Matt Wette
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com \
--to=matt.wette@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).