summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-02-22 11:06:13 +0100
committerAndy Wingo <wingo@pobox.com>2009-02-22 11:06:13 +0100
commitaf6c20b731c66397ab3886e162d6b6252d810cbb (patch)
tree3c39c5c35910f76e37f83af0cb05ef82d8211982 /module
parent8c306808c25fb1f353dca2b1d6a1356193e72dea (diff)
downloadguile-af6c20b731c66397ab3886e162d6b6252d810cbb.tar.gz
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.
Diffstat (limited to 'module')
-rw-r--r--module/language/ecmascript/compile-ghil.scm3
-rw-r--r--module/language/ecmascript/impl.scm31
2 files changed, 32 insertions, 2 deletions
diff --git a/module/language/ecmascript/compile-ghil.scm b/module/language/ecmascript/compile-ghil.scm
index 1d1a94c69..3aa007a7e 100644
--- a/module/language/ecmascript/compile-ghil.scm
+++ b/module/language/ecmascript/compile-ghil.scm
@@ -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)
diff --git a/module/language/ecmascript/impl.scm b/module/language/ecmascript/impl.scm
index 737639fd4..c31c29d73 100644
--- a/module/language/ecmascript/impl.scm
+++ b/module/language/ecmascript/impl.scm
@@ -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))