> On Nov 9, 2017, at 11:10 AM, Roel Janssen <r...@gnu.org> wrote: > > > Matt Wette writes: > >> Hi All, >> >> I am working on a ffi-helper: a program that will read in a C dot-h file and >> generate a Guile dot-scm file >> which defines a module to provide hooks into the associated C library. Goal >> is to release something in >> Oct 2017 but that date is likely to slip. >> >> Current shortcomings: >> 1) Guile does not currently handle some types (e..g, long long, uintptr_t). >> 2) Guile does not have support for varargs (e.g., printf(char *, ...) ). >> I may take a look at this. One idea I have is to use '... in the call >> interface spec >> and use (type . value) pairs in the calls. >> 3) The bytestructures module does not support function declarations. >> 4) ... (probably more) >> >> Someone asked to have libgit2 converted and this, and some others, turned >> out to give visibility >> to several limitations and bugs in my C parser. For one, how #include >> <foo/bar.h> is interpreted >> is not specified by the language: it is implementation defined, and I had to >> track down how libgit2 >> was including files. I also had to add some GNUC extensions (e.g., asm, >> statement-block expressions, >> include_next) to the parser and preprocessor. As one can see from the file >> listing below, libgit2 >> has a large number of files, and declarations. >> >> ... > > Thanks for creating this! It seems to be very useful and powerful. > > I wanted to try ffi-helper on htslib, but I am confused on how to get > started. Where does the "compile-ffi" subcommand for "guild" come from? > > Kind regards, > Roel Janssen
See the following, but I'm seeing a parse error so may be a bug in my C99 parser. And not sure "hts.h" is the only include you need. mwette$ git clone -b c99dev git://git.savannah.nongnu.org/nyacc.git nyacc Cloning into 'nyacc'... remote: Counting objects: 5927, done. mwette$ cd nyacc mwette$ cd examples mwette$ source env.sh mwette$ cd ffi mwette$ cp TMPL.ffi htslib.ffi mwette$ vi htslib.ffi mwette$ cat htslib.ffi ;; htslib.ffi -*- Scheme -*- (define-ffi-module (ffi htslib) #:pkg-config "htslib" #:include '("htslib/hts.h") #:inc-filter (lambda (file-spec path-spec) (string-contains path-spec "htslib/" 0)) ) ;; --- last line --- mwette$ guild compile ffi/htslib.fif ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument to disable. ;;; compiling /var/tmp/yy/nyacc/examples/scripts/compile-ffi.scm ... ;;; compiled .../c99/ffi-help.scm.go TODO: fix gen-lookup-proc: it's including imported symbols ;;; scripts/compile-ffi.scm:119:8: warning: possibly unbound variable `compile' ;;; compiled /Users/mwette/.cache/guile/ccache/2.2-LE-8-3.A/private/var/tmp/yy/nyacc/examples/scripts/compile-ffi.scm.go ffi-help: WARNING: the FFI helper is experimental /opt/local/include/htslib/hts.h:774: parse failed at state 313, on input "U" (unknown):1: C99 parse error *** compile-ffi: parse failed The offending line is the following, which seems to indicate my lexer is not reading "LLU" constants. I will check. v = ((v & 0x00000000FFFFFFFFLLU) << 32) | (v >> 32); Had the above worked, then you should be able to `(use-modules (ffi htslib))': mwette$ guile GNU Guile 2.2.2 Copyright (C) 1995-2017 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (use-modules (ffi htslib)) ERROR: no code for module (ffi htslib)