implementing string and char stacks
This commit is contained in:
parent
44257bd94e
commit
452e7a2b49
@ -44,6 +44,7 @@ library
|
||||
, Instructions.GenericInstructions
|
||||
, Instructions.LogicalInstructions
|
||||
, Instructions.CodeInstructions
|
||||
, Instructions.StringInstructions
|
||||
|
||||
-- Modules included in this library but not exported.
|
||||
-- other-modules:
|
||||
|
@ -6,10 +6,6 @@ the functions in the pyshgp list.
|
||||
|
||||
https://erp12.github.io/pyshgp/html/core_instructions.html
|
||||
|
||||
I'm not going to include no-ops.
|
||||
|
||||
Interpush doesn't have the code stack. Time to test this against pysh.
|
||||
|
||||
## Tasks
|
||||
* [ ] Post minimal core of exec to haskell discourse for advice about speed optimization.
|
||||
* [x] Do test-driven development on this one.
|
||||
|
@ -23,9 +23,13 @@ instructionParameterLoad state@(State {_parameter = (p : _)}) = case p of
|
||||
(GeneInt val) -> state & int .~ val : view int state
|
||||
(GeneFloat val) -> state & float .~ val : view float state
|
||||
(GeneBool val) -> state & bool .~ val : view bool state
|
||||
(GeneString val) -> state & string .~ val : view string state
|
||||
(GeneChar val) -> state & char .~ val : view char state
|
||||
(GeneIntVector val) -> state & intVector .~ val : view intVector state
|
||||
(GeneFloatVector val) -> state & floatVector .~ val : view floatVector state
|
||||
(GeneBoolVector val) -> state & boolVector .~ val : view boolVector state
|
||||
(GeneStringVector val) -> state & stringVector .~ val : view stringVector state
|
||||
(GeneCharVector val) -> state & charVector .~ val : view charVector state
|
||||
(StateFunc _) -> undefined
|
||||
(PlaceInput _) -> undefined
|
||||
Close -> undefined
|
||||
@ -53,9 +57,13 @@ interpretExec state@(State {_exec = (e : es)}) =
|
||||
(GeneInt val) -> interpretExec (state & exec .~ es & int .~ val : view int state)
|
||||
(GeneFloat val) -> interpretExec (state & exec .~ es & float .~ val : view float state)
|
||||
(GeneBool val) -> interpretExec (state & exec .~ es & bool .~ val : view bool state)
|
||||
(GeneString val) -> interpretExec (state & exec .~ es & string .~ val : view string state)
|
||||
(GeneChar val) -> interpretExec (state & exec .~ es & char .~ val : view char state)
|
||||
(GeneIntVector val) -> interpretExec (state & exec .~ es & intVector .~ val : view intVector state)
|
||||
(GeneFloatVector val) -> interpretExec (state & exec .~ es & floatVector .~ val : view floatVector state)
|
||||
(GeneBoolVector val) -> interpretExec (state & exec .~ es & boolVector .~ val : view boolVector state)
|
||||
(GeneStringVector val) -> interpretExec (state & exec .~ es & stringVector .~ val : view stringVector state)
|
||||
(GeneCharVector val) -> interpretExec (state & exec .~ es & charVector .~ val : view charVector state)
|
||||
(StateFunc func) -> interpretExec $ func state {_exec = es}
|
||||
(Block block) -> interpretExec (state {_exec = block ++ es})
|
||||
(PlaceInput val) -> interpretExec (state {_exec = (view input state Map.! val) : es})
|
||||
|
24
src/State.hs
24
src/State.hs
@ -13,9 +13,13 @@ data Gene
|
||||
= GeneInt Int
|
||||
| GeneFloat Float
|
||||
| GeneBool Bool
|
||||
| GeneString String
|
||||
| GeneChar Char
|
||||
| GeneIntVector [Int]
|
||||
| GeneFloatVector [Float]
|
||||
| GeneBoolVector [Bool]
|
||||
| GeneStringVector [String]
|
||||
| GeneCharVector [Char]
|
||||
| StateFunc (State -> State)
|
||||
| PlaceInput String
|
||||
| Close
|
||||
@ -25,10 +29,14 @@ instance Eq Gene where
|
||||
GeneInt x == GeneInt y = x == y
|
||||
GeneFloat x == GeneFloat y = x == y
|
||||
GeneBool x == GeneBool y = x == y
|
||||
GeneString x == GeneString y = x == y
|
||||
GeneChar x == GeneChar y = x == y
|
||||
PlaceInput x == PlaceInput y = x == y
|
||||
GeneIntVector xs == GeneIntVector ys = xs == ys
|
||||
GeneFloatVector xs == GeneFloatVector ys = xs == ys
|
||||
GeneBoolVector xs == GeneBoolVector ys = xs == ys
|
||||
GeneStringVector xs == GeneStringVector ys = xs == ys
|
||||
GeneCharVector xs == GeneCharVector ys = xs == ys
|
||||
Close == Close = True
|
||||
StateFunc _ == StateFunc _ = True -- This line is probably not the best thing to do
|
||||
Block x == Block y = x == y
|
||||
@ -38,11 +46,15 @@ instance Show Gene where
|
||||
show (GeneInt x) = "Int: " <> show x
|
||||
show (GeneFloat x) = "Float: " <> show x
|
||||
show (GeneBool x) = "Bool: " <> show x
|
||||
show (GeneString x) = "String: " <> x
|
||||
show (GeneChar x) = "Char: " <> show x
|
||||
show (StateFunc _) = "Func: unnamed"
|
||||
show (PlaceInput x) = "In: " <> x
|
||||
show (GeneIntVector xs) = "Int Vec: " <> show xs
|
||||
show (GeneFloatVector xs) = "Float Vec: " <> show xs
|
||||
show (GeneBoolVector xs) = "Bool Vec: " <> show xs
|
||||
show (GeneStringVector xs) = "String Vec: " <> show xs
|
||||
show (GeneCharVector xs) = "Char Vec: " <> show xs
|
||||
show Close = "Close"
|
||||
show (Block xs) = "Block: " <> show xs
|
||||
|
||||
@ -52,9 +64,13 @@ data State = State
|
||||
_int :: [Int],
|
||||
_float :: [Float],
|
||||
_bool :: [Bool],
|
||||
_string :: [String],
|
||||
_char :: [Char],
|
||||
_intVector :: [[Int]],
|
||||
_floatVector :: [[Float]],
|
||||
_boolVector :: [[Bool]],
|
||||
_stringVector :: [[String]],
|
||||
_charVector :: [[Char]],
|
||||
_parameter :: [Gene],
|
||||
_input :: Map.Map String Gene
|
||||
}
|
||||
@ -70,10 +86,14 @@ emptyState =
|
||||
_int = [],
|
||||
_float = [],
|
||||
_bool = [],
|
||||
_string = [],
|
||||
_char = [],
|
||||
_parameter = [],
|
||||
_intVector = [],
|
||||
_floatVector = [],
|
||||
_boolVector = [],
|
||||
_stringVector = [],
|
||||
_charVector = [],
|
||||
_input = Map.empty
|
||||
}
|
||||
|
||||
@ -85,9 +105,13 @@ exampleState =
|
||||
_int = [32, 56],
|
||||
_float = [3.23, 9.235],
|
||||
_bool = [True, False],
|
||||
_string = ["abc", "123"],
|
||||
_char = ['d', 'e', 'f'],
|
||||
_parameter = [],
|
||||
_intVector = [[1, 2], [5, 6, 8]],
|
||||
_floatVector = [[1.234, 9.21], [5.42, 6.221, 8.5493]],
|
||||
_boolVector = [[True, False], [False, False, True]],
|
||||
_stringVector = [["this is a sentence", "this is also a sentence"], ["s0", "s1", "s2"]],
|
||||
_charVector = [['z', 'x'], ['r', 'a', 't', 'l']],
|
||||
_input = Map.empty
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user