Commit 2ec835f5 authored by Damien George's avatar Damien George
Browse files

tests: Add more tests for viper 16/32-bit load/store, and ellipsis.

parent 59a41e8f
...@@ -18,6 +18,12 @@ def viper_ret_none() -> int: ...@@ -18,6 +18,12 @@ def viper_ret_none() -> int:
return None return None
print(viper_ret_none()) print(viper_ret_none())
# return Ellipsis as object
@micropython.viper
def viper_ret_ellipsis() -> object:
return ...
print(viper_ret_ellipsis())
# 3 args # 3 args
@micropython.viper @micropython.viper
def viper_3args(a:int, b:int, c:int) -> int: def viper_3args(a:int, b:int, c:int) -> int:
......
6 6
3 3
0 0
Ellipsis
6 6
7 7
20 20
......
...@@ -16,7 +16,17 @@ def memadd(src:ptr16, n:int) -> int: ...@@ -16,7 +16,17 @@ def memadd(src:ptr16, n:int) -> int:
sum += src[i] sum += src[i]
return sum return sum
@micropython.viper
def memadd2(src_in) -> int:
src = ptr16(src_in)
n = int(len(src_in)) >> 1
sum = 0
for i in range(n):
sum += src[i]
return sum
b = bytearray(b'1234') b = bytearray(b'1234')
print(b) print(b)
print(get(b), get1(b)) print(get(b), get1(b))
print(memadd(b, 2)) print(memadd(b, 2))
print(memadd2(b))
bytearray(b'1234') bytearray(b'1234')
12849 13363 12849 13363
26212 26212
26212
...@@ -4,16 +4,33 @@ ...@@ -4,16 +4,33 @@
def set(dest:ptr16, val:int): def set(dest:ptr16, val:int):
dest[0] = val dest[0] = val
@micropython.viper
def set1(dest:ptr16, val:int):
dest[1] = val
@micropython.viper @micropython.viper
def memset(dest:ptr16, val:int, n:int): def memset(dest:ptr16, val:int, n:int):
for i in range(n): for i in range(n):
dest[i] = val dest[i] = val
@micropython.viper
def memset2(dest_in, val:int):
dest = ptr16(dest_in)
n = int(len(dest_in)) >> 1
for i in range(n):
dest[i] = val
b = bytearray(4) b = bytearray(4)
print(b) print(b)
set(b, 0x4242) set(b, 0x4242)
print(b) print(b)
memset(b, 0x4343, len(b) // 2) set1(b, 0x4343)
print(b)
memset(b, 0x4444, len(b) // 2)
print(b)
memset2(b, 0x4545)
print(b) print(b)
bytearray(b'\x00\x00\x00\x00') bytearray(b'\x00\x00\x00\x00')
bytearray(b'BB\x00\x00') bytearray(b'BB\x00\x00')
bytearray(b'CCCC') bytearray(b'BBCC')
bytearray(b'DDDD')
bytearray(b'EEEE')
...@@ -15,7 +15,17 @@ def memadd(src:ptr32, n:int) -> int: ...@@ -15,7 +15,17 @@ def memadd(src:ptr32, n:int) -> int:
sum += src[i] sum += src[i]
return sum return sum
@micropython.viper
def memadd2(src_in) -> int:
src = ptr32(src_in)
n = int(len(src_in)) >> 2
sum = 0
for i in range(n):
sum += src[i]
return sum
b = bytearray(b'\x12\x12\x12\x12\x34\x34\x34\x34') b = bytearray(b'\x12\x12\x12\x12\x34\x34\x34\x34')
print(b) print(b)
print(hex(get(b)), hex(get1(b))) print(hex(get(b)), hex(get1(b)))
print(hex(memadd(b, 2))) print(hex(memadd(b, 2)))
print(hex(memadd2(b)))
bytearray(b'\x12\x12\x12\x124444') bytearray(b'\x12\x12\x12\x124444')
0x12121212 0x34343434 0x12121212 0x34343434
0x46464646 0x46464646
0x46464646
...@@ -13,6 +13,13 @@ def memset(dest:ptr32, val:int, n:int): ...@@ -13,6 +13,13 @@ def memset(dest:ptr32, val:int, n:int):
for i in range(n): for i in range(n):
dest[i] = val dest[i] = val
@micropython.viper
def memset2(dest_in, val:int):
dest = ptr32(dest_in)
n = int(len(dest_in)) >> 2
for i in range(n):
dest[i] = val
b = bytearray(8) b = bytearray(8)
print(b) print(b)
...@@ -24,3 +31,6 @@ print(b) ...@@ -24,3 +31,6 @@ print(b)
memset(b, 0x44444444, len(b) // 4) memset(b, 0x44444444, len(b) // 4)
print(b) print(b)
memset2(b, 0x45454545)
print(b)
...@@ -2,3 +2,4 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') ...@@ -2,3 +2,4 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'BBBB\x00\x00\x00\x00') bytearray(b'BBBB\x00\x00\x00\x00')
bytearray(b'BBBBCCCC') bytearray(b'BBBBCCCC')
bytearray(b'DDDDDDDD') bytearray(b'DDDDDDDD')
bytearray(b'EEEEEEEE')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment