mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 08:40:19 +02:00
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) {}...
This commit is contained in:
parent
bb67fe27ab
commit
e05320fa54
4 changed files with 65 additions and 27 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue