Added another complex stlg test file
This commit is contained in:
@@ -212,4 +212,11 @@ mod tests {
|
|||||||
let output = compile_with_and_without_optimization(source);
|
let output = compile_with_and_without_optimization(source);
|
||||||
insta::assert_snapshot!(output);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user