summaryrefslogtreecommitdiff
path: root/tests/micropython/viper.py
blob: 2ed70ade60ee49cf96893997925ce9536e690c7e (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import micropython

# viper function taking and returning ints
@micropython.viper
def f(x:int, y:int) -> int:
    return x + y + 3

# viper function taking and returning objects
@micropython.viper
def g(x:object, y:object) -> object:
    return x + y

# a local (should have automatic type int)
@micropython.viper
def h(x:int) -> int:
    y = 4
    return x + y

# without type annotation, types should default to object
@micropython.viper
def i(x, y):
    return x * y

# a for loop
@micropython.viper
def viper_sum(a:int, b:int) -> int:
    total = 0
    for x in range(a, b):
        total += x
    return total

# this doesn't work at the moment
#@micropython.viper
#def g() -> uint:
#    return -1

print(f(1, 2))
print(g(1, 2))
print(h(3))
print(i(4, 5))
print(viper_sum(10, 10000))