summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-05-17 13:15:20 +1000
committerJed Barber <jjbarber@y7mail.com>2014-05-17 13:15:20 +1000
commit76ea8799fbe281fe8caee99002f9e1829de16f0a (patch)
treed32ca93cab690416402c9e77cb658ae441bbb62e /src
parent24271f7e6fa7c7c7ea896f465b31497becac4976 (diff)
add instruction complete
Diffstat (limited to 'src')
-rw-r--r--src/Grasp/Interpreter.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index 35a3de0..8cfe502 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -145,7 +145,7 @@ setI g ip = do
g' <- case inL of
[] -> return g
_ -> (getStdRandom (randomR (0,length inL))) >>=
- (\x -> return (foldl' (\g n -> reLabel g n (inL !! x)) g outN) )
+ (\x -> return (foldl' (\gr n -> reLabel gr n (inL !! x)) g outN) )
ip' <- updateIP ip nextLN
@@ -215,8 +215,28 @@ 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)
+addI g ip = do
+ let node = fst . head $ ip
+ edges = Graph.out g node
+
+ argL = targetLabels g (getByLabel "arg" edges)
+ outN = targetNodes (getByLabel "out" edges)
+ nextLN = targetLNodes g (getByLabel "next" edges)
+
+ g' <- case argL of
+ x | not (all isFloat x) -> error ("Instruction " ++ (show node) ++
+ " has non numeric arguments")
+ x -> let s = sum . map (read :: String -> Float) $ x
+ in return (foldl' (\gr n -> reLabel gr n (show s)) g outN)
+
+ ip' <- updateIP ip nextLN
+
+ return (g',ip')
+
+
mulI :: GraspProgram -> IP -> IO (GraspProgram, IP)
mulI g ip = return (g,ip)