Implemented auto-bytes on AMD64
[voodoo-lang.git] / test / auto-bytes.voo
blob7a80f436fe9b33d32cb2039215af3ac8348779c2
1 #### Test program for auto-bytes
3 section data
5 print_endline_fmt:
6 string "%s\n\x00"
8 print_int_fmt:
9 string "%d\n\x00"
11 section functions
12 export main
13 import printf
15 align
16 test:
17 function
18     let bytes auto-bytes 17
19     let i 0
20     let j 97
21 test_loop:
22     iflt i 16
23         set-byte bytes i j
24         set i add i 1
25         set j add j 1
26         goto test_loop
27     end if
28     set-byte bytes 16 0
29     call printf print_endline_fmt bytes
30     call test_pass bytes
32     block
33         let a 42
34         let more-bytes auto-bytes 19
35         let b 0
36         let c 72
37 test_loop1:
38         iflt b 18
39             set-byte more-bytes b c
40             set b add b 1
41             set c add c 1
42             goto test_loop1
43         end if
44         set-byte more-bytes 18 0
45         call printf print_endline_fmt more-bytes
46         call printf print_int_fmt a
47         call printf print_int_fmt b
48         call printf print_int_fmt c
49     end block
51     call printf print_int_fmt i
52     call printf print_int_fmt j
53     call printf print_endline_fmt bytes
55     # Allocate memory in a block inside a loop. The memory
56     # should be freed on each iteration, so this should not
57     # run out of memory.
58     set i 0
59 test_loop2:
60     iflt i 262144
61         block
62             set bytes auto-bytes 16384
63         end block
64         set i add i 1
65         goto test_loop2
66     end if
68     return 0
69 end function
71 align
72 test_pass:
73 function text
74     call printf print_endline_fmt text
75     let bytes auto-bytes 4
76     set-byte bytes 0 48
77     set-byte bytes 1 49
78     set-byte bytes 2 50
79     set-byte bytes 3 0
80     call printf print_endline_fmt bytes
81     return 0
82 end function
84 align
85 main:
86 function argc argv
87     call test
88     return 0
89 end function