summaryrefslogtreecommitdiff
path: root/src/Grasp
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-08-30 22:16:16 +1000
committerJed Barber <jjbarber@y7mail.com>2014-08-30 22:16:16 +1000
commit85cb6b7f7537a1d33c2efaada6ef6844c148219f (patch)
treec57d8089583ea620062b76ae92c6cd27c947b7f5 /src/Grasp
parentafde234fd91c2037025b8d44d8c78c69e2b70574 (diff)
Cleaned up code for push instructions
Diffstat (limited to 'src/Grasp')
-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