add generic(ish) int instructions
This commit is contained in:
parent
e11b813d00
commit
f991792787
@ -81,6 +81,39 @@ instructionIntStackDepth :: State -> State
|
||||
instructionIntStackDepth state = instructionStackDepth state int
|
||||
|
||||
-- int specific
|
||||
-- instructionIntYank :: State -> State
|
||||
-- instructionIntYank state@(State {_int = index : i2 : is}) = undefined
|
||||
-- instructionIntYank state = state
|
||||
instructionIntYank :: State -> State
|
||||
-- instructionIntYank state = instructionYank state int
|
||||
instructionIntYank state@(State {_int = rawIndex : i1 : is}) =
|
||||
let
|
||||
myIndex :: Int
|
||||
myIndex = max 0 (min rawIndex (length is - 1))
|
||||
in
|
||||
state {_int = is !! myIndex : i1 : deleteAt myIndex is}
|
||||
instructionIntYank state = state
|
||||
|
||||
instructionIntYankDup :: State -> State
|
||||
instructionIntYankDup state@(State {_int = rawIndex : item : is}) =
|
||||
let
|
||||
myIndex :: Int
|
||||
myIndex = max 0 (min rawIndex (length is - 1))
|
||||
in
|
||||
state {_int = is !! myIndex : item : is}
|
||||
instructionIntYankDup state = state
|
||||
|
||||
instructionIntShove :: State -> State
|
||||
instructionIntShove state@(State {_int = rawIndex : item : is}) =
|
||||
let
|
||||
myIndex :: Int
|
||||
myIndex = max 0 (min rawIndex (length is - 1))
|
||||
in
|
||||
state {_int = combineTuple item (splitAt myIndex is)}
|
||||
instructionIntShove state = state
|
||||
|
||||
instructionIntShoveDup :: State -> State
|
||||
instructionIntShoveDup state@(State {_int = rawIndex : item : is}) =
|
||||
let
|
||||
myIndex :: Int
|
||||
myIndex = max 0 (min rawIndex (length is - 1))
|
||||
in
|
||||
state {_int = item : combineTuple item (splitAt myIndex is)}
|
||||
instructionIntShoveDup state = state
|
||||
|
@ -42,6 +42,10 @@ main = do
|
||||
intTestFunc "instructionIntRotFail" [7, 8] [GeneInt 8, GeneInt 7, StateFunc instructionIntRot] emptyState
|
||||
intTestFunc "instructionIntFlush" [] [GeneInt 9696, GeneInt 92, GeneInt 420, StateFunc instructionIntFlush] emptyState -- I think I'm funny
|
||||
intTestFunc "instructionIntStackDepth" [2, 51, 52] [GeneInt 52, GeneInt 51, StateFunc instructionIntStackDepth] emptyState
|
||||
intTestFunc "instructionIntYank" [3,3,2,1] [GeneInt 3, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 4, StateFunc instructionIntYank] emptyState
|
||||
intTestFunc "instructionIntYankDup" [3,3,2,1,3] [GeneInt 3, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 4, StateFunc instructionIntYankDup] emptyState
|
||||
intTestFunc "instructionIntShove" [2,1,3,1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShove] emptyState
|
||||
intTestFunc "instructionIntShoveDup" [3,2,1,3,1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShoveDup] emptyState
|
||||
|
||||
-- Exec tests
|
||||
intTestFunc "instructionExecIf" [6, 5] [GeneBool True, StateFunc instructionExecIf, Block [GeneInt 5, GeneInt 6], Block [GeneInt 7, GeneInt 8]] emptyState
|
||||
|
Loading…
x
Reference in New Issue
Block a user