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 Subject: Re: Bytestructures: a "type system" for bytevectors Date: Fri, 24 Jun 2016 07:33:48 -0700 Message-ID: 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 1466781078 14601 80.91.229.3 (24 Jun 2016 15:11:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 15:11:18 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 24 17:11:14 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 1bGSlF-0000gX-NF for guile-user@m.gmane.org; Fri, 24 Jun 2016 17:11:13 +0200 Original-Received: from localhost ([::1]:44179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSlE-0007OK-QM for guile-user@m.gmane.org; Fri, 24 Jun 2016 11:11:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSBp-0002Cw-CK for guile-user@gnu.org; Fri, 24 Jun 2016 10:34:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGSBh-0000TF-Tj for guile-user@gnu.org; Fri, 24 Jun 2016 10:34:36 -0400 Original-Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:36387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSBh-0000Sq-Dv for guile-user@gnu.org; Fri, 24 Jun 2016 10:34:29 -0400 Original-Received: by mail-pf0-x231.google.com with SMTP id t190so39898442pfb.3 for ; Fri, 24 Jun 2016 07:34:28 -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=ob6CUjCO4IQgWvG/XWdBGYSQhuydzb/NZ6xDac6k3q4=; b=HE4m+BU8sA9tPRSO4WkHFWqexlsnZ5l5Pyr/S7cMVBJo+XpoZfmknKiePGThXfvUvV bGmyLMElgBGtGIYweEsL1bC/L+ekFGmXFYXoNoPyNSKkhFssSgnv7mjUeCcFrMZfDvgt V9nIROJYgvl/HRKRnpsZUUWjWqBvvDloKWEjPlQyZO+wwW0iiW78TgQfmaexLE+hSxhc I15WxpVhpbYG21/nyDdbjNV4W0vGPIH7qAzC/Pr9QB2kEQBp43pZ8OPtm+hwAE/ti6xQ 9rrfT65RNuN0cR2id1rqj73+SIRoM1yxnpH5AUNfIyqQ2cH1wHlwCwHr6kT0ltx5Wl8X WFiw== 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=ob6CUjCO4IQgWvG/XWdBGYSQhuydzb/NZ6xDac6k3q4=; b=Pr2G85bVWjJeFKPbSJz6iLX4nJHbJtSupA+e5QDFBZh4rjbxFpRjZ080YScTVdHQJ+ rEU91o75LQk0acqpB7kCy0dSD9+bNPZl1mwOYyusxrmG68B3iRaE37cUjBt5lQl4ebOe Bdw+nIX2hTt2C9bxOYXh8csWAi4Qz6oSmiFlLA2yKyLNOwmrzM2mMpWD2lp8BKECSG9B XQSPHON6uHTEd/AdAs4ksEitAr26AAdKerW0SIU7KCO3aIJ00nBTbIFpgnxFGNWAwhV9 LEflXAKyxnCYP6hucxycNIqgJlaB6SMYtqj1k84OjZUuL+UjHB2rFXwGNcZBy8Jjlaie j/4A== X-Gm-Message-State: ALyK8tJkvhRUbeQZpXkeU1ivZVWJBhkrkPsVrgID4Qs2l5BWVUNnPK0EyQVljRXAS8nLRQ== X-Received: by 10.98.51.4 with SMTP id z4mr7937740pfz.100.1466778867720; Fri, 24 Jun 2016 07:34:27 -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 ez6sm713029pab.12.2016.06.24.07.34.24 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jun 2016 07:34:26 -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:c00::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:12698 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))))))))