unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: Roel Janssen <roel@gnu.org>
Cc: Guile User <guile-user@gnu.org>, guile-devel <guile-devel@gnu.org>
Subject: Re: ffi-help: status to 19 Aug 2017
Date: Thu, 9 Nov 2017 17:00:23 -0800	[thread overview]
Message-ID: <0B1CB7F6-A400-487D-BBCA-BE08E75033CA@gmail.com> (raw)
In-Reply-To: <878tfffet8.fsf@gnu.org>


> On Nov 9, 2017, at 11:10 AM, Roel Janssen <roel@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)




  reply	other threads:[~2017-11-10  1:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <D30BE676-0171-4E8F-8CD0-B40A74B08850@gmail.com>
2017-08-19 15:30 ` ffi-help: status to 19 Aug 2017 Matt Wette
2017-09-08  3:32   ` ffi-help: #:use-ffi-module Matt Wette
2017-09-08  3:40     ` Matt Wette
2017-11-09 19:10   ` ffi-help: status to 19 Aug 2017 Roel Janssen
2017-11-10  1:00     ` Matt Wette [this message]
2017-11-10  2:34       ` Matt Wette
2017-11-10  2:39     ` Matt Wette
2017-11-10 23:04       ` Stefan Israelsson Tampe
2017-11-11  4:38         ` Matt Wette
2017-11-14 18:06     ` Ricardo Wurmus

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=0B1CB7F6-A400-487D-BBCA-BE08E75033CA@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=roel@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).