summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VM.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/VM.hs b/VM.hs
index ae9dc6f..7baea0d 100644
--- a/VM.hs
+++ b/VM.hs
@@ -129,8 +129,11 @@ vmRunBuiltin state "sys-close-file" [RVNum fid] = do
hClose (sHandles state ! fid)
return (RVList [], state { sHandles = Map.delete fid (sHandles state) })
vmRunBuiltin state "sys-get-char" [RVNum fid] = do
- ch <- hGetChar (sHandles state ! fid)
- return (RVString [ch], state)
+ let h = sHandles state ! fid
+ eof <- hIsEOF h
+ if eof
+ then return (RVList [], state)
+ else hGetChar h >>= \ch -> return (RVString [ch], state)
vmRunBuiltin state "sys-put-string" [RVNum fid, RVString str] = do
hPutStr (sHandles state ! fid) str
return (RVList [], state)