1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

more arithmetic on non-numbers

* module/language/ecmascript/compile-ghil.scm (comp): Convert to number
  on unary +.

* module/language/ecmascript/impl.scm: Define -, *, /, <, <=, >=, >
  operations on non-numbers.
This commit is contained in:
Andy Wingo 2009-02-22 11:06:13 +01:00
parent 8c306808c2
commit af6c20b731
2 changed files with 32 additions and 2 deletions

View file

@ -89,7 +89,8 @@
(this
(@impl e l get-this '()))
((+ ,a)
(make-ghil-inline e l 'add (list (comp a e) (make-ghil-quote e l 0))))
(make-ghil-inline e l 'add (list (@impl e l ->number (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)

View file

@ -26,7 +26,7 @@
#:use-module (language ecmascript array)
#:re-export (*undefined* *this* call/this*
pget pput pdel has-property?
->boolean
->boolean ->number
new-object new new-array)
#:export (js-init get-this
typeof
@ -110,3 +110,32 @@
(define-method (+ a b)
(+ (->number a) (->number b)))
(define-method (- a b)
(- (->number a) (->number b)))
(define-method (* a b)
(* (->number a) (->number b)))
(define-method (/ a b)
(/ (->number a) (->number b)))
(define-method (< a b)
(< (->number a) (->number b)))
(define-method (< (a <string>) (b <string>))
(string< a b))
(define-method (<= a b)
(<= (->number a) (->number b)))
(define-method (<= (a <string>) (b <string>))
(string<= a b))
(define-method (>= a b)
(>= (->number a) (->number b)))
(define-method (>= (a <string>) (b <string>))
(string>= a b))
(define-method (> a b)
(> (->number a) (->number b)))
(define-method (> (a <string>) (b <string>))
(string> a b))