From 1d9855bd39cd04f70d17aa9bbf57245ef98c9d85 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 28 Jul 2009 14:37:06 -0700 Subject: Implement if, for (modulo ranges), break, continue, increment, and decrement. blockCompilers now form a tree the mimics the nesting of scopes and provide convenient ways to enter and exit scopes. blockCompilers also track the break and continue PC for the current block. The statement testing interface now works in lists of statements, which simplifies a bunch of things. R=rsc APPROVED=rsc DELTA=401 (335 added, 44 deleted, 22 changed) OCL=32308 CL=32317 --- usr/austin/eval/compiler.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'usr/austin/eval/compiler.go') diff --git a/usr/austin/eval/compiler.go b/usr/austin/eval/compiler.go index 47ff12f36..6dd6437e1 100644 --- a/usr/austin/eval/compiler.go +++ b/usr/austin/eval/compiler.go @@ -65,10 +65,24 @@ type blockCompiler struct { *funcCompiler; scope *Scope; returned bool; + // The PC break statements should jump to, or nil if a break + // statement is invalid. + breakPC *uint; + // The PC continue statements should jump to, or nil if a + // continue statement is invalid. + continuePC *uint; + // The blockCompiler for the block enclosing this one, or nil + // for a function-level block. + parent *blockCompiler; + // The blockCompiler for the nested block currently being + // compiled, or nil if compilation is not in a nested block. + child *blockCompiler; } -func (a *blockCompiler) compileBlock(body *ast.BlockStmt) - +func (a *blockCompiler) compileStmt(s ast.Stmt) +func (a *blockCompiler) compileStmts(body *ast.BlockStmt) +func (a *blockCompiler) enterChild() *blockCompiler +func (a *blockCompiler) exit() // An exprContext stores information used throughout the compilation // of a single expression. It does not embed funcCompiler because -- cgit v1.2.3