From d5ec72501f774c86d1fbe3c74b4edafc5065987e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 19 Dec 2014 15:18:42 +1100 Subject: cond edges now work (how did I overlook that?) --- src/Grasp/Interpreter.hs | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs index ca28578..82304c1 100644 --- a/src/Grasp/Interpreter.hs +++ b/src/Grasp/Interpreter.hs @@ -49,26 +49,31 @@ interpret = do n <- GMonad.peekIP if (Maybe.isNothing n) then return () else do - case (IN.toString . GN.toInst . Maybe.fromJust $ n) of - "set" -> setI - "new" -> newI - "del" -> delI - "push" -> pushI - "pop" -> popI - "pick" -> pickI - "call" -> callI - "ret" -> retI - "add" -> addI - "mul" -> mulI - "sub" -> subI - "div" -> divI - "mod" -> modI - "getc" -> getcI - "putc" -> putcI - "gets" -> getsI - "puts" -> putsI - inst | Maybe.isJust . IN.toInt . IN.mk $ inst -> implicitPushI - x -> error ("Unknown instruction " ++ x) + condNodes <- GMonad.nodesOut (EL.mk "cond") (Maybe.fromJust n) + let condValues = map (IN.toFloat . GN.toInst) condNodes + + if (all (\x -> (Maybe.isJust x) && ((/=0) . Maybe.fromJust $ x)) condValues) + then case (IN.toString . GN.toInst . Maybe.fromJust $ n) of + "set" -> setI + "new" -> newI + "del" -> delI + "push" -> pushI + "pop" -> popI + "pick" -> pickI + "call" -> callI + "ret" -> retI + "add" -> addI + "mul" -> mulI + "sub" -> subI + "div" -> divI + "mod" -> modI + "getc" -> getcI + "putc" -> putcI + "gets" -> getsI + "puts" -> putsI + inst | Maybe.isJust . IN.toInt . IN.mk $ inst -> implicitPushI + x -> error ("Unknown instruction " ++ x) + else GMonad.updateIP GMonad.nextIP interpret -- cgit