reject programs that import symbols after using them
[voodoo-lang.git] / test / block.voo
blob9193b168a1e34bb73a5f9320a0bbd5bbe56a88bb
1 # Test case for blocks
3 section data
5 format:
6 string "%d\n\x00"
9 section functions
10 import printf
11 export main
13 align
14 fib_step:
15 function min1 min2
16     return add min1 min2
17 end function
19 align
20 fib:
21 function n
22     # Some function that uses a number of local variables,
23     # some of them in a block inside a conditional. Probably not
24     # the best way to compute Fibonacci numbers, but a decent way
25     # to exercise the compiler.
26     let fib0 0
27     let fib0_result 0
28     let fib1 1
29     let fib1_result 1
30     ifle n fib0
31         return fib0_result
32     else ifeq n fib1
33         return fib1_result
34     else
35         block
36             let i 2
37             let cur 1
38             let min1 1
39             let min2 0
40 fib_loop:
41             ifge i n
42                 goto fib_done
43             end if
44             set min2 min1
45             set min1 cur
46             set cur call fib_step min1 min2
47             set i add i 1
48             goto fib_loop
49 fib_done:
50             return cur
51         end block
52     end if
53 end function
55 align
56 main:
57 function argc argv
58     block
59         let x 12
60         call printf format x
62         block
63             let x 42
64             call printf format x
65         end block
67         call printf format x
69         block
70             let y 67
71             call printf format x
72             call printf format y
73         end block
75         call printf format x
76     end block
78     let x call fib 11
79     call printf format x
81     return 0
82 end function