summaryrefslogtreecommitdiff
path: root/src/Grasp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Grasp')
-rw-r--r--src/Grasp/Interpreter.hs118
1 files changed, 79 insertions, 39 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index 5086078..965aa13 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -57,8 +57,8 @@ interpret g ips = if (ips == []) then return () else execute g ips []
execute :: GraspProgram -> [IP] -> [IP] -> IO ()
execute g [] out = interpret g (reverse out)
execute g ([]:ips) out = execute g ips out
-execute g (cur:rest) out =
- let (g', cur') =
+execute g (cur:rest) out = do
+ (g', cur') <-
case (snd . head $ cur) of
"set" -> setI g cur
"new" -> newI g cur
@@ -82,7 +82,7 @@ execute g (cur:rest) out =
x -> error ("Unknown instruction at " ++ (show x))
- in execute g' rest (cur':out)
+ execute g' rest (cur':out)
@@ -102,57 +102,97 @@ reLabel g n s =
-setI :: GraspProgram -> IP -> (GraspProgram, IP)
-setI g ip = (g,ip)
+getByLabel :: String -> [LEdge String] -> [LEdge String]
+getByLabel name = filter (\(_,_,x) -> x == name)
-newI :: GraspProgram -> IP -> (GraspProgram, IP)
-newI g ip = (g,ip)
-delI :: GraspProgram -> IP -> (GraspProgram, IP)
-delI g ip = (g,ip)
-pushI :: GraspProgram -> IP -> (GraspProgram, IP)
-pushI g ip = (g,ip)
+targetLabels :: GraspProgram -> [LEdge String] -> [String]
+targetLabels g = map (\(_,x,_) -> fromJust (Graph.lab g x))
-popI :: GraspProgram -> IP -> (GraspProgram, IP)
-popI g ip = (g,ip)
+targetNodes :: [LEdge String] -> [Node]
+targetNodes = map (\(_,x,_) -> x)
-pickI :: GraspProgram -> IP -> (GraspProgram, IP)
-pickI g ip = (g,ip)
+targetLNodes :: GraspProgram -> [LEdge String] -> [LNode String]
+targetLNodes g = map (\(_,x,_) -> (x, fromJust (Graph.lab g x)) )
-callI :: GraspProgram -> IP -> (GraspProgram, IP)
-callI g ip = (g,ip)
-retI :: GraspProgram -> IP -> (GraspProgram, IP)
-retI g ip = (g,ip)
-addI :: GraspProgram -> IP -> (GraspProgram, IP)
-addI g ip = (g,ip)
+updateIP :: IP -> [LNode String] -> IO IP
+updateIP _ [] = return []
+updateIP ip next =
+ getStdRandom (randomR (0,length next)) >>=
+ (\x -> return ((next !! x):(tail ip)) )
-mulI :: GraspProgram -> IP -> (GraspProgram, IP)
-mulI g ip = (g,ip)
-subI :: GraspProgram -> IP -> (GraspProgram, IP)
-subI g ip = (g,ip)
-divI :: GraspProgram -> IP -> (GraspProgram, IP)
-divI g ip = (g,ip)
+setI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+setI g ip = do
+ let edges = Graph.out g (fst . head $ ip)
-modI :: GraspProgram -> IP -> (GraspProgram, IP)
-modI g ip = (g,ip)
+ inL = targetLabels g (getByLabel "in" edges)
+ outN = targetNodes (getByLabel "out" edges)
+ nextLN = targetLNodes g (getByLabel "next" edges)
+
+ g' <- case inL of
+ [] -> return g
+ _ -> (getStdRandom (randomR (0,length inL))) >>=
+ (\x -> foldl' (\g n -> reLabel g n (inL !! x)) (return g) outN)
+
+ ip' <- updateIP ip nextLN
-getcI :: GraspProgram -> IP -> (GraspProgram, IP)
-getcI g ip = (g,ip)
+ return (g',ip')
-putcI :: GraspProgram -> IP -> (GraspProgram, IP)
-putcI g ip = (g,ip)
-getsI :: GraspProgram -> IP -> (GraspProgram, IP)
-getsI g ip = (g,ip)
-putsI :: GraspProgram -> IP -> (GraspProgram, IP)
-putsI g ip = (g,ip)
+newI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+newI g ip = return (g,ip)
-implicitPushI :: GraspProgram -> IP -> (GraspProgram, IP)
-implicitPushI g ip = (g,ip)
+delI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+delI g ip = return (g,ip)
+
+pushI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+pushI g ip = return (g,ip)
+
+popI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+popI g ip = return (g,ip)
+
+pickI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+pickI g ip = return (g,ip)
+
+callI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+callI g ip = return (g,ip)
+
+retI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+retI g ip = return (g,ip)
+
+addI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+addI g ip = return (g,ip)
+
+mulI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+mulI g ip = return (g,ip)
+
+subI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+subI g ip = return (g,ip)
+
+divI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+divI g ip = return (g,ip)
+
+modI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+modI g ip = return (g,ip)
+
+getcI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+getcI g ip = return (g,ip)
+
+putcI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+putcI g ip = return (g,ip)
+
+getsI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+getsI g ip = return (g,ip)
+
+putsI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+putsI g ip = return (g,ip)
+
+implicitPushI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+implicitPushI g ip = return (g,ip)