1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

implement object literals

* module/language/ecmascript/impl.scm:
* module/language/ecmascript/compile-ghil.scm (comp): Object literals.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix some
  object literal parsing.
This commit is contained in:
Andy Wingo 2009-02-19 17:14:16 +01:00
parent 984dce236b
commit b72880eb17
3 changed files with 25 additions and 6 deletions

View file

@ -101,6 +101,17 @@
(make-ghil-inline e l 'return (list (comp expr e))))
((array . ,args)
(@impl e l new-array (map (lambda (x) (comp x e)) args)))
((object . ,args)
(@impl e l new-object
(map (lambda (x)
(pmatch x
((,prop ,val)
(make-ghil-inline e l 'cons
(list (make-ghil-quote e l prop)
(comp val e))))
(else
(error "bad prop-val pair" x))))
args)))
((pref ,obj ,prop)
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
((= (ref ,name) ,val)

View file

@ -31,7 +31,8 @@
->primitive ->boolean ->number ->integer ->int32 ->uint32
->uint16 ->string ->object
new-array))
new-array
new-object))
(define *undefined* ((@@ (oop goops) make-unbound)))
@ -227,3 +228,10 @@
(vector-set! vect i (car vals))
(lp (1+ i) (cdr vals)))
(else o))))))
(define (new-object . pairs)
(let ((o (make <js-object>)))
(map (lambda (pair)
(pput o (car pair) (cdr pair)))
pairs)
o))

View file

@ -199,11 +199,11 @@
(ObjectLiteral (lbrace rbrace) -> `(object)
(lbrace PropertyNameAndValueList rbrace) -> `(object ,@$2))
(PropertyNameAndValueList (PropertyName colon AssignmentExpression) -> `((,$1 . ,$3))
(PropertyNameAndValueList comma PropertyName colon AssignmentExpression) -> `(,@$1 (,$3 . ,$5)))
(PropertyName (Identifier) -> `(ref ,$1)
(StringLiteral) -> `(string ,$1)
(NumericLiteral) -> `(number ,$1))
(PropertyNameAndValueList (PropertyName colon AssignmentExpression) -> `((,$1 ,$3))
(PropertyNameAndValueList comma PropertyName colon AssignmentExpression) -> `(,@$1 (,$3 ,$5)))
(PropertyName (Identifier) -> $1
(StringLiteral) -> (string->symbol $1)
(NumericLiteral) -> $1)
(MemberExpression (PrimaryExpression) -> $1
(FunctionExpression) -> $1