diff options
author | Damien George <damien.p.george@gmail.com> | 2015-10-13 00:50:17 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-10-13 00:50:17 +0100 |
commit | b8f9ac54111ad0962401c764112c9a5669699deb (patch) | |
tree | 6157856fa4470f3c4af55a7105b4dc448d74999f /tests | |
parent | 21f43ba9b0a9a2bc74398e041c6f767a8d1278db (diff) | |
download | micropython-b8f9ac54111ad0962401c764112c9a5669699deb.tar.gz micropython-b8f9ac54111ad0962401c764112c9a5669699deb.zip |
py: Implement ptr32 load and store in viper emitter.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/micropython/viper_ptr32_load.py | 21 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_load.py.exp | 3 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_store.py | 26 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_store.py.exp | 4 |
4 files changed, 54 insertions, 0 deletions
diff --git a/tests/micropython/viper_ptr32_load.py b/tests/micropython/viper_ptr32_load.py new file mode 100644 index 0000000000..d552b9df67 --- /dev/null +++ b/tests/micropython/viper_ptr32_load.py @@ -0,0 +1,21 @@ +# test loading from ptr32 type + +@micropython.viper +def get(src:ptr32) -> int: + return src[0] + +@micropython.viper +def get1(src:ptr32) -> int: + return src[1] + +@micropython.viper +def memadd(src:ptr32, n:int) -> int: + 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))) diff --git a/tests/micropython/viper_ptr32_load.py.exp b/tests/micropython/viper_ptr32_load.py.exp new file mode 100644 index 0000000000..e7ce2d972d --- /dev/null +++ b/tests/micropython/viper_ptr32_load.py.exp @@ -0,0 +1,3 @@ +bytearray(b'\x12\x12\x12\x124444') +0x12121212 0x34343434 +0x46464646 diff --git a/tests/micropython/viper_ptr32_store.py b/tests/micropython/viper_ptr32_store.py new file mode 100644 index 0000000000..b63bac9ee3 --- /dev/null +++ b/tests/micropython/viper_ptr32_store.py @@ -0,0 +1,26 @@ +# test store to ptr32 type + +@micropython.viper +def set(dest:ptr32, val:int): + dest[0] = val + +@micropython.viper +def set1(dest:ptr32, val:int): + dest[1] = val + +@micropython.viper +def memset(dest:ptr32, val:int, n:int): + for i in range(n): + dest[i] = val + +b = bytearray(8) +print(b) + +set(b, 0x42424242) +print(b) + +set1(b, 0x43434343) +print(b) + +memset(b, 0x44444444, len(b) // 4) +print(b) diff --git a/tests/micropython/viper_ptr32_store.py.exp b/tests/micropython/viper_ptr32_store.py.exp new file mode 100644 index 0000000000..13b9f418f8 --- /dev/null +++ b/tests/micropython/viper_ptr32_store.py.exp @@ -0,0 +1,4 @@ +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'BBBB\x00\x00\x00\x00') +bytearray(b'BBBBCCCC') +bytearray(b'DDDDDDDD') |