2015-03-25 19:10:09 -04:00
|
|
|
# tests for natively compiled functions
|
|
|
|
|
|
|
|
# basic test
|
2014-08-24 11:28:17 -04:00
|
|
|
@micropython.native
|
|
|
|
def native_test(x):
|
|
|
|
print(1, [], x)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2014-08-24 11:28:17 -04:00
|
|
|
native_test(2)
|
|
|
|
|
|
|
|
# check that GC doesn't collect the native function
|
|
|
|
import gc
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2014-08-24 11:28:17 -04:00
|
|
|
gc.collect()
|
|
|
|
native_test(3)
|
2015-03-25 19:10:09 -04:00
|
|
|
|
|
|
|
# native with 2 args
|
|
|
|
@micropython.native
|
|
|
|
def f(a, b):
|
|
|
|
print(a + b)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2015-03-25 19:10:09 -04:00
|
|
|
f(1, 2)
|
|
|
|
|
|
|
|
# native with 3 args
|
|
|
|
@micropython.native
|
|
|
|
def f(a, b, c):
|
|
|
|
print(a + b + c)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2015-03-25 19:10:09 -04:00
|
|
|
f(1, 2, 3)
|
|
|
|
|
|
|
|
# check not operator
|
|
|
|
@micropython.native
|
|
|
|
def f(a):
|
|
|
|
print(not a)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2015-03-25 19:10:09 -04:00
|
|
|
f(False)
|
|
|
|
f(True)
|
2021-07-18 23:13:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
# stack settling in branch
|
|
|
|
@micropython.native
|
|
|
|
def f(a):
|
|
|
|
print(1, 2, 3, 4 if a else 5)
|
|
|
|
|
|
|
|
|
|
|
|
f(False)
|
|
|
|
f(True)
|