From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: Bytestructures: a "type system" for bytevectors Date: Fri, 24 Jun 2016 07:47:35 -0700 Message-ID: <098F06F0-0EA1-48A9-A746-8578BA020955@gmail.com> References: <87r3mkg2iy.fsf@T420.taylan> <87y460gfhd.fsf@pobox.com> <87k2hjseh4.fsf@T420.taylan> <23A3AD54-4CFC-42BA-8617-A2F6A587D278@gmail.com> <87porbnfor.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1466779724 24035 80.91.229.3 (24 Jun 2016 14:48:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 14:48:44 +0000 (UTC) To: guile-user@gnu.org, guile-devel@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 24 16:48:39 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bGSPJ-0004NT-Fl for guile-user@m.gmane.org; Fri, 24 Jun 2016 16:48:33 +0200 Original-Received: from localhost ([::1]:44032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSPH-0000Uy-0B for guile-user@m.gmane.org; Fri, 24 Jun 2016 10:48:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSOX-0000QX-5E for guile-user@gnu.org; Fri, 24 Jun 2016 10:47:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGSOS-0004Ga-3A for guile-user@gnu.org; Fri, 24 Jun 2016 10:47:44 -0400 Original-Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:33101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSOR-0004GF-JQ; Fri, 24 Jun 2016 10:47:40 -0400 Original-Received: by mail-pa0-x22c.google.com with SMTP id b13so38241242pat.0; Fri, 24 Jun 2016 07:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:message-id:mime-version:subject:date:references:to:in-reply-to; bh=QS9GfT/Cy3y5xkaT04FwQDAxE825Af+XUgRy48Caz2g=; b=d2Y2EIbTLiwllbYXqyTrSb6Hlxt+CemB7v+pIKsA/GtkBs2bU169l9+0D6LyaCe1Gh lWkCpc6Cw+bwA9x8muA1nmxjHUmuxRW6U2+afOnsRGRkZmMWet7nHnvyMGePhr80+DDa Ds7lvpeAYUqrDOG9Bp1sSyhN7JReYk0PVNfN53t3cX7NbP4DHEqeYM8INE+yhnnKDT1p CZpm6Ia0uK5YQNC6nahWFv5cExqBU9v8OMmB6JD3ZQAsnMScRfsjfUEHsdjlxCiikUoe W03u7kOxUmGy9PXhXbMSsWnLdlR+YJoCMuqu0wKEDz8BP/7xdSxcbMgE+aSXqnoJiLLY jfWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:mime-version:subject:date :references:to:in-reply-to; bh=QS9GfT/Cy3y5xkaT04FwQDAxE825Af+XUgRy48Caz2g=; b=F5lrimWABALtjUMthnB9EcP+vEIRvX1VFr4x9osauHZu422SyKFbe2/+/MyXupPt5v p+AVLC4ZicRJepU/zUYFmhxetPp1q60w6CLZwo+LF6NzMVzcM0DCtPON9GkslZAtwCrv ZzCdYYqUARorbXJJ5qzQOI9U1R7BJORpMEyL2X1qzYRXKrVZ+TXDSVP/u/3w3ZTWaC0M gjn6c1li1LqxtYOHaSO14VrIzjspRFtwEMG72BZRlYLnj/aPE51m+Z/qVNfIiR3kOS9R L4kZZXiFkU6MbPlQIGDp6ORXqX+FBsywxbUl5jWmTOZ+UeNEK2Uev2KM74ohpxfsBh6e Ceow== X-Gm-Message-State: ALyK8tKZ0UG/Y4dD2hmM5/8wTe7BWGszwRSbSjQp2hnkblpiQ0Qm3nj2Rq7+AVQw6eCkcw== X-Received: by 10.66.15.232 with SMTP id a8mr8395212pad.129.1466779658244; Fri, 24 Jun 2016 07:47:38 -0700 (PDT) Original-Received: from nautilus.championbroadband.com (216-165-228-109.championbroadband.com. [216.165.228.109]) by smtp.gmail.com with ESMTPSA id c2sm555375paw.45.2016.06.24.07.47.36 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jun 2016 07:47:37 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.2104) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::22c 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:12697 gmane.lisp.guile.devel:18416 Archived-At: =20 > On Jun 21, 2016, at 5:53 AM, Matt Wette wrote: >=20 >> On Jun 21, 2016, at 12:50 AM, Taylan Ulrich Bay=C4=B1rl=C4=B1/Kammer = wrote: >>=20 >> Matt Wette writes: >>=20 >>> nyacc is an all-guile implementation of yacc and comes with a c99 >>> parser, available from www.nongnu.org.=20 >>> The parser outputs parse trees in sxml format. It is beta-level = code. >>>=20 >>> Matt >>=20 >> Wow! That covers a big chunk of the task, if I implement it from >> scratch. In fact, given I don't have to deal with typedefs and such = for >> doing something like Lua's FFI, it covers most of the task. >=20 > There is code to expand typedefs. Check =E2=80=9Cstripdown=E2=80=9D = routine in (nyacc lang c99 util2). It also provides a keyword arg = (#:keep) to provide a list of typedefs to not expand. I should expand a little. The nyacc c99 parser provides functionality = that I think will be valuable to FFI: 1) preserves file context: the parse tree for included files is stuffed = under an associated cpp-stmt include node 2) provides utility to expand typedef references into base types (with = =E2=80=9Ckeepers=E2=80=9D arg to select which typedef references to = preserve) 3) provides parser argument to choose which defines get expanded 4) provides utility to unwrap declarations There is still a lot to do to support FFI. E.g., what to do about = system dependencies (e.g., is =E2=80=9Cint" 32 bits or 64 bits) My stuff is all still pretty rough right now. Here is some demo code = for features (1) and (2). =20 ;; demo.scm (use-modules (nyacc lang c99 parser)) (use-modules (nyacc lang c99 util1)) (use-modules (nyacc lang c99 util2)) (use-modules (ice-9 pretty-print)) (let* ((tree (with-input-from-file "ex1.h" parse-c99)) (ud1 (reverse (tree->udict tree)))) ;; decl's only in ex1.h (display "\ntree:\n") (pretty-print tree) (display "\nud1:\n") (pretty-print ud1) (let ((ud0 (tree->udict (merge-inc-trees! tree)))) ;; decl's in all (for-each (lambda (pair) (let* ((udecl (cdr pair)) (tdexp (expand-decl-typerefs udecl ud0 #:keep = '("int32_t"))) (mspec (udecl->mspec tdexp))) (display "\ntdexp:\n") (pretty-print tdexp))) ud1))) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // ex1.h #include "ex0.h" typedef struct { double d; foo_t x; } bar_t; bar_t ftn1(int*); =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D // ex0.h typedef int int32_t; typedef int32_t foo_t; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D tree: (trans-unit (comment " ex1.h") (cpp-stmt (include "\"ex0.h\"" (trans-unit (comment " ex0.h") (decl (decl-spec-list (stor-spec (typedef)) (type-spec (fixed-type "int"))) (init-declr-list (init-declr (ident "int32_t")))) (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "int32_t"))) (init-declr-list (init-declr (ident "foo_t"))))))) (decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def (field-list (comp-decl (decl-spec-list (type-spec (float-type "double"))) (comp-declr-list (comp-declr (ident "d")))) (comp-decl (decl-spec-list (type-spec (typename "foo_t"))) (comp-declr-list (comp-declr (ident "x")))))))) (init-declr-list (init-declr (ident "bar_t")))) (decl (decl-spec-list (type-spec (typename "bar_t"))) (init-declr-list (init-declr (ftn-declr (ident "ftn1") (param-list (param-decl (decl-spec-list (type-spec (fixed-type "int"))) (param-declr (abs-declr (pointer)))))))))) ud1: (("bar_t" decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def (field-list (comp-decl (decl-spec-list (type-spec (float-type "double"))) (comp-declr-list (comp-declr (ident "d")))) (comp-decl (decl-spec-list (type-spec (typename "foo_t"))) (comp-declr-list (comp-declr (ident "x")))))))) (init-declr (ident "bar_t"))) ("ftn1" decl (decl-spec-list (type-spec (typename "bar_t"))) (init-declr (ftn-declr (ident "ftn1") (param-list (param-decl (decl-spec-list (type-spec (fixed-type "int"))) (param-declr (abs-declr (pointer))))))))) tdexp: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (struct-def (field-list (comp-decl (decl-spec-list (type-spec (float-type "double"))) (comp-declr (ident "d"))) (comp-decl (decl-spec-list (type-spec (typename "int32_t"))) (comp-declr (ident "x"))))))) (init-declr (ident "bar_t"))) tdexp: (decl (decl-spec-list (type-spec (struct-def (field-list (comp-decl (decl-spec-list (type-spec (float-type "double"))) (comp-declr (ident "d"))) (comp-decl (decl-spec-list (type-spec (typename "int32_t"))) (comp-declr (ident "x"))))))) (init-declr (ftn-declr (ident "ftn1") (param-list (param-decl (decl-spec-list (type-spec (fixed-type "int"))) (param-declr (abs-declr (pointer))))))))