guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to use ffi-help


From: Matt Wette
Subject: Re: how to use ffi-help
Date: Sun, 30 Dec 2018 10:49:40 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

On 12/30/18 10:07 AM, Amirouche Boubekki wrote:


1. Is it possible to have a program or subcommand of guild that
   does take a header file from stdin and prints the bindings to stdout.

This could be done.  I will think about it.

2. What do you think of PSSI https://github.com/ktakashi/r6rs-pffi

This seems like the functionality of Guile ffi API and the scheme-bytestructure 
package.
I don't see a reason to port the FH to PSSI at this point.

3. is it possible to specify a 'renamer' procedure that takes as argument
   a symbol representing the kind of thing (enum, member, static variable,    struct, typdef, function, constant macro...) and the original name of the    original name of the thing. The goal here is to allow to have schemey variable
   names.

The syntax of define-ffi-module provides a #:renamer form that takes a 
procedure to
reform symbols.  I don't think I have implemented it.  This is on my list.

4. In the module definition, is it possible to add some code that will be appended
   to the generated file?

Yes.  I do this all the time.  Please see one of the examples in 
nyacc/examples/ffi,
like for glib.ffi shown below.  You can also specify C declarations using the
#:api-code form.  See example below.

(define-ffi-module (ffi glib)
  #:pkg-config "glib-2.0"
  #:include '("glib.h")
  #:inc-filter (lambda (file-spec path-spec)
                 (or (string-contains path-spec "glib/" 0)
                     (string=? file-spec "<glibconfig.h>")))
  )

(define-public G_PI (ffi-glib-symbol-val 'G_PI))
(define-public G_PI_2 (ffi-glib-symbol-val 'G_PI_2))
(define-public G_PI_4 (ffi-glib-symbol-val 'G_PI_4))
...


(define-ffi-module (hack)
  #:api-code "double sqrt(double);")
=>
(define-module (hack)
...
;; double sqrt(double);
(define sqrt
  (let ((~sqrt (delay (fh-link-proc
                        ffi:double
                        "sqrt"
                        (list ffi:double)
                        hack-llibs))))
    (lambda (arg-0)
      (let ((~arg-0 (unwrap~float arg-0)))
        ((force ~sqrt) ~arg-0)))))
(export sqrt)
...

5. In the module definition, is it possible to declare the interface of the generated
   module?

I'm not sure what you mean, but for

  (define-ffi-module (ffi glib) ...

the generated module is

  (define-module (ffi glib) ...

Is this what you are asking for?

Matt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]