summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Price <ianprice90@googlemail.com>2017-08-27 22:18:40 +0100
committerIan Price <ianprice90@googlemail.com>2017-08-27 22:18:40 +0100
commitd4ef33f6cfc6882b0ff02faf2069610b69e74ab4 (patch)
tree118158bed6b99b93c746c68eb5268b5986b51ac9
parentc5fa12f344b128b10213f326cfe1e4631a0b1673 (diff)
downloadguile-d4ef33f6cfc6882b0ff02faf2069610b69e74ab4.tar.gz
Add assignment js-type to (language javascript)
* module/language/javascript.scm (assign): new js-type (print-exp, unparse-js): Handle case. * module/language/javascript/simplify.scm (flatten-blocks): Handle case.
-rw-r--r--module/language/javascript.scm11
-rw-r--r--module/language/javascript/simplify.scm2
2 files changed, 13 insertions, 0 deletions
diff --git a/module/language/javascript.scm b/module/language/javascript.scm
index 8829b3be0..4a4943545 100644
--- a/module/language/javascript.scm
+++ b/module/language/javascript.scm
@@ -4,6 +4,7 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
#:export (
+ make-assign assign
make-const const
make-function function
make-return return
@@ -50,6 +51,7 @@
(define (print-js exp port)
(format port "#<js ~S>" (unparse-js exp)))
+(define-js-type assign id exp)
(define-js-type const c)
(define-js-type function args body)
(define-js-type return exp)
@@ -66,6 +68,8 @@
(define (unparse-js exp)
(match exp
+ (($ assign id exp)
+ `(assign ,id ,(unparse-js exp)))
(($ const c)
`(const ,c))
(($ function args body)
@@ -99,6 +103,13 @@
(define (print-exp exp port)
(match exp
+ (($ assign id exp)
+ (print-id id port)
+ (format port " = ")
+ (display "(" port)
+ (print-exp exp port)
+ (display ")" port))
+
(($ const c)
(print-const c port))
diff --git a/module/language/javascript/simplify.scm b/module/language/javascript/simplify.scm
index 2e3bde5f0..a26b7fd2e 100644
--- a/module/language/javascript/simplify.scm
+++ b/module/language/javascript/simplify.scm
@@ -15,6 +15,8 @@
(fold-right flatten '() stmts))
(define (flatten-exp exp)
(match exp
+ (($ assign id exp)
+ (make-assign id (flatten-exp exp)))
(($ const c) exp)
(($ new exp)
(make-new (flatten-exp exp)))