1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00

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.
This commit is contained in:
Ian Price 2017-08-27 22:18:40 +01:00
parent c5fa12f344
commit d4ef33f6cf
2 changed files with 13 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#:use-module (srfi srfi-9) #:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-9 gnu)
#:export ( #:export (
make-assign assign
make-const const make-const const
make-function function make-function function
make-return return make-return return
@ -50,6 +51,7 @@
(define (print-js exp port) (define (print-js exp port)
(format port "#<js ~S>" (unparse-js exp))) (format port "#<js ~S>" (unparse-js exp)))
(define-js-type assign id exp)
(define-js-type const c) (define-js-type const c)
(define-js-type function args body) (define-js-type function args body)
(define-js-type return exp) (define-js-type return exp)
@ -66,6 +68,8 @@
(define (unparse-js exp) (define (unparse-js exp)
(match exp (match exp
(($ assign id exp)
`(assign ,id ,(unparse-js exp)))
(($ const c) (($ const c)
`(const ,c)) `(const ,c))
(($ function args body) (($ function args body)
@ -99,6 +103,13 @@
(define (print-exp exp port) (define (print-exp exp port)
(match exp (match exp
(($ assign id exp)
(print-id id port)
(format port " = ")
(display "(" port)
(print-exp exp port)
(display ")" port))
(($ const c) (($ const c)
(print-const c port)) (print-const c port))

View file

@ -15,6 +15,8 @@
(fold-right flatten '() stmts)) (fold-right flatten '() stmts))
(define (flatten-exp exp) (define (flatten-exp exp)
(match exp (match exp
(($ assign id exp)
(make-assign id (flatten-exp exp)))
(($ const c) exp) (($ const c) exp)
(($ new exp) (($ new exp)
(make-new (flatten-exp exp))) (make-new (flatten-exp exp)))