1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 01:30:27 +02:00

implement more operations

* module/language/ecmascript/base.scm: Implement some more robust
  property getters that convert strings to symbols. Implement
  has-property?.

* module/language/ecmascript/compile-ghil.scm (comp): Implement lots more
  mathematical operators. We now do all expressions; on to statements.

* module/language/ecmascript/impl.scm: Define some math helpers. They
  probably need to call ->number on some things.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix a typo.
This commit is contained in:
Andy Wingo 2009-02-20 18:16:34 +01:00
parent 45c10edb74
commit b358fe6502
4 changed files with 122 additions and 13 deletions

View file

@ -73,6 +73,14 @@
(make-ghil-quote e l str))
(this
(@impl e l get-this '()))
((+ ,a)
(make-ghil-inline e l 'add (list (comp a e) (make-ghil-quote e l 0))))
((- ,a)
(make-ghil-inline e l 'sub (list (make-ghil-quote e l 0) (comp a e))))
((~ ,a)
(@impl e l bitwise-not (list (comp a e))))
((! ,a)
(@impl e l logical-not (list (comp a e))))
((+ ,a ,b)
(make-ghil-inline e l 'add (list (comp a e) (comp b e))))
((- ,a ,b)
@ -81,6 +89,48 @@
(make-ghil-inline e l 'div (list (comp a e) (comp b e))))
((* ,a ,b)
(make-ghil-inline e l 'mul (list (comp a e) (comp b e))))
((% ,a ,b)
(@impl e l mod (list (comp a e) (comp b e))))
((<< ,a ,b)
(@impl e l shift (list (comp a e) (comp b e))))
((>> ,a ,b)
(@impl e l shift (list (comp a e) (comp `(- ,b) e))))
((< ,a ,b)
(make-ghil-inline e l 'lt? (list (comp a e) (comp b e))))
((<= ,a ,b)
(make-ghil-inline e l 'le? (list (comp a e) (comp b e))))
((> ,a ,b)
(make-ghil-inline e l 'gt? (list (comp a e) (comp b e))))
((>= ,a ,b)
(make-ghil-inline e l 'ge? (list (comp a e) (comp b e))))
((in ,a ,b)
(@impl e l has-property? (list (comp a e) (comp b e))))
((== ,a ,b)
(make-ghil-inline e l 'equal? (list (comp a e) (comp b e))))
((!= ,a ,b)
(make-ghil-inline e l 'not
(list
(make-ghil-inline e l 'equal?
(list (comp a e) (comp b e))))))
((=== ,a ,b)
(make-ghil-inline e l 'eqv? (list (comp a e) (comp b e))))
((!== ,a ,b)
(make-ghil-inline e l 'not
(list
(make-ghil-inline e l 'eqv?
(list (comp a e) (comp b e))))))
((& ,a ,b)
(@impl e l band (list (comp a e) (comp b e))))
((^ ,a ,b)
(@impl e l bxor (list (comp a e) (comp b e))))
((bor ,a ,b)
(@impl e l bior (list (comp a e) (comp b e))))
((and ,a ,b)
(make-ghil-and e l (list (comp a e) (comp b e))))
((or ,a ,b)
(make-ghil-or e l (list (comp a e) (comp b e))))
((if ,test ,then ,else)
(make-ghil-if e l (comp test e) (comp then e) (comp else e)))
((postinc (ref ,foo))
(begin1 (comp `(ref ,foo) e)
(lambda (var)
@ -273,11 +323,36 @@
((aref ,obj ,index)
(@impl e l pget (list (comp obj e) (comp index e))))
((= (ref ,name) ,val)
(make-ghil-set e l (ghil-var-for-set! e name) (comp val e)))
(let ((v (ghil-var-for-set! e name)))
(make-ghil-begin e l
(list (make-ghil-set e l v (comp val e))
(make-ghil-ref e l v)))))
((= (pref ,obj ,prop) ,val)
(@impl e l pput (list (comp obj e) (make-ghil-quote e l prop) (comp val e))))
((= (aref ,obj ,prop) ,val)
(@impl e l pput (list (comp obj e) (comp prop e) (comp val e))))
((+= ,what ,val)
(comp `(= ,what (+ ,what ,val)) e))
((-= ,what ,val)
(comp `(= ,what (- ,what ,val)) e))
((/= ,what ,val)
(comp `(= ,what (/ ,what ,val)) e))
((*= ,what ,val)
(comp `(= ,what (* ,what ,val)) e))
((%= ,what ,val)
(comp `(= ,what (% ,what ,val)) e))
((>>= ,what ,val)
(comp `(= ,what (>> ,what ,val)) e))
((<<= ,what ,val)
(comp `(= ,what (<< ,what ,val)) e))
((>>>= ,what ,val)
(comp `(= ,what (>>> ,what ,val)) e))
((&= ,what ,val)
(comp `(= ,what (& ,what ,val)) e))
((bor= ,what ,val)
(comp `(= ,what (bor ,what ,val)) e))
((^= ,what ,val)
(comp `(= ,what (^ ,what ,val)) e))
((new ,what ,args)
(@impl e l new (map (lambda (x) (comp x e)) (cons what args))))
((delete (pref ,obj ,prop))