Returns true if there is a next instruction and moves on.
()
| 43 | |
| 44 | // Returns true if there is a next instruction and moves on. |
| 45 | func (it *instructionIterator) Next() bool { |
| 46 | if it.error != nil || uint64(len(it.code)) <= it.pc { |
| 47 | // We previously reached an error or the end. |
| 48 | return false |
| 49 | } |
| 50 | |
| 51 | if it.started { |
| 52 | // Since the iteration has been already started we move to the next instruction. |
| 53 | if it.arg != nil { |
| 54 | it.pc += uint64(len(it.arg)) |
| 55 | } |
| 56 | it.pc++ |
| 57 | } else { |
| 58 | // We start the iteration from the first instruction. |
| 59 | it.started = true |
| 60 | } |
| 61 | |
| 62 | if uint64(len(it.code)) <= it.pc { |
| 63 | // We reached the end. |
| 64 | return false |
| 65 | } |
| 66 | |
| 67 | it.op = vm.OpCode(it.code[it.pc]) |
| 68 | if it.op.IsPush() { |
| 69 | a := uint64(it.op) - uint64(vm.PUSH1) + 1 |
| 70 | u := it.pc + 1 + a |
| 71 | if uint64(len(it.code)) <= it.pc || uint64(len(it.code)) < u { |
| 72 | it.error = fmt.Errorf("incomplete push instruction at %v", it.pc) |
| 73 | return false |
| 74 | } |
| 75 | it.arg = it.code[it.pc+1 : u] |
| 76 | } else { |
| 77 | it.arg = nil |
| 78 | } |
| 79 | return true |
| 80 | } |
| 81 | |
| 82 | // Returns any error that may have been encountered. |
| 83 | func (it *instructionIterator) Error() error { |