lib/min_io.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os, strutils import ../core/types, ../core/parser, ../core/interpreter, ../core/utils # I/O proc io_module*(i: In) = i.define("io") .symbol("newline") do (i: In): echo "" .symbol("put") do (i: In): let a = i.peek echo $$a .symbol("get") do (i: In): i.push newVal(stdin.readLine()) .symbol("print") do (i: In): let a = i.peek a.print .symbol("fread") do (i: In): var a: MinValue i.reqString a i.push newVal(a.strVal.readFile) .symbol("fwrite") do (i: In): var a, b: MinValue i.reqTwoStrings a, b a.strVal.writeFile(b.strVal) .symbol("fappend") do (i: In): var a, b: MinValue i.reqTwoStrings a, b var f:File discard f.open(a.strVal, fmAppend) f.write(b.strVal) f.close() .finalize() |