X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=blobdiff_plain;f=src%2Fforth.jl;fp=src%2Fforth.jl;h=01b39a2835cee700af82193e106a3f97aee0eae5;hp=e391d0053e210231567879fabeac419fe85ce420;hb=537dae593d08b551430039129dccc2dbdd11ad2d;hpb=acee38d57f2ee38911c4ed46bab9b7a864686c24 diff --git a/src/forth.jl b/src/forth.jl index e391d00..01b39a2 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -683,8 +683,6 @@ READ_LINE_CFA = defPrimWord("READ-LINE", () -> begin eofFlag = endswith(line, '\n') ? 0 : -1 line = chomp(line) - #println("Reading: $line"); - putString(line, addr, maxSize) pushPS(length(line)) @@ -694,6 +692,25 @@ READ_LINE_CFA = defPrimWord("READ-LINE", () -> begin return NEXT end) +READ_FILE_CFA = defPrimWord("READ-FILE", () -> begin + fid = popPS() + size = popPS() + addr = popPS() + + fh = openFiles[fid] + + string = join(map(x -> Char(x), read(fh, size)), "") + + eofFlag = length(string) == size ? 0 : -1 ; + + putString(string, addr, length(string)) + + pushPS(length(string)) + pushPS(eofFlag) + + return NEXT +end) + EMIT_CFA = defPrimWord("EMIT", () -> begin print(Char(popPS()))