unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ian Price <ianprice90@googlemail.com>
To: guile-devel@gnu.org
Subject: Re: lua branch
Date: Tue, 26 Mar 2013 05:50:11 +0000	[thread overview]
Message-ID: <87boa6pv58.fsf@Kagami.home> (raw)
In-Reply-To: <87fvzipxn7.fsf@Kagami.home> (Ian Price's message of "Tue, 26 Mar 2013 04:56:12 +0000")

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

Ian Price <ianprice90@googlemail.com> writes:

> I don't know much about Lua, but I think I could do the following.
> 1. Fix the lua-lexer failure.
> 2. Disable or fix[1] the variable-arguments functionality.
> 3. Rebase or merge with modern stable or master
> 4. Fix the errors that arise as a result of 3.

I have patches for 1 & 2.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: typo patch --]
[-- Type: text/x-patch, Size: 797 bytes --]

From de139a394dbf4984b6006646a2bd648a1257a01b Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Tue, 26 Mar 2013 03:52:40 +0000
Subject: [PATCH 1/2] Fix typo in lua lexer test.

* test-suite/tests/lua-lexer.test ("lua-lexer"): #:vararg -> #:varargs
---
 test-suite/tests/lua-lexer.test |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test-suite/tests/lua-lexer.test b/test-suite/tests/lua-lexer.test
index 51e9efa..7b916be 100644
--- a/test-suite/tests/lua-lexer.test
+++ b/test-suite/tests/lua-lexer.test
@@ -62,7 +62,7 @@ comment]]"))
     (test "name" 'name)
     (test "return" #:return)
     (test ".." #:concat)
-    (test "..." #:vararg)
+    (test "..." #:varargs)
     (test ";" #\;)
     (test "-" #\-)
     (test "+" #\+)
-- 
1.7.7.6


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: compile patch --]
[-- Type: text/x-patch, Size: 5596 bytes --]

From beb958de895fccd5f81ce2064050ef624a409104 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Tue, 26 Mar 2013 05:41:32 +0000
Subject: [PATCH 2/2] Compile Lua's ... form.

* module/language/lua/compile-tree-il.scm (compile): Add clause for
  ast-variable-arguments.
* module/language/lua/parser.scm (define-ast, make-parser): Add
  vararg-gensym field to functions, gensym field to variable-arguments.
  Propagate *vararg-gensym* from functions to variable-arguments.
* test-suite/tests/lua-eval-2.test ("lua-eval"): Check for #nil
---
 module/language/lua/compile-tree-il.scm |   11 ++++++++---
 module/language/lua/parser.scm          |   15 +++++++++++----
 test-suite/tests/lua-eval-2.test        |    2 +-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/module/language/lua/compile-tree-il.scm b/module/language/lua/compile-tree-il.scm
index 48c1a58..72c0d1b 100644
--- a/module/language/lua/compile-tree-il.scm
+++ b/module/language/lua/compile-tree-il.scm
@@ -156,7 +156,7 @@ dropped silently"
           src (make-primitive-ref src 'return/values)
           (if (list? exp) (map-compile exp #t) (list (compile exp))))))
 
-    ((ast-function src name arguments argument-gensyms variable-arguments? body)
+    ((ast-function src name arguments argument-gensyms variable-arguments? vararg-gensym body)
      ;; ... is always attached because lua functions must ignore
      ;; variable arguments; the parser will catch it if ... is used in a
      ;; function that doesn't have ... in the parameter list
@@ -165,7 +165,7 @@ dropped silently"
         src meta
         (make-lambda-case src '() arguments '... #f
                           (map (lambda (x) (make-const src #nil)) arguments)
-                          (append argument-gensyms (list (gensym "...")))
+                          (append argument-gensyms (list vararg-gensym))
                           (compile body)
                           #f))))
 
@@ -476,7 +476,12 @@ dropped silently"
                 (make-lexical-ref src 'and-tmp tmp)
                 right
                 (make-lexical-ref src 'and-tmp tmp)))))
-         (else (error #:COMPILE "unknown binary operator" operator)))))))
+         (else (error #:COMPILE "unknown binary operator" operator)))))
+    ((ast-variable-arguments src gensym)
+     (make-application src
+                       (make-primitive-ref src 'apply)
+                       (list (make-primitive-ref src 'values)
+                             (make-lexical-ref src '... gensym))))))
 
 ;; exported compiler function
 (define (compile-tree-il exp env opts)
diff --git a/module/language/lua/parser.scm b/module/language/lua/parser.scm
index dbe73f6..2ee81ce 100644
--- a/module/language/lua/parser.scm
+++ b/module/language/lua/parser.scm
@@ -106,10 +106,10 @@
    (numeric-for-loop named initial limit step body)
    (list-for-loop names gs-names exps body)
    (break)
-   (function name arguments argument-gensyms variable-arguments? body)
+   (function name arguments argument-gensyms variable-arguments? vararg-gensym body)
    (function-call operator operands)
    (binary-operation operator left right)
-   (variable-arguments))
+   (variable-arguments gensym))
 
   ) ; letrec-syntax
 
@@ -219,6 +219,9 @@
   ;; True if inside a function and the function accepts variable arguments
   (define *vararg-function* #f)
 
+  ;; refers to the gensym for '...' in a function that accepts variable arguments
+  (define *vararg-gensym* #f)
+
   ;;;;; ENVIRONMENTS
   (define (enter-environment!)
     "Create a new environment, and set ENVIRONMENT to it"
@@ -482,8 +485,10 @@
     (enforce-next! #\()
     ;; parameter-list
     (receive (parameters variable-arguments?) (parameter-list name)
-      (let* ((old-vararg-function *vararg-function*))
+      (let* ((old-vararg-function *vararg-function*)
+             (old-vararg-gensym *vararg-gensym*))
         (set! *vararg-function* variable-arguments?)
+        (set! *vararg-gensym* (and variable-arguments? (gensym "...")))
         (enforce-next! #\))
         ;; create function
         (enter-environment!)
@@ -504,11 +509,13 @@
                              (list (environment-lookup-gensym 'self)))
                      parameter-gensyms)
                  variable-arguments?
+                 *vararg-gensym*
                  (if (null? body) *void-literal* body))))
           (leave-environment!)
           ;; END
           (enforce-next! #:end)
           (set! *vararg-function* old-vararg-function)
+          (set! *vararg-gensym* old-vararg-gensym)
           result))))
 
   ;; expression-list -> expression { ',' expression }
@@ -535,7 +542,7 @@
         ((#:varargs)
          (unless *vararg-function*
            (syntax-error src "cannot use '...' outside of a variable arguments function"))
-         (advance! (make-ast-variable-arguments src)))
+         (advance! (make-ast-variable-arguments src *vararg-gensym*)))
         ;; FUNCTION function-body
         ((#:function) (advance!) (function-body src))
         ;; primary-expression
diff --git a/test-suite/tests/lua-eval-2.test b/test-suite/tests/lua-eval-2.test
index 0787a3f..e07e827 100644
--- a/test-suite/tests/lua-eval-2.test
+++ b/test-suite/tests/lua-eval-2.test
@@ -99,7 +99,7 @@
     (test "print \"hello world\"; return true")
 
     ;; variable arguments
-    (test "function test(...) print(...) end test(1,2)")
+    (test "function test(...) print(...) end return test(1,2)" #nil)
 
     ;; numeric for loop
     (test "for x = 1,2,1 do print(true) end return true")
-- 
1.7.7.6


  reply	other threads:[~2013-03-26  5:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-26  4:56 lua branch Ian Price
2013-03-26  5:50 ` Ian Price [this message]
2013-03-26  6:14   ` Nala Ginrut
2013-03-26  6:28     ` Ian Price
2013-03-26 21:52   ` Ludovic Courtès
2013-04-12 14:27 ` Ian Price
2013-04-17 23:09   ` Ian Price
2013-05-21 20:42     ` Phil
2013-05-21 21:25       ` Phil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87boa6pv58.fsf@Kagami.home \
    --to=ianprice90@googlemail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).