From 5f8fd03bcbe4d98aac3e247a2d39ec275a6fd451 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 23 Jul 2014 01:20:10 +1000 Subject: mod instruction added --- src/Grasp/Interpreter.hs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/Grasp') diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs index 4e9914b..6662c0f 100644 --- a/src/Grasp/Interpreter.hs +++ b/src/Grasp/Interpreter.hs @@ -276,7 +276,32 @@ subdivI f g ip = do modI :: GraspProgram -> IP -> IO (GraspProgram, IP) -modI g ip = return (g,ip) +modI g ip = do + let node = fst . head $ ip + edges = Graph.out g node + + leftL = targetLabels g (getByLabel "left" edges) + rightL = targetLabels g (getByLabel "right" edges) + outN = targetNodes (getByLabel "out" edges) + nextLN = targetLNodes g (getByLabel "next" edges) + + g' <- case (leftL, rightL) of + (x,y) | length x /= 1 || length y /= 1 -> + error ("Instruction " ++ (show node) ++ " requires " ++ + "a single left edge and a single right edge") + + (x,y) | not (all isFloat x && all isFloat y) -> + error ("Instruction " ++ (show node) ++ + " has non numeric arguments") + + (x,y) -> let s = (read . head $ x) `mod` (read . head $ y) + in return (foldl' (\gr n -> reLabel gr n (show s)) g outN) + + ip' <- updateIP ip nextLN + + return (g',ip') + + getcI :: GraspProgram -> IP -> IO (GraspProgram, IP) getcI g ip = return (g,ip) -- cgit