a fully working interpreter?
This commit is contained in:
parent
4ccd660763
commit
e865ba7407
15
src/Push.hs
15
src/Push.hs
@ -44,20 +44,21 @@ emptyState =
|
|||||||
-- That is more efficient than checking length.
|
-- That is more efficient than checking length.
|
||||||
-- Everntually, this can be part of the apply func to state helpers,
|
-- Everntually, this can be part of the apply func to state helpers,
|
||||||
-- which should take the number and type of parameter they have.
|
-- which should take the number and type of parameter they have.
|
||||||
intAdd :: State -> State
|
instructionIntAdd :: State -> State
|
||||||
intAdd (State es [] fs bs ss ps) = State es [] fs bs ss ps
|
instructionIntAdd (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
|
instructionIntAdd (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 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))
|
-- let result = sum (take 2 (int state))
|
||||||
-- dropped = drop 2 (int state)
|
-- dropped = drop 2 (int state)
|
||||||
-- in updateIntStack (result : dropped) state
|
-- in updateIntStack (result : dropped) state
|
||||||
-- For safety, pattern match on [] and i:is or check for <2 long list after take 2?
|
-- 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
|
-- Optionally, split this off into independent functions
|
||||||
parameterLoad :: State -> State
|
instructionParameterLoad :: State -> State
|
||||||
parameterLoad (State es is fs bs ss []) = State es is fs bs ss []
|
instructionParameterLoad (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 es is fs bs ss (p : ps)) = case p of
|
||||||
(IntGene val) -> State es (val : is) fs bs ss ps
|
(IntGene val) -> State es (val : is) fs bs ss ps
|
||||||
(FloatGene val) -> State es is (val : fs) bs ss ps
|
(FloatGene val) -> State es is (val : fs) bs ss ps
|
||||||
(BoolGene val) -> State es is fs (val : bs) ss ps
|
(BoolGene val) -> State es is fs (val : bs) ss ps
|
||||||
|
@ -13,9 +13,9 @@ exampleState =
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- intAdd
|
-- 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
|
-- interpretExec
|
||||||
testResult2 = [12] == int (interpretExec loaded)
|
testResult2 = [7,6,1,2,3] == int (interpretExec loaded)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user