Commit f6258511 authored by Austin Clements's avatar Austin Clements

Fix segfault on unnamed function arguments. Make continue

jump to the post statement instead of the condition check.

R=rsc
APPROVED=rsc
DELTA=10  (6 added, 1 deleted, 3 changed)
OCL=32359
CL=32379
parent d27bae50
...@@ -588,7 +588,7 @@ func (a *stmtCompiler) DoForStmt(s *ast.ForStmt) { ...@@ -588,7 +588,7 @@ func (a *stmtCompiler) DoForStmt(s *ast.ForStmt) {
bc.compileStmt(s.Init); bc.compileStmt(s.Init);
} }
var bodyPC, checkPC, endPC uint; var bodyPC, postPC, checkPC, endPC uint;
// Jump to condition check. We generate slightly less code by // Jump to condition check. We generate slightly less code by
// placing the condition check after the body. // placing the condition check after the body.
...@@ -598,11 +598,12 @@ func (a *stmtCompiler) DoForStmt(s *ast.ForStmt) { ...@@ -598,11 +598,12 @@ func (a *stmtCompiler) DoForStmt(s *ast.ForStmt) {
bodyPC = a.nextPC(); bodyPC = a.nextPC();
body := bc.enterChild(); body := bc.enterChild();
body.breakPC = &endPC; body.breakPC = &endPC;
body.continuePC = &checkPC; body.continuePC = &postPC;
body.compileStmts(s.Body); body.compileStmts(s.Body);
body.exit(); body.exit();
// Compile post, if any // Compile post, if any
postPC = a.nextPC();
if s.Post != nil { if s.Post != nil {
// TODO(austin) Does the parser disallow short // TODO(austin) Does the parser disallow short
// declarations in s.Post? // declarations in s.Post?
...@@ -711,13 +712,17 @@ func (a *compiler) compileFunc(scope *Scope, decl *FuncDecl, body *ast.BlockStmt ...@@ -711,13 +712,17 @@ func (a *compiler) compileFunc(scope *Scope, decl *FuncDecl, body *ast.BlockStmt
// corresponding function. // corresponding function.
bodyScope := scope.Fork(); bodyScope := scope.Fork();
for i, t := range decl.Type.In { for i, t := range decl.Type.In {
if decl.InNames[i] != nil {
bodyScope.DefineVar(decl.InNames[i].Value, t); bodyScope.DefineVar(decl.InNames[i].Value, t);
} else {
// TODO(austin) Not technically a temp
bodyScope.DefineTemp(t);
}
} }
for i, t := range decl.Type.Out { for i, t := range decl.Type.Out {
if decl.OutNames[i] != nil { if decl.OutNames[i] != nil {
bodyScope.DefineVar(decl.OutNames[i].Value, t); bodyScope.DefineVar(decl.OutNames[i].Value, t);
} else { } else {
// TODO(austin) Not technically a temp
bodyScope.DefineTemp(t); bodyScope.DefineTemp(t);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment