all repos — min @ e3d14865a90c31798aad081b399589d56df75843

A small but practical concatenative programming language.

Added init parameter to register custom native modules.
h3rald h3rald@h3rald.com
Sun, 06 Nov 2016 10:42:07 +0100
commit

e3d14865a90c31798aad081b399589d56df75843

parent

64b5b3977bf06564d7cd498257f8916376708147

1 files changed, 8 insertions(+), 7 deletions(-)

jump to
M minim.nimminim.nim

@@ -116,10 +116,11 @@ if not MINIMRC.fileExists:

MINIMRC.writeFile("") i.eval MINIMRC.readFile() -proc minimStream(s: Stream, filename: string, debugging = false) = +proc minimStream(s: Stream, filename: string, debugging = false, init = proc(i: In) = discard) = var i = newMinInterpreter(debugging) i.pwd = filename.parentDir i.stdLib() + i.init() i.open(s, filename) discard i.parser.getToken() try:

@@ -128,22 +129,22 @@ except:

discard i.close() -proc minimString*(buffer: string, debugging = false) = - minimStream(newStringStream(buffer), "input", debugging) +proc minimString*(buffer: string, debugging = false, init = proc(i: In) = discard) = + minimStream(newStringStream(buffer), "input", debugging, init) -proc minimFile*(filename: string, debugging = false) = +proc minimFile*(filename: string, debugging = false, init = proc(i: In) = discard) = var stream = newFileStream(filename, fmRead) if stream == nil: stderr.writeLine("Error - Cannot read from file: "& filename) stderr.flushFile() - minimStream(stream, filename, debugging) + minimStream(stream, filename, debugging, init) -proc minimFile*(file: File, filename="stdin", debugging = false) = +proc minimFile*(file: File, filename="stdin", debugging = false, init = proc(i: In) = discard) = var stream = newFileStream(stdin) if stream == nil: stderr.writeLine("Error - Cannot read from "& filename) stderr.flushFile() - minimStream(stream, filename, debugging) + minimStream(stream, filename, debugging, init) proc printResult(i: In, res: MinValue) = if res.isNil: