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.devel,gmane.lisp.guile.user Subject: Re: ffi helper Date: Sat, 13 May 2017 09:19:11 -0700 Message-ID: <72CC7F94-A45B-40FA-955C-AB1EDFE41B2C@gmail.com> References: <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@gmail.com> <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com> <201FF019-FA10-4B35-A96D-BC0AD078F5DB@gmail.com> <093A1AB8-D7BD-4DAF-B5EC-DC0228D6A29C@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1494692373 11089 195.159.176.226 (13 May 2017 16:19:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 13 May 2017 16:19:33 +0000 (UTC) To: guile-user@gnu.org, guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat May 13 18:19:28 2017 Return-path: Envelope-to: guile-devel@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 1d9ZlN-0002hk-8K for guile-devel@m.gmane.org; Sat, 13 May 2017 18:19:25 +0200 Original-Received: from localhost ([::1]:58251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9ZlS-0000M5-O4 for guile-devel@m.gmane.org; Sat, 13 May 2017 12:19:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9ZlK-0000KX-BV for guile-devel@gnu.org; Sat, 13 May 2017 12:19:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9ZlJ-0004z9-GJ for guile-devel@gnu.org; Sat, 13 May 2017 12:19:22 -0400 Original-Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:34807) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9ZlE-0004yR-B4; Sat, 13 May 2017 12:19:16 -0400 Original-Received: by mail-pf0-x231.google.com with SMTP id 9so3553266pfj.1; Sat, 13 May 2017 09:19:16 -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=ErgbxZ5DheEThUCghoZYC5EkHhNYtV2lh7sRJ1qNc8U=; b=flE+yJJcn8XCNAZcMpT7+eU1cjefNeg1qrmZfZap4OguM/f+z93gqBybBk7S9qjJuH vucWGj+h2k8S0MT4Rqr88eKQA2QAiDX0RfJnMjV89An6jAmMmYp3jQfOnch0cmE0Kf6L dP0DosNZTEx0R+WwYELCHKlBhcw1vdzBDwB9gDKYabwSS3lxHpZfbvbyw+uT7iPKoYEg DBHyo27W40iW1YR3AQJlesWwE58UZXzS6QuksEU8u2WybxeiNpb45UcdYMs89b0kvl4b V+Cp5JVoS3qUSjnGrerYF9HxB/K340drjwfT7pHDPisBKJ5ZnvhoZqSNEmQCP//ujlfg LXSw== 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=ErgbxZ5DheEThUCghoZYC5EkHhNYtV2lh7sRJ1qNc8U=; b=VB82Ur5MDya/dIuIjrDkbWlQ1oBXdfnlN3cztfXEkjG3C7oTbfJS3quNAs7xEN+VQe yTcAwqwMKUh0ia8QmPGMEtxS8Ym/Inm7rUSPpNf7JQnx1TQINZod+t9YHevrN3pEFGvh tkVHqUaW/UtVQ+ZtebmmDdjk1SJG8Ls88mghmAoEWai3DXgUp13HrCmqWJb+tV3zMSkg wM1wdoEgRwUNV0wsaH19MwUqAw9qKMPXjNqZgS2GwAFGaiaauoUwLtIN2l/JTQaB8weD hX75QWat0SBdtmXASFd81ngIQTELMxJWpFOYb7AoqK+Ylo8qNO6d060L2pWEqFZUK1Eb kEEQ== X-Gm-Message-State: AODbwcCY8tY3pKkUPmCl6UAO/n3Rz5zsB/GWQcMTrtGGFo3roHVvhpgk hT08TEr/3azdBMKML10= X-Received: by 10.84.135.129 with SMTP id 1mr13406541plj.57.1494692354758; Sat, 13 May 2017 09:19:14 -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 z5sm11243313pfd.76.2017.05.13.09.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 May 2017 09:19:13 -0700 (PDT) In-Reply-To: <093A1AB8-D7BD-4DAF-B5EC-DC0228D6A29C@gmail.com> X-Mailer: Apple Mail (2.3273) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::231 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19145 gmane.lisp.guile.user:13713 Archived-At: > On Apr 17, 2017, at 7:26 PM, Matt Wette wrote: >=20 >=20 >> On Mar 21, 2017, at 3:40 PM, Matt Wette wrote: >>> On Mar 19, 2017, at 10:23 AM, Matt Wette = wrote: >>>> On Mar 13, 2017, at 5:53 PM, Matt Wette = wrote: >>>>> On Mar 8, 2017, at 6:06 PM, Matt Wette = wrote: >>>>> I=E2=80=99m now working on a FFI helper based on the nyacc C99 = parser. =20 Still grinding away. I can generate wrappers for function pointers = passed to C routines: see cairo_destroy_func_t below. I don=E2=80=99t = know if the converter should be called =E2=80=9Cwrap=E2=80=9D or = something else as, wrt the pointer wrappers, we are adding a =E2=80=9CC=E2= =80=9D wrapper instead of a =E2=80=9Cscheme=E2=80=9D wrapper. I am deciding how to handle enums. I will likely have wrapper to map = symbols to integers and vice versa, but I will have to handle anonymous = enums as well (e.g." enum { ABC =3D 1 };=E2=80=9D).=20 Matt (use-modules (ffi-help)) (define-ffi-helper (cairo cairo) #:pkg-config "cairo" #:include "cairo-svg.h" #:library "libcairo" #:filter (lambda (path) (string=3D? "cairo" (substring path 0 5))) ) =3D=3D[GENERATES]=3D=3D>[filter samples]=3D=3D> ;; ;; auto-generated by ffi-help.scm ;; (define-module (cairo cairo) #:use-module (ffi-help) #:use-module ((system foreign) #:prefix ffi:) #:use-module ((bytestructures guile) #:prefix bs:) ) (define bs:struct bs:bs:struct) (define lib-link (dynamic-link "libcairo")) (define (lib-func name) (dynamic-func name lib-link)) ;; typedef struct _cairo_surface cairo_surface_t; (define-std-pointer-wrapper cairo_surface_t*) ;; cairo_matrix_t (define cairo_matrix_t (bs:struct (list `(xx ,bs:double) `(yx ,bs:double) `(xy ,bs:double) `(yy ,bs:double) `(x0 ,bs:double) `(y0 ,bs:double)))) (export cairo_matrix_t) ;; typedef void (*cairo_destroy_func_t)(void *data); (define (wrap-cairo_destroy_func_t proc) ;; =3D> pointer (ffi:procedure->pointer ffi:void proc (list '*)) ) (export wrap-cairo_destroy_func_t) ;; cairo_t *cairo_create(cairo_surface_t *target); (define cairo_create (let ((f (ffi:pointer->procedure '* (lib-func "cairo_create") (list '*)))) (lambda (target) (let ((~target ((unwrap-cairo_surface_t* target)))) (identity (f ~target)))))) (export cairo_create) ;; typedef struct _cairo_region cairo_region_t; (define-std-pointer-wrapper cairo_region_t*) ;; cairo_bool_t cairo_region_contains_point(const cairo_region_t = *region, int=20 ;; x, int y); (define cairo_region_contains_point (let ((f (ffi:pointer->procedure ffi:int (lib-func "cairo_region_contains_point") (list '* ffi:int ffi:int)))) (lambda (region x y) (let ((~region ((unwrap-cairo_region_t* region)))) (f ~region x y))))) (export cairo_region_contains_point) ;; --- last line ---