diff --git a/src/Push.hs b/src/Push.hs index 5ec0881..e56fc2e 100644 --- a/src/Push.hs +++ b/src/Push.hs @@ -44,20 +44,21 @@ emptyState = -- That is more efficient than checking length. -- Everntually, this can be part of the apply func to state helpers, -- which should take the number and type of parameter they have. -intAdd :: State -> State -intAdd (State es [] fs bs ss ps) = State es [] fs bs ss ps -intAdd (State es [i] fs bs ss ps) = State es [i] fs bs ss ps -intAdd (State es (i : is) fs bs ss ps) = State es ((i + head is) : drop 1 is) fs bs ss ps +instructionIntAdd :: State -> State +instructionIntAdd (State es [] fs bs ss ps) = State es [] fs bs ss ps +instructionIntAdd (State es [i] fs bs ss ps) = State es [i] fs bs ss ps +instructionIntAdd (State es (i : is) fs bs ss ps) = State es ((i + head is) : drop 1 is) fs bs ss ps -- let result = sum (take 2 (int state)) -- dropped = drop 2 (int state) -- in updateIntStack (result : dropped) state -- For safety, pattern match on [] and i:is or check for <2 long list after take 2? +-- This is one of the push genome functions itself, not infrastructure. -- Optionally, split this off into independent functions -parameterLoad :: State -> State -parameterLoad (State es is fs bs ss []) = State es is fs bs ss [] -parameterLoad (State es is fs bs ss (p : ps)) = case p of +instructionParameterLoad :: State -> State +instructionParameterLoad (State es is fs bs ss []) = State es is fs bs ss [] +instructionParameterLoad (State es is fs bs ss (p : ps)) = case p of (IntGene val) -> State es (val : is) fs bs ss ps (FloatGene val) -> State es is (val : fs) bs ss ps (BoolGene val) -> State es is fs (val : bs) ss ps diff --git a/src/Tests.hs b/src/Tests.hs index 24ae1d3..c4705c7 100644 --- a/src/Tests.hs +++ b/src/Tests.hs @@ -13,9 +13,9 @@ exampleState = } -- intAdd -testResult1 = [3, 3] == int (intAdd exampleState) +testResult1 = [3, 3] == int (instructionIntAdd exampleState) -loaded = loadProgarm [IntGene 6, IntGene 6, StateFunc intAdd] emptyState +loaded = loadProgarm [IntGene 6, IntGene 6, StateFunc instructionParameterLoad, StateFunc instructionIntAdd] exampleState -- interpretExec -testResult2 = [12] == int (interpretExec loaded) +testResult2 = [7,6,1,2,3] == int (interpretExec loaded)