From 24271f7e6fa7c7c7ea896f465b31497becac4976 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 17 May 2014 10:59:51 +1000 Subject: del instruction complete --- src/Grasp/Interpreter.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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) -- cgit