From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: ffi helper Date: Sun, 19 Mar 2017 10:23:14 -0700 Message-ID: <201FF019-FA10-4B35-A96D-BC0AD078F5DB@gmail.com> References: <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@gmail.com> <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1489944236 21896 195.159.176.226 (19 Mar 2017 17:23:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Mar 2017 17:23:56 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Mar 19 18:23:51 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpeYU-0004w4-MO for guile-user@m.gmane.org; Sun, 19 Mar 2017 18:23:46 +0100 Original-Received: from localhost ([::1]:57590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpeYa-0002fj-LV for guile-user@m.gmane.org; Sun, 19 Mar 2017 13:23:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpeY7-0002dC-EC for guile-user@gnu.org; Sun, 19 Mar 2017 13:23:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpeY3-0001O4-Bo for guile-user@gnu.org; Sun, 19 Mar 2017 13:23:23 -0400 Original-Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]:33747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cpeY3-0001MB-4i for guile-user@gnu.org; Sun, 19 Mar 2017 13:23:19 -0400 Original-Received: by mail-pf0-x233.google.com with SMTP id e129so17413273pfh.0 for ; Sun, 19 Mar 2017 10:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=bCl/X+FHGNkbUgqBWXJFQN2IRRPGGS2n5c3HUkbCknU=; b=ZTX09cFF1P9rGfWiImZDcftwAC8ik/xMg33ZLrAP3q98TBpzTAEizKLLOwKnEby+PK D017iGzl66+29P3RhgV7F1jPiC4XL3Mc/Q4VAtl/Z5kf/NHCLMZGo1lB5zV8pBCbuMDS 2iRx9oHZ4IBUeAPqCk5qztX7bZHt6k+VCBGFb9dManWGWXMfjY24Hf+9edacwMd4P2az cFm+4vcDrjT5RJkj5zaZTGLfp659wEfOipqmaPQ7tRhOZ+0Pb7IsSQEtErZSMgKy7D3I ZRI/XjGLLvbPy6edC/O8Gf6+PTmV6Yy/c0rz37NvxKzgkf5ryL+QbB8/A7X+8lBeyuS6 CHTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=bCl/X+FHGNkbUgqBWXJFQN2IRRPGGS2n5c3HUkbCknU=; b=QJ8XymvfXncczEv4Pp6INwkyjud7RYQK0wbId/0rySqTapvEvOjDBUbPLb/TQ78tVV 36xop2h9Rb6LWIpkbxIBo0tCQ6eSpV7WEairH0xJiykbDGTqcjrVaArm76TJSdkfaGMN 0L1VMIU5pM64RbikxLErlw+YV5KAZ9nNojkRce3O8BPGt7obDY2FMBX7IwhdALKph2sB 4LKWa99rJToZYSMithkZkWijvL9swR0ILbs3EwzkUkGN6RZe4JbuDkErKRZAZDolus/X HXpLAzZzE0XM4hzs+aGF/f1qozmsM0WGQpfeZomrQr6jx08z37c8+IlDgH3+qHM3sOLo h3zg== X-Gm-Message-State: AFeK/H2BoaK2ZoGzzR2u9m+a1I/gE9r9JcXYdywMxOE0LF9dy5lyEh+yG2BcjioxZIcl3A== X-Received: by 10.84.206.37 with SMTP id f34mr34790958ple.175.1489944197459; Sun, 19 Mar 2017 10:23:17 -0700 (PDT) Original-Received: from [192.168.2.114] (216-165-236-44.championbroadband.com. [216.165.236.44]) by smtp.gmail.com with ESMTPSA id e2sm28408191pga.61.2017.03.19.10.23.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Mar 2017 10:23:16 -0700 (PDT) In-Reply-To: <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com> X-Mailer: Apple Mail (2.3259) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::233 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13564 Archived-At: > On Mar 13, 2017, at 5:53 PM, Matt Wette wrote: >=20 >=20 >> On Mar 8, 2017, at 6:06 PM, Matt Wette wrote: >>=20 >> I=E2=80=99m now working on a FFI helper based on the nyacc C99 = parser. =20 >=20 I am making some progress with some ragged prototype code. Here is a top-level program, just pulling out three declarations to = start: (let* ((file "/opt/local/include/cairo/cairo-svg.h") (defs '()) (incs '("/opt/local/include" "/opt/local/include/cairo" = "/usr/include")) (tree (my-parse defs incs file)) (file-decls (reverse (c99-trans-unit->udict tree #:filter = cairo-filter))) (udecl-dict (c99-trans-unit->udict/deep tree))) (fold (lambda (pair type-list) (udecl->ffi-decl (cdr pair) type-list)) fixed-width-int-names (filter (lambda (e) (member (car e) '("cairo_matrix_t" "cairo_surface_t" = "cairo_svg_surface_create"))) file-decls))) And here is the autogenerated output for the declarations: (define-std-pointer-wrapper cairo_surface_t*) (define cairo_matrix_t (bs:struct `(,(string->symbol "xx") ,double) `(,(string->symbol "yx") ,double) `(,(string->symbol "xy") ,double) `(,(string->symbol "yy") ,double) `(,(string->symbol "x0") ,double) `(,(string->symbol "y0") ,double))) (define cairo_svg_surface_create (let ((f (pointer->procedure '* (libcairo-func "cairo_svg_surface_create") (list '* double double)))) (lambda (filename width_in_points height_in_points) (let ((~filename (string->pointer filename)) (~width_in_points width_in_points) (~height_in_points height_in_points) (~result (f ~filename ~width_in_points ~height_in_points))) (wrap-cairo_surface_t* ~result))))) I was not able to come up with a procedure that would take arguments = =E2=80=9Cxx=E2=80=9D and =E2=80=9Cdouble=E2=80=9D and generate the = bs:struct pattern `(xx ,double). Help is welcome.=