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)
|
2021-03-15 09:57:36 -04:00
|
|
|
|
|
|
|
|
2014-08-24 11:28:17 -04:00
|
|
|
native_test(2)
|
|
|
|
|
|
|
|
# check that GC doesn't collect the native function
|
|
|
|
import gc
|
2021-03-15 09:57:36 -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)
|
2021-03-15 09:57:36 -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)
|
2021-03-15 09:57:36 -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)
|
2021-03-15 09:57:36 -04:00
|
|
|
|
|
|
|
|
2015-03-25 19:10:09 -04:00
|
|
|
f(False)
|
|
|
|
f(True)
|