diff --git a/rust_compiler/libs/integration_tests/src/bitwise_tests.rs b/rust_compiler/libs/integration_tests/src/bitwise_tests.rs new file mode 100644 index 0000000..be08802 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/bitwise_tests.rs @@ -0,0 +1,77 @@ +#[cfg(test)] +mod bitwise_tests { + use crate::common::compile_with_and_without_optimization; + use indoc::indoc; + + #[test] + fn test_bitwise_operations() { + let source = indoc! {" + let a = 5; + let b = 3; + let and_result = a & b; + let or_result = a | b; + let xor_result = a ^ b; + let not_result = ~a; + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_bitwise_shifts() { + let source = indoc! {" + let x = 8; + let left_shift = x << 2; + let arithmetic_shift = x >> 1; + let logical_shift = x >>> 1; + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_bitwise_constant_folding() { + let source = indoc! {" + let packed = (1 << 16) & (255 << 8) & 2; + let mask = 0xFF & 0x0F; + let combined = (15 | 4096); + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_bitwise_with_variables() { + let source = indoc! {" + fn pack_bits(high, low) { + let packed = (high << 8) | low; + return packed; + } + fn extract_bits(value) { + let high = (value >> 8) & 0xFF; + let low = value & 0xFF; + return (high, low); + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_complex_bit_manipulation() { + let source = indoc! {" + fn encode_flags(enabled, mode, priority) { + let flag_byte = (enabled << 7) | (mode << 4) | priority; + return flag_byte; + } + fn decode_flags(byte) { + let enabled = (byte >> 7) & 1; + let mode = (byte >> 4) & 0x7; + let priority = byte & 0xF; + return (enabled, mode, priority); + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } +} diff --git a/rust_compiler/libs/integration_tests/src/common.rs b/rust_compiler/libs/integration_tests/src/common.rs new file mode 100644 index 0000000..9998892 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/common.rs @@ -0,0 +1,46 @@ +use compiler::Compiler; +use parser::Parser; +use tokenizer::Tokenizer; + +/// Compile Slang source code and return both unoptimized and optimized output +pub fn compile_with_and_without_optimization(source: &str) -> String { + // Compile for unoptimized output + let tokenizer = Tokenizer::from(source); + let parser = Parser::new(tokenizer); + let compiler = Compiler::new(parser, None); + let result = compiler.compile(); + + // Get unoptimized output + let mut unoptimized_writer = std::io::BufWriter::new(Vec::new()); + result + .instructions + .write(&mut unoptimized_writer) + .expect("Failed to write unoptimized output"); + let unoptimized_bytes = unoptimized_writer + .into_inner() + .expect("Failed to get bytes"); + let unoptimized = String::from_utf8(unoptimized_bytes).expect("Invalid UTF-8"); + + // Compile again for optimized output + let tokenizer2 = Tokenizer::from(source); + let parser2 = Parser::new(tokenizer2); + let compiler2 = Compiler::new(parser2, None); + let result2 = compiler2.compile(); + + // Apply optimizations + let optimized_instructions = optimizer::optimize(result2.instructions); + + // Get optimized output + let mut optimized_writer = std::io::BufWriter::new(Vec::new()); + optimized_instructions + .write(&mut optimized_writer) + .expect("Failed to write optimized output"); + let optimized_bytes = optimized_writer.into_inner().expect("Failed to get bytes"); + let optimized = String::from_utf8(optimized_bytes).expect("Invalid UTF-8"); + + // Combine both outputs with clear separators + format!( + "## Unoptimized Output\n\n{}\n## Optimized Output\n\n{}", + unoptimized, optimized + ) +} diff --git a/rust_compiler/libs/integration_tests/src/function_tests.rs b/rust_compiler/libs/integration_tests/src/function_tests.rs new file mode 100644 index 0000000..d44d61a --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/function_tests.rs @@ -0,0 +1,48 @@ +#[cfg(test)] +mod function_tests { + use crate::common::compile_with_and_without_optimization; + use indoc::indoc; + + #[test] + fn test_simple_leaf_function() { + let source = "fn test() { let x = 10; }"; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_function_with_call() { + let source = indoc! {" + fn add(a, b) { return a + b; } + fn main() { let x = add(5, 10); } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_leaf_function_no_stack_frame() { + let source = indoc! {" + fn increment(x) { + x = x + 1; + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_nested_function_calls() { + let source = indoc! {" + fn add(a, b) { return a + b; } + fn multiply(x, y) { return x * 2; } + fn complex(a, b) { + let sum = add(a, b); + let doubled = multiply(sum, 2); + return doubled; + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } +} diff --git a/rust_compiler/libs/integration_tests/src/lib.rs b/rust_compiler/libs/integration_tests/src/lib.rs index 7295e46..5a06fd2 100644 --- a/rust_compiler/libs/integration_tests/src/lib.rs +++ b/rust_compiler/libs/integration_tests/src/lib.rs @@ -4,174 +4,20 @@ //! and optimization passes work correctly together using snapshot testing. #[cfg(test)] -mod tests { - use compiler::Compiler; +mod bitwise_tests; +#[cfg(test)] +mod common; +#[cfg(test)] +mod function_tests; +#[cfg(test)] +mod number_literal_tests; +#[cfg(test)] +mod optimization_tests; + +#[cfg(test)] +mod integration_tests { + use crate::common::compile_with_and_without_optimization; use indoc::indoc; - use parser::Parser; - use tokenizer::Tokenizer; - - /// Compile Slang source code and return both unoptimized and optimized output - fn compile_with_and_without_optimization(source: &str) -> String { - // Compile for unoptimized output - let tokenizer = Tokenizer::from(source); - let parser = Parser::new(tokenizer); - let compiler = Compiler::new(parser, None); - let result = compiler.compile(); - - // Get unoptimized output - let mut unoptimized_writer = std::io::BufWriter::new(Vec::new()); - result - .instructions - .write(&mut unoptimized_writer) - .expect("Failed to write unoptimized output"); - let unoptimized_bytes = unoptimized_writer - .into_inner() - .expect("Failed to get bytes"); - let unoptimized = String::from_utf8(unoptimized_bytes).expect("Invalid UTF-8"); - - // Compile again for optimized output - let tokenizer2 = Tokenizer::from(source); - let parser2 = Parser::new(tokenizer2); - let compiler2 = Compiler::new(parser2, None); - let result2 = compiler2.compile(); - - // Apply optimizations - let optimized_instructions = optimizer::optimize(result2.instructions); - - // Get optimized output - let mut optimized_writer = std::io::BufWriter::new(Vec::new()); - optimized_instructions - .write(&mut optimized_writer) - .expect("Failed to write optimized output"); - let optimized_bytes = optimized_writer.into_inner().expect("Failed to get bytes"); - let optimized = String::from_utf8(optimized_bytes).expect("Invalid UTF-8"); - - // Combine both outputs with clear separators - format!( - "## Unoptimized Output\n\n{}\n## Optimized Output\n\n{}", - unoptimized, optimized - ) - } - - #[test] - fn test_simple_leaf_function() { - let source = "fn test() { let x = 10; }"; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_function_with_call() { - let source = indoc! {" - fn add(a, b) { return a + b; } - fn main() { let x = add(5, 10); } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_constant_folding() { - let source = "let x = 5 + 10;"; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_algebraic_simplification() { - let source = "let x = 5; let y = x * 1;"; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_strength_reduction() { - let source = "fn double(x) { return x * 2; }"; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_dead_code_elimination() { - let source = indoc! {" - fn compute(x) { - let unused = 20; - return x + 1; - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_peephole_comparison_fusion() { - let source = indoc! {" - fn compare(x, y) { - if (x > y) { - let z = 1; - } - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_select_optimization() { - let source = indoc! {" - fn ternary(cond) { - let result = 0; - if (cond) { - result = 10; - } else { - result = 20; - } - return result; - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_leaf_function_no_stack_frame() { - let source = indoc! {" - fn increment(x) { - x = x + 1; - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_complex_arithmetic() { - let source = indoc! {" - fn compute(a, b, c) { - let x = a * 2; - let y = b + 0; - let z = c * 1; - return x + y + z; - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } - - #[test] - fn test_nested_function_calls() { - let source = indoc! {" - fn add(a, b) { return a + b; } - fn multiply(x, y) { return x * 2; } - fn complex(a, b) { - let sum = add(a, b); - let doubled = multiply(sum, 2); - return doubled; - } - "}; - let output = compile_with_and_without_optimization(source); - insta::assert_snapshot!(output); - } #[test] fn test_tuples() { diff --git a/rust_compiler/libs/integration_tests/src/number_literal_tests.rs b/rust_compiler/libs/integration_tests/src/number_literal_tests.rs new file mode 100644 index 0000000..fafeeb5 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/number_literal_tests.rs @@ -0,0 +1,29 @@ +#[cfg(test)] +mod number_literal_tests { + use crate::common::compile_with_and_without_optimization; + use indoc::indoc; + + #[test] + fn test_binary_literals() { + let source = indoc! {" + let binary = 0b1010_1100; + let octal = 0o755; + let hex_upper = 0xDEAD_BEEF; + let hex_lower = 0xcafe; + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_number_literal_optimization() { + let source = indoc! {" + let decimal = 42_000; + let negative_hex = -0xFF; + let negative_binary = -0b1111_0000; + let temp_c = 100c; + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } +} diff --git a/rust_compiler/libs/integration_tests/src/optimization_tests.rs b/rust_compiler/libs/integration_tests/src/optimization_tests.rs new file mode 100644 index 0000000..07bf416 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/optimization_tests.rs @@ -0,0 +1,82 @@ +#[cfg(test)] +mod optimization_tests { + use crate::common::compile_with_and_without_optimization; + use indoc::indoc; + + #[test] + fn test_constant_folding() { + let source = "let x = 5 + 10;"; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_algebraic_simplification() { + let source = "let x = 5; let y = x * 1;"; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_strength_reduction() { + let source = "fn double(x) { return x * 2; }"; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_dead_code_elimination() { + let source = indoc! {" + fn compute(x) { + let unused = 20; + return x + 1; + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_peephole_comparison_fusion() { + let source = indoc! {" + fn compare(x, y) { + if (x > y) { + let z = 1; + } + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_select_optimization() { + let source = indoc! {" + fn ternary(cond) { + let result = 0; + if (cond) { + result = 10; + } else { + result = 20; + } + return result; + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } + + #[test] + fn test_complex_arithmetic() { + let source = indoc! {" + fn compute(a, b, c) { + let x = a * 2; + let y = b + 0; + let z = c * 1; + return x + y + z; + } + "}; + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } +} diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_constant_folding.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_constant_folding.snap new file mode 100644 index 0000000..8abc3c4 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_constant_folding.snap @@ -0,0 +1,18 @@ +--- +source: libs/integration_tests/src/bitwise_tests.rs +assertion_line: 40 +expression: output +--- +## Unoptimized Output + +j main +main: +move r8 0 +move r9 15 +move r10 4111 + +## Optimized Output + +move r8 0 +move r9 15 +move r10 4111 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_operations.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_operations.snap new file mode 100644 index 0000000..042f486 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_operations.snap @@ -0,0 +1,29 @@ +--- +source: libs/integration_tests/src/bitwise_tests.rs +assertion_line: 17 +expression: output +--- +## Unoptimized Output + +j main +main: +move r8 5 +move r9 3 +and r1 r8 r9 +move r10 r1 +or r2 r8 r9 +move r11 r2 +xor r3 r8 r9 +move r12 r3 +not r4 r8 +move r13 r4 + +## Optimized Output + +move r8 5 +move r9 3 +and r10 r8 r9 +or r11 r8 r9 +xor r12 r8 r9 +not r4 r8 +move r13 r4 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_shifts.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_shifts.snap new file mode 100644 index 0000000..56bd8aa --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_shifts.snap @@ -0,0 +1,26 @@ +--- +source: libs/integration_tests/src/bitwise_tests.rs +assertion_line: 29 +expression: output +--- +## Unoptimized Output + +j main +main: +move r8 8 +sll r1 r8 2 +move r9 r1 +sra r2 r8 1 +move r10 r2 +srl r3 r8 1 +move r11 r3 + +## Optimized Output + +move r8 8 +sll r1 r8 2 +move r9 r1 +sra r2 r8 1 +move r10 r2 +srl r3 r8 1 +move r11 r3 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_with_variables.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_with_variables.snap new file mode 100644 index 0000000..2ffdc35 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__bitwise_with_variables.snap @@ -0,0 +1,67 @@ +--- +source: libs/integration_tests/src/bitwise_tests.rs +assertion_line: 57 +expression: output +--- +## Unoptimized Output + +j main +pack_bits: +pop r8 +pop r9 +push sp +push ra +sll r1 r9 8 +or r2 r1 r8 +move r10 r2 +move r15 r10 +j __internal_L1 +__internal_L1: +pop ra +pop sp +j ra +extract_bits: +pop r8 +push sp +push ra +sra r1 r8 8 +and r2 r1 255 +move r9 r2 +and r3 r8 255 +move r10 r3 +push r9 +push r10 +sub r0 sp 4 +get r0 db r0 +move r15 r0 +j __internal_L2 +__internal_L2: +sub r0 sp 3 +get ra db r0 +j ra + +## Optimized Output + +j main +pop r8 +pop r9 +push sp +push ra +sll r1 r9 8 +or r15 r1 r8 +pop ra +pop sp +j ra +pop r8 +push sp +push ra +sra r1 r8 8 +and r9 r1 255 +and r10 r8 255 +push r9 +push r10 +sub r0 sp 4 +get r15 db r0 +sub r0 sp 3 +get ra db r0 +j ra diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__complex_bit_manipulation.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__complex_bit_manipulation.snap new file mode 100644 index 0000000..6518acd --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__bitwise_tests__bitwise_tests__complex_bit_manipulation.snap @@ -0,0 +1,80 @@ +--- +source: libs/integration_tests/src/bitwise_tests.rs +assertion_line: 75 +expression: output +--- +## Unoptimized Output + +j main +encode_flags: +pop r8 +pop r9 +pop r10 +push sp +push ra +sll r1 r10 7 +sll r2 r9 4 +or r3 r1 r2 +or r4 r3 r8 +move r11 r4 +move r15 r11 +j __internal_L1 +__internal_L1: +pop ra +pop sp +j ra +decode_flags: +pop r8 +push sp +push ra +sra r1 r8 7 +and r2 r1 1 +move r9 r2 +sra r3 r8 4 +and r4 r3 7 +move r10 r4 +and r5 r8 15 +move r11 r5 +push r9 +push r10 +push r11 +sub r0 sp 5 +get r0 db r0 +move r15 r0 +j __internal_L2 +__internal_L2: +sub r0 sp 4 +get ra db r0 +j ra + +## Optimized Output + +j main +pop r8 +pop r9 +pop r10 +push sp +push ra +sll r1 r10 7 +sll r2 r9 4 +or r3 r1 r2 +or r15 r3 r8 +pop ra +pop sp +j ra +pop r8 +push sp +push ra +sra r1 r8 7 +and r9 r1 1 +sra r3 r8 4 +and r10 r3 7 +and r11 r8 15 +push r9 +push r10 +push r11 +sub r0 sp 5 +get r15 db r0 +sub r0 sp 4 +get ra db r0 +j ra diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__function_with_call.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__function_with_call.snap similarity index 85% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__function_with_call.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__function_with_call.snap index 264b371..c0c0c7e 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__function_with_call.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__function_with_call.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 70 +source: libs/integration_tests/src/function_tests.rs +assertion_line: 20 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__leaf_function_no_stack_frame.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__leaf_function_no_stack_frame.snap similarity index 77% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__leaf_function_no_stack_frame.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__leaf_function_no_stack_frame.snap index 3362dcd..bfe66cd 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__leaf_function_no_stack_frame.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__leaf_function_no_stack_frame.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 144 +source: libs/integration_tests/src/function_tests.rs +assertion_line: 31 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__nested_function_calls.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__nested_function_calls.snap similarity index 92% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__nested_function_calls.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__nested_function_calls.snap index a9fbdd7..67fa4b6 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__nested_function_calls.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__nested_function_calls.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 173 +source: libs/integration_tests/src/function_tests.rs +assertion_line: 46 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__simple_leaf_function.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__simple_leaf_function.snap similarity index 73% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__simple_leaf_function.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__simple_leaf_function.snap index f093e06..a4f5c5d 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__simple_leaf_function.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__function_tests__function_tests__simple_leaf_function.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 60 +source: libs/integration_tests/src/function_tests.rs +assertion_line: 10 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__larre_script.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__larre_script.snap new file mode 100644 index 0000000..5173db1 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__larre_script.snap @@ -0,0 +1,224 @@ +--- +source: libs/integration_tests/src/lib.rs +assertion_line: 54 +expression: output +--- +## Unoptimized Output + +j main +waitForIdle: +push sp +push ra +yield +__internal_L2: +l r1 d0 Idle +seq r2 r1 0 +beqz r2 __internal_L3 +yield +j __internal_L2 +__internal_L3: +__internal_L1: +pop ra +pop sp +j ra +deposit: +push sp +push ra +s d0 Setting 1 +jal waitForIdle +move r1 r15 +s d0 Activate 1 +jal waitForIdle +move r2 r15 +s d1 Open 0 +__internal_L4: +pop ra +pop sp +j ra +checkAndHarvest: +pop r8 +push sp +push ra +sle r1 r8 1 +ls r15 d0 255 Seeding +slt r2 r15 1 +or r3 r1 r2 +beqz r3 __internal_L6 +j __internal_L5 +__internal_L6: +__internal_L7: +ls r15 d0 255 Mature +beqz r15 __internal_L8 +yield +s d0 Activate 1 +j __internal_L7 +__internal_L8: +ls r15 d0 255 Occupied +move r9 r15 +s d0 Setting 1 +push r8 +push r9 +jal waitForIdle +pop r9 +pop r8 +move r4 r15 +push r8 +push r9 +jal deposit +pop r9 +pop r8 +move r5 r15 +beqz r9 __internal_L9 +push r8 +push r9 +jal deposit +pop r9 +pop r8 +move r6 r15 +__internal_L9: +s d0 Setting r8 +push r8 +push r9 +jal waitForIdle +pop r9 +pop r8 +move r6 r15 +ls r15 d0 0 Occupied +beqz r15 __internal_L10 +s d0 Activate 1 +__internal_L10: +push r8 +push r9 +jal waitForIdle +pop r9 +pop r8 +move r7 r15 +__internal_L5: +pop ra +pop sp +j ra +main: +move r8 0 +__internal_L11: +yield +l r1 d0 Idle +seq r2 r1 0 +beqz r2 __internal_L13 +j __internal_L11 +__internal_L13: +add r3 r8 1 +sgt r4 r3 19 +add r5 r8 1 +select r6 r4 2 r5 +move r9 r6 +push r8 +push r9 +push r8 +jal checkAndHarvest +pop r9 +pop r8 +move r7 r15 +s d0 Setting r9 +move r8 r9 +j __internal_L11 +__internal_L12: + +## Optimized Output + +j 77 +push sp +push ra +yield +l r1 d0 Idle +bne r1 0 8 +yield +j 4 +pop ra +pop sp +j ra +push sp +push ra +s d0 Setting 1 +jal 1 +move r1 r15 +s d0 Activate 1 +jal 1 +move r2 r15 +s d1 Open 0 +pop ra +pop sp +j ra +pop r8 +push sp +push ra +sle r1 r8 1 +ls r15 d0 255 Seeding +slt r2 r15 1 +or r3 r1 r2 +beqz r3 32 +j 74 +ls r15 d0 255 Mature +beqz r15 37 +yield +s d0 Activate 1 +j 32 +ls r9 d0 255 Occupied +s d0 Setting 1 +push r8 +push r9 +jal 1 +pop r9 +pop r8 +move r4 r15 +push r8 +push r9 +jal 11 +pop r9 +pop r8 +move r5 r15 +beqz r9 58 +push r8 +push r9 +jal 11 +pop r9 +pop r8 +move r6 r15 +s d0 Setting r8 +push r8 +push r9 +jal 1 +pop r9 +pop r8 +move r6 r15 +ls r15 d0 0 Occupied +beqz r15 68 +s d0 Activate 1 +push r8 +push r9 +jal 1 +pop r9 +pop r8 +move r7 r15 +pop ra +pop sp +j ra +move r8 0 +yield +l r1 d0 Idle +bne r1 0 82 +j 78 +add r3 r8 1 +sgt r4 r3 19 +add r5 r8 1 +select r6 r4 2 r5 +move r9 r6 +push r8 +push r9 +push r8 +jal 23 +pop r9 +pop r8 +move r7 r15 +s d0 Setting r9 +move r8 r9 +j 78 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__reagent_processing.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__reagent_processing.snap new file mode 100644 index 0000000..ae4b277 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__reagent_processing.snap @@ -0,0 +1,112 @@ +--- +source: libs/integration_tests/src/lib.rs +assertion_line: 61 +expression: output +--- +## Unoptimized Output + +j main +main: +s d2 Mode 1 +s d2 On 0 +move r8 0 +move r9 0 +__internal_L1: +yield +l r1 d0 Reagents +move r10 r1 +sge r2 r10 100 +sge r3 r9 2 +or r4 r2 r3 +beqz r4 __internal_L3 +move r8 1 +__internal_L3: +slt r5 r10 100 +ls r15 d0 0 Occupied +seq r6 r15 0 +and r7 r5 r6 +add r1 r9 1 +select r2 r7 r1 0 +move r9 r2 +l r3 d0 Rpm +slt r4 r3 1 +and r5 r8 r4 +beqz r5 __internal_L4 +s d0 Open 1 +seq r6 r10 0 +ls r15 d0 0 Occupied +and r7 r6 r15 +seq r1 r7 0 +move r8 r1 +__internal_L4: +seq r6 r8 0 +s d0 On r6 +ls r15 d1 0 Quantity +move r11 r15 +l r7 d3 Pressure +sgt r1 r7 200 +beqz r1 __internal_L5 +j __internal_L1 +__internal_L5: +sgt r2 r11 0 +s d1 On r2 +sgt r3 r11 0 +s d1 Activate r3 +l r4 d3 Pressure +sgt r5 r4 0 +l r6 d1 Activate +or r7 r5 r6 +s d2 On r7 +l r1 d1 Activate +s db Setting r1 +j __internal_L1 +__internal_L2: + +## Optimized Output + +s d2 Mode 1 +s d2 On 0 +move r8 0 +move r9 0 +yield +l r10 d0 Reagents +sge r2 r10 100 +sge r3 r9 2 +or r4 r2 r3 +beqz r4 11 +move r8 1 +slt r5 r10 100 +ls r15 d0 0 Occupied +seq r6 r15 0 +and r7 r5 r6 +add r1 r9 1 +select r2 r7 r1 0 +move r9 r2 +l r3 d0 Rpm +slt r4 r3 1 +and r5 r8 r4 +beqz r5 27 +s d0 Open 1 +seq r6 r10 0 +ls r15 d0 0 Occupied +and r7 r6 r15 +seq r8 r7 0 +seq r6 r8 0 +s d0 On r6 +ls r15 d1 0 Quantity +move r11 r15 +l r7 d3 Pressure +ble r7 200 34 +j 4 +sgt r2 r11 0 +s d1 On r2 +sgt r3 r11 0 +s d1 Activate r3 +l r4 d3 Pressure +sgt r5 r4 0 +l r6 d1 Activate +or r7 r5 r6 +s d2 On r7 +l r1 d1 Activate +s db Setting r1 +j 4 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__larre_script.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_larre_script.snap similarity index 100% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__larre_script.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_larre_script.snap diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__reagent_processing.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_reagent_processing.snap similarity index 100% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__reagent_processing.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_reagent_processing.snap diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__tuples.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_tuples.snap similarity index 100% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__tuples.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__test_tuples.snap diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__tuples.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__tuples.snap new file mode 100644 index 0000000..da3c808 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__integration_tests__tuples.snap @@ -0,0 +1,93 @@ +--- +source: libs/integration_tests/src/lib.rs +assertion_line: 47 +expression: output +--- +## Unoptimized Output + +j main +getSomethingElse: +pop r8 +push sp +push ra +add r1 r8 1 +move r15 r1 +j __internal_L1 +__internal_L1: +pop ra +pop sp +j ra +getSensorData: +push sp +push ra +l r1 d0 Vertical +push r1 +l r2 d0 Horizontal +push r2 +push 3 +jal getSomethingElse +move r3 r15 +push r3 +sub r0 sp 5 +get r0 db r0 +move r15 r0 +j __internal_L2 +__internal_L2: +sub r0 sp 4 +get ra db r0 +j ra +main: +__internal_L3: +yield +jal getSensorData +pop r0 +pop r9 +pop r8 +move sp r15 +jal getSensorData +pop r0 +pop r0 +pop r9 +move sp r15 +s db Setting r9 +j __internal_L3 +__internal_L4: + +## Optimized Output + +j 23 +pop r8 +push sp +push ra +add r15 r8 1 +pop ra +pop sp +j ra +push sp +push ra +l r1 d0 Vertical +push r1 +l r2 d0 Horizontal +push r2 +push 3 +jal 1 +move r3 r15 +push r3 +sub r0 sp 5 +get r15 db r0 +sub r0 sp 4 +get ra db r0 +j ra +yield +jal 8 +pop r0 +pop r9 +pop r8 +move sp r15 +jal 8 +pop r0 +pop r0 +pop r9 +move sp r15 +s db Setting r9 +j 23 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__binary_literals.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__binary_literals.snap new file mode 100644 index 0000000..4fe37e5 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__binary_literals.snap @@ -0,0 +1,20 @@ +--- +source: libs/integration_tests/src/number_literal_tests.rs +assertion_line: 15 +expression: output +--- +## Unoptimized Output + +j main +main: +move r8 172 +move r9 493 +move r10 3735928559 +move r11 51966 + +## Optimized Output + +move r8 172 +move r9 493 +move r10 3735928559 +move r11 51966 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__number_literal_optimization.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__number_literal_optimization.snap new file mode 100644 index 0000000..aae49e6 --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__number_literal_tests__number_literal_tests__number_literal_optimization.snap @@ -0,0 +1,20 @@ +--- +source: libs/integration_tests/src/number_literal_tests.rs +assertion_line: 27 +expression: output +--- +## Unoptimized Output + +j main +main: +move r8 42000 +move r9 -255 +move r10 -240 +move r11 373.15 + +## Optimized Output + +move r8 42000 +move r9 -255 +move r10 -240 +move r11 373.15 diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__algebraic_simplification.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__algebraic_simplification.snap similarity index 66% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__algebraic_simplification.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__algebraic_simplification.snap index ce3aa70..1772850 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__algebraic_simplification.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__algebraic_simplification.snap @@ -1,5 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 17 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__complex_arithmetic.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__complex_arithmetic.snap similarity index 84% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__complex_arithmetic.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__complex_arithmetic.snap index f18794c..981241e 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__complex_arithmetic.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__complex_arithmetic.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 158 +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 80 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__constant_folding.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__constant_folding.snap similarity index 58% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__constant_folding.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__constant_folding.snap index 075159a..0963bc5 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__constant_folding.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__constant_folding.snap @@ -1,5 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 10 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__dead_code_elimination.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__dead_code_elimination.snap similarity index 77% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__dead_code_elimination.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__dead_code_elimination.snap index 9404104..da82825 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__dead_code_elimination.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__dead_code_elimination.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 103 +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 36 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__peephole_comparison_fusion.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__peephole_comparison_fusion.snap similarity index 79% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__peephole_comparison_fusion.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__peephole_comparison_fusion.snap index 880034c..aa3675d 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__peephole_comparison_fusion.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__peephole_comparison_fusion.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 116 +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 49 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__select_optimization.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__select_optimization.snap similarity index 81% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__select_optimization.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__select_optimization.snap index 20172da..069229f 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__select_optimization.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__select_optimization.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 133 +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 66 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__strength_reduction.snap b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__strength_reduction.snap similarity index 76% rename from rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__strength_reduction.snap rename to rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__strength_reduction.snap index a2615e0..85b3443 100644 --- a/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__strength_reduction.snap +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__optimization_tests__optimization_tests__strength_reduction.snap @@ -1,6 +1,6 @@ --- -source: libs/integration_tests/src/lib.rs -assertion_line: 91 +source: libs/integration_tests/src/optimization_tests.rs +assertion_line: 24 expression: output --- ## Unoptimized Output diff --git a/rust_compiler/libs/tokenizer/src/token.rs b/rust_compiler/libs/tokenizer/src/token.rs index df07d78..e81c5d7 100644 --- a/rust_compiler/libs/tokenizer/src/token.rs +++ b/rust_compiler/libs/tokenizer/src/token.rs @@ -789,7 +789,7 @@ documented! { /// } /// ``` Continue, - /// Prepresents the `const` keyword. This allows you to define a variable that will never + /// Represents the `const` keyword. This allows you to define a variable that will never /// change throughout the lifetime of the program, similar to `define` in IC10. If you are /// not planning on mutating the variable (changing it), it is recommend you store it as a /// const, as the compiler will not assign it to a register or stack variable. @@ -931,7 +931,10 @@ mod tests { let tokens = lexer.collect::>(); - assert!(!tokens.iter().any(|res| res.is_err())); + assert!( + !tokens.iter().any(|res| res.is_err()), + "Expected no lexing errors for CRLF endings" + ); Ok(()) }