From ccce0ec28fa9d1978b41c36a1eb28732c0374a8a Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Sat, 30 May 2026 08:56:44 +0000 Subject: [PATCH] Adding more tests with the new framework --- generate_expected_outputs.py | 87 ++++++++++++++++++ program | Bin 0 -> 16224 bytes .../conditionals/boolean_logic.exitcode | 1 + .../runtime/conditionals/boolean_logic.stderr | 0 .../runtime/conditionals/boolean_logic.stdout | 10 ++ .../conditionals/complex_bool.exitcode | 1 + .../runtime/conditionals/complex_bool.stderr | 0 .../runtime/conditionals/complex_bool.stdout | 3 + .../conditionals/if-elif-else.exitcode | 2 +- .../runtime/conditionals/if-elif.exitcode | 2 +- .../runtime/conditionals/if-else.exitcode | 2 +- .../expected/runtime/conditionals/if.exitcode | 2 +- .../runtime/conditionals/nested.exitcode | 1 + .../runtime/conditionals/nested.stderr | 0 .../runtime/conditionals/nested.stdout | 2 + .../runtime/functions/basics.exitcode | 2 +- .../runtime/functions/composition.exitcode | 1 + .../runtime/functions/composition.stderr | 0 .../runtime/functions/composition.stdout | 5 + .../runtime/functions/recursive.exitcode | 2 +- .../runtime/functions/scopes.exitcode | 2 +- .../runtime/functions/sequences.exitcode | 1 + .../runtime/functions/sequences.stderr | 0 .../runtime/functions/sequences.stdout | 3 + .../runtime/loops/break_continue.exitcode | 1 + .../runtime/loops/break_continue.stderr | 0 .../runtime/loops/break_continue.stdout | 2 + tests/expected/runtime/loops/control.exitcode | 2 +- .../runtime/loops/increment_patterns.exitcode | 1 + .../runtime/loops/increment_patterns.stderr | 0 .../runtime/loops/increment_patterns.stdout | 3 + .../runtime/loops/increments.exitcode | 1 + .../expected/runtime/loops/increments.stderr | 0 .../expected/runtime/loops/increments.stdout | 3 + tests/expected/runtime/loops/nested.exitcode | 1 + tests/expected/runtime/loops/nested.stderr | 0 tests/expected/runtime/loops/nested.stdout | 2 + .../runtime/loops/nested_control.exitcode | 1 + .../runtime/loops/nested_control.stderr | 0 .../runtime/loops/nested_control.stdout | 2 + tests/expected/runtime/loops/sums.exitcode | 1 + tests/expected/runtime/loops/sums.stderr | 0 tests/expected/runtime/loops/sums.stdout | 2 + .../runtime/loops/with_verify.exitcode | 1 + .../expected/runtime/loops/with_verify.stderr | 0 .../expected/runtime/loops/with_verify.stdout | 1 + .../operations/basic_comparisons.exitcode | 1 + .../operations/basic_comparisons.stderr | 0 .../operations/basic_comparisons.stdout | 12 +++ .../runtime/operations/binary.exitcode | 2 +- .../runtime/operations/factorials.exitcode | 1 + .../runtime/operations/factorials.stderr | 0 .../runtime/operations/factorials.stdout | 5 + .../operations/floating_point.exitcode | 1 + .../runtime/operations/floating_point.stderr | 0 .../runtime/operations/floating_point.stdout | 7 ++ .../operations/increment_decrement.exitcode | 1 + .../operations/increment_decrement.stderr | 0 .../operations/increment_decrement.stdout | 6 ++ .../runtime/operations/mixed_types.exitcode | 1 + .../runtime/operations/mixed_types.stderr | 0 .../runtime/operations/mixed_types.stdout | 4 + .../runtime/operations/unary.exitcode | 2 +- tests/expected/runtime/strings/basic.exitcode | 1 + tests/expected/runtime/strings/basic.stderr | 0 tests/expected/runtime/strings/basic.stdout | 2 + .../expected/runtime/strings/escapes.exitcode | 2 +- tests/expected/runtime/types.exitcode | 2 +- .../expected/runtime/types/all_types.exitcode | 1 + tests/expected/runtime/types/all_types.stderr | 0 tests/expected/runtime/types/all_types.stdout | 3 + .../runtime/types/boundaries.exitcode | 1 + .../expected/runtime/types/boundaries.stderr | 0 .../expected/runtime/types/boundaries.stdout | 7 ++ tests/expected/runtime/variables.exitcode | 2 +- tests/expected/runtime/variables.stdout | 2 +- .../variables/sequential_assign.exitcode | 1 + .../variables/sequential_assign.stderr | 0 .../variables/sequential_assign.stdout | 9 ++ .../runtime/variables/shadowing.exitcode | 1 + .../runtime/variables/shadowing.stderr | 0 .../runtime/variables/shadowing.stdout | 6 ++ tests/runtime/conditionals/boolean_logic.zz | 69 ++++++++++++++ tests/runtime/conditionals/complex_bool.zz | 37 ++++++++ tests/runtime/conditionals/nested.zz | 48 ++++++++++ tests/runtime/functions/composition.zz | 39 ++++++++ tests/runtime/functions/sequences.zz | 25 +++++ tests/runtime/loops/break_continue.zz | 24 +++++ tests/runtime/loops/increment_patterns.zz | 25 +++++ tests/runtime/loops/increments.zz | 25 +++++ tests/runtime/loops/nested.zz | 37 ++++++++ tests/runtime/loops/nested_control.zz | 23 +++++ tests/runtime/loops/sums.zz | 20 ++++ tests/runtime/loops/with_verify.zz | 21 +++++ tests/runtime/operations/basic_comparisons.zz | 34 +++++++ tests/runtime/operations/factorials.zz | 16 ++++ tests/runtime/operations/floating_point.zz | 24 +++++ .../runtime/operations/increment_decrement.zz | 18 ++++ tests/runtime/operations/mixed_types.zz | 29 ++++++ tests/runtime/strings/basic.zz | 16 ++++ tests/runtime/types/all_types.zz | 23 +++++ tests/runtime/types/boundaries.zz | 30 ++++++ tests/runtime/variables/sequential_assign.zz | 30 ++++++ tests/runtime/variables/shadowing.zz | 29 ++++++ 104 files changed, 864 insertions(+), 14 deletions(-) create mode 100644 generate_expected_outputs.py create mode 100755 program create mode 100644 tests/expected/runtime/conditionals/boolean_logic.exitcode create mode 100644 tests/expected/runtime/conditionals/boolean_logic.stderr create mode 100644 tests/expected/runtime/conditionals/boolean_logic.stdout create mode 100644 tests/expected/runtime/conditionals/complex_bool.exitcode create mode 100644 tests/expected/runtime/conditionals/complex_bool.stderr create mode 100644 tests/expected/runtime/conditionals/complex_bool.stdout create mode 100644 tests/expected/runtime/conditionals/nested.exitcode create mode 100644 tests/expected/runtime/conditionals/nested.stderr create mode 100644 tests/expected/runtime/conditionals/nested.stdout create mode 100644 tests/expected/runtime/functions/composition.exitcode create mode 100644 tests/expected/runtime/functions/composition.stderr create mode 100644 tests/expected/runtime/functions/composition.stdout create mode 100644 tests/expected/runtime/functions/sequences.exitcode create mode 100644 tests/expected/runtime/functions/sequences.stderr create mode 100644 tests/expected/runtime/functions/sequences.stdout create mode 100644 tests/expected/runtime/loops/break_continue.exitcode create mode 100644 tests/expected/runtime/loops/break_continue.stderr create mode 100644 tests/expected/runtime/loops/break_continue.stdout create mode 100644 tests/expected/runtime/loops/increment_patterns.exitcode create mode 100644 tests/expected/runtime/loops/increment_patterns.stderr create mode 100644 tests/expected/runtime/loops/increment_patterns.stdout create mode 100644 tests/expected/runtime/loops/increments.exitcode create mode 100644 tests/expected/runtime/loops/increments.stderr create mode 100644 tests/expected/runtime/loops/increments.stdout create mode 100644 tests/expected/runtime/loops/nested.exitcode create mode 100644 tests/expected/runtime/loops/nested.stderr create mode 100644 tests/expected/runtime/loops/nested.stdout create mode 100644 tests/expected/runtime/loops/nested_control.exitcode create mode 100644 tests/expected/runtime/loops/nested_control.stderr create mode 100644 tests/expected/runtime/loops/nested_control.stdout create mode 100644 tests/expected/runtime/loops/sums.exitcode create mode 100644 tests/expected/runtime/loops/sums.stderr create mode 100644 tests/expected/runtime/loops/sums.stdout create mode 100644 tests/expected/runtime/loops/with_verify.exitcode create mode 100644 tests/expected/runtime/loops/with_verify.stderr create mode 100644 tests/expected/runtime/loops/with_verify.stdout create mode 100644 tests/expected/runtime/operations/basic_comparisons.exitcode create mode 100644 tests/expected/runtime/operations/basic_comparisons.stderr create mode 100644 tests/expected/runtime/operations/basic_comparisons.stdout create mode 100644 tests/expected/runtime/operations/factorials.exitcode create mode 100644 tests/expected/runtime/operations/factorials.stderr create mode 100644 tests/expected/runtime/operations/factorials.stdout create mode 100644 tests/expected/runtime/operations/floating_point.exitcode create mode 100644 tests/expected/runtime/operations/floating_point.stderr create mode 100644 tests/expected/runtime/operations/floating_point.stdout create mode 100644 tests/expected/runtime/operations/increment_decrement.exitcode create mode 100644 tests/expected/runtime/operations/increment_decrement.stderr create mode 100644 tests/expected/runtime/operations/increment_decrement.stdout create mode 100644 tests/expected/runtime/operations/mixed_types.exitcode create mode 100644 tests/expected/runtime/operations/mixed_types.stderr create mode 100644 tests/expected/runtime/operations/mixed_types.stdout create mode 100644 tests/expected/runtime/strings/basic.exitcode create mode 100644 tests/expected/runtime/strings/basic.stderr create mode 100644 tests/expected/runtime/strings/basic.stdout create mode 100644 tests/expected/runtime/types/all_types.exitcode create mode 100644 tests/expected/runtime/types/all_types.stderr create mode 100644 tests/expected/runtime/types/all_types.stdout create mode 100644 tests/expected/runtime/types/boundaries.exitcode create mode 100644 tests/expected/runtime/types/boundaries.stderr create mode 100644 tests/expected/runtime/types/boundaries.stdout create mode 100644 tests/expected/runtime/variables/sequential_assign.exitcode create mode 100644 tests/expected/runtime/variables/sequential_assign.stderr create mode 100644 tests/expected/runtime/variables/sequential_assign.stdout create mode 100644 tests/expected/runtime/variables/shadowing.exitcode create mode 100644 tests/expected/runtime/variables/shadowing.stderr create mode 100644 tests/expected/runtime/variables/shadowing.stdout create mode 100644 tests/runtime/conditionals/boolean_logic.zz create mode 100644 tests/runtime/conditionals/complex_bool.zz create mode 100644 tests/runtime/conditionals/nested.zz create mode 100644 tests/runtime/functions/composition.zz create mode 100644 tests/runtime/functions/sequences.zz create mode 100644 tests/runtime/loops/break_continue.zz create mode 100644 tests/runtime/loops/increment_patterns.zz create mode 100644 tests/runtime/loops/increments.zz create mode 100644 tests/runtime/loops/nested.zz create mode 100644 tests/runtime/loops/nested_control.zz create mode 100644 tests/runtime/loops/sums.zz create mode 100644 tests/runtime/loops/with_verify.zz create mode 100644 tests/runtime/operations/basic_comparisons.zz create mode 100644 tests/runtime/operations/factorials.zz create mode 100644 tests/runtime/operations/floating_point.zz create mode 100644 tests/runtime/operations/increment_decrement.zz create mode 100644 tests/runtime/operations/mixed_types.zz create mode 100644 tests/runtime/strings/basic.zz create mode 100644 tests/runtime/types/all_types.zz create mode 100644 tests/runtime/types/boundaries.zz create mode 100644 tests/runtime/variables/sequential_assign.zz create mode 100644 tests/runtime/variables/shadowing.zz diff --git a/generate_expected_outputs.py b/generate_expected_outputs.py new file mode 100644 index 0000000..0fab3d2 --- /dev/null +++ b/generate_expected_outputs.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +import subprocess +import sys +from pathlib import Path +import tempfile +import shutil + +ZPILER = Path("/home/xzist/zust/build/zpiler") +TESTS_DIR = Path("/home/xzist/zust/tests") +RUNTIME_DIR = TESTS_DIR / "runtime" +EXPECTED_DIR = TESTS_DIR / "expected" / "runtime" + +def run_command(cmd, check=True): + result = subprocess.run(cmd, capture_output=True, text=False) + if check and result.returncode != 0: + print(f"Command failed: {' '.join(cmd)}") + print(f"stdout: {result.stdout.decode()}") + print(f"stderr: {result.stderr.decode()}") + sys.exit(1) + return result + +def generate_outputs_for_test(test_file): + """Generate expected outputs for a single test file""" + rel_path = test_file.relative_to(RUNTIME_DIR) + expected_dir = EXPECTED_DIR / rel_path.parent + expected_dir.mkdir(parents=True, exist_ok=True) + + test_name = test_file.stem + + # Compile to assembly + with tempfile.TemporaryDirectory() as tmpdir: + tmpdir = Path(tmpdir) + asm_file = tmpdir / f"{test_name}.s" + obj_file = tmpdir / f"{test_name}.o" + exe_file = tmpdir / f"{test_name}" + + # Compile + print(f"Compiling {rel_path}...", end=" ") + result = run_command([str(ZPILER), "--format", "x86_64-linux", "-o", str(asm_file), str(test_file)], check=False) + if result.returncode != 0: + print(f"FAILED to compile") + return False + + # Assemble + result = run_command(["as", str(asm_file), "-o", str(obj_file)], check=False) + if result.returncode != 0: + print(f"FAILED to assemble") + return False + + # Link + result = run_command(["gcc", str(obj_file), "-o", str(exe_file)], check=False) + if result.returncode != 0: + print(f"FAILED to link") + return False + + # Run + result = run_command([str(exe_file)], check=False) + + # Save outputs + stdout_file = expected_dir / f"{test_name}.stdout" + stderr_file = expected_dir / f"{test_name}.stderr" + exitcode_file = expected_dir / f"{test_name}.exitcode" + + stdout_file.write_bytes(result.stdout) + stderr_file.write_bytes(result.stderr) + exitcode_file.write_bytes(str(result.returncode).encode()) + + print(f"OK (exit code: {result.returncode})") + return True + +def main(): + # Find all .zz files in runtime directory + test_files = sorted(RUNTIME_DIR.rglob("*.zz")) + + success_count = 0 + fail_count = 0 + + for test_file in test_files: + if generate_outputs_for_test(test_file): + success_count += 1 + else: + fail_count += 1 + + print(f"\nGenerated outputs for {success_count} tests, {fail_count} failed") + +if __name__ == "__main__": + main() diff --git a/program b/program new file mode 100755 index 0000000000000000000000000000000000000000..3d799a19d4f6bd08b9cd25822f29b36247b95d99 GIT binary patch literal 16224 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 rXeB< int32_t; + +fn print_bool(x: boolean) -> none { + if(x == 1){ + printf("true\n"); + }else{ + printf("false\n"); + } +} + +let a: int64_t = 10; +let b: int64_t = 20; +let c: int64_t = 15; + +fn main() { + // AND operator + let cmp_ab: boolean = a < b; + let cmp_bc: boolean = b > c; + let and1: boolean = cmp_ab && cmp_bc; + + let cmp_ab2: boolean = a > b; + let and2: boolean = cmp_ab2 && cmp_bc; + + let cmp_ca: boolean = c < a; + let and3: boolean = cmp_ab && cmp_ca; + + // OR operator + let cmp_ab3: boolean = a < b; + let cmp_ab4: boolean = a > b; + let or1: boolean = cmp_ab3 || cmp_ab4; + + let cmp_ab5: boolean = a > b; + let cmp_ab6: boolean = a > b; + let or2: boolean = cmp_ab5 || cmp_ab6; + + let cmp_ab7: boolean = a > b; + let cmp_ca2: boolean = c > a; + let or3: boolean = cmp_ab7 || cmp_ca2; + + // NOT operator + let cmp_ab8: boolean = a < b; + let not1: boolean = !cmp_ab8; + + let cmp_ab9: boolean = a > b; + let not2: boolean = !cmp_ab9; + + // Complex combinations + let cmp_ab10: boolean = a < b; + let cmp_bc2: boolean = b > c; + let cmp_ab11: boolean = a > b; + let complex1: boolean = cmp_ab10 && cmp_bc2 || cmp_ab11; + + let cmp_ab12: boolean = a > b; + let cmp_ca3: boolean = c > a; + let cmp_ab13: boolean = a < b; + let complex2: boolean = cmp_ab12 || cmp_ca3 && cmp_ab13; + + print_bool(and1); + print_bool(and2); + print_bool(and3); + print_bool(or1); + print_bool(or2); + print_bool(or3); + print_bool(not1); + print_bool(not2); + print_bool(complex1); + print_bool(complex2); +} diff --git a/tests/runtime/conditionals/complex_bool.zz b/tests/runtime/conditionals/complex_bool.zz new file mode 100644 index 0000000..9f6113b --- /dev/null +++ b/tests/runtime/conditionals/complex_bool.zz @@ -0,0 +1,37 @@ +// Test boolean combinations with mixed types +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let a: int64_t = 5; + let b: int64_t = 10; + let f: float = 7.5; + let flag: boolean = true; + + // Complex boolean expression + let cmp1: boolean = a < b; + let cmp2: boolean = f > a; + let expr1: boolean = cmp1 && cmp2; + + let cmp3: boolean = a > b; + let expr2: boolean = cmp3 || flag; + + let cmp4: boolean = a == b; + let expr3: boolean = !cmp4; + + let cmp5: boolean = a < b; + let cmp6: boolean = b < 20; + let expr4: boolean = cmp5 && cmp6 && flag; + + if (expr1 && expr2) { + printf("1\n"); + } + + let not_flag: boolean = !flag; + if (expr3 || not_flag) { + printf("1\n"); + } + + if (expr4) { + printf("1\n"); + } +} diff --git a/tests/runtime/conditionals/nested.zz b/tests/runtime/conditionals/nested.zz new file mode 100644 index 0000000..5ae7c85 --- /dev/null +++ b/tests/runtime/conditionals/nested.zz @@ -0,0 +1,48 @@ +// Test nested if-else statements +extern fn printf(fmt: string, ...) -> int32_t; + +fn print_int(x: int64_t) -> none { + printf("%d\n", x); +} + +fn main() { + let x: int64_t = 50; + let y: int64_t = 100; + let z: int64_t = 75; + + // Nested conditions for comparison logic + let cmp1: boolean = x < y; + if (cmp1) { + let cmp2: boolean = z < y; + if (cmp2) { + let cmp3: boolean = z > x; + if (cmp3) { + print_int(1); // All conditions met + } else { + print_int(2); + } + } else { + print_int(3); + } + } else { + let cmp4: boolean = y > z; + if (cmp4) { + print_int(4); + } else { + print_int(5); + } + } + + // Nested with multiple levels + let a: int64_t = 10; + let cmp5: boolean = a > 5; + if (cmp5) { + let cmp6: boolean = a < 20; + if (cmp6) { + let cmp7: boolean = a != 15; + if (cmp7) { + print_int(6); // True path + } + } + } +} diff --git a/tests/runtime/functions/composition.zz b/tests/runtime/functions/composition.zz new file mode 100644 index 0000000..f408f8e --- /dev/null +++ b/tests/runtime/functions/composition.zz @@ -0,0 +1,39 @@ +// Test function composition and chaining +extern fn printf(fmt: string, ...) -> int32_t; + +fn double_value(x: int64_t) -> int64_t { + return x * 2; +} + +fn add_ten(x: int64_t) -> int64_t { + return x + 10; +} + +fn cube(x: int64_t) -> int64_t { + return x * x * x; +} + +fn absolute(x: int64_t) -> int64_t { + if (x < 0) { + return x * -1; + } + return x; +} + +fn main() { + let result1: int64_t = double_value(5); + printf("%d\n", result1); // 10 + + let result2: int64_t = add_ten(result1); + printf("%d\n", result2); // 20 + + let result3: int64_t = cube(3); + printf("%d\n", result3); // 27 + + let result4: int64_t = absolute(-15); + printf("%d\n", result4); // 15 + + // Chained calls + let chained: int64_t = add_ten(double_value(5)); + printf("%d\n", chained); // 20 +} diff --git a/tests/runtime/functions/sequences.zz b/tests/runtime/functions/sequences.zz new file mode 100644 index 0000000..5c58165 --- /dev/null +++ b/tests/runtime/functions/sequences.zz @@ -0,0 +1,25 @@ +// Test calling multiple functions in sequence +extern fn printf(fmt: string, ...) -> int32_t; + +fn get_five() -> int64_t { + return 5; +} + +fn double_it(x: int64_t) -> int64_t { + return x * 2; +} + +fn add_seven(x: int64_t) -> int64_t { + return x + 7; +} + +fn main() { + let five: int64_t = get_five(); + printf("%d\n", five); // 5 + + let doubled: int64_t = double_it(five); + printf("%d\n", doubled); // 10 + + let result: int64_t = add_seven(doubled); + printf("%d\n", result); // 17 +} diff --git a/tests/runtime/loops/break_continue.zz b/tests/runtime/loops/break_continue.zz new file mode 100644 index 0000000..c428d65 --- /dev/null +++ b/tests/runtime/loops/break_continue.zz @@ -0,0 +1,24 @@ +// Test for loop control with break at specific positions +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + // Break in middle + let sum1: int32_t = 0; + for(let i: int32_t = 0; i < 10; i = i + 1;) { + if (i == 5) { + break; + } + sum1 = sum1 + i; + } + printf("%d\n", sum1); // 0+1+2+3+4 = 10 + + // Continue to skip + let sum2: int32_t = 0; + for(let i: int32_t = 0; i < 5; i = i + 1;) { + if (i == 2) { + continue; + } + sum2 = sum2 + i; + } + printf("%d\n", sum2); // 0+1+3+4 = 8 +} diff --git a/tests/runtime/loops/increment_patterns.zz b/tests/runtime/loops/increment_patterns.zz new file mode 100644 index 0000000..177ede3 --- /dev/null +++ b/tests/runtime/loops/increment_patterns.zz @@ -0,0 +1,25 @@ +// Test different increment patterns in loops +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + // Increment by 1 + let result1: int64_t = 0; + for(let i: int64_t = 0; i < 3; i = i + 1;) { + result1 = result1 + i; + } + printf("%d\n", result1); // 0+1+2 = 3 + + // Increment by 5 + let result2: int64_t = 0; + for(let i: int64_t = 0; i < 20; i = i + 5;) { + result2 = result1 + 1; + } + printf("%d\n", result2); // 3+1 = 4 + + // Decrement + let result3: int64_t = 0; + for(let i: int64_t = 10; i > 0; i = i - 2;) { + result3 = result3 + 1; + } + printf("%d\n", result3); // 5 iterations +} diff --git a/tests/runtime/loops/increments.zz b/tests/runtime/loops/increments.zz new file mode 100644 index 0000000..2dc4e5e --- /dev/null +++ b/tests/runtime/loops/increments.zz @@ -0,0 +1,25 @@ +// Test for-loop with various increment patterns +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + // Count by 1 + let count1: int32_t = 0; + for(let i: int32_t = 0; i < 5; i = i + 1;) { + count1 = count1 + 1; + } + printf("%d\n", count1); // 5 + + // Count by 2 + let sum: int32_t = 0; + for(let i: int32_t = 0; i <= 10; i = i + 2;) { + sum = sum + i; + } + printf("%d\n", sum); // 0+2+4+6+8+10 = 30 + + // Countdown + let countdown_sum: int32_t = 0; + for(let i: int32_t = 5; i > 0; i = i - 1;) { + countdown_sum = countdown_sum + i; + } + printf("%d\n", countdown_sum); // 5+4+3+2+1 = 15 +} diff --git a/tests/runtime/loops/nested.zz b/tests/runtime/loops/nested.zz new file mode 100644 index 0000000..6cff159 --- /dev/null +++ b/tests/runtime/loops/nested.zz @@ -0,0 +1,37 @@ +// Test nested loops with break and continue +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let sum: int32_t = 0; + + // Nested loop with continue and break + for(let i: int32_t = 0; i < 5; i = i + 1;) { + for(let j: int32_t = 0; j < 5; j = j + 1;) { + if (j == 2) { + continue; // Skip j=2 + } + if (j == 4) { + break; // Exit inner loop at j=4 + } + sum = sum + 1; + } + } + + printf("%d\n", sum); // Should be 15: 5 iterations * 3 valid j values + + // Nested while loops + let a: int32_t = 0; + let b: int32_t = 0; + let total: int32_t = 0; + + while(a < 3) { + b = 0; + while(b < 3) { + total = total + 1; + b = b + 1; + } + a = a + 1; + } + + printf("%d\n", total); // Should be 9: 3*3 +} diff --git a/tests/runtime/loops/nested_control.zz b/tests/runtime/loops/nested_control.zz new file mode 100644 index 0000000..86af405 --- /dev/null +++ b/tests/runtime/loops/nested_control.zz @@ -0,0 +1,23 @@ +// Test nested if with continue and break patterns +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let outer_count: int32_t = 0; + let inner_count: int32_t = 0; + + for(let i: int32_t = 0; i < 3; i = i + 1;) { + for(let j: int32_t = 0; j < 4; j = j + 1;) { + if (j == 1) { + continue; + } + if (i == 2 && j == 3) { + break; + } + inner_count = inner_count + 1; + } + outer_count = outer_count + 1; + } + + printf("%d\n", outer_count); // 3 + printf("%d\n", inner_count); // (3*3) for i=0,1 + (2) for i=2 = 11 +} diff --git a/tests/runtime/loops/sums.zz b/tests/runtime/loops/sums.zz new file mode 100644 index 0000000..f2c4467 --- /dev/null +++ b/tests/runtime/loops/sums.zz @@ -0,0 +1,20 @@ +// Test simple sum accumulation pattern +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + // Sum first 5 numbers + let sum: int32_t = 0; + + for(let i: int32_t = 1; i <= 5; i = i + 1;) { + sum = sum + i; + } + + printf("%d\n", sum); // 1+2+3+4+5 = 15 + + // Sum even numbers + let sum_even: int32_t = 0; + for(let j: int32_t = 2; j <= 10; j = j + 2;) { + sum_even = sum_even + j; + } + printf("%d\n", sum_even); // 2+4+6+8+10 = 30 +} diff --git a/tests/runtime/loops/with_verify.zz b/tests/runtime/loops/with_verify.zz new file mode 100644 index 0000000..2dcd17c --- /dev/null +++ b/tests/runtime/loops/with_verify.zz @@ -0,0 +1,21 @@ +// Test conditional with exit codes +extern fn exit(code: int32_t) -> none; +extern fn printf(fmt: string, ...) -> int32_t; + +fn verify_sum(sum: int32_t, expected: int32_t) -> none { + if (sum != expected) { + exit(1); + } +} + +fn main() { + let total: int32_t = 0; + + for(let i: int32_t = 1; i <= 5; i = i + 1;) { + total = total + i; + } + + verify_sum(total, 15); // 1+2+3+4+5 = 15 + + printf("1\n"); // This should print if verify_sum passes +} diff --git a/tests/runtime/operations/basic_comparisons.zz b/tests/runtime/operations/basic_comparisons.zz new file mode 100644 index 0000000..015f22f --- /dev/null +++ b/tests/runtime/operations/basic_comparisons.zz @@ -0,0 +1,34 @@ +// Test comparison operators +extern fn printf(fmt: string, ...) -> int32_t; + +fn print_bool(x: boolean) -> none { + if(x == 1){ + printf("true\n"); + }else{ + printf("false\n"); + } +} + +fn main() { + let a: int64_t = 5; + let b: int64_t = 10; + let c: int64_t = 5; + + // Equality + print_bool(a == c); // true + print_bool(a == b); // false + print_bool(a != b); // true + print_bool(a != c); // false + + // Less/Greater + print_bool(a < b); // true + print_bool(b > a); // true + print_bool(a > b); // false + print_bool(b < a); // false + + // Less/Greater or equal + print_bool(a <= c); // true + print_bool(a <= b); // true + print_bool(b >= a); // true + print_bool(c >= a); // true +} diff --git a/tests/runtime/operations/factorials.zz b/tests/runtime/operations/factorials.zz new file mode 100644 index 0000000..c93d506 --- /dev/null +++ b/tests/runtime/operations/factorials.zz @@ -0,0 +1,16 @@ +// Test factorial with intermediate results +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let factorial_1: int64_t = 1; + let factorial_2: int64_t = 1 * 2; + let factorial_3: int64_t = 1 * 2 * 3; + let factorial_4: int64_t = 1 * 2 * 3 * 4; + let factorial_5: int64_t = 1 * 2 * 3 * 4 * 5; + + printf("%d\n", factorial_1); // 1 + printf("%d\n", factorial_2); // 2 + printf("%d\n", factorial_3); // 6 + printf("%d\n", factorial_4); // 24 + printf("%d\n", factorial_5); // 120 +} diff --git a/tests/runtime/operations/floating_point.zz b/tests/runtime/operations/floating_point.zz new file mode 100644 index 0000000..1fca60c --- /dev/null +++ b/tests/runtime/operations/floating_point.zz @@ -0,0 +1,24 @@ +// Test floating point arithmetic precision +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let a: float = 0.1; + let b: float = 0.2; + let c: float = 0.3; + + printf("%f\n", a); + printf("%f\n", b); + printf("%f\n", c); + + let sum: float = a + b; + printf("%f\n", sum); + + let product: float = a * b; + printf("%f\n", product); + + // Double precision + let d1: double = 1.23456789; + let d2: double = 9.87654321; + printf("%f\n", d1); + printf("%f\n", d2); +} diff --git a/tests/runtime/operations/increment_decrement.zz b/tests/runtime/operations/increment_decrement.zz new file mode 100644 index 0000000..5ef27f7 --- /dev/null +++ b/tests/runtime/operations/increment_decrement.zz @@ -0,0 +1,18 @@ +// Test post-increment and post-decrement operators +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let x: int64_t = 10; + printf("%d\n", x); + x++; + printf("%d\n", x); + x++; + printf("%d\n", x); + + let y: int64_t = 20; + printf("%d\n", y); + y--; + printf("%d\n", y); + y--; + printf("%d\n", y); +} diff --git a/tests/runtime/operations/mixed_types.zz b/tests/runtime/operations/mixed_types.zz new file mode 100644 index 0000000..83adba9 --- /dev/null +++ b/tests/runtime/operations/mixed_types.zz @@ -0,0 +1,29 @@ +// Test mixed type arithmetic and comparisons +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let i: int64_t = 10; + let f: float = 3.5; + let d: double = 5.2; + + // Mixed type operations + let mix1: float = i + f; // 10 + 3.5 = 13.5 + printf("%f\n", mix1); + + let mix2: double = d + i; // 5.2 + 10 = 15.2 + printf("%f\n", mix2); + + let mix3: float = f * 2; // 3.5 * 2 = 7.0 + printf("%f\n", mix3); + + // Mixed type comparisons + let cmp1: boolean = i > f; // 10 > 3.5 = true + if (cmp1) { + printf("1\n"); + } + + let cmp2: boolean = f < d; // 3.5 < 5.2 = true + if (cmp2) { + printf("1\n"); + } +} diff --git a/tests/runtime/strings/basic.zz b/tests/runtime/strings/basic.zz new file mode 100644 index 0000000..81e2aca --- /dev/null +++ b/tests/runtime/strings/basic.zz @@ -0,0 +1,16 @@ +// Test string operations and types +extern fn printf(fmt: string, ...) -> int32_t; + +fn print_string_type(s: string) -> none { + printf(s); +} + +fn main() { + let s1: string = "Hello"; + let s2: string = "World"; + + printf(s1); + printf("\n"); + printf(s2); + printf("\n"); +} diff --git a/tests/runtime/types/all_types.zz b/tests/runtime/types/all_types.zz new file mode 100644 index 0000000..a6e1bc0 --- /dev/null +++ b/tests/runtime/types/all_types.zz @@ -0,0 +1,23 @@ +// Test all basic type declarations +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let i8: int8_t = -100; + let i16: int16_t = -1000; + let i32: int32_t = -100000; + let i64: int64_t = -9000000; + + let u8: uint8_t = 255; + let u16: uint16_t = 65535; + let u32: uint32_t = 4000000; + let u64: uint64_t = 8000000; + + let f: float = 1.5; + let d: double = 2.5; + + let b: boolean = true; + + printf("%d\n", i64); + printf("%d\n", u64); + printf("%f\n", d); +} diff --git a/tests/runtime/types/boundaries.zz b/tests/runtime/types/boundaries.zz new file mode 100644 index 0000000..1590eb6 --- /dev/null +++ b/tests/runtime/types/boundaries.zz @@ -0,0 +1,30 @@ +// Test type boundaries and edge cases +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + // Test boundary values + let max_u8: uint8_t = 255; + let min_u8: uint8_t = 0; + + printf("%d\n", max_u8); + printf("%d\n", min_u8); + + // Test zero handling + let zero: int64_t = 0; + let result: int64_t = zero + 100; + printf("%d\n", result); + + // Test negative numbers + let neg: int64_t = -42; + printf("%d\n", neg); + + let pos: int64_t = 42; + printf("%d\n", pos); + + // Test mixed signs + let sum: int64_t = pos + neg; // 42 + (-42) = 0 + printf("%d\n", sum); + + let diff: int64_t = neg - pos; // -42 - 42 = -84 + printf("%d\n", diff); +} diff --git a/tests/runtime/variables/sequential_assign.zz b/tests/runtime/variables/sequential_assign.zz new file mode 100644 index 0000000..8675a69 --- /dev/null +++ b/tests/runtime/variables/sequential_assign.zz @@ -0,0 +1,30 @@ +// Test multiple sequential assignments +extern fn printf(fmt: string, ...) -> int32_t; + +fn main() { + let x: int64_t = 0; + let y: int64_t = 0; + let z: int64_t = 0; + + printf("%d\n", x); + printf("%d\n", y); + printf("%d\n", z); + + x = 10; + y = 20; + z = 30; + + printf("%d\n", x); + printf("%d\n", y); + printf("%d\n", z); + + // Reassignments + x = y + z; + printf("%d\n", x); + + y = x - 10; + printf("%d\n", y); + + z = x * y; + printf("%d\n", z); +} diff --git a/tests/runtime/variables/shadowing.zz b/tests/runtime/variables/shadowing.zz new file mode 100644 index 0000000..7be48ef --- /dev/null +++ b/tests/runtime/variables/shadowing.zz @@ -0,0 +1,29 @@ +// Test variable shadowing and scope +extern fn printf(fmt: string, ...) -> int32_t; + +let global_x: int64_t = 100; + +fn test_scope() -> int64_t { + let global_x: int64_t = 50; // Shadows global + return global_x; +} + +fn main() { + printf("%d\n", global_x); // 100 + + let result: int64_t = test_scope(); + printf("%d\n", result); // 50 + + printf("%d\n", global_x); // Still 100 + + // Local shadowing + let local_var: int64_t = 10; + printf("%d\n", local_var); + + if (local_var > 5) { + let local_var: int64_t = 20; // Shadow in block + printf("%d\n", local_var); // 20 + } + + printf("%d\n", local_var); // Still 10 +}