From 85cb6b7f7537a1d33c2efaada6ef6844c148219f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 30 Aug 2014 22:16:16 +1000 Subject: Cleaned up code for push instructions --- src/Grasp/Interpreter.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/Grasp') diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs index 4d9853c..67632bc 100644 --- a/src/Grasp/Interpreter.hs +++ b/src/Grasp/Interpreter.hs @@ -203,19 +203,18 @@ delI g node = pushI :: GraspProgram -> Node -> IO GraspProgram -pushI g node = +pushI g node = do let edges = Graph.out g node stackN = targetNodes (getByLabel "stack" edges) inL = targetLabels g (getByLabel "in" edges) - in if (length stackN /= 1) then error ("Instruction " ++ (show node) ++ - " should only have one stack argument") - else do - label <- if (inL == []) then return "" - else (getStdRandom (randomR (0,length inL - 1))) >>= (\x -> return (inL !! x)) + rnd <- getStdRandom (randomR (0,length inL -1)) + let label = if (inL == []) then "" else inL !! rnd - doPushI g (head stackN) label + if (length stackN /= 1) + then error ("Instruction " ++ (show node) ++ " should only have one stack argument") + else doPushI g (head stackN) label @@ -226,8 +225,8 @@ implicitPushI g node = stackN = targetNodes (getByLabel "stack" edges) label = fromJust $ Graph.lab g node - in if (length stackN /= 1) then error ("Instruction " ++ (show node) ++ - " should only have one stack argument") + in if (length stackN /= 1) + then error ("Instruction " ++ (show node) ++ " should only have one stack argument") else doPushI g (head stackN) label -- cgit