From de8fedb5d1b3fea1838c8cd856c154a7471a1391 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Fri, 24 Jan 2025 01:38:54 -0600 Subject: [PATCH] more instructions --- src/Instructions/GenericInstructions.hs | 15 +++++++++++++++ src/Instructions/StringInstructions.hs | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/Instructions/StringInstructions.hs diff --git a/src/Instructions/GenericInstructions.hs b/src/Instructions/GenericInstructions.hs index 835f510..308d261 100644 --- a/src/Instructions/GenericInstructions.hs +++ b/src/Instructions/GenericInstructions.hs @@ -108,3 +108,18 @@ instructionShoveDup state@(State {_int = []}) _ = state -- also also not int generic instructionShove :: State -> Lens' State [a] -> State instructionShove state accessor = instructionShoveDup state accessor & accessor .~ drop 1 (view accessor (instructionShoveDup state accessor)) + +-- not char generic +instructionConcat :: Semigroup a => State -> Lens' State [a] -> State +instructionConcat state accessor = + if (length . take 2 $ view accessor state) == 2 + then droppedState & accessor .~ (head (view accessor state) <> view accessor state !! 1) : view accessor droppedState + -- then undefined + else state + where + droppedState :: State + droppedState = state & accessor .~ drop 2 (view accessor state) + +-- evolve fodder??????????? +instructionNoOp :: State -> State +instructionNoOp state = state diff --git a/src/Instructions/StringInstructions.hs b/src/Instructions/StringInstructions.hs new file mode 100644 index 0000000..fd7e5e9 --- /dev/null +++ b/src/Instructions/StringInstructions.hs @@ -0,0 +1,17 @@ +module Instructions.StringInstructions where + +import State +import Instructions.GenericInstructions + +combineString :: String -> (String, String) -> String +combineString toInsert (front, back) = front <> toInsert <> back + +instructionStringConcat :: State -> State +instructionStringConcat state = instructionConcat state string + +instructionStringSwap :: State -> State +instructionStringSwap state = instructionSwap state string + +instructionStringInsertString :: State -> State +instructionStringInsertString state@(State{_string = s1 : s2 : ss, _int = i1 : is}) = state {_string = combineString s2 (splitAt i1 s1) : ss, _int = is} +instructionStringInsertString state = state