diff options
author | Andy Wingo <wingo@pobox.com> | 2009-02-22 16:01:11 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-02-22 16:01:11 +0100 |
commit | e05320fa549af175c8cbb7bed8cd4ece873033da (patch) | |
tree | faaaca78867b6d3fd14ea6600f5f24b86343880c /module/language/ecmascript/compile-ghil.scm | |
parent | bb67fe27ab5cda3fcefaa1c471f75c8241cc12b2 (diff) | |
download | guile-e05320fa549af175c8cbb7bed8cd4ece873033da.tar.gz |
compile for-in
* module/language/ecmascript/base.scm (prop-keys): New method, returns
the list of keys of props of this instance.
* module/language/ecmascript/impl.scm: Refactor the global object into a
special kind of module object. Provide a prop-keys implementation for
module objects.
* module/language/ecmascript/compile-ghil.scm (comp): Compile for-in.
* module/language/ecmascript/impl.scm: Reshuffly things, and implement
make-enumerator, a helper for use in for-in statements.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix parsing of
for (var foo in bar) {}...
Diffstat (limited to 'module/language/ecmascript/compile-ghil.scm')
-rw-r--r-- | module/language/ecmascript/compile-ghil.scm | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/module/language/ecmascript/compile-ghil.scm b/module/language/ecmascript/compile-ghil.scm index d2c8385fb..47745e53d 100644 --- a/module/language/ecmascript/compile-ghil.scm +++ b/module/language/ecmascript/compile-ghil.scm @@ -307,7 +307,6 @@ (make-ghil-lambda env l vars #t '() (comp-body env l body formals '%args))))) ((call/this ,obj ,prop ,args) - ;; FIXME: only evaluate "obj" once (@impl e l call/this* (list obj (make-ghil-lambda e l '() #f '() @@ -449,6 +448,39 @@ '()))) (@implv e l *undefined*)))))) (make-ghil-call e l (make-ghil-ref e l (car vars)) '())))))) + ((for-in ,var ,object ,statement) + (call-with-ghil-bindings e '(%continue %enum) + (lambda (vars) + (make-ghil-begin + e l + (list + (make-ghil-set + e l (car vars) + (call-with-ghil-environment e '() + (lambda (e _) + (make-ghil-lambda + e l '() #f '() + (make-ghil-if + e l (@impl e l ->boolean + (list (@impl e l pget + (list (make-ghil-ref + e l (ghil-var-for-ref! e '%enum)) + (make-ghil-quote e l 'length))))) + (make-ghil-begin + e l (list (comp `(= ,var (call/this ,(make-ghil-ref + e l (ghil-var-for-ref! e '%enum)) + ,(make-ghil-quote e l 'pop) + ())) + e) + (comp statement e) + (make-ghil-call e l (make-ghil-ref + e l (ghil-var-for-ref! e '%continue)) + '()))) + (@implv e l *undefined*)))))) + (make-ghil-set + e l (cadr vars) + (@impl e l make-enumerator (list (comp object e)))) + (make-ghil-call e l (make-ghil-ref e l (car vars)) '())))))) ((break) (let ((var (ghil-var-for-ref! e '%continue))) (if (and (ghil-env? (ghil-var-env var)) |