From cef9c92b56fe896ce1af462b3803f5264df127ca Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Wed, 29 Jan 2025 16:35:05 -0600 Subject: [PATCH] more instructions, gonna rework the unit testing framework --- HushGP.cabal | 3 + src/Instructions/GenericInstructions.hs | 3 +- src/Instructions/VectorCharInstructions.hs | 67 +++++++++++++++++++ src/Instructions/VectorFloatInstructions.hs | 7 +- src/Instructions/VectorLogicalInstructions.hs | 67 +++++++++++++++++++ src/Instructions/VectorStringInstructions.hs | 67 +++++++++++++++++++ 6 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 src/Instructions/VectorCharInstructions.hs create mode 100644 src/Instructions/VectorLogicalInstructions.hs create mode 100644 src/Instructions/VectorStringInstructions.hs diff --git a/HushGP.cabal b/HushGP.cabal index 06f47f4..7e224d7 100644 --- a/HushGP.cabal +++ b/HushGP.cabal @@ -49,6 +49,9 @@ library , Instructions.CharInstructions , Instructions.VectorIntInstructions , Instructions.VectorFloatInstructions + , Instructions.VectorStringInstructions + , Instructions.VectorLogicalInstructions + , Instructions.VectorCharInstructions -- Modules included in this library but not exported. -- other-modules: diff --git a/src/Instructions/GenericInstructions.hs b/src/Instructions/GenericInstructions.hs index 7f0e850..89bcd4d 100644 --- a/src/Instructions/GenericInstructions.hs +++ b/src/Instructions/GenericInstructions.hs @@ -143,7 +143,6 @@ instructionEq state accessor = stackTop = take 2 $ view accessor state instructionStackDepth :: State -> Lens' State [a] -> State --- instructionStackDepth state accessor = state & int .~ (length (view accessor state) : view int state) instructionStackDepth state@(State {_int = is}) accessor = state{_int = length (view accessor state) : is} -- Will have a non-generic definition for the int stack @@ -152,7 +151,7 @@ instructionYankDup state@(State {_int = i : is}) accessor = if notEmptyStack state accessor then (state & accessor .~ (view accessor state !! max 0 (min i (length (view accessor state) - 1))) : view accessor state) {_int = is} else state -instructionYankDup state@(State {_int = []}) _ = state +instructionYankDup state _ = state -- Is this optimal? Running instrucitonYankDup twice????? -- int non generic too diff --git a/src/Instructions/VectorCharInstructions.hs b/src/Instructions/VectorCharInstructions.hs new file mode 100644 index 0000000..e0c6fd1 --- /dev/null +++ b/src/Instructions/VectorCharInstructions.hs @@ -0,0 +1,67 @@ +module Instructions.VectorCharInstructions where + +import State +import Instructions.GenericInstructions + +instructionVectorCharConcat :: State -> State +instructionVectorCharConcat state = instructionConcat state vectorChar + +instructionVectorCharConj :: State -> State +instructionVectorCharConj state = instructionConj state char vectorChar + +instructionVectorCharTakeN :: State -> State +instructionVectorCharTakeN state = instructionTakeN state vectorChar + +instructionVectorCharSubVector :: State -> State +instructionVectorCharSubVector state = instructionSubVector state vectorChar + +instructionVectorCharFirst :: State -> State +instructionVectorCharFirst state = instructionVectorFirst state char vectorChar + +instructionVectorCharLast :: State -> State +instructionVectorCharLast state = instructionVectorLast state char vectorChar + +instructionVectorCharNth :: State -> State +instructionVectorCharNth state = instructionVectorNth state char vectorChar + +instructionVectorCharRest :: State -> State +instructionVectorCharRest state = instructionRest state vectorChar + +instructionVectorCharButLast :: State -> State +instructionVectorCharButLast state = instructionButLast state vectorChar + +instructionVectorCharLength :: State -> State +instructionVectorCharLength state = instructionLength state vectorChar + +instructionVectorCharReverse :: State -> State +instructionVectorCharReverse state = instructionReverse state vectorChar + +instructionVectorCharPushAll :: State -> State +instructionVectorCharPushAll state = instructionPushAll state char vectorChar + +instructionVectorCharMakeEmpty :: State -> State +instructionVectorCharMakeEmpty state = instructionVectorMakeEmpty state vectorChar + +instructionVectorCharIsEmpty :: State -> State +instructionVectorCharIsEmpty state = instructionVectorIsEmpty state vectorChar + +instructionVectorCharIndexOf :: State -> State +instructionVectorCharIndexOf state = instructionVectorIndexOf state char vectorChar + +instructionVectorCharOccurrencesOf :: State -> State +instructionVectorCharOccurrencesOf state = instructionVectorOccurrencesOf state char vectorChar + +instructionVectorCharSetNth :: State -> State +instructionVectorCharSetNth state = instructionVectorSetNth state char vectorChar + +instructionVectorCharReplace :: State -> State +instructionVectorCharReplace state = instructionVectorReplace state char vectorChar + +instructionVectorCharReplaceFirst :: State -> State +instructionVectorCharReplaceFirst state = instructionVectorReplaceFirst state char vectorChar + +instructionVectorCharRemove :: State -> State +instructionVectorCharRemove state = instructionVectorRemove state char vectorChar + +instructionVectorCharIterate :: State -> State +instructionVectorCharIterate state = instructionVectorIterate state char vectorChar GeneVectorChar instructionVectorCharIterate diff --git a/src/Instructions/VectorFloatInstructions.hs b/src/Instructions/VectorFloatInstructions.hs index 56472be..0006903 100644 --- a/src/Instructions/VectorFloatInstructions.hs +++ b/src/Instructions/VectorFloatInstructions.hs @@ -10,10 +10,10 @@ instructionVectorFloatConj :: State -> State instructionVectorFloatConj state = instructionConj state float vectorFloat instructionVectorFloatTakeN :: State -> State -instructionVectorFloatTakeN state = instructionTakeN state vectorInt +instructionVectorFloatTakeN state = instructionTakeN state vectorFloat instructionVectorFloatSubVector :: State -> State -instructionVectorFloatSubVector state = instructionSubVector state vectorInt +instructionVectorFloatSubVector state = instructionSubVector state vectorFloat instructionVectorFloatFirst :: State -> State instructionVectorFloatFirst state = instructionVectorFirst state float vectorFloat @@ -62,3 +62,6 @@ instructionVectorFloatReplaceFirst state = instructionVectorReplaceFirst state f instructionVectorFloatRemove :: State -> State instructionVectorFloatRemove state = instructionVectorRemove state float vectorFloat + +instructionVectorFloatIterate :: State -> State +instructionVectorFloatIterate state = instructionVectorIterate state float vectorFloat GeneVectorFloat instructionVectorFloatIterate diff --git a/src/Instructions/VectorLogicalInstructions.hs b/src/Instructions/VectorLogicalInstructions.hs new file mode 100644 index 0000000..e9a4a3f --- /dev/null +++ b/src/Instructions/VectorLogicalInstructions.hs @@ -0,0 +1,67 @@ +module Instructions.VectorLogicalInstructions where + +import State +import Instructions.GenericInstructions + +instructionVectorBoolConcat :: State -> State +instructionVectorBoolConcat state = instructionConcat state vectorBool + +instructionVectorBoolConj :: State -> State +instructionVectorBoolConj state = instructionConj state bool vectorBool + +instructionVectorBoolTakeN :: State -> State +instructionVectorBoolTakeN state = instructionTakeN state vectorBool + +instructionVectorBoolSubVector :: State -> State +instructionVectorBoolSubVector state = instructionSubVector state vectorBool + +instructionVectorBoolFirst :: State -> State +instructionVectorBoolFirst state = instructionVectorFirst state bool vectorBool + +instructionVectorBoolLast :: State -> State +instructionVectorBoolLast state = instructionVectorLast state bool vectorBool + +instructionVectorBoolNth :: State -> State +instructionVectorBoolNth state = instructionVectorNth state bool vectorBool + +instructionVectorBoolRest :: State -> State +instructionVectorBoolRest state = instructionRest state vectorBool + +instructionVectorBoolButLast :: State -> State +instructionVectorBoolButLast state = instructionButLast state vectorBool + +instructionVectorBoolLength :: State -> State +instructionVectorBoolLength state = instructionLength state vectorBool + +instructionVectorBoolReverse :: State -> State +instructionVectorBoolReverse state = instructionReverse state vectorBool + +instructionVectorBoolPushAll :: State -> State +instructionVectorBoolPushAll state = instructionPushAll state bool vectorBool + +instructionVectorBoolMakeEmpty :: State -> State +instructionVectorBoolMakeEmpty state = instructionVectorMakeEmpty state vectorBool + +instructionVectorBoolIsEmpty :: State -> State +instructionVectorBoolIsEmpty state = instructionVectorIsEmpty state vectorBool + +instructionVectorBoolIndexOf :: State -> State +instructionVectorBoolIndexOf state = instructionVectorIndexOf state bool vectorBool + +instructionVectorBoolOccurrencesOf :: State -> State +instructionVectorBoolOccurrencesOf state = instructionVectorOccurrencesOf state bool vectorBool + +instructionVectorBoolSetNth :: State -> State +instructionVectorBoolSetNth state = instructionVectorSetNth state bool vectorBool + +instructionVectorBoolReplace :: State -> State +instructionVectorBoolReplace state = instructionVectorReplace state bool vectorBool + +instructionVectorBoolReplaceFirst :: State -> State +instructionVectorBoolReplaceFirst state = instructionVectorReplaceFirst state bool vectorBool + +instructionVectorBoolRemove :: State -> State +instructionVectorBoolRemove state = instructionVectorRemove state bool vectorBool + +instructionVectorBoolIterate :: State -> State +instructionVectorBoolIterate state = instructionVectorIterate state bool vectorBool GeneVectorBool instructionVectorBoolIterate diff --git a/src/Instructions/VectorStringInstructions.hs b/src/Instructions/VectorStringInstructions.hs new file mode 100644 index 0000000..23ec76f --- /dev/null +++ b/src/Instructions/VectorStringInstructions.hs @@ -0,0 +1,67 @@ +module Instructions.VectorStringInstructions where + +import State +import Instructions.GenericInstructions + +instructionVectorStringConcat :: State -> State +instructionVectorStringConcat state = instructionConcat state vectorString + +instructionVectorStringConj :: State -> State +instructionVectorStringConj state = instructionConj state string vectorString + +instructionVectorStringTakeN :: State -> State +instructionVectorStringTakeN state = instructionTakeN state vectorString + +instructionVectorStringSubVector :: State -> State +instructionVectorStringSubVector state = instructionSubVector state vectorString + +instructionVectorStringFirst :: State -> State +instructionVectorStringFirst state = instructionVectorFirst state string vectorString + +instructionVectorStringLast :: State -> State +instructionVectorStringLast state = instructionVectorLast state string vectorString + +instructionVectorStringNth :: State -> State +instructionVectorStringNth state = instructionVectorNth state string vectorString + +instructionVectorStringRest :: State -> State +instructionVectorStringRest state = instructionRest state vectorString + +instructionVectorStringButLast :: State -> State +instructionVectorStringButLast state = instructionButLast state vectorString + +instructionVectorStringLength :: State -> State +instructionVectorStringLength state = instructionLength state vectorString + +instructionVectorStringReverse :: State -> State +instructionVectorStringReverse state = instructionReverse state vectorString + +instructionVectorStringPushAll :: State -> State +instructionVectorStringPushAll state = instructionPushAll state string vectorString + +instructionVectorStringMakeEmpty :: State -> State +instructionVectorStringMakeEmpty state = instructionVectorMakeEmpty state vectorString + +instructionVectorStringIsEmpty :: State -> State +instructionVectorStringIsEmpty state = instructionVectorIsEmpty state vectorString + +instructionVectorStringIndexOf :: State -> State +instructionVectorStringIndexOf state = instructionVectorIndexOf state string vectorString + +instructionVectorStringOccurrencesOf :: State -> State +instructionVectorStringOccurrencesOf state = instructionVectorOccurrencesOf state string vectorString + +instructionVectorStringSetNth :: State -> State +instructionVectorStringSetNth state = instructionVectorSetNth state string vectorString + +instructionVectorStringReplace :: State -> State +instructionVectorStringReplace state = instructionVectorReplace state string vectorString + +instructionVectorStringReplaceFirst :: State -> State +instructionVectorStringReplaceFirst state = instructionVectorReplaceFirst state string vectorString + +instructionVectorStringRemove :: State -> State +instructionVectorStringRemove state = instructionVectorRemove state string vectorString + +instructionVectorStringIterate :: State -> State +instructionVectorStringIterate state = instructionVectorIterate state string vectorString GeneVectorString instructionVectorStringIterate