diff options
-rw-r--r-- | VM.hs | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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) |