From: Ian Price <ianprice90@googlemail.com>
To: guile-devel@gnu.org
Subject: Re: lua branch
Date: Thu, 18 Apr 2013 00:09:16 +0100 [thread overview]
Message-ID: <87zjwwkb4z.fsf@Kagami.home> (raw)
In-Reply-To: <87r4if6czh.fsf@Kagami.home> (Ian Price's message of "Fri, 12 Apr 2013 15:27:14 +0100")
[-- Attachment #1: Type: text/plain, Size: 693 bytes --]
Ian Price <ianprice90@googlemail.com> writes:
> The current issues with lua vs master are as follows
> 1) <application> has been renamed to <call> on master
> 2) <sequence> has been replaced with <seq> which is not quite a drop-in
> 3) while was being compiled into something with improper scoping.
>
> I have fixes for these locally. There is just the question of rebase vs
> merge for bringing the branch up to date. Any preference there?
Sorry, got distracted.
Is it okay to merge master into lua, and push these three patches?
--
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: Fix <application> --]
[-- Type: text/x-patch, Size: 12164 bytes --]
From 80887b0913479c980e31534d16d0a872d437e18e Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Wed, 17 Apr 2013 23:53:31 +0100
Subject: [PATCH 1/3] Use `make-application' instead of removed `make-call'.
* module/language/lua/compile-tree-il.scm: Rename.
---
module/language/lua/compile-tree-il.scm | 102 +++++++++++++++---------------
1 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/module/language/lua/compile-tree-il.scm b/module/language/lua/compile-tree-il.scm
index 72c0d1b..e81e929 100644
--- a/module/language/lua/compile-tree-il.scm
+++ b/module/language/lua/compile-tree-il.scm
@@ -41,7 +41,7 @@
(define (make-runtime-application src name arguments)
"Shorthand for creating an application of a function in the (language lua runtime) module"
- (make-application src (ref-runtime src name) arguments))
+ (make-call src (ref-runtime src name) arguments))
(define (make-table-ref src table index)
"Shorthand for calling the index function in (language lua runtime)"
@@ -79,7 +79,7 @@
(define (apply-named-lua-function src name get-body)
(let* ((name (gensym (string-append " " name)))
(parameters (list name)))
- (make-application
+ (make-call
src
(make-module-ref src '(guile) 'catch #t)
(list
@@ -89,7 +89,7 @@
src
parameters parameters
(list (make-lambda src '() (get-body name)))
- (make-application src (make-lexical-ref src name name) '())))
+ (make-call src (make-lexical-ref src name name) '())))
(make-arg-ignoring-lambda src
(make-void src))))))
@@ -104,7 +104,7 @@
(make-sequence
src
(list body
- (make-application src (make-lexical-ref src loop loop) '())))
+ (make-call src (make-lexical-ref src loop loop) '())))
(make-void src)))))
(define (could-result-in-multiple-values? x)
@@ -149,10 +149,10 @@ dropped silently"
((ast-return src exp)
(if tail?
(if (and (list? exp) (not (= (length exp) 1)))
- (make-application src (make-primitive-ref src 'values)
+ (make-call src (make-primitive-ref src 'values)
(map-compile exp))
(compile (if (list? exp) (car exp) exp) #t))
- (make-application
+ (make-call
src (make-primitive-ref src 'return/values)
(if (list? exp) (map-compile exp #t) (list (compile exp))))))
@@ -183,23 +183,23 @@ dropped silently"
;; and a function that takes variable arguments. Then
;; append those variable arguments to the rest of the
;; expression, and apply the first function to it)
- (make-application src
+ (make-call src
(make-primitive-ref src 'call-with-values)
(list
(make-argless-lambda src (make-sequence src (last-pair args)))
(let ((rest-gensym (gensym "rest")))
(make-catch-all-lambda src
- (make-application src (make-primitive-ref src 'apply)
+ (make-call src (make-primitive-ref src 'apply)
(list
proc
- (make-application src
+ (make-call src
(make-module-ref src '(srfi srfi-1) 'append! #t)
(list
- (make-application src (make-primitive-ref src 'list) (drop-right args 1))
+ (make-call src (make-primitive-ref src 'list) (drop-right args 1))
(make-lexical-ref src 'rest rest-gensym)))))
rest-gensym))))
- (make-application src proc args)))
+ (make-call src proc args)))
;; If this is function is a global variable, prepend a call to
;; check-global-function to make sure it's defined before
@@ -208,7 +208,7 @@ dropped silently"
(make-sequence
src (list
;; FIXME: use module binders instead
- (make-application
+ (make-call
src (make-module-ref src '(language lua runtime)
'check-global-function #t)
(list (make-const src (ast-global-ref-name operator))
@@ -252,7 +252,7 @@ dropped silently"
(unless (memq (context) '(while-loop list-for-loop numeric-for-loop))
(syntax-error src "no loop to break"))
;; FIXME: use abort instead of throw
- (make-application src (make-module-ref src '(guile) 'throw #t)
+ (make-call src (make-module-ref src '(guile) 'throw #t)
(list (make-const src 'lua-break))))
;; FIXME: use prompt and abort instead of throw and catch
@@ -278,32 +278,32 @@ dropped silently"
(begin
;; even more complicated, assigning the values to
;; the loop variables
- (apply (primitive call-with-values)
- (lambda ()
- (lambda-case
- (,no-arguments
- (apply (lexical iterator ,gs-iterator)
- (lexical state ,gs-state)
- (lexical variable ,gs-variable)))))
- (lambda ()
- (lambda-case
- ((,names #f #f #f () ,gs-names)
- ;; almost to the actual loop body, hang
- ;; in there
- (begin
- (set! (lexical variable ,gs-variable)
- (lexical ,(car names) ,(car gs-names)))
- (if (apply (primitive eq?)
- (lexical variable ,gs-variable)
- (const #nil))
- (apply (@ (guile) throw) (const lua-break))
- (void))
- ,(parameterize ((context 'list-for-loop))
- (unparse-tree-il (compile body)))
- (apply (lexical loop ,gs-loop))))))))))))
+ (call (primitive call-with-values)
+ (lambda ()
+ (lambda-case
+ (,no-arguments
+ (call (lexical iterator ,gs-iterator)
+ (lexical state ,gs-state)
+ (lexical variable ,gs-variable)))))
+ (lambda ()
+ (lambda-case
+ ((,names #f #f #f () ,gs-names)
+ ;; almost to the actual loop body, hang
+ ;; in there
+ (begin
+ (set! (lexical variable ,gs-variable)
+ (lexical ,(car names) ,(car gs-names)))
+ (if (call (primitive eq?)
+ (lexical variable ,gs-variable)
+ (const #nil))
+ (call (@ (guile) throw) (const lua-break))
+ (void))
+ ,(parameterize ((context 'list-for-loop))
+ (unparse-tree-il (compile body)))
+ (call (lexical loop ,gs-loop))))))))))))
;; initialize variables and start loop
(begin
- (apply (primitive call-with-values)
+ (call (primitive call-with-values)
(lambda ()
(lambda-case
(,no-arguments
@@ -320,12 +320,12 @@ dropped silently"
(lexical state ,gs-state2))
(set! (lexical variable ,gs-variable)
(lexical variable ,gs-variable2)))))))
- (apply (@ (guile) catch)
+ (call (@ (guile) catch)
(const lua-break)
(lambda ()
(lambda-case
(,no-arguments
- (apply (lexical loop ,gs-loop)))))
+ (call (lexical loop ,gs-loop)))))
(lambda ()
(lambda-case
(((key) #f #f #f () (,(gensym "key")))
@@ -348,11 +348,11 @@ dropped silently"
(gs-step (gensym "step"))
(gs-loop (gensym "loop"))
(while-condition
- `(if (apply (primitive >) (lexical step ,gs-step) (const 0))
- (if (apply (primitive <=)
+ `(if (call (primitive >) (lexical step ,gs-step) (const 0))
+ (if (call (primitive <=)
(lexical variable ,gs-variable)
(lexical limit ,gs-limit))
- (apply (lexical loop ,gs-loop))
+ (call (lexical loop ,gs-loop))
(void))
(void))))
(parse-tree-il
@@ -366,8 +366,8 @@ dropped silently"
'(const #f)
(append
(map (lambda (x)
- `(apply (@ (language lua runtime) tonumber)
- ,(unparse-tree-il (compile x))))
+ `(call (@ (language lua runtime) tonumber)
+ ,(unparse-tree-il (compile x))))
(list initial limit step))
;; loop body
(list
@@ -382,14 +382,14 @@ dropped silently"
,(parameterize ((context 'numeric-for-loop))
(unparse-tree-il (compile body)))
(set! (lexical variable ,gs-variable)
- (apply (primitive +)
- (lexical variable ,gs-variable)
- (lexical step ,gs-step)))
+ (call (primitive +)
+ (lexical variable ,gs-variable)
+ (lexical step ,gs-step)))
,while-condition)))))))
;; body
(begin
;; if not (var and limit and step) then error() end
- (if (apply (primitive not)
+ (if (call (primitive not)
(if (lexical variable ,gs-variable)
(if (lexical limit ,gs-limit)
(if (lexical step ,gs-step)
@@ -397,7 +397,7 @@ dropped silently"
(const #f))
(const #f))
(const #f)))
- (apply (@ (guile) error))
+ (call (@ (guile) error))
(void))
,while-condition
)))))
@@ -437,7 +437,7 @@ dropped silently"
(if (and (eq? operator #\-) (ast-literal? right)
(number? (ast-literal-exp right)))
(make-const src (- (ast-literal-exp right)))
- (make-application
+ (make-call
src
(case operator
((#\-) (ref-runtime src 'unm))
@@ -478,7 +478,7 @@ dropped silently"
(make-lexical-ref src 'and-tmp tmp)))))
(else (error #:COMPILE "unknown binary operator" operator)))))
((ast-variable-arguments src gensym)
- (make-application src
+ (make-call src
(make-primitive-ref src 'apply)
(list (make-primitive-ref src 'values)
(make-lexical-ref src '... gensym))))))
--
1.7.7.6
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: Fix <sequence> --]
[-- Type: text/x-patch, Size: 1109 bytes --]
From a8a3a1cdc67fa7bf3be6435500cd4a1fe77be8a8 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Wed, 17 Apr 2013 23:58:09 +0100
Subject: [PATCH 2/3] Add missing `make-sequence' procedure.
* module/language/lua/compile-tree-il.scm (make-sequence): New procedure.
---
module/language/lua/compile-tree-il.scm | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/module/language/lua/compile-tree-il.scm b/module/language/lua/compile-tree-il.scm
index e81e929..e0ecfa3 100644
--- a/module/language/lua/compile-tree-il.scm
+++ b/module/language/lua/compile-tree-il.scm
@@ -53,6 +53,11 @@
(make-runtime-application src 'new-index!
(list table (if (symbol? index) (make-const src (symbol->string index)) index) exp)))
+(define (make-sequence src body)
+ (if (null? (cdr body))
+ (car body)
+ (make-seq src (car body) (make-sequence #f (cdr body)))))
+
;; Calling conventions
(define* (make-plain-lambda-case src args gensyms body #:optional alternate)
(make-lambda-case src args #f #f #f '() (or gensyms args) body alternate))
--
1.7.7.6
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Fix while --]
[-- Type: text/x-patch, Size: 1120 bytes --]
From e964c5acf2f54871d6ce06a627f48e0b8331b5c0 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90@googlemail.com>
Date: Thu, 18 Apr 2013 00:03:34 +0100
Subject: [PATCH 3/3] Fix code generated for `while'.
* module/language/lua/compile-tree-il.scm (while-loop->tree-il):
Generate `letrec' instead of `let'.
Generate valid `lambda' expression.
---
module/language/lua/compile-tree-il.scm | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/module/language/lua/compile-tree-il.scm b/module/language/lua/compile-tree-il.scm
index e0ecfa3..4472b05 100644
--- a/module/language/lua/compile-tree-il.scm
+++ b/module/language/lua/compile-tree-il.scm
@@ -90,10 +90,10 @@
(list
(make-const src 'lua-break)
(make-argless-lambda src
- (make-let
+ (make-letrec #f
src
parameters parameters
- (list (make-lambda src '() (get-body name)))
+ (list (make-argless-lambda src (get-body name)))
(make-call src (make-lexical-ref src name name) '())))
(make-arg-ignoring-lambda src
(make-void src))))))
--
1.7.7.6
next prev parent reply other threads:[~2013-04-17 23:09 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
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 [this message]
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=87zjwwkb4z.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).