From: Matt Wette <matt.wette@gmail.com>
To: Guile User <guile-user@gnu.org>
Subject: [ANN] nyacc-2.01.3 released
Date: Sun, 3 Nov 2024 13:03:44 -0800 [thread overview]
Message-ID: <801d55e3-28c1-4eeb-9c91-c1d27ac070d8@gmail.com> (raw)
This release extends the capability to provide guile procedures
directly to functions which take callback arguments. More explanation
below.
NYACC, for Not Yet Another Compiler Compiler, is set of guile modules for
generating parsers and lexical analyzers. It also provides sample parsers
and pretty-printers using SXML trees as an intermediate representation.
It provides a decent C parser and a `FFI Helper' tool to help create
Guile Scheme bindings for C-based libraries.
It provides (partially implemented) compilers based on above mentioned
parsers to allow execution with Guile as extension languages.
NEWS
* ffi-helper: cover more cases where passing procedure (e.g.,
callback) to functions works; was only function-ptr typedefs
* for forward ref structs, unions which are never elaborated,
don't generate a definition
* update some documentation for nyacc-fh-ug and cdata
A little more detail on the fix. Consider the following functions
with callback argument `cb'. With nyacc-2.01.2 `f1' would accept a
guile procedure directly (i.e., without user translating via
procedure->pointer), but `f2' and `f3' would not. With nyacc-2.01.3,
all three work.
(define-ffi-module (ffi dbug)
#:api-code "
typedef void (*t1)(int);
typedef void (t2)(int);
int f1(int, t1 cb);
int f2(int, t2 *cb);
int f3(int, void (*cb)(int));")
Expanded code appears below.
NYACC maturity is production/stable level.
NYACC is free software; the full source distribution is available through
* the tarball repository:
https://download.savannah.gnu.org/releases/nyacc/
* the git repository:
git://git.savannah.nongnu.org/nyacc.git
home page, project page and user's guides:
* https://www.nongnu.org/nyacc
* https://savannah.nongnu.org/projects/nyacc
* https://www.nongnu.org/nyacc/nyacc-ug.html
* https://www.nongnu.org/nyacc/ffi-help.html
Report bugs:
* https://savannah.nongnu.org/bugs/?group=nyacc
Get support:
* https://savannah.nongnu.org/support/?group=nyacc
Copyright (C) 2017-2024 Matthew Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
Copyright (C) 2017-2024 Matthew Wette
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
============================================
nyacc v2.01.2
;; int f1(int, t1 cb);
(define-public f1
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f1")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer cb t1)))
((force ~proc) arg0 cb)))))
;; int f2(int, t2 *cb);
(define-public f2
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f2")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer cb)))
((force ~proc) arg0 cb)))))
;; int f3(int, void (*cb)(int));
(define-public f3
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f3")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer cb)))
((force ~proc) arg0 cb)))))
============================================
nyacc v2.01.3
;; int f1(int, t1 cb);
(define-public f1
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f1")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer cb t1)))
((force ~proc) arg0 cb)))))
;; int f2(int, t2 *cb);
(define-public f2
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f2")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer cb t2*)))
((force ~proc) arg0 cb)))))
;; int f3(int, void (*cb)(int));
(define-public f3
(let ((~proc (delay (ffi:pointer->procedure
ffi:int
(foreign-pointer-search "f3")
(list ffi:int '*)))))
(lambda (arg0 cb)
(let ((arg0 (unwrap-number arg0))
(cb (unwrap-pointer
cb
(cpointer
(cfunction
(lambda (~proc)
(ffi:procedure->pointer
ffi:void
(lambda (arg0) (~proc arg0))
(list ffi:int)))
(lambda (p) 'unused))))))
((force ~proc) arg0 cb)))))
reply other threads:[~2024-11-03 21:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=801d55e3-28c1-4eeb-9c91-c1d27ac070d8@gmail.com \
--to=matt.wette@gmail.com \
--cc=guile-user@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).