From 5f4335dbcc42c285434f3c10e4aaad7625ee42a4 Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Wed, 31 Dec 2025 14:12:19 -0700 Subject: [PATCH] Added another complex stlg test file --- .../libs/integration_tests/src/lib.rs | 7 ++ ...tion_tests__tests__reagent_processing.snap | 112 ++++++++++++++++++ .../src/test_files/reagent_processing.stlg | 49 ++++++++ 3 files changed, 168 insertions(+) create mode 100644 rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__reagent_processing.snap create mode 100644 rust_compiler/libs/integration_tests/src/test_files/reagent_processing.stlg diff --git a/rust_compiler/libs/integration_tests/src/lib.rs b/rust_compiler/libs/integration_tests/src/lib.rs index 5d818ff..7295e46 100644 --- a/rust_compiler/libs/integration_tests/src/lib.rs +++ b/rust_compiler/libs/integration_tests/src/lib.rs @@ -212,4 +212,11 @@ mod tests { let output = compile_with_and_without_optimization(source); insta::assert_snapshot!(output); } + + #[test] + fn test_reagent_processing() { + let source = include_str!("./test_files/reagent_processing.stlg"); + let output = compile_with_and_without_optimization(source); + insta::assert_snapshot!(output); + } } 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__tests__reagent_processing.snap new file mode 100644 index 0000000..2fc77ae --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/snapshots/integration_tests__tests__reagent_processing.snap @@ -0,0 +1,112 @@ +--- +source: libs/integration_tests/src/lib.rs +assertion_line: 220 +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 r9 +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 r9 +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/test_files/reagent_processing.stlg b/rust_compiler/libs/integration_tests/src/test_files/reagent_processing.stlg new file mode 100644 index 0000000..dfe7a7f --- /dev/null +++ b/rust_compiler/libs/integration_tests/src/test_files/reagent_processing.stlg @@ -0,0 +1,49 @@ +device combustion = "d0"; +device furnace = "d1"; +device vent = "d2"; +device gasSensor = "d3"; +device self = "db"; + +const MAX_WAIT_ITER = 2; +const STACK_SIZE = 100; + +vent.Mode = 1; // Vent inward into pipes +vent.On = false; +let ejecting = false; +let combustionWaitIter = 0; + +loop { + yield(); + + let reagentCount = combustion.Reagents; + + if (reagentCount >= STACK_SIZE || combustionWaitIter >= MAX_WAIT_ITER) { + ejecting = true; + } + + combustionWaitIter = (reagentCount < STACK_SIZE && !ls(combustion, 0, "Occupied")) + ? combustionWaitIter + 1 + : 0; + + if (ejecting && combustion.Rpm < 1) { + combustion.Open = true; + ejecting = !(reagentCount == 0 && ls(combustion, 0, "Occupied")); + } + + combustion.On = !ejecting; + + let furnaceAmt = ls(furnace, 0, "Quantity"); + + if (gasSensor.Pressure > 200) { + // safety: don't turn this on if we have gas still to process + // This should prevent pipes from blowing. This will NOT hault + // The in-progress burn job, but it'll prevent new jobs from + // blowing the walls or pipes. + continue; + } + + furnace.On = furnaceAmt > 0; + furnace.Activate = furnaceAmt > 0; + vent.On = gasSensor.Pressure > 0 || furnace.Activate; + self.Setting = furnace.Activate; +} \ No newline at end of file