summaryrefslogtreecommitdiff
path: root/src/Grasp
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-07-24 01:54:13 +1000
committerJed Barber <jjbarber@y7mail.com>2014-07-24 01:54:13 +1000
commit25eb3e6e8ceeb8b6bf84f5e863dcb94c8decadb4 (patch)
tree15e9bae84940238e3fdc3c14dc6b224b1d741e7a /src/Grasp
parent7e9f4b138f8a5336bdb7eb1633547932f0d13da5 (diff)
getc now returns -1 on EOF
Diffstat (limited to 'src/Grasp')
-rw-r--r--src/Grasp/Interpreter.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs
index 0ea7a57..56ead7b 100644
--- a/src/Grasp/Interpreter.hs
+++ b/src/Grasp/Interpreter.hs
@@ -4,8 +4,10 @@ module Grasp.Interpreter (
import Control.Monad
+import Control.Exception
import System.Random
import System.IO
+import System.IO.Error
import Text.Read( readMaybe )
import Data.Graph.Inductive.Graph( Node, LNode, LEdge, (&) )
import qualified Data.Graph.Inductive.Graph as Graph
@@ -295,13 +297,16 @@ getcI g node = do
fhL = targetLabels g (getByLabel "fh" edges)
c <- case fhL of
- x | length x == 0 -> getChar >>= return . ord
+ x | length x == 0 -> getChar >>=
+ (\x -> if (x == '\EOT') then return (-1) else return (ord x))
x | length x == 1 -> do
h <- openFile (head fhL) ReadMode
- c <- hGetChar h
+ input <- try (hGetChar h)
hClose h
- return (ord c)
+ case input of
+ Left e -> if (isEOFError e) then return (-1) else ioError e
+ Right inpChr -> return (ord inpChr)
x -> error ("Instruction " ++ (show node) ++
" may only have one file handle")