From 448b71dab16cc2f67ddea7fdf26adb46b1fce7d9 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Sun, 19 Jan 2025 00:40:46 -0600 Subject: [PATCH] add stack depth --- src/Instructions/ExecInstructions.hs | 3 +++ src/Instructions/FloatInstructions.hs | 3 +++ src/Instructions/GenericInstructions.hs | 3 +++ src/Instructions/IntInstructions.hs | 3 +++ 4 files changed, 12 insertions(+) diff --git a/src/Instructions/ExecInstructions.hs b/src/Instructions/ExecInstructions.hs index cb28fb2..5c5888d 100644 --- a/src/Instructions/ExecInstructions.hs +++ b/src/Instructions/ExecInstructions.hs @@ -32,6 +32,9 @@ instructionExecFlush state = instructionFlush state exec instructionExecEq :: State -> State instructionExecEq state = instructionEq state exec +instructionExecStackDepth :: State -> State +instructionExecStackDepth state = instructionStackDepth state exec + instructionExecDoRange :: State -> State instructionExecDoRange state@(State {_exec = (e1 : es), _int = (i0 : i1 : is)}) = if increment i0 i1 /= 0 diff --git a/src/Instructions/FloatInstructions.hs b/src/Instructions/FloatInstructions.hs index fc05e0f..9064ce2 100644 --- a/src/Instructions/FloatInstructions.hs +++ b/src/Instructions/FloatInstructions.hs @@ -71,3 +71,6 @@ instructionFloatFlush state = instructionFlush state float instructionFloatEq :: State -> State instructionFloatEq state = instructionEq state float + +instructionFloatStackDepth :: State -> State +instructionFloatStackDepth state = instructionStackDepth state float diff --git a/src/Instructions/GenericInstructions.hs b/src/Instructions/GenericInstructions.hs index a1ff7ba..df956d2 100644 --- a/src/Instructions/GenericInstructions.hs +++ b/src/Instructions/GenericInstructions.hs @@ -63,3 +63,6 @@ instructionEq state accessor = where stackTop :: [a] stackTop = take 2 $ view accessor state + +instructionStackDepth :: State -> Lens' State [a] -> State +instructionStackDepth state accessor = state & int .~ (length (view accessor state) : view int state) diff --git a/src/Instructions/IntInstructions.hs b/src/Instructions/IntInstructions.hs index 87d9112..ae58588 100644 --- a/src/Instructions/IntInstructions.hs +++ b/src/Instructions/IntInstructions.hs @@ -76,3 +76,6 @@ instructionIntFlush state = instructionFlush state int instructionIntEq :: State -> State instructionIntEq state = instructionEq state int + +instructionIntStackDepth :: State -> State +instructionIntStackDepth state = instructionStackDepth state int