diff options
| author | Damien George <damien.p.george@gmail.com> | 2015-06-04 11:52:16 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2015-06-04 11:52:16 +0100 |
| commit | 4d9cad180dbaf25cdbb9dd0c54a637483db933a7 (patch) | |
| tree | dc736f2530cd66c726eaeda903c1d03fb646fffc /tests/micropython/viper_subscr.py | |
| parent | a3cf4ea2f69e3568944bad7ee1a017b7095efc3d (diff) | |
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.
Diffstat (limited to 'tests/micropython/viper_subscr.py')
| -rw-r--r-- | tests/micropython/viper_subscr.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/micropython/viper_subscr.py b/tests/micropython/viper_subscr.py new file mode 100644 index 000000000..2198ed731 --- /dev/null +++ b/tests/micropython/viper_subscr.py @@ -0,0 +1,20 @@ +# 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)) |
