diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 0cd82d6..43a17b7 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -83,7 +83,7 @@ cargo test --package compiler --lib -- test::tuple_literals::test::test_tuple_li ```bash cd rust_compiler # Compile Slang code to IC10 using current compiler changes -echo 'let x = 5;' | cargo run --bin slang -- +echo 'let x = 5;' | cargo run --bin slang # Or from file cargo run --bin slang -- input.slang -o output.ic10 # Optimize the output with -z flag diff --git a/rust_compiler/libs/compiler/src/test/tuple_literals.rs b/rust_compiler/libs/compiler/src/test/tuple_literals.rs index 79410b5..eaa75bd 100644 --- a/rust_compiler/libs/compiler/src/test/tuple_literals.rs +++ b/rust_compiler/libs/compiler/src/test/tuple_literals.rs @@ -1288,4 +1288,67 @@ mod test { Ok(()) } + + #[test] + fn test_tuple_all_forms_combined() -> anyhow::Result<()> { + // Test all three tuple forms in one test: + // 1. Tuple literal declaration: let (x, y) = (1, 2); + // 2. Tuple literal assignment: (x, y) = (3, 4); + // 3. Function return tuple: let (a, b) = func(); + let compiled = compile!( + check + r#" + fn swap(x, y) { + return (y, x); + }; + + let (a, b) = (10, 20); // Literal declaration + (a, b) = (30, 40); // Literal assignment + let (c, d) = swap(a, b); // Function return + "# + ); + + assert!( + compiled.errors.is_empty(), + "Expected no errors, got: {:?}", + compiled.errors + ); + + assert_eq!( + compiled.output, + indoc! { + " + j main + swap: + pop r8 + pop r9 + push sp + push ra + push r8 + push r9 + sub r0 sp 4 + get r0 db r0 + move r15 r0 + j __internal_L1 + __internal_L1: + sub r0 sp 3 + get ra db r0 + j ra + main: + move r8 10 + move r9 20 + move r8 30 + move r9 40 + push r8 + push r9 + jal swap + pop r11 + pop r10 + move sp r15 + " + } + ); + + Ok(()) + } }