summaryrefslogtreecommitdiff
path: root/tests/micropython/heapalloc.py
blob: c62428a08417fac5160cf99dd1ae1e7c976785f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# check that we can do certain things without allocating heap memory

import gc

def f(a):
    print(a)

def g(a, b=2):
    print(a, b)

global_var = 1

def h():
    global global_var
    global_var = 2      # set an existing global variable
    for i in range(2):  # for loop
        f(i)            # function call
        f(i * 2 + 1)    # binary operation with small ints
        f(a=i)          # keyword arguments
        g(i)            # default arg (second one)
        g(i, i)         # 2 args

# call h with heap allocation disabled
gc.disable()
h()
gc.enable()