summaryrefslogtreecommitdiff
path: root/src/Grasp
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-05-17 14:10:32 +1000
committerJed Barber <jjbarber@y7mail.com>2014-05-17 14:10:32 +1000
commit845c5043f321365c7751eb5d8377ca62869f9f4f (patch)
tree43b21889c46f538c05b4956de5c7d73d3935d8d0 /src/Grasp
parent76ea8799fbe281fe8caee99002f9e1829de16f0a (diff)
mul instruction complete
Diffstat (limited to 'src/Grasp')
-rw-r--r--src/Grasp/Interpreter.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index 8cfe502..7d38ebd 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -218,7 +218,13 @@ retI g ip = return (g,ip)
addI :: GraspProgram -> IP -> IO (GraspProgram, IP)
-addI g ip = do
+addI = addmulI sum
+
+mulI :: GraspProgram -> IP -> IO (GraspProgram, IP)
+mulI = addmulI product
+
+addmulI :: ([Float] -> Float) -> GraspProgram -> IP -> IO (GraspProgram, IP)
+addmulI f g ip = do
let node = fst . head $ ip
edges = Graph.out g node
@@ -229,7 +235,7 @@ addI g ip = do
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
+ x -> let s = f . map (read :: String -> Float) $ x
in return (foldl' (\gr n -> reLabel gr n (show s)) g outN)
ip' <- updateIP ip nextLN
@@ -238,9 +244,6 @@ addI g ip = do
-mulI :: GraspProgram -> IP -> IO (GraspProgram, IP)
-mulI g ip = return (g,ip)
-
subI :: GraspProgram -> IP -> IO (GraspProgram, IP)
subI g ip = return (g,ip)