| author | |
| committer | |
| log | 358d699fa9e879cf0e027b2fd60d9dc739dac642 |
| tree | c30f039920637bc800dcc85e238ad3dab7d9ab9d |
| parent | e8550814c5e4387e8b758736a1254a5c3b32674e |
2 files changed, 70 insertions(+), 2 deletions(-)
example/arrays/arrays.zig+28-2| ... | ... | @@ -7,9 +7,35 @@ extern { |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | export fn _start() -> unreachable { |
| 10 | let mut array : [i32; 10]; | |
| 10 | let mut array : [i32; 5]; | |
| 11 | 11 | |
| 12 | array[4] = array[1] + 5; | |
| 12 | let mut i = 0; | |
| 13 | loop_start: | |
| 14 | if i == 5 { | |
| 15 | goto loop_end; | |
| 16 | } | |
| 17 | array[i] = i + 1; | |
| 18 | i = array[i]; | |
| 19 | goto loop_start; | |
| 20 | ||
| 21 | loop_end: | |
| 22 | ||
| 23 | i = 0; | |
| 24 | let mut accumulator = 0; | |
| 25 | loop_2_start: | |
| 26 | if i == 5 { | |
| 27 | goto loop_2_end; | |
| 28 | } | |
| 29 | ||
| 30 | accumulator = accumulator + array[i]; | |
| 31 | ||
| 32 | i = i + 1; | |
| 33 | goto loop_2_start; | |
| 34 | loop_2_end: | |
| 35 | ||
| 36 | if accumulator == 15 { | |
| 37 | puts("OK"); | |
| 38 | } | |
| 13 | 39 | |
| 14 | 40 | exit(0); |
| 15 | 41 | } |
test/run_tests.cpp+42| ... | ... | @@ -355,6 +355,48 @@ done: |
| 355 | 355 | exit(0); |
| 356 | 356 | } |
| 357 | 357 | )SOURCE", "zero\nloop\nloop\nloop\n"); |
| 358 | ||
| 359 | add_simple_case("arrays", R"SOURCE( | |
| 360 | #link("c") | |
| 361 | extern { | |
| 362 | fn puts(s: *const u8) -> i32; | |
| 363 | fn exit(code: i32) -> unreachable; | |
| 364 | } | |
| 365 | ||
| 366 | export fn _start() -> unreachable { | |
| 367 | let mut array : [i32; 5]; | |
| 368 | ||
| 369 | let mut i = 0; | |
| 370 | loop_start: | |
| 371 | if i == 5 { | |
| 372 | goto loop_end; | |
| 373 | } | |
| 374 | array[i] = i + 1; | |
| 375 | i = array[i]; | |
| 376 | goto loop_start; | |
| 377 | ||
| 378 | loop_end: | |
| 379 | ||
| 380 | i = 0; | |
| 381 | let mut accumulator = 0; | |
| 382 | loop_2_start: | |
| 383 | if i == 5 { | |
| 384 | goto loop_2_end; | |
| 385 | } | |
| 386 | ||
| 387 | accumulator = accumulator + array[i]; | |
| 388 | ||
| 389 | i = i + 1; | |
| 390 | goto loop_2_start; | |
| 391 | loop_2_end: | |
| 392 | ||
| 393 | if accumulator == 15 { | |
| 394 | puts("OK"); | |
| 395 | } | |
| 396 | ||
| 397 | exit(0); | |
| 398 | } | |
| 399 | )SOURCE", "OK\n"); | |
| 358 | 400 | } |
| 359 | 401 | |
| 360 | 402 | static void add_compile_failure_test_cases(void) { |