From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.user Subject: Re: progress on my NYACC javascript example complier Date: Sat, 3 Jun 2017 09:52:40 +0800 Message-ID: References: <4959B7EB-6E65-4431-940F-998AE6F60056@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1496454792 12584 195.159.176.226 (3 Jun 2017 01:53:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 3 Jun 2017 01:53:12 +0000 (UTC) Cc: Guile User To: Matt Wette Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jun 03 03:53:07 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 1dGyFW-0002u9-OA for guile-user@m.gmane.org; Sat, 03 Jun 2017 03:53:06 +0200 Original-Received: from localhost ([::1]:52117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGyFa-000680-H9 for guile-user@m.gmane.org; Fri, 02 Jun 2017 21:53:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGyFB-00067t-RP for guile-user@gnu.org; Fri, 02 Jun 2017 21:52:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGyF9-0007SG-UC for guile-user@gnu.org; Fri, 02 Jun 2017 21:52:45 -0400 Original-Received: from mail-oi0-x235.google.com ([2607:f8b0:4003:c06::235]:33340) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGyF9-0007QY-My for guile-user@gnu.org; Fri, 02 Jun 2017 21:52:43 -0400 Original-Received: by mail-oi0-x235.google.com with SMTP id s3so20441053oia.0 for ; Fri, 02 Jun 2017 18:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=soquMBlFBIQYS5FNFZRTziVFvMMzVHplaGs6Jp8ZNTw=; b=F1ybGMPlCGE79T2ZFGGtddgK6cHEoeaLjcb0lFCa1bDy2PmbvqRnDbcBjnRYZ6zto7 qC1w9wAa/lxDuX/Y2tEPCPuTgFOAeYhOpCL1jOLpmsLz4vpfn30VBap6JGKpsq1/0tz9 ArPY+ith1aBivQ5jNSR93RFsHDWJWLFv5hDxYuVOzwiB5nv0Ci/eih9TZuvsBJXOf/CR SRa3+VmcdzGS7ppSziINV45LsXUo/GEpIYbmUzW/sn4IKdUTzmDLLaLX4MfXkU3D+1wG Paip2v0zDYyvO82G5Eck43b/CjfARb9QXKWJFuW8ClJDj3DnttS9S11E3LSxgkQ6lHPv u4iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=soquMBlFBIQYS5FNFZRTziVFvMMzVHplaGs6Jp8ZNTw=; b=TyHsHR8bSSMM0tF3Z6A3EJ75jDEbUrnDpxXByilM3fZIplArc+rlyVD9xiVO8pRvFV 1krh7Y58ojdR5B+pZ9OjXKjblxS32bAtnFGpS+wrtlaHipNvg1UrDKQz7WyVOtNeBBOj og0UWv5y3neeY3w0hxm/rQ3kLjBtnUofOj1wsRCOFdsnOPf6Hmjl08B4xILwmUyN+QAy Dk3sjXcQA16Q3ZIHMqH2utl27DDN70dW3ydPOmpBYqfufdchyd7oNQ9pQsn8C3nlJogN zCKsyfe8BLi3HcqJkkUUF+cUXCYIbOJjMM84VIz360Y6Pe7DaULfDE1CNFkCDFbDhAyY UW9w== X-Gm-Message-State: AODbwcA0oiWlqMg7RY7gVVy0SYla4xTxdgPXh0y9Q+Nn8v23svlf2cFW WfBr5sfw38CI0IJIQ0npLSETXflh4w== X-Received: by 10.202.168.140 with SMTP id r134mr5263660oie.57.1496454761255; Fri, 02 Jun 2017 18:52:41 -0700 (PDT) Original-Received: by 10.157.53.6 with HTTP; Fri, 2 Jun 2017 18:52:40 -0700 (PDT) Original-Received: by 10.157.53.6 with HTTP; Fri, 2 Jun 2017 18:52:40 -0700 (PDT) In-Reply-To: <4959B7EB-6E65-4431-940F-998AE6F60056@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::235 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:13761 Archived-At: Hi Matt! Thanks for working on that. It's really cool! IMO, translate AST to tree-il simply is not enough to implement spec-compatible front-end for most of real languages. They just looks like JS/Lua/Python, but not them at all. This conclusion is from my experience on developing guile-lua-rebirth. The real implementation needs to do far more than simple translator. But provide spec-compatible AST is relative easier, then let anyone who interested in compiler hacking try their luck. Another common concern is that Guile IR may not suitable for non-FP languages. But IMO, the CPS is general enough for any turing-complete language. People may thought SSA is required for imperitive languages, but I don't think so, actually Appel had a paper to prove SSA is kind of FP language too. And all these intermediate representations: SSA, CPS, ANF, sequent-caculus ... are equivalent. The difference is the expressiveness. Just like the difference between functional and imperitive language. People may concern that GuileVM is not general enough for any languages. But it is improvable if we can figure out what is missing in the current VM implementation. No mention Guile is going for native code generating in the future. 2017=E5=B9=B46=E6=9C=883=E6=97=A5 =E4=B8=8A=E5=8D=887:57=EF=BC=8C"Matt Wett= e" =E5=86=99=E9=81=93=EF=BC=9A > I started working on NYACC documentation and that got me on cleaning up > the example (but very incomplete) javascript example. This example uses = an > architecture where syntax trees emitted from the parser are in SXML > format. From there I use foldts*-values (developed by Andy Wingo) to > convert to Tree-IL and from there the Guile compiler tower takes over. > This effort is my sandbox for getting familiar with all tools and > techniques. I have no plan to implement everything. > > foldts*-values allows me to trap new scope on the way down the tree: I > push scope levels there and update the symbol table if needed. On the wa= y > down I also pick off simple constructs (e.g., constants and identifiers). > Also, on the way down, I splice in javascript Blocks to track scope of ne= w > variables introduced by JavaScript variable declarations. On the way up, > the trees are converted to Tree-IL. > > The top-level variables live in the default module scope, so I can call > Guile procedures and Guile can make use of top-level functions defined in > the Javascript. The following is an example from =E2=80=9CJavaScript, Th= e > Definitive Guide=E2=80=9D in which a closure is used to provide a functio= n that has > a private var to generate incrementing numeric identifiers. What you see > below is > 1) the javascript code > 2) the output of running this in Guile > 3) the SXML syntax tree emitted from the parser > 4) the tree-il syntax tree emitted from the compiler > > var uid =3D (function() { var id =3D 0; return function () { return id++; > };})(); > display(uid()); newline(); > display(uid()); newline(); > display(uid()); newline(); > display(uid()); newline(); > > =3D> > > 0 > 1 > 2 > 3 > # > > SXML: > (Program > (SourceElements > (VariableStatement > (VariableDeclarationList > (VariableDeclaration > (Identifier "uid") > (Initializer > (CallExpression > (FunctionExpression > (FormalParameterList) > (SourceElements > (VariableStatement > (VariableDeclarationList > (VariableDeclaration > (Identifier "id") > (Initializer > (PrimaryExpression (NumericLiteral "0")))))) > (ReturnStatement > (FunctionExpression > (FormalParameterList) > (SourceElements > (ReturnStatement > (post-inc > (PrimaryExpression (Identifier "id"))))))))) > (ArgumentList)))))) > (EmptyStatement) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "display")) > (ArgumentList > (CallExpression > (PrimaryExpression (Identifier "uid")) > (ArgumentList))))) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "newline")) > (ArgumentList))) > (EmptyStatement) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "display")) > (ArgumentList > (CallExpression > (PrimaryExpression (Identifier "uid")) > (ArgumentList))))) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "newline")) > (ArgumentList))) > (EmptyStatement) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "display")) > (ArgumentList > (CallExpression > (PrimaryExpression (Identifier "uid")) > (ArgumentList))))) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "newline")) > (ArgumentList))) > (EmptyStatement) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "display")) > (ArgumentList > (CallExpression > (PrimaryExpression (Identifier "uid")) > (ArgumentList))))) > (ExpressionStatement > (CallExpression > (PrimaryExpression (Identifier "newline")) > (ArgumentList))) > (EmptyStatement))) > > > tree-il: > (begin > (begin > (define uid > (apply (lambda () > (lambda-case > ((() #f @args #f () (JS~6715)) > (prompt > (const return) > (begin > (let (id) > (JS~6716) > ((const 0)) > (begin > (lambda () > (lambda-case > ((() #f @args #f () (JS~6718)) > (prompt > (const return) > (begin > (let (~ref) > (JS~6719) > ((lexical id JS~6716)) > (begin > (set! (lexical id JS~6716) > (apply (@@ (nyacc lang > javascript jslib) > js:+) > (const 1) > (lexical ~ref JS~6719))= ) > (lexical ~ref JS~6719)))) > (lambda-case > (((tag val) #f #f #f () (JS~6720 > JS~6721)) > (lexical val JS~6721)))))))))) > (lambda-case > (((tag val) #f #f #f () (JS~6722 JS~6723)) > (lexical val JS~6723)))))))))) > (apply (@@ (guile-user) display) > (apply (toplevel uid))) > (apply (@@ (guile-user) newline)) > (apply (@@ (guile-user) display) > (apply (toplevel uid))) > (apply (@@ (guile-user) newline)) > (apply (@@ (guile-user) display) > (apply (toplevel uid))) > (apply (@@ (guile-user) newline)) > (apply (@@ (guile-user) display) > (apply (toplevel uid))) > (apply (@@ (guile-user) newline))) > >