diff --git a/HushGP.cabal b/HushGP.cabal index 49c8ce5..1d128fd 100644 --- a/HushGP.cabal +++ b/HushGP.cabal @@ -28,7 +28,7 @@ category: Data build-type: Simple common warnings - ghc-options: -Wall + ghc-options: -Wall -XTemplateHaskell library -- Import common warning flags. @@ -57,6 +57,7 @@ library , HushGP.PushTests.IntTests , HushGP.PushTests.GenericTests , HushGP.PushTests.UtilTests + , HushGP.TH -- Modules included in this library but not exported. -- other-modules: @@ -66,7 +67,7 @@ library -- Other library packages from which modules are imported. build-depends: - base, containers, lens, split, QuickCheck + base, containers, lens, split, QuickCheck, regex-tdfa, template-haskell -- Directories containing source files. hs-source-dirs: src diff --git a/TODO.md b/TODO.md index b7d6c54..2561fd5 100644 --- a/TODO.md +++ b/TODO.md @@ -14,7 +14,7 @@ - [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 the generic functions -~~[ ] Use template haskell to generate function lists~~ +- [X] Use template haskell to generate function lists - [X] Move utility functions to their own file - [ ] Make add/sub/mult/div/mod instructions generic diff --git a/src/HushGP/Instructions.hs b/src/HushGP/Instructions.hs index fcc9be3..6a8859d 100644 --- a/src/HushGP/Instructions.hs +++ b/src/HushGP/Instructions.hs @@ -12,18 +12,6 @@ module HushGP.Instructions module HushGP.Instructions.VectorStringInstructions, module HushGP.Instructions.VectorBoolInstructions, module HushGP.Instructions.VectorCharInstructions, - allIntInstructions, - allFloatInstructions, - allBoolInstructions, - allCharInstructions, - allCodeInstructions, - allExecInstructions, - allStringInstructions, - allVectorIntInstructions, - allVectorFloatInstructions, - allVectorCharInstructions, - allVectorStringInstructions, - allVectorBoolInstructions, allInstructions, ) where @@ -43,643 +31,7 @@ import HushGP.Instructions.VectorIntInstructions import HushGP.Instructions.VectorStringInstructions import HushGP.State -allIntInstructions :: [Gene] -allIntInstructions = - map - StateFunc - [ (instructionIntFromFloat, "instructionIntFromFloat"), - (instructionIntFromBool, "instructionIntFromBool"), - (instructionIntAdd, "instructionIntAdd"), - (instructionIntSub, "instructionIntSub"), - (instructionIntMul, "instructionIntMul"), - (instructionIntDiv, "instructionIntDiv"), - (instructionIntMod, "instructionIntMod"), - (instructionIntMin, "instructionIntMin"), - (instructionIntMax, "instructionIntMax"), - (instructionIntInc, "instructionIntInc"), - (instructionIntDec, "instructionIntDec"), - (instructionIntLT, "instructionIntLT"), - (instructionIntGT, "instructionIntGT"), - (instructionIntLTE, "instructionIntLTE"), - (instructionIntGTE, "instructionIntGTE"), - (instructionIntDup, "instructionIntDup"), - (instructionIntPop, "instructionIntPop"), - (instructionIntDupN, "instructionIntDupN"), - (instructionIntSwap, "instructionIntSwap"), - (instructionIntRot, "instructionIntRot"), - (instructionIntFlush, "instructionIntFlush"), - (instructionIntEq, "instructionIntEq"), - (instructionIntYank, "instructionIntYank"), - (instructionIntYankDup, "instructionIntYankDup"), - (instructionIntShove, "instructionIntShove"), - (instructionIntIsStackEmpty, "instructionIntIsStackEmpty"), - (instructionIntFromChar, "instructionIntFromChar"), - (instructionIntFromString, "instructionIntFromString"), - (instructionIntDupItems, "instructionIntDupItems") - ] - -allFloatInstructions :: [Gene] -allFloatInstructions = - map - StateFunc - [ (instructionFloatFromInt, "instructionFloatFromInt"), - (instructionFloatFromBool, "instructionFloatFromBool"), - (instructionFloatAdd, "instructionFloatAdd"), - (instructionFloatSub, "instructionFloatSub"), - (instructionFloatMul, "instructionFloatMul"), - (instructionFloatDiv, "instructionFloatDiv"), - (instructionFloatMod, "instructionFloatMod"), - (instructionFloatMin, "instructionFloatMin"), - (instructionFloatMax, "instructionFloatMax"), - (instructionFloatInc, "instructionFloatInc"), - (instructionFloatDec, "instructionFloatDec"), - (instructionFloatLT, "instructionFloatLT"), - (instructionFloatGT, "instructionFloatGT"), - (instructionFloatLTE, "instructionFloatLTE"), - (instructionFloatGTE, "instructionFloatGTE"), - (instructionFloatDup, "instructionFloatDup"), - (instructionFloatPop, "instructionFloatPop"), - (instructionFloatDupN, "instructionFloatDupN"), - (instructionFloatSwap, "instructionFloatSwap"), - (instructionFloatRot, "instructionFloatRot"), - (instructionFloatFlush, "instructionFloatFlush"), - (instructionFloatEq, "instructionFloatEq"), - (instructionFloatYank, "instructionFloatYank"), - (instructionFloatYankDup, "instructionFloatYankDup"), - (instructionFloatShove, "instructionFloatShove"), - (instructionFloatIsStackEmpty, "instructionFloatIsStackEmpty"), - (instructionFloatFromChar, "instructionFloatFromChar"), - (instructionFloatFromString, "instructionFloatFromString"), - (instructionFloatDupItems, "instructionFloatDupItems") - ] - -allBoolInstructions :: [Gene] -allBoolInstructions = - map - StateFunc - [ (instructionBoolFromInt, "instructionBoolFromInt"), - (instructionBoolFromFloat, "instructionBoolFromFloat"), - (instructionBoolAnd, "instructionBoolAnd"), - (instructionBoolInvertFirstThenAnd, "instructionBoolInvertFirstThenAnd"), - (instructionBoolInvertSecondThenAnd, "instructionBoolInvertSecondThenAnd"), - (instructionBoolOr, "instructionBoolOr"), - (instructionBoolXor, "instructionBoolXor"), - (instructionBoolPop, "instructionBoolPop"), - (instructionBoolDup, "instructionBoolDup"), - (instructionBoolDupN, "instructionBoolDupN"), - (instructionBoolSwap, "instructionBoolSwap"), - (instructionBoolRot, "instructionBoolRot"), - (instructionBoolFlush, "instructionBoolFlush"), - (instructionBoolEq, "instructionBoolEq"), - (instructionBoolStackDepth, "instructionBoolStackDepth"), - (instructionBoolYank, "instructionBoolYank"), - (instructionBoolYankDup, "instructionBoolYankDup"), - (instructionBoolShove, "instructionBoolShove"), - (instructionBoolShoveDup, "instructionBoolShoveDup"), - (instructionBoolIsStackEmpty, "instructionBoolIsStackEmpty"), - (instructionBoolDupItems, "instructionBoolDupItems") - ] - -allCharInstructions :: [Gene] -allCharInstructions = - map - StateFunc - [ (instructionCharConcat, "instructionCharConcat"), - (instructionCharFromFirstChar, "instructionCharFromFirstChar"), - (instructionCharFromLastChar, "instructionCharFromLastChar"), - (instructionCharFromNthChar, "instructionCharFromNthChar"), - (instructionCharIsWhitespace, "instructionCharIsWhitespace"), - (instructionCharIsLetter, "instructionCharIsLetter"), - (instructionCharIsDigit, "instructionCharIsDigit"), - (instructionCharFromBool, "instructionCharFromBool"), - (instructionCharFromAsciiInt, "instructionCharFromAsciiInt"), - (instructionCharFromAsciiFloat, "instructionCharFromAsciiFloat"), - (instructionCharsFromString, "instructionCharsFromString"), - (instructionCharPop, "instructionCharPop"), - (instructionCharDup, "instructionCharDup"), - (instructionCharDupN, "instructionCharDupN"), - (instructionCharSwap, "instructionCharSwap"), - (instructionCharRot, "instructionCharRot"), - (instructionCharFlush, "instructionCharFlush"), - (instructionCharEq, "instructionCharEq"), - (instructionCharStackDepth, "instructionCharStackDepth"), - (instructionCharYank, "instructionCharYank"), - (instructionCharYankDup, "instructionCharYankDup"), - (instructionCharShove, "instructionCharShove"), - (instructionCharShoveDup, "instructionCharShoveDup"), - (instructionCharIsStackEmpty, "instructionCharIsStackEmpty"), - (instructionCharDupItems, "instructionCharDupItems") - ] - -allCodeInstructions :: [Gene] -allCodeInstructions = - map - StateFunc - [ (instructionCodePop, "instructionCodePop"), - (instructionCodeIsCodeBlock, "instructionCodeIsCodeBlock"), - (instructionCodeIsSingular, "instructionCodeIsSingular"), - (instructionCodeLength, "instructionCodeLength"), - (instructionCodeFirst, "instructionCodeFirst"), - (instructionCodeLast, "instructionCodeLast"), - (instructionCodeTail, "instructionCodeTail"), - (instructionCodeInit, "instructionCodeInit"), - (instructionCodeWrap, "instructionCodeWrap"), - (instructionCodeList, "instructionCodeList"), - (instructionCodeCombine, "instructionCodeCombine"), - (instructionCodeDo, "instructionCodeDo"), - (instructionCodeDoDup, "instructionCodeDoDup"), - (instructionCodeDoThenPop, "instructionCodeDoThenPop"), - (instructionCodeDoRange, "instructionCodeDoRange"), - (instructionCodeDoCount, "instructionCodeDoCount"), - (instructionCodeDoTimes, "instructionCodeDoTimes"), - (instructionCodeIf, "instructionCodeIf"), - (instructionCodeWhen, "instructionCodeWhen"), - (instructionCodeMember, "instructionCodeMember"), - (instructionCodeN, "instructionCodeN"), - (instructionMakeEmptyCodeBlock, "instructionMakeEmptyCodeBlock"), - (instructionIsEmptyCodeBlock, "instructionIsEmptyCodeBlock"), - (instructionCodeSize, "instructionCodeSize"), - (instructionCodeExtract, "instructionCodeExtract"), - (instructionCodeInsert, "instructionCodeInsert"), - (instructionCodeFirstPosition, "instructionCodeFirstPosition"), - (instructionCodeReverse, "instructionCodeReverse"), - (instructionCodeDup, "instructionCodeDup"), - (instructionCodeDupN, "instructionCodeDupN"), - (instructionCodeDup, "instructionCodeDup"), - (instructionCodeDupN, "instructionCodeDupN"), - (instructionCodeSwap, "instructionCodeSwap"), - (instructionCodeRot, "instructionCodeRot"), - (instructionCodeFlush, "instructionCodeFlush"), - (instructionCodeEq, "instructionCodeEq"), - (instructionCodeStackDepth, "instructionCodeStackDepth"), - (instructionCodeYank, "instructionCodeYank"), - (instructionCodeYankDup, "instructionCodeYankDup"), - (instructionCodeShove, "instructionCodeShove"), - (instructionCodeShoveDup, "instructionCodeShoveDup"), - (instructionCodeIsStackEmpty, "instructionCodeIsStackEmpty"), - (instructionCodeFromBool, "instructionCodeFromBool"), - (instructionCodeFromInt, "instructionCodeFromInt"), - (instructionCodeFromChar, "instructionCodeFromChar"), - (instructionCodeFromFloat, "instructionCodeFromFloat"), - (instructionCodeFromString, "instructionCodeFromString"), - (instructionCodeFromVectorInt, "instructionCodeFromVectorInt"), - (instructionCodeFromVectorFloat, "instructionCodeFromVectorFloat"), - (instructionCodeFromVectorString, "instructionCodeFromVectorString"), - (instructionCodeFromVectorBool, "instructionCodeFromVectorBool"), - (instructionCodeFromVectorChar, "instructionCodeFromVectorChar"), - (instructionCodeFromExec, "instructionCodeFromExec"), - (instructionCodeContainer, "instructionCodeContainer"), - (instructionCodeDiscrepancy, "instructionCodeDiscrepancy"), - (instructionCodeNoOp, "instructionCodeNoOp"), - (instructionCodeTailN, "instructionCodeTailN"), - (instructionCodeDupItems, "instructionCodeDupItems") - ] - -allExecInstructions :: [Gene] -allExecInstructions = - map - StateFunc - [ (instructionExecIf, "instructionExecIf"), - (instructionExecDup, "instructionExecDup"), - (instructionExecDupN, "instructionExecDupN"), - (instructionExecPop, "instructionExecPop"), - (instructionExecSwap, "instructionExecSwap"), - (instructionExecRot, "instructionExecRot"), - (instructionExecFlush, "instructionExecFlush"), - (instructionExecEq, "instructionExecEq"), - (instructionExecStackDepth, "instructionExecStackDepth"), - (instructionExecYank, "instructionExecYank"), - (instructionExecYankDup, "instructionExecYankDup"), - (instructionExecShove, "instructionExecShove"), - (instructionExecShoveDup, "instructionExecShoveDup"), - (instructionExecIsStackEmpty, "instructionExecIsStackEmpty"), - (instructionExecDoRange, "instructionExecDoRange"), - (instructionExecDoCount, "instructionExecDoCount"), - (instructionExecDoTimes, "instructionExecDoTimes"), - (instructionExecWhile, "instructionExecWhile"), - (instructionExecDoWhile, "instructionExecDoWhile"), - (instructionExecWhen, "instructionExecWhen"), - (instructionExecK, "instructionExecK"), - (instructionExecS, "instructionExecS"), - (instructionExecY, "instrucitonExecY"), - (instructionExecDupItems, "instructionExecDupItems") - ] - -allStringInstructions :: [Gene] -allStringInstructions = - map - StateFunc - [ (instructionStringConcat, "instructionStringConcat"), - (instructionStringSwap, "instructionStringSwap"), - (instructionStringInsertString, "instructionStringInsertString"), - (instructionStringFromFirstChar, "instructionStringFromFirstChar"), - (instructionStringFromLastChar, "instructionStringFromLastChar"), - (instructionStringFromNthChar, "instructionStringFromNthChar"), - (instructionStringIndexOfString, "instructionStringIndexOfString"), - (instructionStringContainsString, "instructionStringContainsString"), - (instructionStringSplitOnString, "instructionStringSplitOnString"), - (instructionStringReplaceFirstString, "instructionStringReplaceFirstString"), - (instructionStringReplaceNString, "instructionStringReplaceNString"), - (instructionStringReplaceAllString, "instructionStringReplaceAllString"), - (instructionStringRemoveFirstString, "instructionStringRemoveFirstString"), - (instructionStringRemoveNString, "instructionStringRemoveNString"), - (instructionStringRemoveAllString, "instructionStringRemoveAllString"), - (instructionStringOccurrencesOfString, "instructionStringOccurrencesOfString"), - (instructionStringInsertChar, "instructionStringInsertChar"), - (instructionStringContainsChar, "instructionStringContainsChar"), - (instructionStringIndexOfChar, "instructionStringIndexOfChar"), - (instructionStringSplitOnChar, "instructionStringSplitOnChar"), - (instructionStringReplaceFirstChar, "instructionStringReplaceFirstChar"), - (instructionStringReplaceNChar, "instructionStringReplaceNChar"), - (instructionStringReplaceAllChar, "instructionStringReplaceAllChar"), - (instructionStringRemoveFirstChar, "instructionStringRemoveFirstChar"), - (instructionStringRemoveNChar, "instructionStringRemoveNChar"), - (instructionStringRemoveAllChar, "instructionStringRemoveAllChar"), - (instructionStringOccurrencesOfChar, "instructionStringOccurrencesOfChar"), - (instructionStringReverse, "instructionStringReverse"), - (instructionStringHead, "instructionStringHead"), - (instructionStringTail, "instructionStringTail"), - (instructionStringPrependChar, "instructionStringPrependChar"), - (instructionStringAppendChar, "instructionStringAppendChar"), - (instructionStringRest, "instructionStringRest"), - (instructionStringButLast, "instructionStringButLast"), - (instructionStringDrop, "instructionStringDrop"), - (instructionStringButLastN, "instructionStringButLastN"), - (instructionStringLength, "instructionStringLength"), - (instructionStringMakeEmpty, "instructionStringMakeEmpty"), - (instructionStringIsEmptyString, "instructionStringIsEmptyString"), - (instructionStringRemoveNth, "instructionStringRemoveNth"), - (instructionStringSetNth, "instructionStringSetNth"), - (instructionStringStripWhitespace, "instructionStringStripWhitespace"), - (instructionStringFromBool, "instructionStringFromBool"), - (instructionStringFromInt, "instructionStringFromInt"), - (instructionStringFromFloat, "instructionStringFromFloat"), - (instructionStringFromChar, "instructionStringFromChar"), - (instructionStringPop, "instructionStringPop"), - (instructionStringDup, "instructionStringDup"), - (instructionStringDupN, "instructionStringDupN"), - (instructionStringSwap, "instructionStringSwap"), - (instructionStringRot, "instructionStringRot"), - (instructionStringFlush, "instructionStringFlush"), - (instructionStringEq, "instructionStringEq"), - (instructionStringStackDepth, "instructionStringStackDepth"), - (instructionStringYank, "instructionStringYank"), - (instructionStringYankDup, "instructionStringYankDup"), - (instructionStringShove, "instructionStringShove"), - (instructionStringShoveDup, "instructionStringShoveDup"), - (instructionStringIsStackEmpty, "instructionStringIsStackEmpty"), - (instructionStringSort, "instructionStringSort"), - (instructionStringSortReverse, "instructionStringSortReverse"), - (instructionStringDupItems, "instructionStringDupItems"), - (instructionStringParseToChar, "instructionStringParseToChar"), - (instructionStringSubString, "instructionStringSubString") - ] - -allVectorIntInstructions :: [Gene] -allVectorIntInstructions = - map - StateFunc - [ (instructionVectorIntConcat, "instructionVectorIntConcat"), - (instructionVectorIntConj, "instructionVectorIntConj"), - (instructionVectorIntConjEnd, "instructionVectorIntConjEnd"), - (instructionVectorIntTakeN, "instructionVectorIntTakeN"), - (instructionVectorIntSubVector, "instructionVectorIntSubVector"), - (instructionVectorIntFirst, "instructionVectorIntFirst"), - (instructionVectorIntFromFirstPrim, "instructionVectorFirstFromPrim"), - (instructionVectorIntFromPrim, "instructionVectorFromPrim"), - (instructionVectorIntLast, "instructionVectorIntLast"), - (instructionVectorIntFromLastPrim, "instructionVectorIntFromLastPrim"), - (instructionVectorIntNth, "instructionVectorIntNth"), - (instructionVectorIntFromNthPrim, "instructionVectorIntFromNthPrim"), - (instructionVectorIntRest, "instructionVectorIntRest"), - (instructionVectorIntButLast, "instructionVectorIntButLast"), - (instructionVectorIntDrop, "instructionVectorIntDrop"), - (instructionVectorIntDropR, "instructionVectorIntDropR"), - (instructionVectorIntLength, "instructionVectorIntLength"), - (instructionVectorIntReverse, "instructionVectorIntReverse"), - (instructionVectorIntPushAll, "instructionVectorIntPushAll"), - (instructionVectorIntMakeEmpty, "instructionVectorIntMakeEmpty"), - (instructionVectorIntIsEmpty, "instructionVectorIntIsEmpty"), - (instructionVectorIntContains, "instructionVectorIntContains"), - (instructionVectorIntContainsVectorInt, "instructionVectorIntContainsVectorInt"), - (instructionVectorIntIndexOf, "instructionVectorIntIndexOf"), - (instructionVectorIntIndexOfVectorInt, "instructionVectorIntIndexOfVectorInt"), - (instructionVectorIntOccurrencesOf, "instructionVectorIntOccurrencesOf"), - (instructionVectorIntOccurrencesOfVectorInt, "instructionVectorIntOccurrencesOfVectorInt"), - (instructionVectorIntParseToInt, "instructionVectorIntParseToInt"), - (instructionVectorIntSetNth, "instructionVectorIntSetNth"), - (instructionVectorIntSplitOn, "instructionVectorIntSplitOn"), - (instructionVectorIntSplitOnVectorInt, "instructionVectorIntSplitOnVectorInt"), - (instructionVectorIntReplaceFirst, "instructionVectorIntReplaceFirst"), - (instructionVectorIntReplaceN, "instructionVectorIntReplaceN"), - (instructionVectorIntReplaceAll, "instructionVectorIntReplaceAll"), - (instructionVectorIntReplaceFirstVectorInt, "instructionVectorIntReplaceFirstVectorInt"), - (instructionVectorIntReplaceVectorIntN, "instructionVectorIntReplaceVectorIntN"), - (instructionVectorIntReplaceAllVectorInt, "instructionVectorIntReplaceAllVectorInt"), - (instructionVectorIntRemoveFirst, "instructionVectorIntRemoveFirst"), - (instructionVectorIntRemoveN, "instructionVectorIntRemoveN"), - (instructionVectorIntRemoveAll, "instructionVectorIntRemoveAll"), - (instructionVectorIntRemoveFirstVectorInt, "instructionVectorIntRemoveFirstVectorInt"), - (instructionVectorIntRemoveNVectorInt, "instructionVectorIntRemoveNVectorInt"), - (instructionVectorIntRemoveAllVectorInt, "instructionVectorIntRemoveAllVectorInt"), - (instructionVectorIntIterate, "instructionVectorIntIterate"), - (instructionVectorIntInsert, "instructionVectorIntInsert"), - (instructionVectorIntInsertVectorInt, "instructionVectorIntInsertVectorInt"), - (instructionVectorIntPop, "instructionVectorIntPop"), - (instructionVectorIntDup, "instructionVectorIntDup"), - (instructionVectorIntDupN, "instructionVectorIntDupN"), - (instructionVectorIntSwap, "instructionVectorIntSwap"), - (instructionVectorIntRot, "instructionVectorIntRot"), - (instructionVectorIntFlush, "instructionVectorIntFlush"), - (instructionVectorIntEq, "instructionVectorIntEq"), - (instructionVectorIntStackDepth, "instructionVectorIntStackDepth"), - (instructionVectorIntYank, "instructionVectorIntYank"), - (instructionVectorIntYankDup, "instructionVectorIntYankDup"), - (instructionVectorIntShove, "instructionVectorIntShove"), - (instructionVectorIntShoveDup, "instructionVectorIntShoveDup"), - (instructionVectorIntDupItems, "intsructionVectorIntDupItems"), - (instructionVectorIntIsStackEmpty, "instructionVectorIntIsStackEmpty"), - (instructionVectorIntSort, "instructionVectorIntSort"), - (instructionVectorIntSortReverse, "instructionVectorIntSortReverse"), - (instructionVectorIntDupItems, "instructionVectorIntDupItems") - ] - -allVectorFloatInstructions :: [Gene] -allVectorFloatInstructions = - map - StateFunc - [ (instructionVectorFloatConcat, "instructionVectorFloatConcat"), - (instructionVectorFloatConj, "instructionVectorFloatConj"), - (instructionVectorFloatConjEnd, "instructionVectorFloatConjEnd"), - (instructionVectorFloatTakeN, "instructionVectorFloatTakeN"), - (instructionVectorFloatSubVector, "instructionVectorFloatSubVector"), - (instructionVectorFloatFirst, "instructionVectorFloatFirst"), - (instructionVectorFloatFromFirstPrim, "instructionVectorFirstFromPrim"), - (instructionVectorFloatFromPrim, "instructionVectorFromPrim"), - (instructionVectorFloatLast, "instructionVectorFloatLast"), - (instructionVectorFloatFromLastPrim, "instructionVectorFloatFromLastPrim"), - (instructionVectorFloatNth, "instructionVectorFloatNth"), - (instructionVectorFloatFromNthPrim, "instructionVectorFloatFromNthPrim"), - (instructionVectorFloatRest, "instructionVectorFloatRest"), - (instructionVectorFloatButLast, "instructionVectorFloatButLast"), - (instructionVectorFloatDrop, "instructionVectorFloatDrop"), - (instructionVectorFloatDropR, "instructionVectorFloatDropR"), - (instructionVectorFloatLength, "instructionVectorFloatLength"), - (instructionVectorFloatReverse, "instructionVectorFloatReverse"), - (instructionVectorFloatPushAll, "instructionVectorFloatPushAll"), - (instructionVectorFloatMakeEmpty, "instructionVectorFloatMakeEmpty"), - (instructionVectorFloatIsEmpty, "instructionVectorFloatIsEmpty"), - (instructionVectorFloatContains, "instructionVectorFloatContains"), - (instructionVectorFloatContainsVectorFloat, "instructionVectorFloatContainsVectorFloat"), - (instructionVectorFloatIndexOf, "instructionVectorFloatIndexOf"), - (instructionVectorFloatIndexOfVectorFloat, "instructionVectorFloatIndexOfVectorFloat"), - (instructionVectorFloatOccurrencesOf, "instructionVectorFloatOccurrencesOf"), - (instructionVectorFloatOccurrencesOfVectorFloat, "instructionVectorFloatOccurrencesOfVectorFloat"), - (instructionVectorFloatParseToFloat, "instructionVectorFloatParseToFloat"), - (instructionVectorFloatSetNth, "instructionVectorFloatSetNth"), - (instructionVectorFloatSplitOn, "instructionVectorFloatSplitOn"), - (instructionVectorFloatSplitOnVectorFloat, "instructionVectorFloatSplitOnVectorFloat"), - (instructionVectorFloatReplaceFirst, "instructionVectorFloatReplaceFirst"), - (instructionVectorFloatReplaceN, "instructionVectorFloatReplaceN"), - (instructionVectorFloatReplaceAll, "instructionVectorFloatReplaceAll"), - (instructionVectorFloatReplaceFirstVectorFloat, "instructionVectorFloatReplaceFirstVectorFloat"), - (instructionVectorFloatReplaceVectorFloatN, "instructionVectorFloatReplaceVectorFloatN"), - (instructionVectorFloatReplaceAllVectorFloat, "instructionVectorFloatReplaceAllVectorFloat"), - (instructionVectorFloatRemoveFirst, "instructionVectorFloatRemoveFirst"), - (instructionVectorFloatRemoveN, "instructionVectorFloatRemoveN"), - (instructionVectorFloatRemoveAll, "instructionVectorFloatRemoveAll"), - (instructionVectorFloatRemoveFirstVectorFloat, "instructionVectorFloatRemoveFirstVectorFloat"), - (instructionVectorFloatRemoveNVectorFloat, "instructionVectorFloatRemoveNVectorFloat"), - (instructionVectorFloatRemoveAllVectorFloat, "instructionVectorFloatRemoveAllVectorFloat"), - (instructionVectorFloatIterate, "instructionVectorFloatIterate"), - (instructionVectorFloatInsert, "instructionVectorFloatInsert"), - (instructionVectorFloatInsertVectorFloat, "instructionVectorFloatInsertVectorFloat"), - (instructionVectorFloatPop, "instructionVectorFloatPop"), - (instructionVectorFloatDup, "instructionVectorFloatDup"), - (instructionVectorFloatDupN, "instructionVectorFloatDupN"), - (instructionVectorFloatSwap, "instructionVectorFloatSwap"), - (instructionVectorFloatRot, "instructionVectorFloatRot"), - (instructionVectorFloatFlush, "instructionVectorFloatFlush"), - (instructionVectorFloatEq, "instructionVectorFloatEq"), - (instructionVectorFloatStackDepth, "instructionVectorFloatStackDepth"), - (instructionVectorFloatYank, "instructionVectorFloatYank"), - (instructionVectorFloatYankDup, "instructionVectorFloatYankDup"), - (instructionVectorFloatShove, "instructionVectorFloatShove"), - (instructionVectorFloatShoveDup, "instructionVectorFloatShoveDup"), - (instructionVectorFloatDupItems, "intsructionVectorFloatDupItems"), - (instructionVectorFloatIsStackEmpty, "instructionVectorFloatIsStackEmpty"), - (instructionVectorFloatSort, "instructionVectorFloatSort"), - (instructionVectorFloatSortReverse, "instructionVectorFloatSortReverse"), - (instructionVectorFloatDupItems, "instructionVectorFloatDupItems") - ] - -allVectorCharInstructions :: [Gene] -allVectorCharInstructions = - map - StateFunc - [ (instructionVectorCharConcat, "instructionVectorCharConcat"), - (instructionVectorCharConj, "instructionVectorCharConj"), - (instructionVectorCharConjEnd, "instructionVectorCharConjEnd"), - (instructionVectorCharTakeN, "instructionVectorCharTakeN"), - (instructionVectorCharSubVector, "instructionVectorCharSubVector"), - (instructionVectorCharFirst, "instructionVectorCharFirst"), - (instructionVectorCharFromFirstPrim, "instructionVectorFirstFromPrim"), - (instructionVectorCharFromPrim, "instructionVectorFromPrim"), - (instructionVectorCharLast, "instructionVectorCharLast"), - (instructionVectorCharFromLastPrim, "instructionVectorCharFromLastPrim"), - (instructionVectorCharNth, "instructionVectorCharNth"), - (instructionVectorCharFromNthPrim, "instructionVectorCharFromNthPrim"), - (instructionVectorCharRest, "instructionVectorCharRest"), - (instructionVectorCharButLast, "instructionVectorCharButLast"), - (instructionVectorCharDrop, "instructionVectorCharDrop"), - (instructionVectorCharDropR, "instructionVectorCharDropR"), - (instructionVectorCharLength, "instructionVectorCharLength"), - (instructionVectorCharReverse, "instructionVectorCharReverse"), - (instructionVectorCharPushAll, "instructionVectorCharPushAll"), - (instructionVectorCharMakeEmpty, "instructionVectorCharMakeEmpty"), - (instructionVectorCharIsEmpty, "instructionVectorCharIsEmpty"), - (instructionVectorCharContains, "instructionVectorCharContains"), - (instructionVectorCharContainsVectorChar, "instructionVectorCharContainsVectorChar"), - (instructionVectorCharIndexOf, "instructionVectorCharIndexOf"), - (instructionVectorCharIndexOfVectorChar, "instructionVectorCharIndexOfVectorChar"), - (instructionVectorCharOccurrencesOf, "instructionVectorCharOccurrencesOf"), - (instructionVectorCharOccurrencesOfVectorChar, "instructionVectorCharOccurrencesOfVectorChar"), - (instructionVectorCharParseToChar, "instructionVectorCharParseToChar"), - (instructionVectorCharSetNth, "instructionVectorCharSetNth"), - (instructionVectorCharSplitOn, "instructionVectorCharSplitOn"), - (instructionVectorCharSplitOnVectorChar, "instructionVectorCharSplitOnVectorChar"), - (instructionVectorCharReplaceFirst, "instructionVectorCharReplaceFirst"), - (instructionVectorCharReplaceN, "instructionVectorCharReplaceN"), - (instructionVectorCharReplaceAll, "instructionVectorCharReplaceAll"), - (instructionVectorCharReplaceFirstVectorChar, "instructionVectorCharReplaceFirstVectorChar"), - (instructionVectorCharReplaceVectorCharN, "instructionVectorCharReplaceVectorCharN"), - (instructionVectorCharReplaceAllVectorChar, "instructionVectorCharReplaceAllVectorChar"), - (instructionVectorCharRemoveFirst, "instructionVectorCharRemoveFirst"), - (instructionVectorCharRemoveN, "instructionVectorCharRemoveN"), - (instructionVectorCharRemoveAll, "instructionVectorCharRemoveAll"), - (instructionVectorCharRemoveFirstVectorChar, "instructionVectorCharRemoveFirstVectorChar"), - (instructionVectorCharRemoveNVectorChar, "instructionVectorCharRemoveNVectorChar"), - (instructionVectorCharRemoveAllVectorChar, "instructionVectorCharRemoveAllVectorChar"), - (instructionVectorCharIterate, "instructionVectorCharIterate"), - (instructionVectorCharInsert, "instructionVectorCharInsert"), - (instructionVectorCharInsertVectorChar, "instructionVectorCharInsertVectorChar"), - (instructionVectorCharPop, "instructionVectorCharPop"), - (instructionVectorCharDup, "instructionVectorCharDup"), - (instructionVectorCharDupN, "instructionVectorCharDupN"), - (instructionVectorCharSwap, "instructionVectorCharSwap"), - (instructionVectorCharRot, "instructionVectorCharRot"), - (instructionVectorCharFlush, "instructionVectorCharFlush"), - (instructionVectorCharEq, "instructionVectorCharEq"), - (instructionVectorCharStackDepth, "instructionVectorCharStackDepth"), - (instructionVectorCharYank, "instructionVectorCharYank"), - (instructionVectorCharYankDup, "instructionVectorCharYankDup"), - (instructionVectorCharShove, "instructionVectorCharShove"), - (instructionVectorCharShoveDup, "instructionVectorCharShoveDup"), - (instructionVectorCharDupItems, "intsructionVectorCharDupItems"), - (instructionVectorCharIsStackEmpty, "instructionVectorCharIsStackEmpty"), - (instructionVectorCharSort, "instructionVectorCharSort"), - (instructionVectorCharSortReverse, "instructionVectorCharSortReverse"), - (instructionVectorCharDupItems, "instructionVectorCharDupItems") - ] - -allVectorStringInstructions :: [Gene] -allVectorStringInstructions = - map - StateFunc - [ (instructionVectorStringConcat, "instructionVectorStringConcat"), - (instructionVectorStringConj, "instructionVectorStringConj"), - (instructionVectorStringConjEnd, "instructionVectorStringConjEnd"), - (instructionVectorStringTakeN, "instructionVectorStringTakeN"), - (instructionVectorStringSubVector, "instructionVectorStringSubVector"), - (instructionVectorStringFirst, "instructionVectorStringFirst"), - (instructionVectorStringFromFirstPrim, "instructionVectorFirstFromPrim"), - (instructionVectorStringFromPrim, "instructionVectorFromPrim"), - (instructionVectorStringLast, "instructionVectorStringLast"), - (instructionVectorStringFromLastPrim, "instructionVectorStringFromLastPrim"), - (instructionVectorStringNth, "instructionVectorStringNth"), - (instructionVectorStringFromNthPrim, "instructionVectorStringFromNthPrim"), - (instructionVectorStringRest, "instructionVectorStringRest"), - (instructionVectorStringButLast, "instructionVectorStringButLast"), - (instructionVectorStringDrop, "instructionVectorStringDrop"), - (instructionVectorStringDropR, "instructionVectorStringDropR"), - (instructionVectorStringLength, "instructionVectorStringLength"), - (instructionVectorStringReverse, "instructionVectorStringReverse"), - (instructionVectorStringPushAll, "instructionVectorStringPushAll"), - (instructionVectorStringMakeEmpty, "instructionVectorStringMakeEmpty"), - (instructionVectorStringIsEmpty, "instructionVectorStringIsEmpty"), - (instructionVectorStringContains, "instructionVectorStringContains"), - (instructionVectorStringContainsVectorString, "instructionVectorStringContainsVectorString"), - (instructionVectorStringIndexOf, "instructionVectorStringIndexOf"), - (instructionVectorStringIndexOfVectorString, "instructionVectorStringIndexOfVectorString"), - (instructionVectorStringOccurrencesOf, "instructionVectorStringOccurrencesOf"), - (instructionVectorStringOccurrencesOfVectorString, "instructionVectorStringOccurrencesOfVectorString"), - (instructionVectorStringParseToString, "instructionVectorStringParseToString"), - (instructionVectorStringSetNth, "instructionVectorStringSetNth"), - (instructionVectorStringSplitOn, "instructionVectorStringSplitOn"), - (instructionVectorStringSplitOnVectorString, "instructionVectorStringSplitOnVectorString"), - (instructionVectorStringReplaceFirst, "instructionVectorStringReplaceFirst"), - (instructionVectorStringReplaceN, "instructionVectorStringReplaceN"), - (instructionVectorStringReplaceAll, "instructionVectorStringReplaceAll"), - (instructionVectorStringReplaceFirstVectorString, "instructionVectorStringReplaceFirstVectorString"), - (instructionVectorStringReplaceVectorStringN, "instructionVectorStringReplaceVectorStringN"), - (instructionVectorStringReplaceAllVectorString, "instructionVectorStringReplaceAllVectorString"), - (instructionVectorStringRemoveFirst, "instructionVectorStringRemoveFirst"), - (instructionVectorStringRemoveN, "instructionVectorStringRemoveN"), - (instructionVectorStringRemoveAll, "instructionVectorStringRemoveAll"), - (instructionVectorStringRemoveFirstVectorString, "instructionVectorStringRemoveFirstVectorString"), - (instructionVectorStringRemoveNVectorString, "instructionVectorStringRemoveNVectorString"), - (instructionVectorStringRemoveAllVectorString, "instructionVectorStringRemoveAllVectorString"), - (instructionVectorStringIterate, "instructionVectorStringIterate"), - (instructionVectorStringInsert, "instructionVectorStringInsert"), - (instructionVectorStringInsertVectorString, "instructionVectorStringInsertVectorString"), - (instructionVectorStringPop, "instructionVectorStringPop"), - (instructionVectorStringDup, "instructionVectorStringDup"), - (instructionVectorStringDupN, "instructionVectorStringDupN"), - (instructionVectorStringSwap, "instructionVectorStringSwap"), - (instructionVectorStringRot, "instructionVectorStringRot"), - (instructionVectorStringFlush, "instructionVectorStringFlush"), - (instructionVectorStringEq, "instructionVectorStringEq"), - (instructionVectorStringStackDepth, "instructionVectorStringStackDepth"), - (instructionVectorStringYank, "instructionVectorStringYank"), - (instructionVectorStringYankDup, "instructionVectorStringYankDup"), - (instructionVectorStringShove, "instructionVectorStringShove"), - (instructionVectorStringShoveDup, "instructionVectorStringShoveDup"), - (instructionVectorStringDupItems, "intsructionVectorStringDupItems"), - (instructionVectorStringIsStackEmpty, "instructionVectorStringIsStackEmpty"), - (instructionVectorStringSort, "instructionVectorStringSort"), - (instructionVectorStringSortReverse, "instructionVectorStringSortReverse"), - (instructionVectorStringDupItems, "instructionVectorStringDupItems") - ] - -allVectorBoolInstructions :: [Gene] -allVectorBoolInstructions = - map - StateFunc - [ (instructionVectorBoolConcat, "instructionVectorBoolConcat"), - (instructionVectorBoolConj, "instructionVectorBoolConj"), - (instructionVectorBoolConjEnd, "instructionVectorBoolConjEnd"), - (instructionVectorBoolTakeN, "instructionVectorBoolTakeN"), - (instructionVectorBoolSubVector, "instructionVectorBoolSubVector"), - (instructionVectorBoolFirst, "instructionVectorBoolFirst"), - (instructionVectorBoolFromFirstPrim, "instructionVectorFirstFromPrim"), - (instructionVectorBoolFromPrim, "instructionVectorFromPrim"), - (instructionVectorBoolLast, "instructionVectorBoolLast"), - (instructionVectorBoolFromLastPrim, "instructionVectorBoolFromLastPrim"), - (instructionVectorBoolNth, "instructionVectorBoolNth"), - (instructionVectorBoolFromNthPrim, "instructionVectorBoolFromNthPrim"), - (instructionVectorBoolRest, "instructionVectorBoolRest"), - (instructionVectorBoolButLast, "instructionVectorBoolButLast"), - (instructionVectorBoolDrop, "instructionVectorBoolDrop"), - (instructionVectorBoolDropR, "instructionVectorBoolDropR"), - (instructionVectorBoolLength, "instructionVectorBoolLength"), - (instructionVectorBoolReverse, "instructionVectorBoolReverse"), - (instructionVectorBoolPushAll, "instructionVectorBoolPushAll"), - (instructionVectorBoolMakeEmpty, "instructionVectorBoolMakeEmpty"), - (instructionVectorBoolIsEmpty, "instructionVectorBoolIsEmpty"), - (instructionVectorBoolContains, "instructionVectorBoolContains"), - (instructionVectorBoolContainsVectorBool, "instructionVectorBoolContainsVectorBool"), - (instructionVectorBoolIndexOf, "instructionVectorBoolIndexOf"), - (instructionVectorBoolIndexOfVectorBool, "instructionVectorBoolIndexOfVectorBool"), - (instructionVectorBoolOccurrencesOf, "instructionVectorBoolOccurrencesOf"), - (instructionVectorBoolOccurrencesOfVectorBool, "instructionVectorBoolOccurrencesOfVectorBool"), - (instructionVectorBoolParseToBool, "instructionVectorBoolParseToBool"), - (instructionVectorBoolSetNth, "instructionVectorBoolSetNth"), - (instructionVectorBoolSplitOn, "instructionVectorBoolSplitOn"), - (instructionVectorBoolSplitOnVectorBool, "instructionVectorBoolSplitOnVectorBool"), - (instructionVectorBoolReplaceFirst, "instructionVectorBoolReplaceFirst"), - (instructionVectorBoolReplaceN, "instructionVectorBoolReplaceN"), - (instructionVectorBoolReplaceAll, "instructionVectorBoolReplaceAll"), - (instructionVectorBoolReplaceFirstVectorBool, "instructionVectorBoolReplaceFirstVectorBool"), - (instructionVectorBoolReplaceVectorBoolN, "instructionVectorBoolReplaceVectorBoolN"), - (instructionVectorBoolReplaceAllVectorBool, "instructionVectorBoolReplaceAllVectorBool"), - (instructionVectorBoolRemoveFirst, "instructionVectorBoolRemoveFirst"), - (instructionVectorBoolRemoveN, "instructionVectorBoolRemoveN"), - (instructionVectorBoolRemoveAll, "instructionVectorBoolRemoveAll"), - (instructionVectorBoolRemoveFirstVectorBool, "instructionVectorBoolRemoveFirstVectorBool"), - (instructionVectorBoolRemoveNVectorBool, "instructionVectorBoolRemoveNVectorBool"), - (instructionVectorBoolRemoveAllVectorBool, "instructionVectorBoolRemoveAllVectorBool"), - (instructionVectorBoolIterate, "instructionVectorBoolIterate"), - (instructionVectorBoolInsert, "instructionVectorBoolInsert"), - (instructionVectorBoolInsertVectorBool, "instructionVectorBoolInsertVectorBool"), - (instructionVectorBoolPop, "instructionVectorBoolPop"), - (instructionVectorBoolDup, "instructionVectorBoolDup"), - (instructionVectorBoolDupN, "instructionVectorBoolDupN"), - (instructionVectorBoolSwap, "instructionVectorBoolSwap"), - (instructionVectorBoolRot, "instructionVectorBoolRot"), - (instructionVectorBoolFlush, "instructionVectorBoolFlush"), - (instructionVectorBoolEq, "instructionVectorBoolEq"), - (instructionVectorBoolStackDepth, "instructionVectorBoolStackDepth"), - (instructionVectorBoolYank, "instructionVectorBoolYank"), - (instructionVectorBoolYankDup, "instructionVectorBoolYankDup"), - (instructionVectorBoolShove, "instructionVectorBoolShove"), - (instructionVectorBoolShoveDup, "instructionVectorBoolShoveDup"), - (instructionVectorBoolDupItems, "intsructionVectorBoolDupItems"), - (instructionVectorBoolIsStackEmpty, "instructionVectorBoolIsStackEmpty"), - (instructionVectorBoolSort, "instructionVectorBoolSort"), - (instructionVectorBoolSortReverse, "instructionVectorBoolSortReverse"), - (instructionVectorBoolDupItems, "instructionVectorBoolDupItems") - ] - +-- | All of the instructions declared in all the instruction submodules allInstructions :: [Gene] allInstructions = allIntInstructions diff --git a/src/HushGP/Instructions/BoolInstructions.hs b/src/HushGP/Instructions/BoolInstructions.hs index c55f929..ece81d6 100644 --- a/src/HushGP/Instructions/BoolInstructions.hs +++ b/src/HushGP/Instructions/BoolInstructions.hs @@ -1,8 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.BoolInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions import HushGP.Instructions.Utility +import HushGP.TH -- |If top of int stack /= 0 pushes True to bool stack, else false. instructionBoolFromInt :: State -> State @@ -94,3 +96,6 @@ instructionBoolIsStackEmpty = instructionIsStackEmpty bool -- |Duplicate the top N items from the bool stack based on the top int from the int stack. instructionBoolDupItems :: State -> State instructionBoolDupItems = instructionDupItems bool + +allBoolInstructions :: [Gene] +allBoolInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/CharInstructions.hs b/src/HushGP/Instructions/CharInstructions.hs index 9c0d540..578dafe 100644 --- a/src/HushGP/Instructions/CharInstructions.hs +++ b/src/HushGP/Instructions/CharInstructions.hs @@ -1,9 +1,11 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.CharInstructions where import Data.Char import HushGP.State import HushGP.Instructions.GenericInstructions import HushGP.Instructions.Utility +import HushGP.TH -- |Combines the top two chars into a string and pushes the result to the string stack. instructionCharConcat :: State -> State @@ -132,3 +134,6 @@ instructionCharDupItems = instructionDupItems char -- all chars in said string to the char stack. instructionCharFromAllString :: State -> State instructionCharFromAllString = instructionPushAll char string + +allCharInstructions :: [Gene] +allCharInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/CodeInstructions.hs b/src/HushGP/Instructions/CodeInstructions.hs index 1588465..6454703 100644 --- a/src/HushGP/Instructions/CodeInstructions.hs +++ b/src/HushGP/Instructions/CodeInstructions.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.CodeInstructions where import Data.List (elemIndex) @@ -5,6 +6,7 @@ import HushGP.State import HushGP.Instructions.GenericInstructions import HushGP.Instructions.IntInstructions import HushGP.Instructions.Utility +import HushGP.TH -- import Debug.Trace -- |Pops the top of the code stack @@ -345,3 +347,6 @@ instructionCodeNoOp state = state -- |Duplicates the top N items of the code stack based on the top of the int stack. instructionCodeDupItems :: State -> State instructionCodeDupItems = instructionDupItems code + +allCodeInstructions :: [Gene] +allCodeInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/ExecInstructions.hs b/src/HushGP/Instructions/ExecInstructions.hs index 48f9005..2c1d0a4 100644 --- a/src/HushGP/Instructions/ExecInstructions.hs +++ b/src/HushGP/Instructions/ExecInstructions.hs @@ -1,8 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.ExecInstructions where import HushGP.State import HushGP.Instructions.IntInstructions import HushGP.Instructions.GenericInstructions +import HushGP.TH -- |Removes the second item from the exec stack if the top of the bool stack is True. -- Removes the first item from the exec stack if the top of the bool stack is False. @@ -153,3 +155,6 @@ instructionExecY state = state -- |Duplicates the top N items of the exec stack based on the top of the int stack. instructionExecDupItems :: State -> State instructionExecDupItems = instructionDupItems exec + +allExecInstructions :: [Gene] +allExecInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/FloatInstructions.hs b/src/HushGP/Instructions/FloatInstructions.hs index 4f542fe..2495b31 100644 --- a/src/HushGP/Instructions/FloatInstructions.hs +++ b/src/HushGP/Instructions/FloatInstructions.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.FloatInstructions where import Data.Fixed (mod') @@ -5,6 +6,7 @@ import HushGP.Instructions.GenericInstructions import HushGP.Instructions.Utility import HushGP.State import Data.Char +import HushGP.TH -- |Converts the top int to a float and pushes the result to the float stack. instructionFloatFromInt :: State -> State @@ -169,3 +171,6 @@ instructionFloatTan state = state -- |Duplicate the top N items from the float stack based on the top int from the int stack. instructionFloatDupItems :: State -> State instructionFloatDupItems = instructionDupItems float + +allFloatInstructions :: [Gene] +allFloatInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/IntInstructions.hs b/src/HushGP/Instructions/IntInstructions.hs index d1a2682..543f0a7 100644 --- a/src/HushGP/Instructions/IntInstructions.hs +++ b/src/HushGP/Instructions/IntInstructions.hs @@ -1,9 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.IntInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions import Data.Char --- import Debug.Trace +import HushGP.TH -- |Converts the top float to an int and pushes the result to the int stack. instructionIntFromFloat :: State -> State @@ -155,3 +156,6 @@ instructionIntIsStackEmpty = instructionIsStackEmpty int -- |Duplicate the top N items from the int stack based on the top int from the int stack. instructionIntDupItems :: State -> State instructionIntDupItems = instructionDupItems int + +allIntInstructions :: [Gene] +allIntInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/StringInstructions.hs b/src/HushGP/Instructions/StringInstructions.hs index 04dcab5..f192b19 100644 --- a/src/HushGP/Instructions/StringInstructions.hs +++ b/src/HushGP/Instructions/StringInstructions.hs @@ -1,8 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.StringInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions import HushGP.Instructions.Utility +import HushGP.TH -- |Concats the top two strings on the string stack and pushes the result. instructionStringConcat :: State -> State @@ -323,3 +325,6 @@ instructionStringSubString = instructionSubVector string -- exec stack along the way. instructionStringIterate :: State -> State instructionStringIterate = instructionVectorIterate char string GeneString instructionStringIterate "instructionStringIterate" + +allStringInstructions :: [Gene] +allStringInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/VectorBoolInstructions.hs b/src/HushGP/Instructions/VectorBoolInstructions.hs index 934495a..2f6987d 100644 --- a/src/HushGP/Instructions/VectorBoolInstructions.hs +++ b/src/HushGP/Instructions/VectorBoolInstructions.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorBoolInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions +import HushGP.TH -- |Pops the top bool vector from the bool vector stack. instructionVectorBoolPop :: State -> State @@ -328,3 +330,6 @@ instructionVectorBoolInsert = instructionVectorInsert bool vectorBool -- pulled from the top of the int stack. instructionVectorBoolInsertVectorBool :: State -> State instructionVectorBoolInsertVectorBool = instructionVectorInsertVector vectorBool + +allVectorBoolInstructions :: [Gene] +allVectorBoolInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/VectorCharInstructions.hs b/src/HushGP/Instructions/VectorCharInstructions.hs index 09084a3..caf52f1 100644 --- a/src/HushGP/Instructions/VectorCharInstructions.hs +++ b/src/HushGP/Instructions/VectorCharInstructions.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorCharInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions +import HushGP.TH -- |Pops the top char vector from the char vector stack. instructionVectorCharPop :: State -> State @@ -328,3 +330,6 @@ instructionVectorCharInsert = instructionVectorInsert char vectorChar -- pulled from the top of the int stack. instructionVectorCharInsertVectorChar :: State -> State instructionVectorCharInsertVectorChar = instructionVectorInsertVector vectorChar + +allVectorCharInstructions :: [Gene] +allVectorCharInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/VectorFloatInstructions.hs b/src/HushGP/Instructions/VectorFloatInstructions.hs index a2a8531..b1b115a 100644 --- a/src/HushGP/Instructions/VectorFloatInstructions.hs +++ b/src/HushGP/Instructions/VectorFloatInstructions.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorFloatInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions +import HushGP.TH -- |Pops the top float vector from the float vector stack. instructionVectorFloatPop :: State -> State @@ -328,3 +330,6 @@ instructionVectorFloatInsert = instructionVectorInsert float vectorFloat -- pulled from the top of the int stack. instructionVectorFloatInsertVectorFloat :: State -> State instructionVectorFloatInsertVectorFloat = instructionVectorInsertVector vectorFloat + +allVectorFloatInstructions :: [Gene] +allVectorFloatInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/VectorIntInstructions.hs b/src/HushGP/Instructions/VectorIntInstructions.hs index cddf728..f021ea0 100644 --- a/src/HushGP/Instructions/VectorIntInstructions.hs +++ b/src/HushGP/Instructions/VectorIntInstructions.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorIntInstructions where import HushGP.Instructions.GenericInstructions import HushGP.State +import HushGP.TH -- |Pops the top int vector from the int vector stack. instructionVectorIntPop :: State -> State @@ -328,3 +330,6 @@ instructionVectorIntInsert = instructionVectorInsert int vectorInt -- pulled from the top of the int stack. instructionVectorIntInsertVectorInt :: State -> State instructionVectorIntInsertVectorInt = instructionVectorInsertVector vectorInt + +allVectorIntInstructions :: [Gene] +allVectorIntInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/Instructions/VectorStringInstructions.hs b/src/HushGP/Instructions/VectorStringInstructions.hs index f4b904e..19f4600 100644 --- a/src/HushGP/Instructions/VectorStringInstructions.hs +++ b/src/HushGP/Instructions/VectorStringInstructions.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorStringInstructions where import HushGP.State import HushGP.Instructions.GenericInstructions +import HushGP.TH -- |Pops the top string vector from the string vector stack. instructionVectorStringPop :: State -> State @@ -328,3 +330,6 @@ instructionVectorStringInsert = instructionVectorInsert string vectorString -- pulled from the top of the int stack. instructionVectorStringInsertVectorString :: State -> State instructionVectorStringInsertVectorString = instructionVectorInsertVector vectorString + +allVectorStringInstructions :: [Gene] +allVectorStringInstructions = map StateFunc ($(functionExtractor "instruction")) diff --git a/src/HushGP/PushTests/IntTests.hs b/src/HushGP/PushTests/IntTests.hs index acd1cdd..caca9ee 100644 --- a/src/HushGP/PushTests/IntTests.hs +++ b/src/HushGP/PushTests/IntTests.hs @@ -26,8 +26,8 @@ prop_IntMod state = aaa1Test int instructionIntMod mod state prop_IntFromFloat :: State -> Property prop_IntFromFloat = ab1Test float int instructionIntFromFloat floor -prop_IntFromProperty :: State -> Property -prop_IntFromProperty = ab1Test bool int instructionIntFromBool (\x -> if x then 1 else 0) +prop_IntFromBool :: State -> Property +prop_IntFromBool = ab1Test bool int instructionIntFromBool (\x -> if x then 1 else 0) prop_IntMin :: State -> Property prop_IntMin = aaa1Test int instructionIntMin min diff --git a/src/HushGP/TH.hs b/src/HushGP/TH.hs new file mode 100644 index 0000000..a53b10d --- /dev/null +++ b/src/HushGP/TH.hs @@ -0,0 +1,38 @@ +module HushGP.TH where + +import Data.List +import Language.Haskell.TH +import Text.Regex.TDFA + +-- This old code made this all possible :) +-- https://github.com/finnsson/template-helper/blob/master/src/Language/Haskell/Extract.hs + +-- | A way to extract all functions from the file +-- `lines file` pulls all of the lines in one string from the file +-- `lex $ lines file` splits the function into a tuple +-- fst = the function nams, snd = the rest of the line +-- `concatMap lex $ lines file` maps lex onto all of the lines +-- and concats the result into a list +-- `filter (=~pattern) $ map fst $ concatMap lex $ lines file` filters +-- any line that doesn't have the passed pattern to it. "function" is a good pattern +-- for Hush. +-- `nub $ filter (=~pattern) $ map fst $ concatMap lex $ lines file` removes all +-- duplicates from the list. Or sets in this case :) +extractAllFunctions :: String -> Q [String] +extractAllFunctions pattern = do + loc <- location + -- file <- runIO $ readFile pattern + file <- runIO $ readFile $ loc_filename loc + return $ nub $ filter (=~ pattern) $ map fst $ concatMap lex $ lines file + +-- | Extracts all functions from a Q [String] (to be used with extractAllFunctions) +-- funcs has a list of all functions from extractAllFunctions +-- makePair makes a tuple of a passed function holding its name as a string and actual function value +-- in that order. StateFunc :) +-- `ListE $ map makePair funcs` makes a list of these function tuples holding all function +-- names and values. +functionExtractor :: String -> Q Exp +functionExtractor pattern = do + funcs <- extractAllFunctions pattern + let makePair n = TupE [Just $ VarE $ mkName n, Just $ LitE $ StringL n] + return $ ListE $ map makePair funcs