circuitpython/tests/micropython/viper_subscr.py
Damien George 4d9cad180d py: Implement implicit cast to obj for viper load/store index/value.
This allows to do "ar[i]" and "ar[i] = val" in viper when ar is a Python
object and i and/or val are native viper types (eg ints).

Patch also includes tests for this feature.
2015-06-04 11:52:16 +01:00

21 lines
342 B
Python

# test standard Python subscr using viper types
@micropython.viper
def get(dest, i:int):
i += 1
return dest[i]
@micropython.viper
def set(dest, i:int, val:int):
i += 1
dest[i] = val + 1
ar = [i for i in range(3)]
for i in range(len(ar)):
set(ar, i - 1, i)
print(ar)
for i in range(len(ar)):
print(get(ar, i - 1))