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