mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 05:00:26 +01:00
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.
This commit is contained in:
29
tests/micropython/viper_ptr8_store.py
Normal file
29
tests/micropython/viper_ptr8_store.py
Normal file
@@ -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)
|
||||
4
tests/micropython/viper_ptr8_store.py.exp
Normal file
4
tests/micropython/viper_ptr8_store.py.exp
Normal file
@@ -0,0 +1,4 @@
|
||||
bytearray(b'\x00\x00\x00\x00')
|
||||
bytearray(b'*\x00\x00\x00')
|
||||
bytearray(b'++++')
|
||||
bytearray(b',,,,')
|
||||
Reference in New Issue
Block a user