forked from TrueCloudLab/neoneo-go
compiler: support for loops with no init/post condition
Make it possible to use `for` loop with a single condition.
This commit is contained in:
parent
01e16e68ad
commit
328267ca6f
2 changed files with 33 additions and 2 deletions
|
@ -585,7 +585,9 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
)
|
||||
|
||||
// Walk the initializer and condition.
|
||||
ast.Walk(c, n.Init)
|
||||
if n.Init != nil {
|
||||
ast.Walk(c, n.Init)
|
||||
}
|
||||
|
||||
// Set label and walk the condition.
|
||||
c.setLabel(fstart)
|
||||
|
@ -596,7 +598,9 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
// Walk body followed by the iterator (post stmt).
|
||||
ast.Walk(c, n.Body)
|
||||
ast.Walk(c, n.Post)
|
||||
if n.Post != nil {
|
||||
ast.Walk(c, n.Post)
|
||||
}
|
||||
|
||||
// Jump back to condition.
|
||||
emitJmp(c.prog.BinWriter, opcode.JMP, int16(fstart))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue