@@ -60,16 +60,18 @@ fn codegen test_loops:
60
60
:after_for_111
61
61
i64 i
62
62
i64 j = 0
63
+ i64 k
63
64
//if(1)
65
+ k = 0
64
66
for(i = 0, i < 20; i++)
65
- __builtin_puts("You should see this print! (for i = 0 to 3 inclusive, 4 times)") ;
67
+ k++ ;
66
68
if(i == 3)
67
69
j--;
68
70
break
69
71
end
70
72
j++;
71
73
end
72
- if(i != 3 || j != (3-1))
74
+ if(i != 3 || j != (3-1) || k != 4 )
73
75
__builtin_puts("Failed Loop Test 1");
74
76
char[50] buf
75
77
__builtin_utoa(buf, i);
@@ -157,7 +159,6 @@ fn codegen test_loops:
157
159
end
158
160
end
159
161
:out2
160
- i64 k
161
162
for(k = 0, k < i, k++)
162
163
;
163
164
end
@@ -176,11 +177,68 @@ fn codegen test_loops:
176
177
177
178
end
178
179
180
+ fn codegen test_switch:
181
+ i64 i = 0
182
+ i64 j = 0
183
+ i64 k = 0
184
+ switch(1+2+3) l0 l1 l2 l3 l4 l5 l6 l7 l8 l9 l10;
185
+
186
+
187
+
188
+ :l0 i = 1 goto l_last
189
+ :l1 i = 1 goto l_last
190
+ :l2 i = 1 goto l_last
191
+ :l3 i = 1 goto l_last
192
+ :l4 i = 1 goto l_last
193
+ :l5 i = 1 goto l_last
194
+ :l6 goto l_last
195
+ :l7 i = 1 goto l_last
196
+ :l8 i = 1 goto l_last
197
+ :l9 i = 1 goto l_last
198
+ :l10 i = 1 goto l_last
199
+ :l11 i = 1 goto l_last
200
+ :l12 i = 1 goto l_last
201
+ :l13 i = 1 goto l_last
202
+ :l14 i = 1 goto l_last
203
+
204
+ :l_last
205
+ if(i != 0)
206
+ have_failed = 1;
207
+ __builtin_puts("Failed switch test")
208
+ end
209
+
210
+ return
211
+ end
212
+
213
+ fn codegen test_writefile_readfile:
214
+ __builtin_open_ofile("test.out");
215
+ __builtin_emit("1234567890",11);
216
+ __builtin_close_ofile();
217
+ u64[1] len
218
+ len[0] = 0
219
+
220
+ char* p = __builtin_read_file("test.out",len);
221
+ if(len[0] != 11 || p == 0)
222
+ __builtin_puts("Failed File I/O test - Could not read file.");
223
+ have_failed = 1;
224
+ end
225
+ if(p strneq "1234567890")
226
+ __builtin_puts("Failed File I/O test - File contents failure.");
227
+ have_failed = 1;
228
+ end
229
+ __builtin_free(p);
230
+ end
231
+
179
232
180
233
fn codegen codegen_main:
181
234
__builtin_puts("TESTING BASIC ARITHMETIC");
182
235
testmath();
236
+ __builtin_puts("TESTING LOOPS");
183
237
test_loops();
238
+ __builtin_puts("TESTING SWITCH");
239
+ test_switch;
240
+ __builtin_puts("TESTING FILES");
241
+ test_writefile_readfile();
184
242
if(!have_failed)
185
243
__builtin_puts("Success!!!!");
186
244
else
0 commit comments