[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, lua, updated. release_1-9-11-41-g08644
From: |
No Itisnt |
Subject: |
[Guile-commits] GNU Guile branch, lua, updated. release_1-9-11-41-g0864403 |
Date: |
Tue, 15 Jun 2010 00:34:39 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=0864403f1224c528ebae22b658732e845c97dfdb
The branch, lua has been updated
via 0864403f1224c528ebae22b658732e845c97dfdb (commit)
via 5eb33a73752892dfe6a75675f18015b733dc2976 (commit)
from 8899ae7e9ba749c3edcccd13dd5b92da4fae5622 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0864403f1224c528ebae22b658732e845c97dfdb
Author: No Itisnt <address@hidden>
Date: Mon Jun 14 19:34:17 2010 -0500
lua: Add local function support
commit 5eb33a73752892dfe6a75675f18015b733dc2976
Author: No Itisnt <address@hidden>
Date: Mon Jun 14 17:14:26 2010 -0500
lua: Fix function parameters and local variable assignments.
-----------------------------------------------------------------------
Summary of changes:
lua.scm | 54 +++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/lua.scm b/lua.scm
index baa256c..2a11a53 100644
--- a/lua.scm
+++ b/lua.scm
@@ -472,14 +472,23 @@ of an identifier"
;; tree-il utilities that need access to this closure
(define (make-lua-function src parameters body-promise)
"Generate a function"
+
;; create a new environment and populate it with the function's parameters
+
+ ;; functions have two environments: one for the function's parameters and
+ ;; another for the function's locals (this is inefficient and is simply to
+ ;; compensate for the simplistic implementation of locals (in CHUNK),
+ ;; perhaps the environment should be extended to track the type of a
+ ;; variable as well)
(enter-environment!)
(for-each environment-define! parameters)
+ (enter-environment!)
(let* ((body (force body-promise))
(parameter-gensyms (map environment-lookup parameters)))
(leave-environment!)
+ (leave-environment!)
(make-lambda
src '()
(make-lambda-case src parameters #f #f #f '() parameter-gensyms (if
(null? body) (make-void src) body) #f))))
@@ -939,6 +948,13 @@ of an identifier"
;; otherwise, it's not a declaration, not an assignment, and
evaluates to nothing
(make-void #f))))))
+ (define (local-function-statement)
+ (assert-token-type 'NAME)
+ (let* ((name token))
+ (environment-define! name)
+ (advance!)
+ (make-lexical-set (get-source-info) name (environment-lookup name)
(function-body))))
+
;; statement
(define (statement)
(case token
@@ -952,7 +968,11 @@ of an identifier"
((#:while) (while-statement))
((#:if) (if-statement))
((#:function) (function-statement))
- ((#:local) (advance!) (local-statement))
+ ((#:local)
+ (advance!)
+ (if (maybe-skip-next! #:function)
+ (local-function-statement)
+ (local-statement)))
((#:do)
(begin
(advance!)
@@ -1119,6 +1139,15 @@ of an identifier"
(test "return;" *unspecified*)
(test "return 1 + -6" -5)
+ ;; logical operators
+ (test "return false or true")
+ (test "return true or false")
+ (test "return false or false or true")
+ (test "return false or nil and true" #nil)
+ (test "return true and true")
+ (test "return true and nil" #nil)
+ (test "return true and false and nil" #f)
+
;; conditionals
(test "if true then return true end")
(test "if false then return false else return true end")
@@ -1126,20 +1155,18 @@ of an identifier"
(test "if false then return false elseif true then return true elseif
false then return false else return false end")
(test "if false then return false elseif false then return false elseif
true then return true else return false end")
(test "if false then return false elseif false then return false elseif
false then return false else return true end")
+
+ ;; function expressions
+ (test "(function(x) return x end)(true)")
- ;; functions
+ ;; function statements
(test "function identity(x) return x end return identity(21)" 21)
(test "function fib(n) if n < 2 then return n else return fib(n-1) +
fib(n-2) end end return fib(20)" 6765)
(test "\n-- fibonacci numbers\nfunction fib(n)\n if n < 2 then\n
return n\n else\n return fib(n-1) + fib(n-2)\n end\nend\nreturn fib(20)"
6765)
+
+ ;; built-in functions
(test "assert(true)")
(test "print(T)" #nil)
- (test "return false or true")
- (test "return true or false")
- (test "return false or false or true")
- (test "return false or nil and true" #nil)
- (test "return true and true")
- (test "return true and nil" #nil)
- (test "return true and false and nil" #f)
(test "print(false or true)" #nil)
;; do
@@ -1178,6 +1205,11 @@ of an identifier"
(test "local a; a = true; return a")
(test "local a = true; return a")
(test "local a,b=false,true; return b")
+ (test "local a,b,c=false,true,false; return b")
+ (test "local a,b,c=false,false,true; return c")
+
+ ;; local function statements
+ (test "local function identity(x) return x end; return identity(true)")
;; - compiler
;; method invocations
@@ -1192,7 +1224,7 @@ of an identifier"
#;(begin
(define var
- "local a,b=false,true; return b")
- (display (compile ((make-parser (open-input-string var)))
+ "local function identity(x) return x end; return identity(true)"
+ ) (display (compile ((make-parser (open-input-string var)))
#:from 'lua #:to 'tree-il))
(newline))
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, lua, updated. release_1-9-11-41-g0864403,
No Itisnt <=