diff options
author | Damien George <damien@micropython.org> | 2020-06-26 18:26:39 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-06-27 00:24:04 +1000 |
commit | 41fa8b5482089bdd7fa5478fe24f32913b23967c (patch) | |
tree | 25efbc78d3b14a448882d4a7a503ddd4d7efcf47 /tests/micropython/viper_binop_bitwise_uint.py | |
parent | b3b8706d27cffbfc4cdd447b204ae7083283d13c (diff) |
py/emitnative: Implement binary operations for viper uint operands.
uint types in viper mode can now be used for all binary operators except
floor-divide and modulo.
Fixes issue #1847 and issue #6177.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/micropython/viper_binop_bitwise_uint.py')
-rw-r--r-- | tests/micropython/viper_binop_bitwise_uint.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/micropython/viper_binop_bitwise_uint.py b/tests/micropython/viper_binop_bitwise_uint.py new file mode 100644 index 000000000..3bc7ba8d1 --- /dev/null +++ b/tests/micropython/viper_binop_bitwise_uint.py @@ -0,0 +1,58 @@ +# test bitwise operators on uint type + + +@micropython.viper +def shl(x: uint, y: uint) -> uint: + return x << y + + +print("shl") +print(shl(1, 0)) +print(shl(1, 30)) +print(shl(-1, 10) & 0xFFFFFFFF) + + +@micropython.viper +def shr(x: uint, y: uint) -> uint: + return x >> y + + +print("shr") +print(shr(1, 0)) +print(shr(16, 3)) +print(shr(-1, 1) in (0x7FFFFFFF, 0x7FFFFFFF_FFFFFFFF)) + + +@micropython.viper +def and_(x: uint, y: uint): + return x & y, y & x + + +print("and") +print(*and_(1, 0)) +print(*and_(1, 3)) +print(*and_(-1, 2)) +print(*(x & 0xFFFFFFFF for x in and_(-1, -2))) + + +@micropython.viper +def or_(x: uint, y: uint): + return x | y, y | x + + +print("or") +print(*or_(1, 0)) +print(*or_(1, 2)) +print(*(x & 0xFFFFFFFF for x in or_(-1, 2))) + + +@micropython.viper +def xor(x: uint, y: uint): + return x ^ y, y ^ x + + +print("xor") +print(*xor(1, 0)) +print(*xor(1, 3)) +print(*(x & 0xFFFFFFFF for x in xor(-1, 3))) +print(*xor(-1, -3)) |