diff options
author | Andy Wingo <wingo@pobox.com> | 2009-02-18 01:17:14 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-02-18 01:18:18 +0100 |
commit | 8fa6886d7af7c012c4cd17f793e5038931ffb4a0 (patch) | |
tree | 4fb22649c856f8b1131d5a1c1b01c5c6612eef5b | |
parent | b912a1cd6b5d22e1fd3eadca10858d8d0dd9c027 (diff) | |
download | guile-8fa6886d7af7c012c4cd17f793e5038931ffb4a0.tar.gz |
add more ecmascript compilation -- functions work now
* module/language/ecmascript/parse.scm (parse-ecmascript): Lambdas always
just have one member in their bodies.
* module/language/ecmascript/compile-ghil.scm (comp): Add some more silly
compilers.
-rw-r--r-- | module/language/ecmascript/compile-ghil.scm | 13 | ||||
-rw-r--r-- | module/language/ecmascript/parse.scm | 12 |
2 files changed, 19 insertions, 6 deletions
diff --git a/module/language/ecmascript/compile-ghil.scm b/module/language/ecmascript/compile-ghil.scm index 03578af77..deaf70805 100644 --- a/module/language/ecmascript/compile-ghil.scm +++ b/module/language/ecmascript/compile-ghil.scm @@ -59,6 +59,19 @@ (make-ghil-inline e l 'div (list (comp a e) (comp b e)))) ((* ,a ,b) (make-ghil-inline e l 'mul (list (comp a e) (comp b e)))) + ((ref ,id) + (make-ghil-ref e l (ghil-var-for-ref! e (string->symbol id)))) + ((define ,id ,val) + (make-ghil-define e l (ghil-var-define! (ghil-env-parent e) (string->symbol id)) + (comp val e))) + ((begin . ,forms) + (make-ghil-begin e l (map (lambda (x) (comp x e)) forms))) + ((lambda ,formals ,body) + (call-with-ghil-environment e formals + (lambda (env vars) + (make-ghil-lambda env l vars #f '() (comp body env))))) + ((call ,proc ,args) + (make-ghil-call e l (comp proc e) (map (lambda (x) (comp x e)) args))) (else (error "compilation not yet implemented:" x))))) diff --git a/module/language/ecmascript/parse.scm b/module/language/ecmascript/parse.scm index ebc7eaae8..0632b6d87 100644 --- a/module/language/ecmascript/parse.scm +++ b/module/language/ecmascript/parse.scm @@ -55,12 +55,12 @@ (SourceElement (Statement) -> $1 (FunctionDeclaration) -> $1) - (FunctionDeclaration (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(define ,$2 (lambda () ,@$6)) - (function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(define ,$2 (lambda ,$4 ,@$7))) - (FunctionExpression (function lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,@$5) - (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,@$6) - (function lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$3 ,@$6) - (function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$4 ,@$7)) + (FunctionDeclaration (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(define ,$2 (lambda () ,$6)) + (function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(define ,$2 (lambda ,$4 ,$7))) + (FunctionExpression (function lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$5) + (function Identifier lparen rparen lbrace FunctionBody rbrace) -> `(lambda () ,$6) + (function lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$3 ,$6) + (function Identifier lparen FormalParameterList rparen lbrace FunctionBody rbrace) -> `(lambda ,$4 ,$7)) (FormalParameterList (Identifier) -> `(,$1) (FormalParameterList comma Identifier) -> `(,@$1 ,$3)) (SourceElements (SourceElement) -> $1 |