@@ -12,6 +12,25 @@ def viper_object(x:object, y:object) -> object:
1212 return x + y
1313print (viper_object (1 , 2 ))
1414
15+ # return None as non-object (should return 0)
16+ @micropython .viper
17+ def viper_ret_none () -> int :
18+ return None
19+ print (viper_ret_none ())
20+
21+ # 3 args
22+ @micropython .viper
23+ def viper_3args (a :int , b :int , c :int ) -> int :
24+ return a + b + c
25+ print (viper_3args (1 , 2 , 3 ))
26+
27+ # 4 args
28+ @micropython .viper
29+ def viper_4args (a :int , b :int , c :int , d :int ) -> int :
30+ return a + b + c + d
31+ # viper call with 4 args not yet supported
32+ #print(viper_4args(1, 2, 3, 4))
33+
1534# a local (should have automatic type int)
1635@micropython .viper
1736def viper_local (x :int ) -> int :
@@ -25,6 +44,13 @@ def viper_no_annotation(x, y):
2544 return x * y
2645print (viper_no_annotation (4 , 5 ))
2746
47+ # unsigned ints
48+ @micropython .viper
49+ def viper_uint () -> uint :
50+ return uint (- 1 )
51+ import sys
52+ print (viper_uint () == (sys .maxsize << 1 | 1 ))
53+
2854# a for loop
2955@micropython .viper
3056def viper_for (a :int , b :int ) -> int :
@@ -48,6 +74,12 @@ def viper_print(x, y:int):
4874 print (x , y + 1 )
4975viper_print (1 , 2 )
5076
77+ # convert constants to objects in tuple
78+ @micropython .viper
79+ def viper_tuple_consts (x ):
80+ return (x , 1 , False , True )
81+ print (viper_tuple_consts (0 ))
82+
5183# making a tuple from an object and an int
5284@micropython .viper
5385def viper_tuple (x , y :int ):
@@ -75,11 +107,6 @@ def viper_raise(x:int):
75107except OSError as e :
76108 print (repr (e ))
77109
78- # this doesn't work at the moment
79- #@micropython.viper
80- #def g() -> uint:
81- # return -1
82-
83110# calling GC after defining the function
84111@micropython .viper
85112def viper_gc () -> int :
0 commit comments