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.
This commit is contained in:
parent
e9c5639d48
commit
81d677eb12
4 changed files with 27 additions and 8 deletions
|
|
@ -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 ();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue