Suggestion: add IF_ZERO or iteration over nat
The IF_ZERO
opcode would take a nat
, n
from the stack, if it's 0, the first branch is executed, if it's not zero, the second branch is exectued with n-1
on the stack. This is equivalent to
DUP; PUSH 0n; IFCMPEQ { DROP ; first_branch } { PUSH 1n; SWAP; SUB; ABS; second_branch }
The idea is to have a convenient 0 | S x
pattern match for loops without having to go throught the ackward cast from int to nat.
Alternatively a ITER_N opcode could be useful to iterate over an integer n, or maybe over a pair of integers (from,to).
Edited by Raphaël Cauderlier