diff options
| author | Damien George | 2014-09-29 22:10:41 +0100 |
|---|---|---|
| committer | Damien George | 2014-09-29 22:10:41 +0100 |
| commit | e9dac3b4d039997f446b6a615d580d284497d59b (patch) | |
| tree | 3ffda8af59c5c5008883d52c54264057b1c49392 /tests/micropython | |
| parent | 44c96b2314f5519643f5c8baa1c05f4f5ce6ff7c (diff) | |
py: Add casting to viper; add native mem stores to viper.
Viper can now do the following:
def store(p:ptr8, c:int):
p[0] = c
This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
Diffstat (limited to 'tests/micropython')
| -rw-r--r-- | tests/micropython/viper_ptr8_store.py | 29 | ||||
| -rw-r--r-- | tests/micropython/viper_ptr8_store.py.exp | 4 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/micropython/viper_ptr8_store.py b/tests/micropython/viper_ptr8_store.py new file mode 100644 index 000000000..fc24290c9 --- /dev/null +++ b/tests/micropython/viper_ptr8_store.py @@ -0,0 +1,29 @@ +# test ptr8 type + +@micropython.viper +def set(dest:ptr8, val:int): + dest[0] = val + +@micropython.viper +def memset(dest:ptr8, val:int, n:int): + for i in range(n): + dest[i] = val + +@micropython.viper +def memset2(dest_in, val:int): + dest = ptr8(dest_in) + n = int(len(dest_in)) + for i in range(n): + dest[i] = val + +b = bytearray(4) +print(b) + +set(b, 42) +print(b) + +memset(b, 43, len(b)) +print(b) + +memset2(b, 44) +print(b) diff --git a/tests/micropython/viper_ptr8_store.py.exp b/tests/micropython/viper_ptr8_store.py.exp new file mode 100644 index 000000000..30ca5b10e --- /dev/null +++ b/tests/micropython/viper_ptr8_store.py.exp @@ -0,0 +1,4 @@ +bytearray(b'\x00\x00\x00\x00') +bytearray(b'*\x00\x00\x00') +bytearray(b'++++') +bytearray(b',,,,') |
