summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-05-17 10:59:51 +1000
committerJed Barber <jjbarber@y7mail.com>2014-05-17 10:59:51 +1000
commit24271f7e6fa7c7c7ea896f465b31497becac4976 (patch)
tree7d70548bac1e33f9932d28c1ce75c8aca95845a2
parenta7a8aa3125818b7ba7913cb1deac690aced0f3db (diff)
del instruction complete
-rw-r--r--src/Grasp/Interpreter.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index e8896cf..35a3de0 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -180,7 +180,25 @@ newI g ip = do
delI :: GraspProgram -> IP -> IO (GraspProgram, IP)
-delI g ip = return (g,ip)
+delI g ip = do
+ let node = fst . head $ ip
+ edges = Graph.out g node
+
+ tailN = targetNodes (getByLabel "tail" edges)
+ headN = targetNodes (getByLabel "head" edges)
+ labelL = targetLabels g (getByLabel "label" edges)
+
+ edgesToDel = filter (\(x,y,z) -> x `elem` tailN &&
+ (headN == [] || y `elem` headN) &&
+ (labelL == [] || z `elem` labelL)) (Graph.labEdges g)
+
+ g' = foldl' (\gr e -> Graph.delLEdge e gr) g edgesToDel
+
+ ip' <- updateIP ip (targetLNodes g' (getByLabel "next" (Graph.out g' node)))
+
+ return (g',ip')
+
+
pushI :: GraspProgram -> IP -> IO (GraspProgram, IP)
pushI g ip = return (g,ip)