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 0000000..3d799a1 Binary files /dev/null and b/program differ diff --git a/tests/expected/runtime/conditionals/boolean_logic.exitcode b/tests/expected/runtime/conditionals/boolean_logic.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/conditionals/boolean_logic.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/boolean_logic.stderr b/tests/expected/runtime/conditionals/boolean_logic.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/conditionals/boolean_logic.stdout b/tests/expected/runtime/conditionals/boolean_logic.stdout new file mode 100644 index 0000000..614952d --- /dev/null +++ b/tests/expected/runtime/conditionals/boolean_logic.stdout @@ -0,0 +1,10 @@ +true +false +false +true +false +true +false +true +true +true diff --git a/tests/expected/runtime/conditionals/complex_bool.exitcode b/tests/expected/runtime/conditionals/complex_bool.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/conditionals/complex_bool.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/complex_bool.stderr b/tests/expected/runtime/conditionals/complex_bool.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/conditionals/complex_bool.stdout b/tests/expected/runtime/conditionals/complex_bool.stdout new file mode 100644 index 0000000..e8183f0 --- /dev/null +++ b/tests/expected/runtime/conditionals/complex_bool.stdout @@ -0,0 +1,3 @@ +1 +1 +1 diff --git a/tests/expected/runtime/conditionals/if-elif-else.exitcode b/tests/expected/runtime/conditionals/if-elif-else.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/conditionals/if-elif-else.exitcode +++ b/tests/expected/runtime/conditionals/if-elif-else.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/if-elif.exitcode b/tests/expected/runtime/conditionals/if-elif.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/conditionals/if-elif.exitcode +++ b/tests/expected/runtime/conditionals/if-elif.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/if-else.exitcode b/tests/expected/runtime/conditionals/if-else.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/conditionals/if-else.exitcode +++ b/tests/expected/runtime/conditionals/if-else.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/if.exitcode b/tests/expected/runtime/conditionals/if.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/conditionals/if.exitcode +++ b/tests/expected/runtime/conditionals/if.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/nested.exitcode b/tests/expected/runtime/conditionals/nested.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/conditionals/nested.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/conditionals/nested.stderr b/tests/expected/runtime/conditionals/nested.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/conditionals/nested.stdout b/tests/expected/runtime/conditionals/nested.stdout new file mode 100644 index 0000000..2b89b77 --- /dev/null +++ b/tests/expected/runtime/conditionals/nested.stdout @@ -0,0 +1,2 @@ +1 +6 diff --git a/tests/expected/runtime/functions/basics.exitcode b/tests/expected/runtime/functions/basics.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/functions/basics.exitcode +++ b/tests/expected/runtime/functions/basics.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/functions/composition.exitcode b/tests/expected/runtime/functions/composition.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/functions/composition.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/functions/composition.stderr b/tests/expected/runtime/functions/composition.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/functions/composition.stdout b/tests/expected/runtime/functions/composition.stdout new file mode 100644 index 0000000..c680ff6 --- /dev/null +++ b/tests/expected/runtime/functions/composition.stdout @@ -0,0 +1,5 @@ +10 +20 +27 +15 +20 diff --git a/tests/expected/runtime/functions/recursive.exitcode b/tests/expected/runtime/functions/recursive.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/functions/recursive.exitcode +++ b/tests/expected/runtime/functions/recursive.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/functions/scopes.exitcode b/tests/expected/runtime/functions/scopes.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/functions/scopes.exitcode +++ b/tests/expected/runtime/functions/scopes.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/functions/sequences.exitcode b/tests/expected/runtime/functions/sequences.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/functions/sequences.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/functions/sequences.stderr b/tests/expected/runtime/functions/sequences.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/functions/sequences.stdout b/tests/expected/runtime/functions/sequences.stdout new file mode 100644 index 0000000..dcde798 --- /dev/null +++ b/tests/expected/runtime/functions/sequences.stdout @@ -0,0 +1,3 @@ +5 +10 +17 diff --git a/tests/expected/runtime/loops/break_continue.exitcode b/tests/expected/runtime/loops/break_continue.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/break_continue.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/break_continue.stderr b/tests/expected/runtime/loops/break_continue.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/break_continue.stdout b/tests/expected/runtime/loops/break_continue.stdout new file mode 100644 index 0000000..ee6898a --- /dev/null +++ b/tests/expected/runtime/loops/break_continue.stdout @@ -0,0 +1,2 @@ +10 +8 diff --git a/tests/expected/runtime/loops/control.exitcode b/tests/expected/runtime/loops/control.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/loops/control.exitcode +++ b/tests/expected/runtime/loops/control.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/increment_patterns.exitcode b/tests/expected/runtime/loops/increment_patterns.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/increment_patterns.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/increment_patterns.stderr b/tests/expected/runtime/loops/increment_patterns.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/increment_patterns.stdout b/tests/expected/runtime/loops/increment_patterns.stdout new file mode 100644 index 0000000..e2e8ea0 --- /dev/null +++ b/tests/expected/runtime/loops/increment_patterns.stdout @@ -0,0 +1,3 @@ +3 +4 +5 diff --git a/tests/expected/runtime/loops/increments.exitcode b/tests/expected/runtime/loops/increments.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/increments.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/increments.stderr b/tests/expected/runtime/loops/increments.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/increments.stdout b/tests/expected/runtime/loops/increments.stdout new file mode 100644 index 0000000..c91f770 --- /dev/null +++ b/tests/expected/runtime/loops/increments.stdout @@ -0,0 +1,3 @@ +5 +30 +15 diff --git a/tests/expected/runtime/loops/nested.exitcode b/tests/expected/runtime/loops/nested.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/nested.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/nested.stderr b/tests/expected/runtime/loops/nested.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/nested.stdout b/tests/expected/runtime/loops/nested.stdout new file mode 100644 index 0000000..3cf64aa --- /dev/null +++ b/tests/expected/runtime/loops/nested.stdout @@ -0,0 +1,2 @@ +15 +9 diff --git a/tests/expected/runtime/loops/nested_control.exitcode b/tests/expected/runtime/loops/nested_control.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/nested_control.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/nested_control.stderr b/tests/expected/runtime/loops/nested_control.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/nested_control.stdout b/tests/expected/runtime/loops/nested_control.stdout new file mode 100644 index 0000000..19d70eb --- /dev/null +++ b/tests/expected/runtime/loops/nested_control.stdout @@ -0,0 +1,2 @@ +3 +8 diff --git a/tests/expected/runtime/loops/sums.exitcode b/tests/expected/runtime/loops/sums.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/sums.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/sums.stderr b/tests/expected/runtime/loops/sums.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/sums.stdout b/tests/expected/runtime/loops/sums.stdout new file mode 100644 index 0000000..5294f7f --- /dev/null +++ b/tests/expected/runtime/loops/sums.stdout @@ -0,0 +1,2 @@ +15 +30 diff --git a/tests/expected/runtime/loops/with_verify.exitcode b/tests/expected/runtime/loops/with_verify.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/loops/with_verify.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/loops/with_verify.stderr b/tests/expected/runtime/loops/with_verify.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/loops/with_verify.stdout b/tests/expected/runtime/loops/with_verify.stdout new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/runtime/loops/with_verify.stdout @@ -0,0 +1 @@ +1 diff --git a/tests/expected/runtime/operations/basic_comparisons.exitcode b/tests/expected/runtime/operations/basic_comparisons.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/operations/basic_comparisons.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/basic_comparisons.stderr b/tests/expected/runtime/operations/basic_comparisons.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/operations/basic_comparisons.stdout b/tests/expected/runtime/operations/basic_comparisons.stdout new file mode 100644 index 0000000..2458bf7 --- /dev/null +++ b/tests/expected/runtime/operations/basic_comparisons.stdout @@ -0,0 +1,12 @@ +true +false +true +false +true +true +false +false +true +true +true +true diff --git a/tests/expected/runtime/operations/binary.exitcode b/tests/expected/runtime/operations/binary.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/operations/binary.exitcode +++ b/tests/expected/runtime/operations/binary.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/factorials.exitcode b/tests/expected/runtime/operations/factorials.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/operations/factorials.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/factorials.stderr b/tests/expected/runtime/operations/factorials.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/operations/factorials.stdout b/tests/expected/runtime/operations/factorials.stdout new file mode 100644 index 0000000..93d631f --- /dev/null +++ b/tests/expected/runtime/operations/factorials.stdout @@ -0,0 +1,5 @@ +1 +2 +6 +24 +120 diff --git a/tests/expected/runtime/operations/floating_point.exitcode b/tests/expected/runtime/operations/floating_point.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/operations/floating_point.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/floating_point.stderr b/tests/expected/runtime/operations/floating_point.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/operations/floating_point.stdout b/tests/expected/runtime/operations/floating_point.stdout new file mode 100644 index 0000000..544c0bb --- /dev/null +++ b/tests/expected/runtime/operations/floating_point.stdout @@ -0,0 +1,7 @@ +0.100000 +0.200000 +0.300000 +0.300000 +0.020000 +1.234568 +9.876543 diff --git a/tests/expected/runtime/operations/increment_decrement.exitcode b/tests/expected/runtime/operations/increment_decrement.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/operations/increment_decrement.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/increment_decrement.stderr b/tests/expected/runtime/operations/increment_decrement.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/operations/increment_decrement.stdout b/tests/expected/runtime/operations/increment_decrement.stdout new file mode 100644 index 0000000..dac49b4 --- /dev/null +++ b/tests/expected/runtime/operations/increment_decrement.stdout @@ -0,0 +1,6 @@ +10 +11 +12 +20 +19 +18 diff --git a/tests/expected/runtime/operations/mixed_types.exitcode b/tests/expected/runtime/operations/mixed_types.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/operations/mixed_types.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/operations/mixed_types.stderr b/tests/expected/runtime/operations/mixed_types.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/operations/mixed_types.stdout b/tests/expected/runtime/operations/mixed_types.stdout new file mode 100644 index 0000000..4114faf --- /dev/null +++ b/tests/expected/runtime/operations/mixed_types.stdout @@ -0,0 +1,4 @@ +13.500000 +15.200000 +7.000000 +1 diff --git a/tests/expected/runtime/operations/unary.exitcode b/tests/expected/runtime/operations/unary.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/operations/unary.exitcode +++ b/tests/expected/runtime/operations/unary.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/strings/basic.exitcode b/tests/expected/runtime/strings/basic.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/strings/basic.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/strings/basic.stderr b/tests/expected/runtime/strings/basic.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/strings/basic.stdout b/tests/expected/runtime/strings/basic.stdout new file mode 100644 index 0000000..f9264f7 --- /dev/null +++ b/tests/expected/runtime/strings/basic.stdout @@ -0,0 +1,2 @@ +Hello +World diff --git a/tests/expected/runtime/strings/escapes.exitcode b/tests/expected/runtime/strings/escapes.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/strings/escapes.exitcode +++ b/tests/expected/runtime/strings/escapes.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/types.exitcode b/tests/expected/runtime/types.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/types.exitcode +++ b/tests/expected/runtime/types.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/types/all_types.exitcode b/tests/expected/runtime/types/all_types.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/types/all_types.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/types/all_types.stderr b/tests/expected/runtime/types/all_types.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/types/all_types.stdout b/tests/expected/runtime/types/all_types.stdout new file mode 100644 index 0000000..948be65 --- /dev/null +++ b/tests/expected/runtime/types/all_types.stdout @@ -0,0 +1,3 @@ +-9000000 +8000000 +2.500000 diff --git a/tests/expected/runtime/types/boundaries.exitcode b/tests/expected/runtime/types/boundaries.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/types/boundaries.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/types/boundaries.stderr b/tests/expected/runtime/types/boundaries.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/types/boundaries.stdout b/tests/expected/runtime/types/boundaries.stdout new file mode 100644 index 0000000..e102384 --- /dev/null +++ b/tests/expected/runtime/types/boundaries.stdout @@ -0,0 +1,7 @@ +255 +0 +100 +-42 +42 +0 +-84 diff --git a/tests/expected/runtime/variables.exitcode b/tests/expected/runtime/variables.exitcode index 573541a..c227083 100644 --- a/tests/expected/runtime/variables.exitcode +++ b/tests/expected/runtime/variables.exitcode @@ -1 +1 @@ -0 +0 \ No newline at end of file diff --git a/tests/expected/runtime/variables.stdout b/tests/expected/runtime/variables.stdout index 89c8485..ebce988 100644 --- a/tests/expected/runtime/variables.stdout +++ b/tests/expected/runtime/variables.stdout @@ -1 +1 @@ -DO_NOT_USE_SHARED_VARIABLES_STDOUT +It is what it is \ No newline at end of file diff --git a/tests/expected/runtime/variables/sequential_assign.exitcode b/tests/expected/runtime/variables/sequential_assign.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/variables/sequential_assign.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/variables/sequential_assign.stderr b/tests/expected/runtime/variables/sequential_assign.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/variables/sequential_assign.stdout b/tests/expected/runtime/variables/sequential_assign.stdout new file mode 100644 index 0000000..d12afea --- /dev/null +++ b/tests/expected/runtime/variables/sequential_assign.stdout @@ -0,0 +1,9 @@ +0 +0 +0 +10 +20 +30 +50 +40 +2000 diff --git a/tests/expected/runtime/variables/shadowing.exitcode b/tests/expected/runtime/variables/shadowing.exitcode new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/expected/runtime/variables/shadowing.exitcode @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/expected/runtime/variables/shadowing.stderr b/tests/expected/runtime/variables/shadowing.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/expected/runtime/variables/shadowing.stdout b/tests/expected/runtime/variables/shadowing.stdout new file mode 100644 index 0000000..b661a7c --- /dev/null +++ b/tests/expected/runtime/variables/shadowing.stdout @@ -0,0 +1,6 @@ +100 +50 +100 +10 +20 +20 diff --git a/tests/runtime/conditionals/boolean_logic.zz b/tests/runtime/conditionals/boolean_logic.zz new file mode 100644 index 0000000..360a33e --- /dev/null +++ b/tests/runtime/conditionals/boolean_logic.zz @@ -0,0 +1,69 @@ +// Test boolean logical operators: &&, ||, ! +extern fn printf(fmt: string, ...) -> 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 +}