[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Binding generator, for Guile, to C libraries
From: |
Danny Milosavljevic |
Subject: |
Binding generator, for Guile, to C libraries |
Date: |
Mon, 3 Jul 2017 01:30:35 +0200 |
Hi,
> >- Currently, the installer invokes the parted executable for
> >partitioning which is quite jarring (it looks very different). It
> >would be nice if it just used the parted library. But there's no
> >good guile-parted yet. I've started hacking on one and it's
> >starting to look OK but it's not done. If you are interested in
> >that I can upload it somewhere (github, gitlab etc).
> I would be happy to work on this.
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 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.
Example Makefile:
---------------------------------------------------
.PHONY: clean all distclean
CC = gcc
all: parted.lu
guile -L . main.scm $^
a.c:
echo "#include <parted/parted.h>" > a.c.new && mv a.c.new a.c
parted.lu: a.c
$(CC) -fsyntax-only -fdump-tree-all-graph=$@ $^
clean:
rm -f a.c
distclean: clean
rm -f parted.lu
--------------------------------------------------
To test it, put this file into guile-gcc-unit (as "Makefile") and then invoke
"guix package -i parted" and then invoke "make".
(I didn't commit it to the repo yet because maybe we can put guile-parted into
an extra repo? Or even just have a helper script that does it all without any
extra repo?)
For the bindings generator, if you want to play with it, what I already can
share is:
(use-modules (system foreign))
(define-public %parted-library (dynamic-link
"/gnu/store/ddpg6rlr5f3xv8fjh8812ll9g584x51z-parted-3.2/lib/libparted"))
(define-public enum-_PedPartitionType
(make-enumeration '(
PED_PARTITION_NORMAL ; 0
PED_PARTITION_LOGICAL ; 1
PED_PARTITION_EXTENDED ; 2
reserved3 ; 3
PED_PARTITION_FREESPACE ; 4
reserved5 ; 5
reserved6 ; 6
reserved7 ; 7
PED_PARTITION_METADATA ; 8
reserved9
reserved10 ; 10
reserved11 ; 11
reserved12 ; 12
reserved13 ; 13
reserved14 ; 14
reserved15 ; 15
PED_PARTITION_PROTECTED ; 16
)))
(define-public long-long uint64)
(define-public PedSector long-long)
(define ped_disk_set_partition_geom (pointer->procedure int (dynamic-func
"ped_disk_set_partition_geom" %parted-library) '* '* '* PedSector PedSector))
So that's the kind of code that should be generated in the end (not sure
whether in Tree-IL or whether to go via the Scheme intermediary).
For the binding generator, I'm thinking of having a global hashtable containing
what symbols are known from C header files - and what is known about them.
So (hypothetical) usage would be like:
; Magically registers all the external function declarations in some global
hashtable (only the declarations, no shared object)
,load "parted/parted.h"
(define-public %parted-library (dynamic-link
"/gnu/store/ddpg6rlr5f3xv8fjh8812ll9g584x51z-parted-3.2/lib/libparted"))
(define ped_disk_set_partition_geom (dynamic-callable-func
"ped_disk_set_partition_geom" %parted-library))
(ped_disk_set_partition_geom ...)
Wouldn't that be cool?
If that's too lowlevel, check out guix wip-installer and try using gurses,
John's ncurses frontend. The installer is under "gnu/system/installer/" :)
We eventually would like to have a nice partitioning interface in the
installer. So if you'd like to you can also add some pages there.
In order to do that, see gnu/system/installer/guixsd-installer.scm . It
contains the list of pages that are used in the installer. You can add your
own pages there.
See gnu/system/installer/mount-point.scm for a simple page.
- Binding generator, for Guile, to C libraries,
Danny Milosavljevic <=