diff options
-rw-r--r-- | module/language/ecmascript/base.scm | 8 | ||||
-rw-r--r-- | module/language/ecmascript/compile-ghil.scm | 16 | ||||
-rw-r--r-- | module/language/ecmascript/impl.scm | 5 | ||||
-rw-r--r-- | module/language/ecmascript/parse.scm | 2 |
4 files changed, 27 insertions, 4 deletions
diff --git a/module/language/ecmascript/base.scm b/module/language/ecmascript/base.scm index 42a659895..b7604a366 100644 --- a/module/language/ecmascript/base.scm +++ b/module/language/ecmascript/base.scm @@ -23,6 +23,7 @@ #:use-module (oop goops) #:export (*undefined* *this* <js-object> *object-prototype* + js-prototype js-props js-prop-attrs js-value js-constructor js-class pget prop-attrs prop-has-attr? pput has-property? pdel object->string object->number object->value/string @@ -31,7 +32,7 @@ ->primitive ->boolean ->number ->integer ->int32 ->uint32 ->uint16 ->string ->object - call/this lambda/this define-js-method + call/this* call/this lambda/this define-js-method new-object)) @@ -82,8 +83,11 @@ (pput o p *undefined*) #t)))) +(define (call/this* this f) + (with-fluid* *this* this f)) + (define-macro (call/this this f . args) - `(with-fluid* *this* ,this (lambda () (f . ,args)))) + `(with-fluid* *this* ,this (lambda () (,f . ,args)))) (define-macro (lambda/this formals . body) `(lambda ,formals (let ((this (fluid-ref *this*))) . ,body))) (define-macro (define-js-method object name-and-args . body) diff --git a/module/language/ecmascript/compile-ghil.scm b/module/language/ecmascript/compile-ghil.scm index 825599d05..2f385643f 100644 --- a/module/language/ecmascript/compile-ghil.scm +++ b/module/language/ecmascript/compile-ghil.scm @@ -62,6 +62,8 @@ (make-ghil-quote e l num)) ((string ,str) (make-ghil-quote e l str)) + (this + (@impl e l get-this '())) ((+ ,a ,b) (make-ghil-inline e l 'add (list (comp a e) (comp b e)))) ((- ,a ,b) @@ -95,6 +97,20 @@ (lambda (env vars) (make-ghil-lambda env l vars #t '() (comp-body env l body formals '%args))))) + ((call/this ,obj ,prop ,args) + (@impl e l call/this* + (list obj (make-ghil-lambda + e l '() #f '() + (make-ghil-call e l (@impl e l pget (list obj prop)) + args))))) + ((call (pref ,obj ,prop) ,args) + (comp `(call/this ,(comp obj e) ,(make-ghil-quote e l prop) + ,(map (lambda (x) (comp x e)) args)) + e)) + ((call (aref ,obj ,prop) ,args) + (comp `(call/this ,(comp obj e) ,(comp prop e) + ,(map (lambda (x) (comp x e)) args)) + e)) ((call ,proc ,args) (make-ghil-call e l (comp proc e) (map (lambda (x) (comp x e)) args))) ((return ,expr) diff --git a/module/language/ecmascript/impl.scm b/module/language/ecmascript/impl.scm index f38a4450b..2ab83a158 100644 --- a/module/language/ecmascript/impl.scm +++ b/module/language/ecmascript/impl.scm @@ -24,9 +24,12 @@ #:use-module (language ecmascript base) #:use-module (language ecmascript function) #:use-module (language ecmascript array) - #:re-export (*undefined* *this* + #:export (get-this) + #:re-export (*undefined* *this* call/this* pget pput pdel new-object new new-array)) +(define (get-this) + (fluid-ref *this*)) diff --git a/module/language/ecmascript/parse.scm b/module/language/ecmascript/parse.scm index 50d70ed3f..2c5e10265 100644 --- a/module/language/ecmascript/parse.scm +++ b/module/language/ecmascript/parse.scm @@ -173,7 +173,7 @@ ;; as to get operator precedence right. ;; - (PrimaryExpression (this) -> '(this) + (PrimaryExpression (this) -> 'this (null) -> 'null (true) -> #t (false) -> #f |