1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 09:40:25 +02:00

property gets and puts implemented, yays

* module/language/ecmascript/compile-ghil.scm (@impl): Ok, don't recurse
  on args here.
  (comp): Implement property gets and puts and lexical assignment.
  (comp-body): Fix scanning of var forms.

* module/language/ecmascript/impl.scm (prop-attrs): Allow for the prop
  attr array to be #f.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix assignment
  parsing.
This commit is contained in:
Andy Wingo 2009-02-19 16:40:22 +01:00
parent 10e1bd278f
commit 7fb4230060
3 changed files with 18 additions and 9 deletions

View file

@ -43,7 +43,7 @@
(make-ghil-ref (make-ghil-ref
,e ,l ,e ,l
(ghil-var-at-module! ,e '(language ecmascript impl) ',sym #t)) (ghil-var-at-module! ,e '(language ecmascript impl) ',sym #t))
(map (lambda (x) (comp x ,e)) ,args))) ,args))
(define (comp x e) (define (comp x e)
(let ((l (location x))) (let ((l (location x)))
@ -84,7 +84,13 @@
((return ,expr) ((return ,expr)
(make-ghil-inline e l 'return (list (comp expr e)))) (make-ghil-inline e l 'return (list (comp expr e))))
((array . ,args) ((array . ,args)
(@impl e l new-array args)) (@impl e l new-array (map (lambda (x) (comp x e)) args)))
((pref ,obj ,prop)
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
((= (ref ,name) ,val)
(make-ghil-set e l (ghil-var-for-set! e name) (comp val e)))
((= (pref ,obj ,prop) ,val)
(@impl e l pput (list (comp obj e) (make-ghil-quote e l prop) (comp val e))))
(else (else
(error "compilation not yet implemented:" x))))) (error "compilation not yet implemented:" x)))))
@ -92,14 +98,16 @@
(define (process) (define (process)
(let lp ((in body) (out '()) (rvars (reverse formals))) (let lp ((in body) (out '()) (rvars (reverse formals)))
(pmatch in (pmatch in
(((var ,x) . ,rest) (((var (,x) . ,morevars) . ,rest)
(lp rest (lp `((var . ,morevars) . ,rest)
out out
(if (memq x rvars) rvars (cons x rvars)))) (if (memq x rvars) rvars (cons x rvars))))
(((var ,x ,y) . ,rest) (((var (,x ,y) . ,morevars) . ,rest)
(lp rest (lp `((var . ,morevars) . ,rest)
`((= (ref ,x) ,y) . ,out) `((= (ref ,x) ,y) . ,out)
(if (memq x rvars) rvars (cons x rvars)))) (if (memq x rvars) rvars (cons x rvars))))
(((var) . ,rest)
(lp rest out rvars))
((,x . ,rest) (guard (and (pair? x) (eq? (car x) 'lambda))) ((,x . ,rest) (guard (and (pair? x) (eq? (car x) 'lambda)))
(lp rest (lp rest
(cons x out) (cons x out)

View file

@ -55,7 +55,8 @@
*undefined*))))) *undefined*)))))
(define-method (prop-attrs (o <js-object>) p) (define-method (prop-attrs (o <js-object>) p)
(or (hashq-ref (js-prop-attrs o) p) (or (let ((attrs (js-prop-attrs o)))
(and attrs (hashq-ref (js-prop-attrs o) p)))
(let ((proto (js-prototype o))) (let ((proto (js-prototype o)))
(if proto (if proto
(prop-attrs proto p) (prop-attrs proto p)

View file

@ -102,8 +102,8 @@
(Identifier Initialiser) -> `(,$1 ,$2)) (Identifier Initialiser) -> `(,$1 ,$2))
(VariableDeclarationNoIn (Identifier) -> `(,$1) (VariableDeclarationNoIn (Identifier) -> `(,$1)
(Identifier Initialiser) -> `(,$1 ,$2)) (Identifier Initialiser) -> `(,$1 ,$2))
(Initialiser (= AssignmentExpression) -> $1) (Initialiser (= AssignmentExpression) -> $2)
(InitialiserNoIn (= AssignmentExpressionNoIn) -> $1) (InitialiserNoIn (= AssignmentExpressionNoIn) -> $2)
(EmptyStatement (semicolon) -> '(begin)) (EmptyStatement (semicolon) -> '(begin))