diff options
author | Alessandro Arzilli <alessandro.arzilli@gmail.com> | 2018-12-07 17:28:35 +0100 |
---|---|---|
committer | alandonovan <adonovan@google.com> | 2018-12-07 11:28:35 -0500 |
commit | 678bafeaa214cf33342b28e76b77c0f1e264671f (patch) | |
tree | e238dd59443cb8ec3df6453c71101cd945853aab /internal | |
parent | d0a402bd6a104746d6256a517e57ce1adde31b45 (diff) | |
download | starlark-go-678bafeaa214cf33342b28e76b77c0f1e264671f.tar.gz |
Add while statement and allow recursion (#39)
Adds a flag, AllowRecursion, that enables while statements and
recursive functions.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/compile/compile.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/compile/compile.go b/internal/compile/compile.go index 4adff67..a5a7a9f 100644 --- a/internal/compile/compile.go +++ b/internal/compile/compile.go @@ -1076,6 +1076,21 @@ func (fcomp *fcomp) stmt(stmt syntax.Stmt) { fcomp.block = tail fcomp.emit(ITERPOP) + case *syntax.WhileStmt: + head := fcomp.newBlock() + body := fcomp.newBlock() + done := fcomp.newBlock() + + fcomp.jump(head) + fcomp.block = head + fcomp.ifelse(stmt.Cond, body, done) + + fcomp.block = body + fcomp.stmts(stmt.Body) + fcomp.jump(head) + + fcomp.block = done + case *syntax.ReturnStmt: if stmt.Result != nil { fcomp.expr(stmt.Result) |