py/native: Improve support for bool type in viper functions.

Variables with type bool now act more like an int, and there is proper
casting to/from Python objects.
This commit is contained in:
Damien George
2019-05-03 23:18:30 +10:00
parent 9a6f6fd68d
commit 5ea38e4d74
4 changed files with 36 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
# test various type conversions
import micropython
# converting incoming arg to bool
@micropython.viper
def f1(x:bool):
print(x)
f1(0)
f1(1)
f1([])
f1([1])
# taking and returning a bool
@micropython.viper
def f2(x:bool) -> bool:
return x
print(f2([]))
print(f2([1]))
# converting to bool within function
@micropython.viper
def f3(x) -> bool:
return bool(x)
print(f3([]))
print(f3(-1))

View File

@@ -0,0 +1,8 @@
False
True
False
True
False
True
False
True