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:
return None
print(viper_ret_none())
# return Ellipsis as object
@micropython.viper
def viper_ret_ellipsis() -> object:
return ...
print(viper_ret_ellipsis())
# 3 args
@micropython.viper
def viper_3args(a:int, b:int, c:int) -> int:
......
......@@ -16,7 +16,17 @@ def memadd(src:ptr16, n:int) -> int:
sum += src[i]
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')
print(b)
print(get(b), get1(b))
print(memadd(b, 2))
print(memadd2(b))
bytearray(b'1234')
12849 13363
26212
26212
......@@ -4,16 +4,33 @@
def set(dest:ptr16, val:int):
dest[0] = val
@micropython.viper
def set1(dest:ptr16, val:int):
dest[1] = val
@micropython.viper
def memset(dest:ptr16, val:int, n:int):
for i in range(n):
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)
print(b)
set(b, 0x4242)
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)
bytearray(b'\x00\x00\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:
sum += src[i]
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')
print(b)
print(hex(get(b)), hex(get1(b)))
print(hex(memadd(b, 2)))
print(hex(memadd2(b)))
bytearray(b'\x12\x12\x12\x124444')
0x12121212 0x34343434
0x46464646
0x46464646
......@@ -13,6 +13,13 @@ def memset(dest:ptr32, val:int, n:int):
for i in range(n):
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)
print(b)
......@@ -24,3 +31,6 @@ print(b)
memset(b, 0x44444444, len(b) // 4)
print(b)
memset2(b, 0x45454545)
print(b)
......@@ -2,3 +2,4 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')
bytearray(b'BBBB\x00\x00\x00\x00')
bytearray(b'BBBBCCCC')
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