1# check that we can do certain things without allocating heap memory
2
3import micropython
4
5# Check for stackless build, which can't call functions without
6# allocating a frame on heap.
7try:
8
9    def stackless():
10        pass
11
12    micropython.heap_lock()
13    stackless()
14    micropython.heap_unlock()
15except RuntimeError:
16    print("SKIP")
17    raise SystemExit
18
19
20def f1(a):
21    print(a)
22
23
24def f2(a, b=2):
25    print(a, b)
26
27
28def f3(a, b, c, d):
29    x1 = x2 = a
30    x3 = x4 = b
31    x5 = x6 = c
32    x7 = x8 = d
33    print(x1, x3, x5, x7, x2 + x4 + x6 + x8)
34
35
36global_var = 1
37
38
39def test():
40    global global_var, global_exc
41    global_var = 2  # set an existing global variable
42    for i in range(2):  # for loop
43        f1(i)  # function call
44        f1(i * 2 + 1)  # binary operation with small ints
45        f1(a=i)  # keyword arguments
46        f2(i)  # default arg (second one)
47        f2(i, i)  # 2 args
48    f3(1, 2, 3, 4)  # function with lots of local state
49
50
51# call test() with heap allocation disabled
52micropython.heap_lock()
53test()
54micropython.heap_unlock()
55