compiler: support break and continue in range loops
This commit is contained in:
parent
ccb53414f2
commit
da89f18999
2 changed files with 71 additions and 2 deletions
|
@ -763,8 +763,14 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
return nil
|
||||
}
|
||||
|
||||
start := c.newLabel()
|
||||
end := c.newLabel()
|
||||
start, label := c.generateLabel(labelStart)
|
||||
end := c.newNamedLabel(labelEnd, label)
|
||||
post := c.newNamedLabel(labelPost, label)
|
||||
|
||||
lastFor := c.currentFor
|
||||
lastSwitch := c.currentSwitch
|
||||
c.currentFor = label
|
||||
c.currentSwitch = label
|
||||
|
||||
ast.Walk(c, n.X)
|
||||
|
||||
|
@ -787,11 +793,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
ast.Walk(c, n.Body)
|
||||
|
||||
c.setLabel(post)
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.INC)
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMP, int16(start))
|
||||
|
||||
c.setLabel(end)
|
||||
|
||||
c.currentFor = lastFor
|
||||
c.currentSwitch = lastSwitch
|
||||
|
||||
return nil
|
||||
|
||||
// We dont really care about assertions for the core logic.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue