that was fast:-) After compiling it in I can confirm it works.
I had a look at Peters example code pieces again and tested and found: The (Damiens) workaround is still needed.
I repeat the code:
Code: Select all
def foo():
x : int = 0
@micropython.viper
def inner() -> int:
nonlocal x
q : int = int(x)
q += 1
x = q << 1 | 1 # <- workaround!
return int(x)
return inner
bar = foo()
bar() # 1
bar() # 2
From this the question comes to my mind:
Shouldn't there be a way to save undistorted (viper / machine) integers through different calls of viper functions?
This was the original problem in https://github.com/micropython/micropython/issues/8086 I suppose.