unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* how to use ffi-help
@ 2018-12-22 18:46 Matt Wette
  2018-12-30 18:07 ` Amirouche Boubekki
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Wette @ 2018-12-22 18:46 UTC (permalink / raw)
  To: guile-user

Hi All,

I have created a helper for generating FFI code for Guile.   The current
use case is to create file called a "ffi module" that specifies includes
and libraries that will be used to create a loadable Guile module. In the
process, the FFI Helper (FH) parses C code and, from that, generates Guile
FFI code.  See

   ffi-helper: https://www.nongnu.org/nyacc/ffi-help.html

   project: https://savannah.nongnu.org/projects/nyacc

I think the package is at a very usable point right now, and
I am starting to converge on a 1.0 release.  So now I am
soliciting inputs on other ways to use this package.  Namely,
are convenience routines needed for some use cases?

For example, one user wanted to be able to write `(include "cairo.h")'.
As you may imagine, it can't be this simple.   I do have this:

   guile> (load-include-file "cairo.h" #:pkg-config "cairo")

but even this is a bit of a challenge for me.  Not to write the code,
but to digest the whole use case.  Do you want the generated scheme
code preserved?  If so, do I need to provide an option for setting the
output file name?  If a "pkg-config" is not available then the user
will need to pass compile flags (e.g., include dirs), load flags,
libraries, etc.  I would need to add more options for this.  It could
get messy.  All that functionality lives in the "ffi-module" paradigm
right now, so maybe this is really not needed.  What do you think?

Maybe you are generating FFI yourself but want to see what FH would do
for a specific struct typedef appearing in a particular include file.
You can do this with the ffi-module approach, using the #:decl-filter
option which allows one to restrict which declarations get expanded.
Is a separate convenience routine needed?

Currently I think all other uses can be derived from the current "ffi
module" paradigm.  Making convenience routines is going to be tricky,
because so many options may need to added.  I don't think it's worth the
work to add them, but I'd like to hear what you have to say.

Comments?

Matt




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to use ffi-help
  2018-12-22 18:46 how to use ffi-help Matt Wette
@ 2018-12-30 18:07 ` Amirouche Boubekki
  2018-12-30 18:49   ` Matt Wette
  0 siblings, 1 reply; 3+ messages in thread
From: Amirouche Boubekki @ 2018-12-30 18:07 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user, guile-user

Le 2018-12-22 19:46, Matt Wette a écrit :
> Hi All,
> 
> I have created a helper for generating FFI code for Guile.   The 
> current
> use case is to create file called a "ffi module" that specifies 
> includes
> and libraries that will be used to create a loadable Guile module. In 
> the
> process, the FFI Helper (FH) parses C code and, from that, generates 
> Guile
> FFI code.

Thanks a lot! I promised to test ffi helper but got side tracked.

>  See
> 
>   ffi-helper: https://www.nongnu.org/nyacc/ffi-help.html
> 
>   project: https://savannah.nongnu.org/projects/nyacc
> 
> I think the package is at a very usable point right now, and
> I am starting to converge on a 1.0 release.  So now I am
> soliciting inputs on other ways to use this package.  Namely,
> are convenience routines needed for some use cases?

[...]

> 
> Comments?
> 

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.

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

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.

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

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

TIA

-- 
Amirouche ~ amz3 ~ http://www.hyperdev.fr



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to use ffi-help
  2018-12-30 18:07 ` Amirouche Boubekki
@ 2018-12-30 18:49   ` Matt Wette
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Wette @ 2018-12-30 18:49 UTC (permalink / raw)
  To: guile-user

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-30 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-22 18:46 how to use ffi-help Matt Wette
2018-12-30 18:07 ` Amirouche Boubekki
2018-12-30 18:49   ` Matt Wette

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).