all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Danny Milosavljevic <dannym@scratchpost.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: Binding generator, for Guile, to C libraries
Date: Thu, 6 Jul 2017 21:57:28 +0200	[thread overview]
Message-ID: <20170706215728.34f1806e@scratchpost.org> (raw)
In-Reply-To: <8737aasg7z.fsf@gnu.org>

Hi Ludo,

On Wed, 05 Jul 2017 23:53:36 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

> Danny Milosavljevic <dannym@scratchpost.org> skribis:
> 
> > Okay, I've cleaned up what I have and put it on github, under:
> >
> > https://github.com/daym/guile-gcc-unit
> >
> > What this does is it allows you to read gcc output files which specify all the prototypes - in our case in order to extract the prototypes and generate Guile bindings (of parted, or whatever).
> >
> > The next steps:
> > - Provide the actual binding generator (I started a version of it - I'll commit a cleaned-up version in a few days I guess).

> > - Get it to work with non-toy examples (see file "tests/huge/input" for the parted non-toy example - the goal is to read this file, find all the record decls and all the function decls in it

This part is working now, also for parted.

> and generate the Guile pendants of them).  If you happen to know LALR parsing theory, I have a question :)
> > - Find out whether that can be integrated as a Guile "language".  Just being able to do something like ',load "foo.h"' and have it register all the functions from it would be way cool.  On the other hand, on non-Guix systems the header files aren't usually installed when the library is installed.  So maybe an offline version would be good as well.  
> 
> Matt Wette, the author of nyacc, was apparently in the process of
> writing a similar tool using nyacc’s C99 parser.  Might be worth looking
> at.

Nice!  I've actually thought about using nyacc and mes for that - but since we use gcc to compile everything, we can also use gcc to find out what it compiled - it's more probable that that actually matches up.  What I like is that gcc actually dumps the declarations even when you *don't* call the function.  So you can actually create a mostly-empty source file with #include in it and gcc will give you everything that is in scope.

But it's definitely worth taking a look at Matt Wette's actual Guile dynamic-* generator, maybe that can be shared between the projects.

> Besides and FWIW, I’m skeptical of binding generators.  Things like
> SWIG, for instance, generate interfaces that are often not quite what
> you’d like, so you end up writing a layer on top of the generated glue
> anyway, not to mention annotation in headers. 

Yeah, probably the bindings will suck a bit.  But one can always write a wrapper and not export all the original functions from there.  Rust for example has a "...-sys" convention where the package "foo-sys" contains the easily-generated bindings and the package "foo" contains the actually simple high-level bindings.

What I don't want is to manually maintain all the bindings.  It's a computer, it should automate it :P

Writing "override" declarations (or maybe even just literally overwriting the definition in Scheme) once every few months I'm fine with.  Adapting the bindings every time upstream adds a function?  No.

If I plan to use something like the "...-sys" convention in Guile, can I somehow re-export all the same names as the "-sys" package did, in a non-sys package?

For example:

(define-module (foo-sys)
  #:export (a b c))

...
------
(define-module (foo)
  #:re-export (same-names-as-in foo-sys, but use newer versions from below if applicable))

(define (b ...)
  fix it up)
-----
Hmm, I guess I can use (include-from-path "foo-sys") in the second module before I overwrite anything.

> (Bindings generated from
> high-level descriptions like GIR and XCB are a different story; those
> seem to work quite well.)

Yeah, I like glib's approach with the def files which specify also the object lifetimes etc.

  reply	other threads:[~2017-07-06 19:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 22:16 Looking to contribute cinder88
2017-06-28 13:49 ` Danny Milosavljevic
2017-06-28 15:01   ` Leo Famulari
2017-06-29 15:49     ` Danny Milosavljevic
2017-06-29 17:02       ` Mekeor Melire
2017-07-01 13:15         ` Deleting system generations Ludovic Courtès
2017-07-01 15:32           ` Thomas Danckaert
2017-07-02 20:22             ` Ludovic Courtès
2017-06-29 13:22   ` Looking to contribute cinder88
2017-06-29 13:46     ` Katherine Cox-Buday
2017-06-29 15:25     ` Alex Vong
2017-06-29 16:42     ` Pjotr Prins
2017-07-02 23:30     ` Binding generator, for Guile, to C libraries Danny Milosavljevic
2017-07-04  0:41       ` Installer development Danny Milosavljevic
2017-07-05 21:53       ` Binding generator, for Guile, to C libraries Ludovic Courtès
2017-07-06 19:57         ` Danny Milosavljevic [this message]
2017-07-07 11:41           ` Ludovic Courtès
2017-07-05 13:20   ` Looking to contribute Danny Milosavljevic
2017-07-07 11:34     ` Installer, ISO9660, etc Ludovic Courtès
2017-07-07 16:13       ` Danny Milosavljevic
2017-07-09 20:08         ` Ludovic Courtès
2017-07-10 13:41           ` Danny Milosavljevic
2017-07-10 21:02             ` Ludovic Courtès
2017-07-10 21:27               ` Danny Milosavljevic
2017-07-11  9:23                 ` Ludovic Courtès
2017-07-11 10:13                   ` Danny Milosavljevic
2017-06-28 13:56 ` Looking to contribute Alex Vong
2017-06-28 17:41 ` James Richardson

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170706215728.34f1806e@scratchpost.org \
    --to=dannym@scratchpost.org \
    --cc=guix-devel@gnu.org \
    --cc=ludo@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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.