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: Mon, 13 Mar 2017 17:53:59 -0700 Message-ID: <95B6EEEF-5278-44C8-B640-647A16AEFD1F@gmail.com> References: <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@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 1489452870 28307 195.159.176.226 (14 Mar 2017 00:54:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 14 Mar 2017 00:54:30 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Mar 14 01:54:24 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 1cnajG-0006dj-Rq for guile-user@m.gmane.org; Tue, 14 Mar 2017 01:54:22 +0100 Original-Received: from localhost ([::1]:55822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnajM-0003si-R1 for guile-user@m.gmane.org; Mon, 13 Mar 2017 20:54:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnaj2-0003sb-W3 for guile-user@gnu.org; Mon, 13 Mar 2017 20:54:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnaiz-00072O-NV for guile-user@gnu.org; Mon, 13 Mar 2017 20:54:08 -0400 Original-Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]:36252) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cnaiz-00071w-Eh for guile-user@gnu.org; Mon, 13 Mar 2017 20:54:05 -0400 Original-Received: by mail-pg0-x231.google.com with SMTP id g2so56724553pge.3 for ; Mon, 13 Mar 2017 17:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=Smqas4+5movrH31KwLz88DfnPX31ay8IxpOuRFn/SG8=; b=DQIEsNZBQwOK+CQ+iZ6sLZCaL8+g/my4QWQhV8FEy1skF8WDj/hcy67sZdICJGfhiW fw7ixK3i7a6Ntls2SsTL5vG7kN89unOaKwNwYRwPeYpmbEMqGapdBFdIzdEZ0dY377F3 YXpwLJncwpHvYDZpgx7y1XOcMXR6JDpqi2HEyMWpMevymYy4sIcCb/aOb+jsHvZvxn9r nv2yhCzIVrgXFRMgkVobajbL3Ka2aKzTt1a9V+bWRMoz38q4BMn5T1fXK6hX4LXRTgha huzIwsvXke716S+xNMhInUaJHbfd3swqgkmIf9CYk/LlIa7LVupNaOegIHvYjd8OtwUz WhKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=Smqas4+5movrH31KwLz88DfnPX31ay8IxpOuRFn/SG8=; b=tuiBOW35NUntmpOn9EAeAHDTl9cgQD6zeRc6kgyQKA163R190NgzaG3fwfRHhWZb8z NTlIHAte3T4R+ftOQCc11f9a2tBnPSBQzfjGqjYuSrJSwyKY2GD6lh23yJsiyWL0mVHI lx3FyLr6zE4hEmeon8FvKB4lw5R09Q78hQ6SYEw5mHNKlz96fSwZCmOkgtfJvNxUq/Ir /rNyHyXoWK7yYTOaks6TlQK3C/hH665pH8hSFyE0gpbIZhHkig4HMXZVEnEo4xXRlIj8 qwYpKQtp3fDnlApioyV2kfvURRGuV9/Hq0lq1c9SGwOQrD3P4NGvb2UN1wSJKGggz8f/ 7MxQ== X-Gm-Message-State: AMke39nC+SYrLVKO044p7Hmu3vrzZKMi78ygy0s9N0tOZ+V7BfV6da2/0ZVh/wGz7TXmfQ== X-Received: by 10.84.140.36 with SMTP id 33mr52099937pls.136.1489452842357; Mon, 13 Mar 2017 17:54:02 -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 c28sm34704468pfj.77.2017.03.13.17.54.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 17:54:01 -0700 (PDT) In-Reply-To: <96434CF4-E3F9-4410-82B6-9EB8DEE130B9@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:c05::231 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:13526 Archived-At: > 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 So, like, I think what might be useful is something that will convert a = dot-h file to a spec file, with certain assumptions about function = signatures (e.g., if passing a pointer to int, then the scheme = implementation is a (system foreign) int*, or maybe a boxed integer). =20= Then the spec is compiled, in a machine-dependent manner to deal with = type sizes and alignment, to a .go file which provides scheme-callable = functions. I=E2=80=99m not sure the output of the dot-H reader can be = machine independent, given all the spaghetti code that typically exists = in /usr/include. It may be worth a try, later. Also, the module should support structures. The bytestructures package = looks promising here. Enums should be provided also. CPP constants (aka #define=E2=80=99s) should be supported. Do CPP macros with arguments need to be supported? This is not just = converting to functions, because CPP macros do not recurse (e.g., = `#define sqrt(F) sqrt(fabs(F))=E2=80=99 is perfectly legal C). Some other tidbits:=20 The nyacc c99 module provides a few neat functions to support this. One = is expand-typerefs (was expand-decl-typerefs). This will convert an = sxml representation of=20 typedef const int (*foo_t)(int a, double b); extern foo_t fctns[2]; into one of=20 extern const int (*fctns[2])(int a, double b); Another function, udecl->mspec, helps with the conversion as follows. = Consider double x[10]; /* state vector */ The c99 parser, followed by tree->udict, followed by cadr will turn the = above into (udecl (decl-spec-list (type-spec (float-type "double"))) (init-declr (array-of (ident "x") (p-expr (fixed "10")))) (comment " state vector =E2=80=9C)) And =E2=80=9Cudecl->mspec/comm=E2=80=9D will convert the above into ("x" " state vector " (array-of "10") (float-type "double=E2=80=9D)) I am in the process of cleaning up the above in order to convert some = function signatures. =20 Matt