summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-09-01 17:46:07 +1000
committerJed Barber <jjbarber@y7mail.com>2014-09-01 17:46:07 +1000
commit80fdb46fc6d69eb0c23efab9a541ffa972f683f5 (patch)
tree6cecc15561ee01abeaa3102b74d0df1ff13b1151
parent8ee878162881f658128c79e334a22baa1db98e2f (diff)
Ret instruction added
-rw-r--r--src/Grasp/Interpreter.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index 0594c95..e7a36c9 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -107,7 +107,7 @@ execute g (cur:rest) out =
(_,x) -> do
(g',cur') <- case x of
"call" -> callI g cur
- "ret" -> retI g cur
+ "ret" -> retI g cur >>= (\(x,y) -> return (garbageCollect x ((y:rest) ++ out), y))
_ -> error ("Execute function reached impossible branch")
execute g' rest (cur':out)
@@ -372,7 +372,26 @@ callI g ip =
retI :: GraspProgram -> IP -> IO (GraspProgram, IP)
-retI g ip = return (g,ip)
+retI g (n:[]) = return (g,[])
+retI g ip =
+ let oldEdges = Graph.out g (fst . head $ ip)
+ returnValues = filter (\(x,y,z) -> z /= "name" && z /= "cond" && z /= "next") oldEdges
+
+ node = fst . head $ (tail ip)
+ edges = Graph.out g node
+
+ nextLN = targetLNodes g (getByLabel "next" edges)
+
+ in if (nextLN == []) then return (g,[])
+ else do
+ ip' <- updateIP (tail ip) nextLN
+
+ let node' = fst . head $ ip'
+ returnEdges = map (\(x,y,z) -> (node',y,z)) returnValues
+
+ g' = Graph.insEdges returnEdges g
+
+ return (g',ip')