blob: 36849abafd32701290b6e375649f8e876cec54d0 (
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
42
43
44
45
46
47
48
49
|
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
# accessing a global
@micropython.viper
def access_global():
global gl
gl = 1
return gl
# 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))
print(access_global(), gl)
|