From: Julian Graham <joolean@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: [PATCH] Fix tree-il code generation for ECMAscript `new' expression.
Date: Tue, 13 Sep 2016 08:42:51 -0400 [thread overview]
Message-ID: <CANdC_RBE5GnowVcCCoi3YYcj_MeKX2AVrVf3A3=0C+sZ3Y+u2g@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 248 bytes --]
Hi Guilers,
Noticed that ECMAscript "new" syntax seemed to be broken. Here's a
patch that fixes it. I'd like to make some incremental improvements in
Guile's ECMAscript support, so if this one's welcome, expect others to
follow!
Regards,
Julian
[-- Attachment #2: 0001-Fix-tree-il-code-generation-for-ECMAscript-new-expre.patch --]
[-- Type: text/x-patch, Size: 2789 bytes --]
From 16ef2df6cc206f829c3aff96b1b315ed6fb50c05 Mon Sep 17 00:00:00 2001
From: Julian Graham <joolean@undecidable.net>
Date: Tue, 13 Sep 2016 08:39:43 -0400
Subject: [PATCH] Fix tree-il code generation for ECMAscript `new' expression.
The compiler was producing `((toplevel foo))' instead of `(toplevel foo)'.
Changed to use `call' form with target type and spliced constructor
arguments.
* module/language/ecmascript/compile-tree-il.scm (comp): Replace `@impl'
shorthand with `call' + `@implv' for better control over resulting
tree-il.
* test-suite/tests/ecmascript.test (compiler): Add test for "new Object();"
---
module/language/ecmascript/compile-tree-il.scm | 8 ++++----
test-suite/tests/ecmascript.test | 8 +++++++-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/module/language/ecmascript/compile-tree-il.scm b/module/language/ecmascript/compile-tree-il.scm
index a9ac3e0..d61f712 100644
--- a/module/language/ecmascript/compile-tree-il.scm
+++ b/module/language/ecmascript/compile-tree-il.scm
@@ -1,6 +1,6 @@
;;; ECMAScript for Guile
-;; Copyright (C) 2009, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011, 2016 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -437,9 +437,9 @@
((^= ,what ,val)
(comp `(= ,what (^ ,what ,val)) e))
((new ,what ,args)
- (@impl new
- (map (lambda (x) (comp x e))
- (cons what args))))
+ `(call ,(@implv new)
+ ,(comp what e)
+ ,@(map (lambda (x) (comp x e)) args)))
((delete (pref ,obj ,prop))
(@impl pdel
(comp obj e)
diff --git a/test-suite/tests/ecmascript.test b/test-suite/tests/ecmascript.test
index 96b1d66..9f2731e 100644
--- a/test-suite/tests/ecmascript.test
+++ b/test-suite/tests/ecmascript.test
@@ -1,6 +1,6 @@
;;;; ecmascript.test --- ECMAScript. -*- mode: scheme; coding: utf-8; -*-
;;;;
-;;;; Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
+;;;; Copyright (C) 2010, 2011, 2013, 2016 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -83,6 +83,12 @@
(ecompile "\"hello\";" "hello")
(ecompile "var test = { bar: 1 };")
+ (pass-if "new Object;"
+ (not (not
+ (compile (call-with-input-string "new Object;" read-ecmascript)
+ #:from 'ecmascript
+ #:to 'tree-il)))) ; Can't reference `Object' as value here
+
;; FIXME: Broken!
;; (ecompile "[1,2,3,4].map(function(x) { return x * x; });"
;; '(1 4 9 16))
--
2.5.0
next reply other threads:[~2016-09-13 12:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 12:42 Julian Graham [this message]
2016-09-20 4:32 ` [PATCH] Fix tree-il code generation for ECMAscript `new' expression Wilfred Hughes
2016-09-20 14:26 ` Julian Graham
2016-09-21 1:55 ` Wilfred Hughes
2016-09-25 2:38 ` Julian Graham
2016-10-25 21:41 ` Ludovic Courtès
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='CANdC_RBE5GnowVcCCoi3YYcj_MeKX2AVrVf3A3=0C+sZ3Y+u2g@mail.gmail.com' \
--to=joolean@gmail.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).