Made auto-bytes and auto-words work with variable arguments on ARM
[voodoo-lang.git] / test / auto-words.voo
bloba518c689875c05737a35e81c3d4a4846702b593c
1 #### Test program for auto-words
3 section data
5 print_word_space_fmt:
6 string "%d \x00"
8 print_int_fmt:
9 string "%d\n\x00"
11 section functions
12 export main
13 import printf
15 align
16 print_words:
17 function words n
18     # Prints n words.
19     let max sub n 1
20     let i 0
21     let x 0
22 print_words_loop:
23     iflt i max
24         set x get-word words i
25         call printf print_word_space_fmt x
26         set i add i 1
27         goto print_words_loop
28     end if
29     set x get-word words max
30     call printf print_int_fmt x
31     return 0        
32 end function
34 align
35 test:
36 function
37     let words auto-words 17
38     let i 0
39 test_loop:
40     iflt i 17
41         set-word words i i
42         set i add i 1
43         goto test_loop
44     end if
45     call print_words words 17
46     call test_pass words
48     block
49         let nwords 19
50         let a 42
51         let more-words auto-words nwords
52         let b 0
53         let c 72
54 test_loop1:
55         iflt b nwords
56             set-word more-words b c
57             set b add b 1
58             set c add c 1
59             goto test_loop1
60         end if
61         call print_words more-words nwords
62         call printf print_int_fmt a
63         call printf print_int_fmt b
64         call printf print_int_fmt c
65     end block
67     call printf print_int_fmt i
68     call print_words words 17
70     # Allocate memory in a block inside a loop. The memory
71     # should be freed on each iteration, so this should not
72     # run out of memory.
73     set i 0
74 test_loop2:
75     iflt i 262144
76         block
77             set words auto-words 16384
78         end block
79         set i add i 1
80         goto test_loop2
81     end if
83     return 0
84 end function
86 align
87 test_pass:
88 function text
89     call print_words text 17
90     let words auto-words 4
91     set-word words 0 48
92     set-word words 1 49
93     set-word words 2 50
94     set-word words 3 0
95     call print_words words 4
96     return 0
97 end function
99 align
100 main:
101 function argc argv
102     call test
103     return 0
104 end function