diff options
author | Andy Wingo <wingo@pobox.com> | 2009-02-21 14:04:53 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-02-21 20:28:28 +0100 |
commit | 81d677eb121834945bf0f9ebec28480e6e945cd0 (patch) | |
tree | c451546a9a5b788376dec178f8e06089f0a1cb04 | |
parent | e9c5639d48fe95f8b0e5aed90d9cc3d30b93bae9 (diff) | |
download | guile-81d677eb121834945bf0f9ebec28480e6e945cd0.tar.gz |
implement break and continue, work around overly recursive pmatch expansion
* libguile/vm-i-system.c (goto/args): On a tail call to a different
procedure, init the locals to valid scheme values. Shouldn't matter for
well-compiled scheme, but inspecting uninitialized locals could give
garbage, or badly-compiled code could cause a crash.
* module/language/Makefile.am (NOCOMP_SOURCES): For the moment, don't
compile compile-ghil.scm. I need to fix this.
* module/language/ecmascript/compile-ghil.scm (load-toplevel): Sigh, and
disable stack checking in the evaluator too. Grr.
(comp): Implement (unnamed) break and continue.
* module/language/ecmascript/parse.scm (parse-ecmascript): Fix var
statements in `for' -- though it still doesn't work.
-rw-r--r-- | libguile/vm-i-system.c | 4 | ||||
-rw-r--r-- | module/language/Makefile.am | 9 | ||||
-rw-r--r-- | module/language/ecmascript/compile-ghil.scm | 14 | ||||
-rw-r--r-- | module/language/ecmascript/parse.scm | 8 |
4 files changed, 27 insertions, 8 deletions
diff --git a/libguile/vm-i-system.c b/libguile/vm-i-system.c index a105c52d9..18e9a781b 100644 --- a/libguile/vm-i-system.c +++ b/libguile/vm-i-system.c @@ -631,6 +631,10 @@ VM_DEFINE_INSTRUCTION (40, goto_args, "goto/args", 1, -1, 1) CONS (external, SCM_UNDEFINED, external); SCM_FRAME_DATA_ADDRESS (fp)[0] = external; + /* Init locals to valid SCM values */ + for (i = 0; i < bp->nlocs; i++) + LOCAL_SET (i + bp->nargs, SCM_UNDEFINED); + /* Call itself */ ip = bp->base; APPLY_HOOK (); diff --git a/module/language/Makefile.am b/module/language/Makefile.am index 6e2bd92a9..c2db20a86 100644 --- a/module/language/Makefile.am +++ b/module/language/Makefile.am @@ -3,13 +3,14 @@ SOURCES=ghil.scm glil.scm assembly.scm \ ecmascript/parse-lalr.scm \ ecmascript/tokenize.scm \ ecmascript/spec.scm \ - ecmascript/compile-ghil.scm \ ecmascript/impl.scm \ ecmascript/base.scm \ ecmascript/function.scm \ ecmascript/array.scm -# unfortunately, the one that we want to compile can't yet be compiled -# -- too many local vars, or something. -NOCOMP_SOURCES = ecmascript/parse.scm +# unfortunately, the ones that we want to compile can't yet be compiled +# -- too many local vars in the first case, and some non-tail-recursion +# in pmatch in the second. +NOCOMP_SOURCES = ecmascript/parse.scm \ + ecmascript/compile-ghil.scm modpath = language include $(top_srcdir)/am/guilec diff --git a/module/language/ecmascript/compile-ghil.scm b/module/language/ecmascript/compile-ghil.scm index ffb34a54d..3826f79e3 100644 --- a/module/language/ecmascript/compile-ghil.scm +++ b/module/language/ecmascript/compile-ghil.scm @@ -25,6 +25,8 @@ #:use-module (system base pmatch) #:export (compile-ghil)) +(eval-case ((load-toplevel) (debug-set! stack 0))) + (define (compile-ghil exp env opts) (values (call-with-ghil-environment (make-ghil-toplevel-env) '() @@ -434,6 +436,18 @@ '()))) (@implv e l *undefined*)))))) (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)) + (eq? (ghil-var-env var) (ghil-env-parent e))) + (make-ghil-inline e l 'return (@implv e l *undefined*)) + (error "bad break, yo")))) + ((continue) + (let ((var (ghil-var-for-ref! e '%continue))) + (if (and (ghil-env? (ghil-var-env var)) + (eq? (ghil-var-env var) (ghil-env-parent e))) + (make-ghil-inline e l 'goto/args (list (make-ghil-ref e l var))) + (error "bad continue, yo")))) ((block ,x) (comp x e)) (else diff --git a/module/language/ecmascript/parse.scm b/module/language/ecmascript/parse.scm index 27070268c..4603f6235 100644 --- a/module/language/ecmascript/parse.scm +++ b/module/language/ecmascript/parse.scm @@ -126,10 +126,10 @@ (for lparen ExpressionNoIn semicolon Expression semicolon rparen Statement) -> `(for ,$3 ,$5 #f ,$8) (for lparen ExpressionNoIn semicolon Expression semicolon Expression rparen Statement) -> `(for ,$3 ,$5 ,$7 ,$9) - (for lparen var VariableDeclarationListNoIn semicolon semicolon rparen Statement) -> `(for (var ,$4) #f #f ,$8) - (for lparen var VariableDeclarationListNoIn semicolon semicolon Expression rparen Statement) -> `(for (var ,$4) #f ,$7 ,$9) - (for lparen var VariableDeclarationListNoIn semicolon Expression semicolon rparen Statement) -> `(for (var ,$4) ,$6 #f ,$9) - (for lparen var VariableDeclarationListNoIn semicolon Expression semicolon Expression rparen Statement) -> `(for (var ,$4) ,$6 ,$8 ,$10) + (for lparen var VariableDeclarationListNoIn semicolon semicolon rparen Statement) -> `(for (var ,@$4) #f #f ,$8) + (for lparen var VariableDeclarationListNoIn semicolon semicolon Expression rparen Statement) -> `(for (var ,@$4) #f ,$7 ,$9) + (for lparen var VariableDeclarationListNoIn semicolon Expression semicolon rparen Statement) -> `(for (var ,@$4) ,$6 #f ,$9) + (for lparen var VariableDeclarationListNoIn semicolon Expression semicolon Expression rparen Statement) -> `(for (var ,@$4) ,$6 ,$8 ,$10) (for lparen LeftHandSideExpression in Expression rparen Statement) -> `(for-in ,$3 ,$5 ,$7) (for lparen var VariableDeclarationNoIn in Expression rparen Statement) -> `(for-in ,$4 ,$6 ,$8)) |