mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
compiler: use iterators in range loops
It is simpler than having some counters on stack and will help us to support maps in future.
This commit is contained in:
parent
34a4c15932
commit
b126056f04
1 changed files with 6 additions and 9 deletions
|
@ -900,20 +900,18 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
c.currentSwitch = label
|
||||
|
||||
ast.Walk(c, n.X)
|
||||
emit.Syscall(c.prog.BinWriter, "Neo.Iterator.Create")
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.SIZE)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSH0)
|
||||
|
||||
c.pushStackLabel(label, 2)
|
||||
c.pushStackLabel(label, 1)
|
||||
c.setLabel(start)
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.OVER)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.OVER)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.LTE) // finish if len <= i
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPIFL, end)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.DUP)
|
||||
emit.Syscall(c.prog.BinWriter, "Neo.Enumerator.Next")
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPIFNOTL, end)
|
||||
|
||||
if n.Key != nil {
|
||||
emit.Opcode(c.prog.BinWriter, opcode.DUP)
|
||||
emit.Syscall(c.prog.BinWriter, "Neo.Iterator.Key")
|
||||
c.emitStoreVar(n.Key.(*ast.Ident).Name)
|
||||
}
|
||||
|
||||
|
@ -921,7 +919,6 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
c.setLabel(post)
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.INC)
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPL, start)
|
||||
|
||||
c.setLabel(end)
|
||||
|
|
Loading…
Reference in a new issue