mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +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:
parent
984dce236b
commit
b72880eb17
3 changed files with 25 additions and 6 deletions
|
@ -101,6 +101,17 @@
|
||||||
(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 (map (lambda (x) (comp x e)) 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)
|
((pref ,obj ,prop)
|
||||||
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
|
(@impl e l pget (list (comp obj e) (make-ghil-quote e l prop))))
|
||||||
((= (ref ,name) ,val)
|
((= (ref ,name) ,val)
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
->primitive ->boolean ->number ->integer ->int32 ->uint32
|
->primitive ->boolean ->number ->integer ->int32 ->uint32
|
||||||
->uint16 ->string ->object
|
->uint16 ->string ->object
|
||||||
|
|
||||||
new-array))
|
new-array
|
||||||
|
new-object))
|
||||||
|
|
||||||
(define *undefined* ((@@ (oop goops) make-unbound)))
|
(define *undefined* ((@@ (oop goops) make-unbound)))
|
||||||
|
|
||||||
|
@ -227,3 +228,10 @@
|
||||||
(vector-set! vect i (car vals))
|
(vector-set! vect i (car vals))
|
||||||
(lp (1+ i) (cdr vals)))
|
(lp (1+ i) (cdr vals)))
|
||||||
(else o))))))
|
(else o))))))
|
||||||
|
|
||||||
|
(define (new-object . pairs)
|
||||||
|
(let ((o (make <js-object>)))
|
||||||
|
(map (lambda (pair)
|
||||||
|
(pput o (car pair) (cdr pair)))
|
||||||
|
pairs)
|
||||||
|
o))
|
||||||
|
|
|
@ -199,11 +199,11 @@
|
||||||
|
|
||||||
(ObjectLiteral (lbrace rbrace) -> `(object)
|
(ObjectLiteral (lbrace rbrace) -> `(object)
|
||||||
(lbrace PropertyNameAndValueList rbrace) -> `(object ,@$2))
|
(lbrace PropertyNameAndValueList rbrace) -> `(object ,@$2))
|
||||||
(PropertyNameAndValueList (PropertyName colon AssignmentExpression) -> `((,$1 . ,$3))
|
(PropertyNameAndValueList (PropertyName colon AssignmentExpression) -> `((,$1 ,$3))
|
||||||
(PropertyNameAndValueList comma PropertyName colon AssignmentExpression) -> `(,@$1 (,$3 . ,$5)))
|
(PropertyNameAndValueList comma PropertyName colon AssignmentExpression) -> `(,@$1 (,$3 ,$5)))
|
||||||
(PropertyName (Identifier) -> `(ref ,$1)
|
(PropertyName (Identifier) -> $1
|
||||||
(StringLiteral) -> `(string ,$1)
|
(StringLiteral) -> (string->symbol $1)
|
||||||
(NumericLiteral) -> `(number ,$1))
|
(NumericLiteral) -> $1)
|
||||||
|
|
||||||
(MemberExpression (PrimaryExpression) -> $1
|
(MemberExpression (PrimaryExpression) -> $1
|
||||||
(FunctionExpression) -> $1
|
(FunctionExpression) -> $1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue