diff --git a/TODO.md b/TODO.md index d5902e5..becfb29 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ ## Push Language TODO -- [ ] Make all vector functions applicable to string functions and vice versa +- [X] Make all vector functions applicable to string functions and vice versa - [X] Implement all functions as seen in propeller - [X] Implement all functions as seen in the specification - [ ] Implement Linear Algebra functions as specified in the previous papers @@ -10,7 +10,7 @@ - [X] Disambiguate isEmpty and stackIsEmpty - [X] Rename Logical to Bool - [X] Make int yank, shove, yankdup, and shovedup generic -- [ ] Write haddock documentation for each function +- [X] Write haddock documentation for each function - [X] Refactor all functions to take state as the final parameter - [X] Standardize the pattern matching parameter names, such as c1 : cs - [ ] Write unit/quickcheck tests for all of the instructions diff --git a/src/HushGP/Instructions/VectorCharInstructions.hs b/src/HushGP/Instructions/VectorCharInstructions.hs index d5e0d29..09084a3 100644 --- a/src/HushGP/Instructions/VectorCharInstructions.hs +++ b/src/HushGP/Instructions/VectorCharInstructions.hs @@ -3,113 +3,328 @@ module HushGP.Instructions.VectorCharInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions -instructionVectorCharConcat :: State -> State -instructionVectorCharConcat = instructionVectorConcat vectorChar - -instructionVectorCharConj :: State -> State -instructionVectorCharConj = instructionVectorConj char vectorChar - -instructionVectorCharTakeN :: State -> State -instructionVectorCharTakeN = instructionVectorTakeN vectorChar - -instructionVectorCharSubVector :: State -> State -instructionVectorCharSubVector = instructionSubVector vectorChar - -instructionVectorCharFirst :: State -> State -instructionVectorCharFirst = instructionVectorFirst char vectorChar - -instructionVectorCharLast :: State -> State -instructionVectorCharLast = instructionVectorLast char vectorChar - -instructionVectorCharNth :: State -> State -instructionVectorCharNth = instructionVectorNth char vectorChar - -instructionVectorCharRest :: State -> State -instructionVectorCharRest = instructionVectorRest vectorChar - -instructionVectorCharButLast :: State -> State -instructionVectorCharButLast = instructionVectorButLast vectorChar - -instructionVectorCharLength :: State -> State -instructionVectorCharLength = instructionLength vectorChar - -instructionVectorCharReverse :: State -> State -instructionVectorCharReverse = instructionReverse vectorChar - -instructionVectorCharPushAll :: State -> State -instructionVectorCharPushAll = instructionPushAll char vectorChar - -instructionVectorCharMakeEmpty :: State -> State -instructionVectorCharMakeEmpty = instructionVectorMakeEmpty vectorChar - -instructionVectorCharIsEmpty :: State -> State -instructionVectorCharIsEmpty = instructionVectorIsEmpty vectorChar - -instructionVectorCharIndexOf :: State -> State -instructionVectorCharIndexOf = instructionVectorIndexOf char vectorChar - -instructionVectorCharOccurrencesOf :: State -> State -instructionVectorCharOccurrencesOf = instructionVectorOccurrencesOf char vectorChar - -instructionVectorCharSetNth :: State -> State -instructionVectorCharSetNth = instructionVectorSetNth char vectorChar - -instructionVectorCharReplace :: State -> State -instructionVectorCharReplace = instructionVectorReplace char vectorChar Nothing - -instructionVectorCharReplaceFirst :: State -> State -instructionVectorCharReplaceFirst = instructionVectorReplace char vectorChar (Just 1) - -instructionVectorCharRemove :: State -> State -instructionVectorCharRemove = instructionVectorRemove char vectorChar Nothing - -instructionVectorCharIterate :: State -> State -instructionVectorCharIterate = instructionVectorIterate char vectorChar GeneVectorChar instructionVectorCharIterate "instructionVectorCharIterate" - +-- |Pops the top char vector from the char vector stack. instructionVectorCharPop :: State -> State instructionVectorCharPop = instructionPop vectorChar +-- |Duplicates the top char vector from the char vector stack. instructionVectorCharDup :: State -> State instructionVectorCharDup = instructionDup vectorChar +-- |Duplicates the top char vector from the char vector stack N times +-- based on the top int from the int stack. instructionVectorCharDupN :: State -> State instructionVectorCharDupN = instructionDupN vectorChar +-- |Swaps the top two char vectors from the char vector stack. instructionVectorCharSwap :: State -> State instructionVectorCharSwap = instructionSwap vectorChar +-- |Rotates the top three char vectors from the char vector stack. instructionVectorCharRot :: State -> State instructionVectorCharRot = instructionRot vectorChar +-- |Sets the vector char stack to [] instructionVectorCharFlush :: State -> State instructionVectorCharFlush = instructionFlush vectorChar +-- |Pushes True to the bool stack if the top two char vectors from +-- the vector char stack are equal. Pushes False otherwise. instructionVectorCharEq :: State -> State instructionVectorCharEq = instructionEq vectorChar +-- |Calculates the size of the vector char stack and pushes that number +-- to the int stack. instructionVectorCharStackDepth :: State -> State instructionVectorCharStackDepth = instructionStackDepth vectorChar +-- |Moves an item from deep within the vector char stack to the top of the vector char stack based on +-- the top int from the int stack. instructionVectorCharYank :: State -> State instructionVectorCharYank = instructionYank vectorChar +-- |Copies an item from deep within the vector char stack to the top of the vector char stack based on +-- the top int from the int stack. instructionVectorCharYankDup :: State -> State instructionVectorCharYankDup = instructionYankDup vectorChar +-- |Pushes True to the bool stack if the vector char stack is empty. False if not. instructionVectorCharIsStackEmpty :: State -> State instructionVectorCharIsStackEmpty = instructionIsStackEmpty vectorChar +-- |Moves an item from the top of the vector char stack to deep within the vector char stack based on +-- the top int from the int stack. instructionVectorCharShove :: State -> State instructionVectorCharShove = instructionShove vectorChar +-- |Copies an item from the top of the vector char stack to deep within the vector char stack based on +-- the top int from the int stack. instructionVectorCharShoveDup :: State -> State instructionVectorCharShoveDup = instructionShoveDup vectorChar +-- |Duplicate the top N items from the vector char stack based on the top int from the int stack. +instructionVectorCharDupItems :: State -> State +instructionVectorCharDupItems = instructionDupItems vectorChar + +-- |Concats the top two vectors on top of the vector char stack. +instructionVectorCharConcat :: State -> State +instructionVectorCharConcat = instructionVectorConcat vectorChar + +-- |Takes the top char from the char stack and prepends it to top char vector +-- on the char vector stack. +instructionVectorCharConj :: State -> State +instructionVectorCharConj = instructionVectorConj char vectorChar + +-- |Takes the top char from the char stack and appends it to top char vector +-- on the char vector stack. +instructionVectorCharConjEnd :: State -> State +instructionVectorCharConjEnd = instructionVectorConjEnd char vectorChar + +-- |Takes the first N chars from the top of the char vector from the char vector +-- and pushes the result to the char vector stack. N is pulled from the top of +-- the int stack. +instructionVectorCharTakeN :: State -> State +instructionVectorCharTakeN = instructionVectorTakeN vectorChar + +-- |Takes the last N chars from the top of the char vector from the char vector +-- and pushes the result to the char vector stack. N is pulled from the top of +-- the int stack. +instructionVectorCharTakeRN :: State -> State +instructionVectorCharTakeRN = instructionVectorTakeRN vectorChar + +-- |Takes a sublist of the top char vector on top of the vector char stack. +-- The two ints to determine bounds are pulled from the top of the int stack. +instructionVectorCharSubVector :: State -> State +instructionVectorCharSubVector = instructionSubVector vectorChar + +-- |Takes the first char from the top of the vector char stack and places +-- it on the char stack. +instructionVectorCharFirst :: State -> State +instructionVectorCharFirst = instructionVectorFirst char vectorChar + +-- |Takes the first char from the top of the vector char stack and places +-- it wrapped in a list on top of the vector char stack. +instructionVectorCharFromFirstPrim :: State -> State +instructionVectorCharFromFirstPrim = instructionVectorFromFirstPrim vectorChar + +-- |Takes the first char from the top of the char stack and places it +-- wrapped in a list on top of the vector char stack. +instructionVectorCharFromPrim :: State -> State +instructionVectorCharFromPrim = instructionVectorFromPrim char vectorChar + +-- |Takes the last char from the top of the vector char stack and places +-- it on the char stack. +instructionVectorCharLast :: State -> State +instructionVectorCharLast = instructionVectorLast char vectorChar + +-- |Takes the last char from the top char vector on the vector char stack and +-- places it on the char stack. +instructionVectorCharFromLastPrim :: State -> State +instructionVectorCharFromLastPrim = instructionVectorFromLastPrim vectorChar + +-- |Takes the Nth char from the top char vector and places it onto the char stack +-- based on an int from the top of the int stack. +instructionVectorCharNth :: State -> State +instructionVectorCharNth = instructionVectorNth char vectorChar + +-- |Takes the Nth char from the top char vector on the vector char stack and +-- creates a vector wrapping that Nth item, pushing it back onto the vector char stack. +-- N is the top item on the int stack. +instructionVectorCharFromNthPrim :: State -> State +instructionVectorCharFromNthPrim = instructionVectorFromNthPrim vectorChar + +-- |Removes the first char from the top char vector on the vector char stack and +-- places the result back onto the vector char stack. +instructionVectorCharRest :: State -> State +instructionVectorCharRest = instructionVectorRest vectorChar + +-- |Removes the last char from the top char vector on the vector char stack and +-- places the result back onto the vector char stack. +instructionVectorCharButLast :: State -> State +instructionVectorCharButLast = instructionVectorButLast vectorChar + +-- |Drops the first N items from the top char vector and pushes the result +-- back to the vector char stack. N is pulled from the top of the int stack. +instructionVectorCharDrop :: State -> State +instructionVectorCharDrop = instructionVectorDrop vectorChar + +-- |Drops the last N items from the top char vector and pushes the result +-- back to the vector char stack. N is pulled from the top of the int stack. +instructionVectorCharDropR :: State -> State +instructionVectorCharDropR = instructionVectorDropR vectorChar + +-- |Pushes the length of the top char vector from the vector char stack +-- to the top of the int stack. +instructionVectorCharLength :: State -> State +instructionVectorCharLength = instructionLength vectorChar + +-- |Reverses the top char vector from the vector char stack and pushes the +-- result to the vector char stack. +instructionVectorCharReverse :: State -> State +instructionVectorCharReverse = instructionReverse vectorChar + +-- |Takes the top char vector from the vector char stack and pushes the +-- individual chars to the vector char stack. +instructionVectorCharPushAll :: State -> State +instructionVectorCharPushAll = instructionPushAll char vectorChar + +-- |Makes an empty vector and pushes it to the vector char stack. +instructionVectorCharMakeEmpty :: State -> State +instructionVectorCharMakeEmpty = instructionVectorMakeEmpty vectorChar + +-- |Checks if the top char vector from the vector char stack is empty. +-- Pushes True if the char vector is empty to the bool stack. False otherwise. +instructionVectorCharIsEmpty :: State -> State +instructionVectorCharIsEmpty = instructionVectorIsEmpty vectorChar + +-- |If the top char vector from the vector char stack contains the top char from the char +-- stack, pushes True to the bool stack and pushes False otherwise. +instructionVectorCharContains :: State -> State +instructionVectorCharContains = instructionVectorContains char vectorChar + +-- |If the second to top char vector can be found within the first char vector from the +-- vector char stack, pushes True to the bool stack if is found, else False. +instructionVectorCharContainsVectorChar :: State -> State +instructionVectorCharContainsVectorChar = instructionVectorContainsVector vectorChar + +-- |Finds the first index of the top char in the char stack inside of the +-- top char vector from the vector char stack and pushes the result to the int stack. +instructionVectorCharIndexOf :: State -> State +instructionVectorCharIndexOf = instructionVectorIndexOf char vectorChar + +-- |Searches and pushes the index of the second char vector inside of the first +-- char vector to the int stack from the vector char stack. Pushes -1 if not found. +instructionVectorCharIndexOfVectorChar :: State -> State +instructionVectorCharIndexOfVectorChar = instructionVectorIndexOfVector vectorChar + +-- |Finds the amount of times the top char on the char stack occurs inside of +-- the top char vector from the vector char stack and pushes the result to the +-- int stack. +instructionVectorCharOccurrencesOf :: State -> State +instructionVectorCharOccurrencesOf = instructionVectorOccurrencesOf char vectorChar + +-- |Counts the amount of occurrences of the second char vector within the first +-- char vector. Pushes the result to the int stack. +instructionVectorCharOccurrencesOfVectorChar :: State -> State +instructionVectorCharOccurrencesOfVectorChar = instructionVectorOccurrencesOfVector vectorChar + +-- |Splits the top char vector from the vector char stack into lists of size one and pushes +-- the result back one the vector char stack. +instructionVectorCharParseToChar :: State -> State +instructionVectorCharParseToChar = instructionVectorParseToPrim vectorChar + +-- |Sets the Nth index inside of the top char vector from the vector char stack to the +-- top value from the primitive stack. N is pulled from the top of the int stack. +instructionVectorCharSetNth :: State -> State +instructionVectorCharSetNth = instructionVectorSetNth char vectorChar + +-- |Splits the char vector on top of the vector char stack with the char from the top +-- of the char stack and pushes the result to the original vector stack. +instructionVectorCharSplitOn :: State -> State +instructionVectorCharSplitOn = instructionVectorSplitOn char vectorChar + +-- |Splits the first char vector based on the second char vector from the vector +-- char stack and pushes the result to the vector char stack. +instructionVectorCharSplitOnVectorChar :: State -> State +instructionVectorCharSplitOnVectorChar = instructionVectorSplitOnVector vectorChar + +-- |Replaces the first occurrence of the top char with the second char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. +instructionVectorCharReplaceFirst :: State -> State +instructionVectorCharReplaceFirst = instructionVectorReplace char vectorChar (Just 1) + +-- |Replaces all occurrences of the top char with the second char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. +instructionVectorCharReplaceAll :: State -> State +instructionVectorCharReplaceAll = instructionVectorReplace char vectorChar Nothing + +-- |Replaces N occurrences of the top char with the second char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. N is pulled from +-- the top of the int stack. +instructionVectorCharReplaceN :: State -> State +instructionVectorCharReplaceN = instructionVectorReplaceN char vectorChar + +-- |Replaces the first occurrence of the second char vector with the third char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. +instructionVectorCharReplaceFirstVectorChar :: State -> State +instructionVectorCharReplaceFirstVectorChar = instructionVectorReplaceVector vectorChar (Just 1) + +-- |Replaces all occurrences of the second char vector with the third char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. +instructionVectorCharReplaceAllVectorChar :: State -> State +instructionVectorCharReplaceAllVectorChar = instructionVectorReplaceVector vectorChar Nothing + +-- |Replaces N occurrences of the second char vector with the third char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. N is pulled from the top of the int stack. +instructionVectorCharReplaceVectorCharN :: State -> State +instructionVectorCharReplaceVectorCharN = instructionVectorReplaceVectorN vectorChar + +-- |Removes the first occurrence of the top char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. +instructionVectorCharRemoveFirst :: State -> State +instructionVectorCharRemoveFirst = instructionVectorRemove char vectorChar (Just 1) + +-- |Removes the all occurrences of the top char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. +instructionVectorCharRemoveAll :: State -> State +instructionVectorCharRemoveAll = instructionVectorRemove char vectorChar Nothing + +-- |Removes N occurrences of the top char from +-- the char stack inside of the top char vector from the vector char stack. +-- Pushes the modified char vector to the vector char stack. N is pulled +-- from the top of the int stack. +instructionVectorCharRemoveN :: State -> State +instructionVectorCharRemoveN = instructionVectorRemoveN char vectorChar + +-- |Removes the first occurrence of the second char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. +instructionVectorCharRemoveFirstVectorChar :: State -> State +instructionVectorCharRemoveFirstVectorChar = instructionVectorRemoveVector vectorChar (Just 1) + +-- |Removes all occurrences of the second char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. +instructionVectorCharRemoveAllVectorChar :: State -> State +instructionVectorCharRemoveAllVectorChar = instructionVectorRemoveVector vectorChar Nothing + +-- |Removes N occurrences of the second char vector +-- inside of the first char vector from the vector char stack. Pushes the result to the +-- vector char stack. N is pulled from the top of the int stack. +instructionVectorCharRemoveNVectorChar :: State -> State +instructionVectorCharRemoveNVectorChar = instructionVectorRemoveVectorN vectorChar + +-- |Iterates over the top char vector on the vector char stack, applying the top instruction of the +-- exec stack along the way. +instructionVectorCharIterate :: State -> State +instructionVectorCharIterate = instructionVectorIterate char vectorChar GeneVectorChar instructionVectorCharIterate "instructionVectorCharIterate" + +-- |Sorts the top char vector on the vector char stack and pushes the result back to the +-- vector char stack. instructionVectorCharSort :: State -> State instructionVectorCharSort = instructionVectorSort vectorChar +-- |Sorts the top char vector on the vector char stack, reverses it, and pushes the result back to the +-- vector char stack. instructionVectorCharSortReverse :: State -> State instructionVectorCharSortReverse = instructionVectorSortReverse vectorChar -instructionVectorCharDupItems :: State -> State -instructionVectorCharDupItems = instructionDupItems vectorChar +-- |Inserts the top char from the char stack into the top char vector from the +-- vector char stack at a specified index and pushes the result to the vector +-- char stack. The index is pulled from the top of the int stack. +instructionVectorCharInsert :: State -> State +instructionVectorCharInsert = instructionVectorInsert char vectorChar + +-- |Inserts the second char vector into the first char vector from the vector char stack +-- at a specified index and pushes the result to the vector char stack. The index is +-- pulled from the top of the int stack. +instructionVectorCharInsertVectorChar :: State -> State +instructionVectorCharInsertVectorChar = instructionVectorInsertVector vectorChar diff --git a/src/HushGP/Instructions/VectorFloatInstructions.hs b/src/HushGP/Instructions/VectorFloatInstructions.hs index 05a7848..a2a8531 100644 --- a/src/HushGP/Instructions/VectorFloatInstructions.hs +++ b/src/HushGP/Instructions/VectorFloatInstructions.hs @@ -3,113 +3,328 @@ module HushGP.Instructions.VectorFloatInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions -instructionVectorFloatConcat :: State -> State -instructionVectorFloatConcat = instructionVectorConcat vectorFloat - -instructionVectorFloatConj :: State -> State -instructionVectorFloatConj = instructionVectorConj float vectorFloat - -instructionVectorFloatTakeN :: State -> State -instructionVectorFloatTakeN = instructionVectorTakeN vectorFloat - -instructionVectorFloatSubVector :: State -> State -instructionVectorFloatSubVector = instructionSubVector vectorFloat - -instructionVectorFloatFirst :: State -> State -instructionVectorFloatFirst = instructionVectorFirst float vectorFloat - -instructionVectorFloatLast :: State -> State -instructionVectorFloatLast = instructionVectorLast float vectorFloat - -instructionVectorFloatNth :: State -> State -instructionVectorFloatNth = instructionVectorNth float vectorFloat - -instructionVectorFloatRest :: State -> State -instructionVectorFloatRest = instructionVectorRest vectorFloat - -instructionVectorFloatButLast :: State -> State -instructionVectorFloatButLast = instructionVectorButLast vectorFloat - -instructionVectorFloatLength :: State -> State -instructionVectorFloatLength = instructionLength vectorFloat - -instructionVectorFloatReverse :: State -> State -instructionVectorFloatReverse = instructionReverse vectorFloat - -instructionVectorFloatPushAll :: State -> State -instructionVectorFloatPushAll = instructionPushAll float vectorFloat - -instructionVectorFloatMakeEmpty :: State -> State -instructionVectorFloatMakeEmpty = instructionVectorMakeEmpty vectorFloat - -instructionVectorFloatIsEmpty :: State -> State -instructionVectorFloatIsEmpty = instructionVectorIsEmpty vectorFloat - -instructionVectorFloatIndexOf :: State -> State -instructionVectorFloatIndexOf = instructionVectorIndexOf float vectorFloat - -instructionVectorFloatOccurrencesOf :: State -> State -instructionVectorFloatOccurrencesOf = instructionVectorOccurrencesOf float vectorFloat - -instructionVectorFloatSetNth :: State -> State -instructionVectorFloatSetNth = instructionVectorSetNth float vectorFloat - -instructionVectorFloatReplace :: State -> State -instructionVectorFloatReplace = instructionVectorReplace float vectorFloat Nothing - -instructionVectorFloatReplaceFirst :: State -> State -instructionVectorFloatReplaceFirst = instructionVectorReplace float vectorFloat (Just 1) - -instructionVectorFloatRemove :: State -> State -instructionVectorFloatRemove = instructionVectorRemove float vectorFloat Nothing - -instructionVectorFloatIterate :: State -> State -instructionVectorFloatIterate = instructionVectorIterate float vectorFloat GeneVectorFloat instructionVectorFloatIterate "instructionVectorFloatIterate" - +-- |Pops the top float vector from the float vector stack. instructionVectorFloatPop :: State -> State instructionVectorFloatPop = instructionPop vectorFloat +-- |Duplicates the top float vector from the float vector stack. instructionVectorFloatDup :: State -> State instructionVectorFloatDup = instructionDup vectorFloat +-- |Duplicates the top float vector from the float vector stack N times +-- based on the top int from the int stack. instructionVectorFloatDupN :: State -> State instructionVectorFloatDupN = instructionDupN vectorFloat +-- |Swaps the top two float vectors from the float vector stack. instructionVectorFloatSwap :: State -> State instructionVectorFloatSwap = instructionSwap vectorFloat +-- |Rotates the top three float vectors from the float vector stack. instructionVectorFloatRot :: State -> State instructionVectorFloatRot = instructionRot vectorFloat +-- |Sets the vector float stack to [] instructionVectorFloatFlush :: State -> State instructionVectorFloatFlush = instructionFlush vectorFloat +-- |Pushes True to the bool stack if the top two float vectors from +-- the vector float stack are equal. Pushes False otherwise. instructionVectorFloatEq :: State -> State instructionVectorFloatEq = instructionEq vectorFloat +-- |Calculates the size of the vector float stack and pushes that number +-- to the int stack. instructionVectorFloatStackDepth :: State -> State instructionVectorFloatStackDepth = instructionStackDepth vectorFloat +-- |Moves an item from deep within the vector float stack to the top of the vector float stack based on +-- the top int from the int stack. instructionVectorFloatYank :: State -> State instructionVectorFloatYank = instructionYank vectorFloat +-- |Copies an item from deep within the vector float stack to the top of the vector float stack based on +-- the top int from the int stack. instructionVectorFloatYankDup :: State -> State instructionVectorFloatYankDup = instructionYankDup vectorFloat +-- |Pushes True to the bool stack if the vector float stack is empty. False if not. instructionVectorFloatIsStackEmpty :: State -> State instructionVectorFloatIsStackEmpty = instructionIsStackEmpty vectorFloat +-- |Moves an item from the top of the vector float stack to deep within the vector float stack based on +-- the top int from the int stack. instructionVectorFloatShove :: State -> State instructionVectorFloatShove = instructionShove vectorFloat +-- |Copies an item from the top of the vector float stack to deep within the vector float stack based on +-- the top int from the int stack. instructionVectorFloatShoveDup :: State -> State instructionVectorFloatShoveDup = instructionShoveDup vectorFloat +-- |Duplicate the top N items from the vector float stack based on the top int from the int stack. +instructionVectorFloatDupItems :: State -> State +instructionVectorFloatDupItems = instructionDupItems vectorFloat + +-- |Concats the top two vectors on top of the vector float stack. +instructionVectorFloatConcat :: State -> State +instructionVectorFloatConcat = instructionVectorConcat vectorFloat + +-- |Takes the top float from the float stack and prepends it to top float vector +-- on the float vector stack. +instructionVectorFloatConj :: State -> State +instructionVectorFloatConj = instructionVectorConj float vectorFloat + +-- |Takes the top float from the float stack and appends it to top float vector +-- on the float vector stack. +instructionVectorFloatConjEnd :: State -> State +instructionVectorFloatConjEnd = instructionVectorConjEnd float vectorFloat + +-- |Takes the first N floats from the top of the float vector from the float vector +-- and pushes the result to the float vector stack. N is pulled from the top of +-- the int stack. +instructionVectorFloatTakeN :: State -> State +instructionVectorFloatTakeN = instructionVectorTakeN vectorFloat + +-- |Takes the last N floats from the top of the float vector from the float vector +-- and pushes the result to the float vector stack. N is pulled from the top of +-- the int stack. +instructionVectorFloatTakeRN :: State -> State +instructionVectorFloatTakeRN = instructionVectorTakeRN vectorFloat + +-- |Takes a sublist of the top float vector on top of the vector float stack. +-- The two ints to determine bounds are pulled from the top of the int stack. +instructionVectorFloatSubVector :: State -> State +instructionVectorFloatSubVector = instructionSubVector vectorFloat + +-- |Takes the first float from the top of the vector float stack and places +-- it on the float stack. +instructionVectorFloatFirst :: State -> State +instructionVectorFloatFirst = instructionVectorFirst float vectorFloat + +-- |Takes the first float from the top of the vector float stack and places +-- it wrapped in a list on top of the vector float stack. +instructionVectorFloatFromFirstPrim :: State -> State +instructionVectorFloatFromFirstPrim = instructionVectorFromFirstPrim vectorFloat + +-- |Takes the first float from the top of the float stack and places it +-- wrapped in a list on top of the vector float stack. +instructionVectorFloatFromPrim :: State -> State +instructionVectorFloatFromPrim = instructionVectorFromPrim float vectorFloat + +-- |Takes the last float from the top of the vector float stack and places +-- it on the float stack. +instructionVectorFloatLast :: State -> State +instructionVectorFloatLast = instructionVectorLast float vectorFloat + +-- |Takes the last float from the top float vector on the vector float stack and +-- places it on the float stack. +instructionVectorFloatFromLastPrim :: State -> State +instructionVectorFloatFromLastPrim = instructionVectorFromLastPrim vectorFloat + +-- |Takes the Nth float from the top float vector and places it onto the float stack +-- based on an int from the top of the int stack. +instructionVectorFloatNth :: State -> State +instructionVectorFloatNth = instructionVectorNth float vectorFloat + +-- |Takes the Nth float from the top float vector on the vector float stack and +-- creates a vector wrapping that Nth item, pushing it back onto the vector float stack. +-- N is the top item on the int stack. +instructionVectorFloatFromNthPrim :: State -> State +instructionVectorFloatFromNthPrim = instructionVectorFromNthPrim vectorFloat + +-- |Removes the first float from the top float vector on the vector float stack and +-- places the result back onto the vector float stack. +instructionVectorFloatRest :: State -> State +instructionVectorFloatRest = instructionVectorRest vectorFloat + +-- |Removes the last float from the top float vector on the vector float stack and +-- places the result back onto the vector float stack. +instructionVectorFloatButLast :: State -> State +instructionVectorFloatButLast = instructionVectorButLast vectorFloat + +-- |Drops the first N items from the top float vector and pushes the result +-- back to the vector float stack. N is pulled from the top of the int stack. +instructionVectorFloatDrop :: State -> State +instructionVectorFloatDrop = instructionVectorDrop vectorFloat + +-- |Drops the last N items from the top float vector and pushes the result +-- back to the vector float stack. N is pulled from the top of the int stack. +instructionVectorFloatDropR :: State -> State +instructionVectorFloatDropR = instructionVectorDropR vectorFloat + +-- |Pushes the length of the top float vector from the vector float stack +-- to the top of the int stack. +instructionVectorFloatLength :: State -> State +instructionVectorFloatLength = instructionLength vectorFloat + +-- |Reverses the top float vector from the vector float stack and pushes the +-- result to the vector float stack. +instructionVectorFloatReverse :: State -> State +instructionVectorFloatReverse = instructionReverse vectorFloat + +-- |Takes the top float vector from the vector float stack and pushes the +-- individual floats to the vector float stack. +instructionVectorFloatPushAll :: State -> State +instructionVectorFloatPushAll = instructionPushAll float vectorFloat + +-- |Makes an empty vector and pushes it to the vector float stack. +instructionVectorFloatMakeEmpty :: State -> State +instructionVectorFloatMakeEmpty = instructionVectorMakeEmpty vectorFloat + +-- |Checks if the top float vector from the vector float stack is empty. +-- Pushes True if the float vector is empty to the bool stack. False otherwise. +instructionVectorFloatIsEmpty :: State -> State +instructionVectorFloatIsEmpty = instructionVectorIsEmpty vectorFloat + +-- |If the top float vector from the vector float stack contains the top float from the float +-- stack, pushes True to the bool stack and pushes False otherwise. +instructionVectorFloatContains :: State -> State +instructionVectorFloatContains = instructionVectorContains float vectorFloat + +-- |If the second to top float vector can be found within the first float vector from the +-- vector float stack, pushes True to the bool stack if is found, else False. +instructionVectorFloatContainsVectorFloat :: State -> State +instructionVectorFloatContainsVectorFloat = instructionVectorContainsVector vectorFloat + +-- |Finds the first index of the top float in the float stack inside of the +-- top float vector from the vector float stack and pushes the result to the int stack. +instructionVectorFloatIndexOf :: State -> State +instructionVectorFloatIndexOf = instructionVectorIndexOf float vectorFloat + +-- |Searches and pushes the index of the second float vector inside of the first +-- float vector to the int stack from the vector float stack. Pushes -1 if not found. +instructionVectorFloatIndexOfVectorFloat :: State -> State +instructionVectorFloatIndexOfVectorFloat = instructionVectorIndexOfVector vectorFloat + +-- |Finds the amount of times the top float on the float stack occurs inside of +-- the top float vector from the vector float stack and pushes the result to the +-- int stack. +instructionVectorFloatOccurrencesOf :: State -> State +instructionVectorFloatOccurrencesOf = instructionVectorOccurrencesOf float vectorFloat + +-- |Counts the amount of occurrences of the second float vector within the first +-- float vector. Pushes the result to the int stack. +instructionVectorFloatOccurrencesOfVectorFloat :: State -> State +instructionVectorFloatOccurrencesOfVectorFloat = instructionVectorOccurrencesOfVector vectorFloat + +-- |Splits the top float vector from the vector float stack into lists of size one and pushes +-- the result back one the vector float stack. +instructionVectorFloatParseToFloat :: State -> State +instructionVectorFloatParseToFloat = instructionVectorParseToPrim vectorFloat + +-- |Sets the Nth index inside of the top float vector from the vector float stack to the +-- top value from the primitive stack. N is pulled from the top of the int stack. +instructionVectorFloatSetNth :: State -> State +instructionVectorFloatSetNth = instructionVectorSetNth float vectorFloat + +-- |Splits the float vector on top of the vector float stack with the float from the top +-- of the float stack and pushes the result to the original vector stack. +instructionVectorFloatSplitOn :: State -> State +instructionVectorFloatSplitOn = instructionVectorSplitOn float vectorFloat + +-- |Splits the first float vector based on the second float vector from the vector +-- float stack and pushes the result to the vector float stack. +instructionVectorFloatSplitOnVectorFloat :: State -> State +instructionVectorFloatSplitOnVectorFloat = instructionVectorSplitOnVector vectorFloat + +-- |Replaces the first occurrence of the top float with the second float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. +instructionVectorFloatReplaceFirst :: State -> State +instructionVectorFloatReplaceFirst = instructionVectorReplace float vectorFloat (Just 1) + +-- |Replaces all occurrences of the top float with the second float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. +instructionVectorFloatReplaceAll :: State -> State +instructionVectorFloatReplaceAll = instructionVectorReplace float vectorFloat Nothing + +-- |Replaces N occurrences of the top float with the second float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. N is pulled from +-- the top of the int stack. +instructionVectorFloatReplaceN :: State -> State +instructionVectorFloatReplaceN = instructionVectorReplaceN float vectorFloat + +-- |Replaces the first occurrence of the second float vector with the third float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. +instructionVectorFloatReplaceFirstVectorFloat :: State -> State +instructionVectorFloatReplaceFirstVectorFloat = instructionVectorReplaceVector vectorFloat (Just 1) + +-- |Replaces all occurrences of the second float vector with the third float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. +instructionVectorFloatReplaceAllVectorFloat :: State -> State +instructionVectorFloatReplaceAllVectorFloat = instructionVectorReplaceVector vectorFloat Nothing + +-- |Replaces N occurrences of the second float vector with the third float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. N is pulled from the top of the int stack. +instructionVectorFloatReplaceVectorFloatN :: State -> State +instructionVectorFloatReplaceVectorFloatN = instructionVectorReplaceVectorN vectorFloat + +-- |Removes the first occurrence of the top float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. +instructionVectorFloatRemoveFirst :: State -> State +instructionVectorFloatRemoveFirst = instructionVectorRemove float vectorFloat (Just 1) + +-- |Removes the all occurrences of the top float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. +instructionVectorFloatRemoveAll :: State -> State +instructionVectorFloatRemoveAll = instructionVectorRemove float vectorFloat Nothing + +-- |Removes N occurrences of the top float from +-- the float stack inside of the top float vector from the vector float stack. +-- Pushes the modified float vector to the vector float stack. N is pulled +-- from the top of the int stack. +instructionVectorFloatRemoveN :: State -> State +instructionVectorFloatRemoveN = instructionVectorRemoveN float vectorFloat + +-- |Removes the first occurrence of the second float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. +instructionVectorFloatRemoveFirstVectorFloat :: State -> State +instructionVectorFloatRemoveFirstVectorFloat = instructionVectorRemoveVector vectorFloat (Just 1) + +-- |Removes all occurrences of the second float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. +instructionVectorFloatRemoveAllVectorFloat :: State -> State +instructionVectorFloatRemoveAllVectorFloat = instructionVectorRemoveVector vectorFloat Nothing + +-- |Removes N occurrences of the second float vector +-- inside of the first float vector from the vector float stack. Pushes the result to the +-- vector float stack. N is pulled from the top of the int stack. +instructionVectorFloatRemoveNVectorFloat :: State -> State +instructionVectorFloatRemoveNVectorFloat = instructionVectorRemoveVectorN vectorFloat + +-- |Iterates over the top float vector on the vector float stack, applying the top instruction of the +-- exec stack along the way. +instructionVectorFloatIterate :: State -> State +instructionVectorFloatIterate = instructionVectorIterate float vectorFloat GeneVectorFloat instructionVectorFloatIterate "instructionVectorFloatIterate" + +-- |Sorts the top float vector on the vector float stack and pushes the result back to the +-- vector float stack. instructionVectorFloatSort :: State -> State instructionVectorFloatSort = instructionVectorSort vectorFloat +-- |Sorts the top float vector on the vector float stack, reverses it, and pushes the result back to the +-- vector float stack. instructionVectorFloatSortReverse :: State -> State instructionVectorFloatSortReverse = instructionVectorSortReverse vectorFloat -instructionVectorFloatDupItems :: State -> State -instructionVectorFloatDupItems = instructionDupItems vectorFloat +-- |Inserts the top float from the float stack into the top float vector from the +-- vector float stack at a specified index and pushes the result to the vector +-- float stack. The index is pulled from the top of the int stack. +instructionVectorFloatInsert :: State -> State +instructionVectorFloatInsert = instructionVectorInsert float vectorFloat + +-- |Inserts the second float vector into the first float vector from the vector float stack +-- at a specified index and pushes the result to the vector float stack. The index is +-- pulled from the top of the int stack. +instructionVectorFloatInsertVectorFloat :: State -> State +instructionVectorFloatInsertVectorFloat = instructionVectorInsertVector vectorFloat diff --git a/src/HushGP/Instructions/VectorIntInstructions.hs b/src/HushGP/Instructions/VectorIntInstructions.hs index 04c7b5e..cddf728 100644 --- a/src/HushGP/Instructions/VectorIntInstructions.hs +++ b/src/HushGP/Instructions/VectorIntInstructions.hs @@ -3,113 +3,328 @@ module HushGP.Instructions.VectorIntInstructions where import HushGP.Instructions.GenericInstructions import HushGP.State +-- |Pops the top int vector from the int vector stack. +instructionVectorIntPop :: State -> State +instructionVectorIntPop = instructionPop vectorInt + +-- |Duplicates the top int vector from the int vector stack. +instructionVectorIntDup :: State -> State +instructionVectorIntDup = instructionDup vectorInt + +-- |Duplicates the top int vector from the int vector stack N times +-- based on the top int from the int stack. +instructionVectorIntDupN :: State -> State +instructionVectorIntDupN = instructionDupN vectorInt + +-- |Swaps the top two int vectors from the int vector stack. +instructionVectorIntSwap :: State -> State +instructionVectorIntSwap = instructionSwap vectorInt + +-- |Rotates the top three int vectors from the int vector stack. +instructionVectorIntRot :: State -> State +instructionVectorIntRot = instructionRot vectorInt + +-- |Sets the vector int stack to [] +instructionVectorIntFlush :: State -> State +instructionVectorIntFlush = instructionFlush vectorInt + +-- |Pushes True to the bool stack if the top two int vectors from +-- the vector int stack are equal. Pushes False otherwise. +instructionVectorIntEq :: State -> State +instructionVectorIntEq = instructionEq vectorInt + +-- |Calculates the size of the vector int stack and pushes that number +-- to the int stack. +instructionVectorIntStackDepth :: State -> State +instructionVectorIntStackDepth = instructionStackDepth vectorInt + +-- |Moves an item from deep within the vector int stack to the top of the vector int stack based on +-- the top int from the int stack. +instructionVectorIntYank :: State -> State +instructionVectorIntYank = instructionYank vectorInt + +-- |Copies an item from deep within the vector int stack to the top of the vector int stack based on +-- the top int from the int stack. +instructionVectorIntYankDup :: State -> State +instructionVectorIntYankDup = instructionYankDup vectorInt + +-- |Pushes True to the bool stack if the vector int stack is empty. False if not. +instructionVectorIntIsStackEmpty :: State -> State +instructionVectorIntIsStackEmpty = instructionIsStackEmpty vectorInt + +-- |Moves an item from the top of the vector int stack to deep within the vector int stack based on +-- the top int from the int stack. +instructionVectorIntShove :: State -> State +instructionVectorIntShove = instructionShove vectorInt + +-- |Copies an item from the top of the vector int stack to deep within the vector int stack based on +-- the top int from the int stack. +instructionVectorIntShoveDup :: State -> State +instructionVectorIntShoveDup = instructionShoveDup vectorInt + +-- |Duplicate the top N items from the vector int stack based on the top int from the int stack. +instructionVectorIntDupItems :: State -> State +instructionVectorIntDupItems = instructionDupItems vectorInt + +-- |Concats the top two vectors on top of the vector int stack. instructionVectorIntConcat :: State -> State instructionVectorIntConcat = instructionVectorConcat vectorInt +-- |Takes the top int from the int stack and prepends it to top int vector +-- on the int vector stack. instructionVectorIntConj :: State -> State instructionVectorIntConj = instructionVectorConj int vectorInt +-- |Takes the top int from the int stack and appends it to top int vector +-- on the int vector stack. +instructionVectorIntConjEnd :: State -> State +instructionVectorIntConjEnd = instructionVectorConjEnd int vectorInt + +-- |Takes the first N ints from the top of the int vector from the int vector +-- and pushes the result to the int vector stack. N is pulled from the top of +-- the int stack. instructionVectorIntTakeN :: State -> State instructionVectorIntTakeN = instructionVectorTakeN vectorInt +-- |Takes the last N ints from the top of the int vector from the int vector +-- and pushes the result to the int vector stack. N is pulled from the top of +-- the int stack. +instructionVectorIntTakeRN :: State -> State +instructionVectorIntTakeRN = instructionVectorTakeRN vectorInt + +-- |Takes a sublist of the top int vector on top of the vector int stack. +-- The two ints to determine bounds are pulled from the top of the int stack. instructionVectorIntSubVector :: State -> State instructionVectorIntSubVector = instructionSubVector vectorInt +-- |Takes the first int from the top of the vector int stack and places +-- it on the int stack. instructionVectorIntFirst :: State -> State instructionVectorIntFirst = instructionVectorFirst int vectorInt +-- |Takes the first int from the top of the vector int stack and places +-- it wrapped in a list on top of the vector int stack. +instructionVectorIntFromFirstPrim :: State -> State +instructionVectorIntFromFirstPrim = instructionVectorFromFirstPrim vectorInt + +-- |Takes the first int from the top of the int stack and places it +-- wrapped in a list on top of the vector int stack. +instructionVectorIntFromPrim :: State -> State +instructionVectorIntFromPrim = instructionVectorFromPrim int vectorInt + +-- |Takes the last int from the top of the vector int stack and places +-- it on the int stack. instructionVectorIntLast :: State -> State instructionVectorIntLast = instructionVectorLast int vectorInt +-- |Takes the last int from the top int vector on the vector int stack and +-- places it on the int stack. +instructionVectorIntFromLastPrim :: State -> State +instructionVectorIntFromLastPrim = instructionVectorFromLastPrim vectorInt + +-- |Takes the Nth int from the top int vector and places it onto the int stack +-- based on an int from the top of the int stack. instructionVectorIntNth :: State -> State instructionVectorIntNth = instructionVectorNth int vectorInt +-- |Takes the Nth int from the top int vector on the vector int stack and +-- creates a vector wrapping that Nth item, pushing it back onto the vector int stack. +-- N is the top item on the int stack. +instructionVectorIntFromNthPrim :: State -> State +instructionVectorIntFromNthPrim = instructionVectorFromNthPrim vectorInt + +-- |Removes the first int from the top int vector on the vector int stack and +-- places the result back onto the vector int stack. instructionVectorIntRest :: State -> State instructionVectorIntRest = instructionVectorRest vectorInt +-- |Removes the last int from the top int vector on the vector int stack and +-- places the result back onto the vector int stack. instructionVectorIntButLast :: State -> State instructionVectorIntButLast = instructionVectorButLast vectorInt +-- |Drops the first N items from the top int vector and pushes the result +-- back to the vector int stack. N is pulled from the top of the int stack. +instructionVectorIntDrop :: State -> State +instructionVectorIntDrop = instructionVectorDrop vectorInt + +-- |Drops the last N items from the top int vector and pushes the result +-- back to the vector int stack. N is pulled from the top of the int stack. +instructionVectorIntDropR :: State -> State +instructionVectorIntDropR = instructionVectorDropR vectorInt + +-- |Pushes the length of the top int vector from the vector int stack +-- to the top of the int stack. instructionVectorIntLength :: State -> State instructionVectorIntLength = instructionLength vectorInt +-- |Reverses the top int vector from the vector int stack and pushes the +-- result to the vector int stack. instructionVectorIntReverse :: State -> State instructionVectorIntReverse = instructionReverse vectorInt +-- |Takes the top int vector from the vector int stack and pushes the +-- individual ints to the vector int stack. instructionVectorIntPushAll :: State -> State instructionVectorIntPushAll = instructionPushAll int vectorInt +-- |Makes an empty vector and pushes it to the vector int stack. instructionVectorIntMakeEmpty :: State -> State instructionVectorIntMakeEmpty = instructionVectorMakeEmpty vectorInt +-- |Checks if the top int vector from the vector int stack is empty. +-- Pushes True if the int vector is empty to the bool stack. False otherwise. instructionVectorIntIsEmpty :: State -> State instructionVectorIntIsEmpty = instructionVectorIsEmpty vectorInt +-- |If the top int vector from the vector int stack contains the top int from the int +-- stack, pushes True to the bool stack and pushes False otherwise. +instructionVectorIntContains :: State -> State +instructionVectorIntContains = instructionVectorContains int vectorInt + +-- |If the second to top int vector can be found within the first int vector from the +-- vector int stack, pushes True to the bool stack if is found, else False. +instructionVectorIntContainsVectorInt :: State -> State +instructionVectorIntContainsVectorInt = instructionVectorContainsVector vectorInt + +-- |Finds the first index of the top int in the int stack inside of the +-- top int vector from the vector int stack and pushes the result to the int stack. instructionVectorIntIndexOf :: State -> State instructionVectorIntIndexOf = instructionVectorIndexOf int vectorInt +-- |Searches and pushes the index of the second int vector inside of the first +-- int vector to the int stack from the vector int stack. Pushes -1 if not found. +instructionVectorIntIndexOfVectorInt :: State -> State +instructionVectorIntIndexOfVectorInt = instructionVectorIndexOfVector vectorInt + +-- |Finds the amount of times the top int on the int stack occurs inside of +-- the top int vector from the vector int stack and pushes the result to the +-- int stack. instructionVectorIntOccurrencesOf :: State -> State instructionVectorIntOccurrencesOf = instructionVectorOccurrencesOf int vectorInt +-- |Counts the amount of occurrences of the second int vector within the first +-- int vector. Pushes the result to the int stack. +instructionVectorIntOccurrencesOfVectorInt :: State -> State +instructionVectorIntOccurrencesOfVectorInt = instructionVectorOccurrencesOfVector vectorInt + +-- |Splits the top int vector from the vector int stack into lists of size one and pushes +-- the result back one the vector int stack. +instructionVectorIntParseToInt :: State -> State +instructionVectorIntParseToInt = instructionVectorParseToPrim vectorInt + +-- |Sets the Nth index inside of the top int vector from the vector int stack to the +-- top value from the primitive stack. N is pulled from the top of the int stack. instructionVectorIntSetNth :: State -> State instructionVectorIntSetNth = instructionVectorSetNth int vectorInt -instructionVectorIntReplace :: State -> State -instructionVectorIntReplace = instructionVectorReplace int vectorInt Nothing +-- |Splits the int vector on top of the vector int stack with the int from the top +-- of the int stack and pushes the result to the original vector stack. +instructionVectorIntSplitOn :: State -> State +instructionVectorIntSplitOn = instructionVectorSplitOn int vectorInt +-- |Splits the first int vector based on the second int vector from the vector +-- int stack and pushes the result to the vector int stack. +instructionVectorIntSplitOnVectorInt :: State -> State +instructionVectorIntSplitOnVectorInt = instructionVectorSplitOnVector vectorInt + +-- |Replaces the first occurrence of the top int with the second int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. instructionVectorIntReplaceFirst :: State -> State instructionVectorIntReplaceFirst = instructionVectorReplace int vectorInt (Just 1) -instructionVectorIntRemove :: State -> State -instructionVectorIntRemove = instructionVectorRemove int vectorInt Nothing +-- |Replaces all occurrences of the top int with the second int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. +instructionVectorIntReplaceAll :: State -> State +instructionVectorIntReplaceAll = instructionVectorReplace int vectorInt Nothing +-- |Replaces N occurrences of the top int with the second int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. N is pulled from +-- the top of the int stack. +instructionVectorIntReplaceN :: State -> State +instructionVectorIntReplaceN = instructionVectorReplaceN int vectorInt + +-- |Replaces the first occurrence of the second int vector with the third int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. +instructionVectorIntReplaceFirstVectorInt :: State -> State +instructionVectorIntReplaceFirstVectorInt = instructionVectorReplaceVector vectorInt (Just 1) + +-- |Replaces all occurrences of the second int vector with the third int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. +instructionVectorIntReplaceAllVectorInt :: State -> State +instructionVectorIntReplaceAllVectorInt = instructionVectorReplaceVector vectorInt Nothing + +-- |Replaces N occurrences of the second int vector with the third int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. N is pulled from the top of the int stack. +instructionVectorIntReplaceVectorIntN :: State -> State +instructionVectorIntReplaceVectorIntN = instructionVectorReplaceVectorN vectorInt + +-- |Removes the first occurrence of the top int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. +instructionVectorIntRemoveFirst :: State -> State +instructionVectorIntRemoveFirst = instructionVectorRemove int vectorInt (Just 1) + +-- |Removes the all occurrences of the top int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. +instructionVectorIntRemoveAll :: State -> State +instructionVectorIntRemoveAll = instructionVectorRemove int vectorInt Nothing + +-- |Removes N occurrences of the top int from +-- the int stack inside of the top int vector from the vector int stack. +-- Pushes the modified int vector to the vector int stack. N is pulled +-- from the top of the int stack. +instructionVectorIntRemoveN :: State -> State +instructionVectorIntRemoveN = instructionVectorRemoveN int vectorInt + +-- |Removes the first occurrence of the second int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. +instructionVectorIntRemoveFirstVectorInt :: State -> State +instructionVectorIntRemoveFirstVectorInt = instructionVectorRemoveVector vectorInt (Just 1) + +-- |Removes all occurrences of the second int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. +instructionVectorIntRemoveAllVectorInt :: State -> State +instructionVectorIntRemoveAllVectorInt = instructionVectorRemoveVector vectorInt Nothing + +-- |Removes N occurrences of the second int vector +-- inside of the first int vector from the vector int stack. Pushes the result to the +-- vector int stack. N is pulled from the top of the int stack. +instructionVectorIntRemoveNVectorInt :: State -> State +instructionVectorIntRemoveNVectorInt = instructionVectorRemoveVectorN vectorInt + +-- |Iterates over the top int vector on the vector int stack, applying the top instruction of the +-- exec stack along the way. instructionVectorIntIterate :: State -> State instructionVectorIntIterate = instructionVectorIterate int vectorInt GeneVectorInt instructionVectorIntIterate "instructionVectorIntIterate" -instructionVectorIntPop :: State -> State -instructionVectorIntPop = instructionPop vectorChar - -instructionVectorIntDup :: State -> State -instructionVectorIntDup = instructionDup vectorChar - -instructionVectorIntDupN :: State -> State -instructionVectorIntDupN = instructionDupN vectorChar - -instructionVectorIntSwap :: State -> State -instructionVectorIntSwap = instructionSwap vectorChar - -instructionVectorIntRot :: State -> State -instructionVectorIntRot = instructionRot vectorChar - -instructionVectorIntFlush :: State -> State -instructionVectorIntFlush = instructionFlush vectorChar - -instructionVectorIntEq :: State -> State -instructionVectorIntEq = instructionEq vectorChar - -instructionVectorIntStackDepth :: State -> State -instructionVectorIntStackDepth = instructionStackDepth vectorChar - -instructionVectorIntYank :: State -> State -instructionVectorIntYank = instructionYank vectorChar - -instructionVectorIntYankDup :: State -> State -instructionVectorIntYankDup = instructionYankDup vectorChar - -instructionVectorIntIsStackEmpty :: State -> State -instructionVectorIntIsStackEmpty = instructionIsStackEmpty vectorChar - -instructionVectorIntShove :: State -> State -instructionVectorIntShove = instructionShove vectorChar - -instructionVectorIntShoveDup :: State -> State -instructionVectorIntShoveDup = instructionShoveDup vectorChar - +-- |Sorts the top int vector on the vector int stack and pushes the result back to the +-- vector int stack. instructionVectorIntSort :: State -> State instructionVectorIntSort = instructionVectorSort vectorInt +-- |Sorts the top int vector on the vector int stack, reverses it, and pushes the result back to the +-- vector int stack. instructionVectorIntSortReverse :: State -> State instructionVectorIntSortReverse = instructionVectorSortReverse vectorInt -instructionVectorIntDupItems :: State -> State -instructionVectorIntDupItems = instructionDupItems vectorInt +-- |Inserts the top int from the int stack into the top int vector from the +-- vector int stack at a specified index and pushes the result to the vector +-- int stack. The index is pulled from the top of the int stack. +instructionVectorIntInsert :: State -> State +instructionVectorIntInsert = instructionVectorInsert int vectorInt + +-- |Inserts the second int vector into the first int vector from the vector int stack +-- at a specified index and pushes the result to the vector int stack. The index is +-- pulled from the top of the int stack. +instructionVectorIntInsertVectorInt :: State -> State +instructionVectorIntInsertVectorInt = instructionVectorInsertVector vectorInt diff --git a/src/HushGP/Instructions/VectorStringInstructions.hs b/src/HushGP/Instructions/VectorStringInstructions.hs index 64966f9..f4b904e 100644 --- a/src/HushGP/Instructions/VectorStringInstructions.hs +++ b/src/HushGP/Instructions/VectorStringInstructions.hs @@ -3,113 +3,328 @@ module HushGP.Instructions.VectorStringInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions -instructionVectorStringConcat :: State -> State -instructionVectorStringConcat = instructionVectorConcat vectorString - -instructionVectorStringConj :: State -> State -instructionVectorStringConj = instructionVectorConj string vectorString - -instructionVectorStringTakeN :: State -> State -instructionVectorStringTakeN = instructionVectorTakeN vectorString - -instructionVectorStringSubVector :: State -> State -instructionVectorStringSubVector = instructionSubVector vectorString - -instructionVectorStringFirst :: State -> State -instructionVectorStringFirst = instructionVectorFirst string vectorString - -instructionVectorStringLast :: State -> State -instructionVectorStringLast = instructionVectorLast string vectorString - -instructionVectorStringNth :: State -> State -instructionVectorStringNth = instructionVectorNth string vectorString - -instructionVectorStringRest :: State -> State -instructionVectorStringRest = instructionVectorRest vectorString - -instructionVectorStringButLast :: State -> State -instructionVectorStringButLast = instructionVectorButLast vectorString - -instructionVectorStringLength :: State -> State -instructionVectorStringLength = instructionLength vectorString - -instructionVectorStringReverse :: State -> State -instructionVectorStringReverse = instructionReverse vectorString - -instructionVectorStringPushAll :: State -> State -instructionVectorStringPushAll = instructionPushAll string vectorString - -instructionVectorStringMakeEmpty :: State -> State -instructionVectorStringMakeEmpty = instructionVectorMakeEmpty vectorString - -instructionVectorStringIsEmpty :: State -> State -instructionVectorStringIsEmpty = instructionVectorIsEmpty vectorString - -instructionVectorStringIndexOf :: State -> State -instructionVectorStringIndexOf = instructionVectorIndexOf string vectorString - -instructionVectorStringOccurrencesOf :: State -> State -instructionVectorStringOccurrencesOf = instructionVectorOccurrencesOf string vectorString - -instructionVectorStringSetNth :: State -> State -instructionVectorStringSetNth = instructionVectorSetNth string vectorString - -instructionVectorStringReplace :: State -> State -instructionVectorStringReplace = instructionVectorReplace string vectorString Nothing - -instructionVectorStringReplaceFirst :: State -> State -instructionVectorStringReplaceFirst = instructionVectorReplace string vectorString (Just 1) - -instructionVectorStringRemove :: State -> State -instructionVectorStringRemove = instructionVectorRemove string vectorString Nothing - -instructionVectorStringIterate :: State -> State -instructionVectorStringIterate = instructionVectorIterate string vectorString GeneVectorString instructionVectorStringIterate "instructionVectorStringIterate" - +-- |Pops the top string vector from the string vector stack. instructionVectorStringPop :: State -> State instructionVectorStringPop = instructionPop vectorString +-- |Duplicates the top string vector from the string vector stack. instructionVectorStringDup :: State -> State instructionVectorStringDup = instructionDup vectorString +-- |Duplicates the top string vector from the string vector stack N times +-- based on the top int from the int stack. instructionVectorStringDupN :: State -> State instructionVectorStringDupN = instructionDupN vectorString +-- |Swaps the top two string vectors from the string vector stack. instructionVectorStringSwap :: State -> State instructionVectorStringSwap = instructionSwap vectorString +-- |Rotates the top three string vectors from the string vector stack. instructionVectorStringRot :: State -> State instructionVectorStringRot = instructionRot vectorString +-- |Sets the vector string stack to [] instructionVectorStringFlush :: State -> State instructionVectorStringFlush = instructionFlush vectorString +-- |Pushes True to the bool stack if the top two string vectors from +-- the vector string stack are equal. Pushes False otherwise. instructionVectorStringEq :: State -> State instructionVectorStringEq = instructionEq vectorString +-- |Calculates the size of the vector string stack and pushes that number +-- to the int stack. instructionVectorStringStackDepth :: State -> State instructionVectorStringStackDepth = instructionStackDepth vectorString +-- |Moves an item from deep within the vector string stack to the top of the vector string stack based on +-- the top int from the int stack. instructionVectorStringYank :: State -> State instructionVectorStringYank = instructionYank vectorString +-- |Copies an item from deep within the vector string stack to the top of the vector string stack based on +-- the top int from the int stack. instructionVectorStringYankDup :: State -> State instructionVectorStringYankDup = instructionYankDup vectorString +-- |Pushes True to the bool stack if the vector string stack is empty. False if not. instructionVectorStringIsStackEmpty :: State -> State instructionVectorStringIsStackEmpty = instructionIsStackEmpty vectorString +-- |Moves an item from the top of the vector string stack to deep within the vector string stack based on +-- the top int from the int stack. instructionVectorStringShove :: State -> State instructionVectorStringShove = instructionShove vectorString +-- |Copies an item from the top of the vector string stack to deep within the vector string stack based on +-- the top int from the int stack. instructionVectorStringShoveDup :: State -> State instructionVectorStringShoveDup = instructionShoveDup vectorString +-- |Duplicate the top N items from the vector string stack based on the top int from the int stack. +instructionVectorStringDupItems :: State -> State +instructionVectorStringDupItems = instructionDupItems vectorString + +-- |Concats the top two vectors on top of the vector string stack. +instructionVectorStringConcat :: State -> State +instructionVectorStringConcat = instructionVectorConcat vectorString + +-- |Takes the top string from the string stack and prepends it to top string vector +-- on the string vector stack. +instructionVectorStringConj :: State -> State +instructionVectorStringConj = instructionVectorConj string vectorString + +-- |Takes the top string from the string stack and appends it to top string vector +-- on the string vector stack. +instructionVectorStringConjEnd :: State -> State +instructionVectorStringConjEnd = instructionVectorConjEnd string vectorString + +-- |Takes the first N strings from the top of the string vector from the string vector +-- and pushes the result to the string vector stack. N is pulled from the top of +-- the int stack. +instructionVectorStringTakeN :: State -> State +instructionVectorStringTakeN = instructionVectorTakeN vectorString + +-- |Takes the last N strings from the top of the string vector from the string vector +-- and pushes the result to the string vector stack. N is pulled from the top of +-- the int stack. +instructionVectorStringTakeRN :: State -> State +instructionVectorStringTakeRN = instructionVectorTakeRN vectorString + +-- |Takes a sublist of the top string vector on top of the vector string stack. +-- The two ints to determine bounds are pulled from the top of the int stack. +instructionVectorStringSubVector :: State -> State +instructionVectorStringSubVector = instructionSubVector vectorString + +-- |Takes the first string from the top of the vector string stack and places +-- it on the string stack. +instructionVectorStringFirst :: State -> State +instructionVectorStringFirst = instructionVectorFirst string vectorString + +-- |Takes the first string from the top of the vector string stack and places +-- it wrapped in a list on top of the vector string stack. +instructionVectorStringFromFirstPrim :: State -> State +instructionVectorStringFromFirstPrim = instructionVectorFromFirstPrim vectorString + +-- |Takes the first string from the top of the string stack and places it +-- wrapped in a list on top of the vector string stack. +instructionVectorStringFromPrim :: State -> State +instructionVectorStringFromPrim = instructionVectorFromPrim string vectorString + +-- |Takes the last string from the top of the vector string stack and places +-- it on the string stack. +instructionVectorStringLast :: State -> State +instructionVectorStringLast = instructionVectorLast string vectorString + +-- |Takes the last string from the top string vector on the vector string stack and +-- places it on the string stack. +instructionVectorStringFromLastPrim :: State -> State +instructionVectorStringFromLastPrim = instructionVectorFromLastPrim vectorString + +-- |Takes the Nth string from the top string vector and places it onto the string stack +-- based on an int from the top of the int stack. +instructionVectorStringNth :: State -> State +instructionVectorStringNth = instructionVectorNth string vectorString + +-- |Takes the Nth string from the top string vector on the vector string stack and +-- creates a vector wrapping that Nth item, pushing it back onto the vector string stack. +-- N is the top item on the int stack. +instructionVectorStringFromNthPrim :: State -> State +instructionVectorStringFromNthPrim = instructionVectorFromNthPrim vectorString + +-- |Removes the first string from the top string vector on the vector string stack and +-- places the result back onto the vector string stack. +instructionVectorStringRest :: State -> State +instructionVectorStringRest = instructionVectorRest vectorString + +-- |Removes the last string from the top string vector on the vector string stack and +-- places the result back onto the vector string stack. +instructionVectorStringButLast :: State -> State +instructionVectorStringButLast = instructionVectorButLast vectorString + +-- |Drops the first N items from the top string vector and pushes the result +-- back to the vector string stack. N is pulled from the top of the int stack. +instructionVectorStringDrop :: State -> State +instructionVectorStringDrop = instructionVectorDrop vectorString + +-- |Drops the last N items from the top string vector and pushes the result +-- back to the vector string stack. N is pulled from the top of the int stack. +instructionVectorStringDropR :: State -> State +instructionVectorStringDropR = instructionVectorDropR vectorString + +-- |Pushes the length of the top string vector from the vector string stack +-- to the top of the int stack. +instructionVectorStringLength :: State -> State +instructionVectorStringLength = instructionLength vectorString + +-- |Reverses the top string vector from the vector string stack and pushes the +-- result to the vector string stack. +instructionVectorStringReverse :: State -> State +instructionVectorStringReverse = instructionReverse vectorString + +-- |Takes the top string vector from the vector string stack and pushes the +-- individual strings to the vector string stack. +instructionVectorStringPushAll :: State -> State +instructionVectorStringPushAll = instructionPushAll string vectorString + +-- |Makes an empty vector and pushes it to the vector string stack. +instructionVectorStringMakeEmpty :: State -> State +instructionVectorStringMakeEmpty = instructionVectorMakeEmpty vectorString + +-- |Checks if the top string vector from the vector string stack is empty. +-- Pushes True if the string vector is empty to the bool stack. False otherwise. +instructionVectorStringIsEmpty :: State -> State +instructionVectorStringIsEmpty = instructionVectorIsEmpty vectorString + +-- |If the top string vector from the vector string stack contains the top string from the string +-- stack, pushes True to the bool stack and pushes False otherwise. +instructionVectorStringContains :: State -> State +instructionVectorStringContains = instructionVectorContains string vectorString + +-- |If the second to top string vector can be found within the first string vector from the +-- vector string stack, pushes True to the bool stack if is found, else False. +instructionVectorStringContainsVectorString :: State -> State +instructionVectorStringContainsVectorString = instructionVectorContainsVector vectorString + +-- |Finds the first index of the top string in the string stack inside of the +-- top string vector from the vector string stack and pushes the result to the int stack. +instructionVectorStringIndexOf :: State -> State +instructionVectorStringIndexOf = instructionVectorIndexOf string vectorString + +-- |Searches and pushes the index of the second string vector inside of the first +-- string vector to the int stack from the vector string stack. Pushes -1 if not found. +instructionVectorStringIndexOfVectorString :: State -> State +instructionVectorStringIndexOfVectorString = instructionVectorIndexOfVector vectorString + +-- |Finds the amount of times the top string on the string stack occurs inside of +-- the top string vector from the vector string stack and pushes the result to the +-- int stack. +instructionVectorStringOccurrencesOf :: State -> State +instructionVectorStringOccurrencesOf = instructionVectorOccurrencesOf string vectorString + +-- |Counts the amount of occurrences of the second string vector within the first +-- string vector. Pushes the result to the int stack. +instructionVectorStringOccurrencesOfVectorString :: State -> State +instructionVectorStringOccurrencesOfVectorString = instructionVectorOccurrencesOfVector vectorString + +-- |Splits the top string vector from the vector string stack into lists of size one and pushes +-- the result back one the vector string stack. +instructionVectorStringParseToString :: State -> State +instructionVectorStringParseToString = instructionVectorParseToPrim vectorString + +-- |Sets the Nth index inside of the top string vector from the vector string stack to the +-- top value from the primitive stack. N is pulled from the top of the int stack. +instructionVectorStringSetNth :: State -> State +instructionVectorStringSetNth = instructionVectorSetNth string vectorString + +-- |Splits the string vector on top of the vector string stack with the string from the top +-- of the string stack and pushes the result to the original vector stack. +instructionVectorStringSplitOn :: State -> State +instructionVectorStringSplitOn = instructionVectorSplitOn string vectorString + +-- |Splits the first string vector based on the second string vector from the vector +-- string stack and pushes the result to the vector string stack. +instructionVectorStringSplitOnVectorString :: State -> State +instructionVectorStringSplitOnVectorString = instructionVectorSplitOnVector vectorString + +-- |Replaces the first occurrence of the top string with the second string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. +instructionVectorStringReplaceFirst :: State -> State +instructionVectorStringReplaceFirst = instructionVectorReplace string vectorString (Just 1) + +-- |Replaces all occurrences of the top string with the second string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. +instructionVectorStringReplaceAll :: State -> State +instructionVectorStringReplaceAll = instructionVectorReplace string vectorString Nothing + +-- |Replaces N occurrences of the top string with the second string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. N is pulled from +-- the top of the int stack. +instructionVectorStringReplaceN :: State -> State +instructionVectorStringReplaceN = instructionVectorReplaceN string vectorString + +-- |Replaces the first occurrence of the second string vector with the third string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. +instructionVectorStringReplaceFirstVectorString :: State -> State +instructionVectorStringReplaceFirstVectorString = instructionVectorReplaceVector vectorString (Just 1) + +-- |Replaces all occurrences of the second string vector with the third string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. +instructionVectorStringReplaceAllVectorString :: State -> State +instructionVectorStringReplaceAllVectorString = instructionVectorReplaceVector vectorString Nothing + +-- |Replaces N occurrences of the second string vector with the third string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. N is pulled from the top of the int stack. +instructionVectorStringReplaceVectorStringN :: State -> State +instructionVectorStringReplaceVectorStringN = instructionVectorReplaceVectorN vectorString + +-- |Removes the first occurrence of the top string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. +instructionVectorStringRemoveFirst :: State -> State +instructionVectorStringRemoveFirst = instructionVectorRemove string vectorString (Just 1) + +-- |Removes the all occurrences of the top string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. +instructionVectorStringRemoveAll :: State -> State +instructionVectorStringRemoveAll = instructionVectorRemove string vectorString Nothing + +-- |Removes N occurrences of the top string from +-- the string stack inside of the top string vector from the vector string stack. +-- Pushes the modified string vector to the vector string stack. N is pulled +-- from the top of the int stack. +instructionVectorStringRemoveN :: State -> State +instructionVectorStringRemoveN = instructionVectorRemoveN string vectorString + +-- |Removes the first occurrence of the second string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. +instructionVectorStringRemoveFirstVectorString :: State -> State +instructionVectorStringRemoveFirstVectorString = instructionVectorRemoveVector vectorString (Just 1) + +-- |Removes all occurrences of the second string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. +instructionVectorStringRemoveAllVectorString :: State -> State +instructionVectorStringRemoveAllVectorString = instructionVectorRemoveVector vectorString Nothing + +-- |Removes N occurrences of the second string vector +-- inside of the first string vector from the vector string stack. Pushes the result to the +-- vector string stack. N is pulled from the top of the int stack. +instructionVectorStringRemoveNVectorString :: State -> State +instructionVectorStringRemoveNVectorString = instructionVectorRemoveVectorN vectorString + +-- |Iterates over the top string vector on the vector string stack, applying the top instruction of the +-- exec stack along the way. +instructionVectorStringIterate :: State -> State +instructionVectorStringIterate = instructionVectorIterate string vectorString GeneVectorString instructionVectorStringIterate "instructionVectorStringIterate" + +-- |Sorts the top string vector on the vector string stack and pushes the result back to the +-- vector string stack. instructionVectorStringSort :: State -> State instructionVectorStringSort = instructionVectorSort vectorString +-- |Sorts the top string vector on the vector string stack, reverses it, and pushes the result back to the +-- vector string stack. instructionVectorStringSortReverse :: State -> State instructionVectorStringSortReverse = instructionVectorSortReverse vectorString -instructionVectorStringDupItems :: State -> State -instructionVectorStringDupItems = instructionDupItems vectorString +-- |Inserts the top string from the string stack into the top string vector from the +-- vector string stack at a specified index and pushes the result to the vector +-- string stack. The index is pulled from the top of the int stack. +instructionVectorStringInsert :: State -> State +instructionVectorStringInsert = instructionVectorInsert string vectorString + +-- |Inserts the second string vector into the first string vector from the vector string stack +-- at a specified index and pushes the result to the vector string stack. The index is +-- pulled from the top of the int stack. +instructionVectorStringInsertVectorString :: State -> State +instructionVectorStringInsertVectorString = instructionVectorInsertVector vectorString diff --git a/src/HushGP/Push.hs b/src/HushGP/Push.hs index 1c9b75f..f243be5 100644 --- a/src/HushGP/Push.hs +++ b/src/HushGP/Push.hs @@ -12,7 +12,7 @@ import HushGP.State -- Everntually, this can be part of the apply func to state helpers, -- which should take the number and type of parameter they have. --- This is one of the push genome functions itself, not infrastructure. +-- |This is one of the push genome functions itself, not infrastructure. -- Optionally, split this off into independent functions instructionParameterLoad :: State -> State instructionParameterLoad state@(State {_parameter = (p : _)}) = case p of @@ -32,11 +32,11 @@ instructionParameterLoad state@(State {_parameter = (p : _)}) = case p of (Block xs) -> state & exec .~ xs <> view exec state instructionParameterLoad state = state --- Loads a genome into the exec stack +-- |Loads a genome into the exec stack loadProgram :: [Gene] -> State -> State loadProgram newstack state = state & exec .~ newstack --- Takes a Push state, and generates the next push state via: +-- |Takes a Push state, and generates the next push state via: -- If the first item on the EXEC stack is a single instruction -- then pop it and execute it. -- Else if the first item on the EXEC stack is a literal @@ -64,23 +64,3 @@ interpretExec state@(State {_exec = e : es}) = (PlaceInput val) -> interpretExec (state {_exec = (view input state Map.! val) : es}) Close -> undefined -- This should be removed later. Will be converted to Blocks in the Plushy -> Exec stack process interpretExec state = state - --- interpretOneStep :: State -> State --- interpretOneStep state@(State {_exec = e : es}) = --- case e of --- (GeneInt val) -> state & exec .~ es & int .~ val : view int state --- (GeneFloat val) -> state & exec .~ es & float .~ val : view float state --- (GeneBool val) -> state & exec .~ es & bool .~ val : view bool state --- (GeneString val) -> state & exec .~ es & string .~ val : view string state --- (GeneChar val) -> state & exec .~ es & char .~ val : view char state --- (GeneVectorInt val) -> state & exec .~ es & vectorInt .~ val : view vectorInt state --- (GeneVectorFloat val) -> state & exec .~ es & vectorFloat .~ val : view vectorFloat state --- (GeneVectorBool val) -> state & exec .~ es & vectorBool .~ val : view vectorBool state --- (GeneVectorString val) -> state & exec .~ es & vectorString .~ val : view vectorString state --- (GeneVectorChar val) -> state & exec .~ es & vectorChar .~ val : view vectorChar state --- (StateFunc (func, _)) -> func state {_exec = es} --- (Block block) -> (state {_exec = block ++ es}) --- (PlaceInput val) -> (state {_exec = (view input state Map.! val) : es}) --- Close -> undefined --- interpretOneStep state = state --- Need to make interpretExec strict, right? diff --git a/src/HushGP/State.hs b/src/HushGP/State.hs index acccbc2..62afec4 100644 --- a/src/HushGP/State.hs +++ b/src/HushGP/State.hs @@ -8,7 +8,7 @@ import Data.Map qualified as Map import GHC.Generics import Test.QuickCheck --- The exec stack must store heterogenous types, +-- |The exec stack must store heterogenous types, -- and we must be able to detect that type at runtime. -- One solution is for the exec stack to be a list of [Gene]. -- The parameter stack could be singular [Gene] or multiple [atomic] types. @@ -83,6 +83,7 @@ instance Arbitrary Gene where return Close ] +-- |The structure that holds all of the values. data State = State { _exec :: [Gene], _code :: [Gene],