mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
compiler: allow for loops with empty condition
This commit is contained in:
parent
198fffb9b8
commit
f0b6f783aa
2 changed files with 22 additions and 3 deletions
|
@ -781,10 +781,12 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
// Set label and walk the condition.
|
// Set label and walk the condition.
|
||||||
c.pushStackLabel(label, 0)
|
c.pushStackLabel(label, 0)
|
||||||
c.setLabel(fstart)
|
c.setLabel(fstart)
|
||||||
ast.Walk(c, n.Cond)
|
if n.Cond != nil {
|
||||||
|
ast.Walk(c, n.Cond)
|
||||||
|
|
||||||
// Jump if the condition is false
|
// Jump if the condition is false
|
||||||
emit.Jmp(c.prog.BinWriter, opcode.JMPIFNOT, fend)
|
emit.Jmp(c.prog.BinWriter, opcode.JMPIFNOT, fend)
|
||||||
|
}
|
||||||
|
|
||||||
// Walk body followed by the iterator (post stmt).
|
// Walk body followed by the iterator (post stmt).
|
||||||
ast.Walk(c, n.Body)
|
ast.Walk(c, n.Body)
|
||||||
|
|
|
@ -374,6 +374,23 @@ func TestDec(t *testing.T) {
|
||||||
eval(t, src, big.NewInt(1))
|
eval(t, src, big.NewInt(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForLoopEmpty(t *testing.T) {
|
||||||
|
src := `
|
||||||
|
package foo
|
||||||
|
func Main() int {
|
||||||
|
x := 0
|
||||||
|
for {
|
||||||
|
x++
|
||||||
|
if x == 2 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
`
|
||||||
|
eval(t, src, big.NewInt(2))
|
||||||
|
}
|
||||||
|
|
||||||
func TestForLoopBigIter(t *testing.T) {
|
func TestForLoopBigIter(t *testing.T) {
|
||||||
src := `
|
src := `
|
||||||
package foo
|
package foo
|
||||||
|
|
Loading…
Reference in a new issue