summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Grasp/Interpreter.hs17
1 files changed, 8 insertions, 9 deletions
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