Added READ-LINE
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 2 Oct 2016 00:12:42 +0000 (13:12 +1300)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 2 Oct 2016 00:12:42 +0000 (13:12 +1300)
src/forth.jl

index d911e21..aa93c2d 100644 (file)
@@ -665,6 +665,22 @@ CLOSE_FILES_CFA = defPrimWord("CLOSE-FILES", () -> begin
 end)
 
 READ_LINE_CFA = defPrimWord("READ-LINE", () -> begin
+    fid = popPS()
+    maxSize = popPS()
+    addr = popPS()
+
+    fh = openFiles[fid]
+    line = readline(fh)
+
+    eofFlag = endswith(line, '\n') ? 0 : -1
+    line = chomp(line)
+
+    putString(line, addr, maxSize)
+
+    pushPS(length(line))
+    pushPS(eofFlag)
+    pushPS(0)
+
     return NEXT
 end)