all repos — min @ 464ed0071111ead5e51fe40eaa952aca30385d4f

A small but practical concatenative programming language.

Merge branch 'master' of github.com:h3rald/min
h3rald h3rald@h3rald.com
Sun, 26 Jan 2020 12:11:03 +0100
commit

464ed0071111ead5e51fe40eaa952aca30385d4f

parent

d5a0977174c8fa31e454bfd966c07ae3244e373c

2 files changed, 43 insertions(+), 24 deletions(-)

jump to
M min.nimmin.nim

@@ -242,32 +242,43 @@ echo " ".repeat(n.len) & " }"

else: echo "[$1] -> $2" % [$i.stack.len, $i.stack[i.stack.len - 1]] -proc minRepl*(i: var MinInterpreter) = +proc minRepl*(i: var MinInterpreter, simple = false) = i.stdLib() i.dynLib() var s = newStringStream("") i.open(s, "<repl>") var line: string var ed = initEditor(historyFile = MINHISTORY) - while true: - let symbols = toSeq(i.scope.symbols.keys) - ed.completionCallback = proc(ed: LineEditor): seq[string] = - return ed.getCompletions(symbols) - # evaluate prompt - i.push("prompt".newSym) - let vals = i.expect("string") - let v = vals[0] - let prompt = v.getString() - line = ed.readLine(prompt) - i.printResult i.interpret($line) + if simple: + while true: + i.push("prompt".newSym) + let vals = i.expect("string") + let v = vals[0] + let prompt = v.getString() + stdout.write(prompt) + line = stdin.readLine() + i.printResult i.interpret($line) + else: + while true: + let symbols = toSeq(i.scope.symbols.keys) + ed.completionCallback = proc(ed: LineEditor): seq[string] = + return ed.getCompletions(symbols) + # evaluate prompt + i.push("prompt".newSym) + let vals = i.expect("string") + let v = vals[0] + let prompt = v.getString() + line = ed.readLine(prompt) + i.printResult i.interpret($line) -proc minRepl*() = +proc minRepl*(simple = false) = var i = newMinInterpreter(filename = "<repl>") - i.minRepl + i.minRepl(simple) when isMainModule: var REPL = false + var SIMPLEREPL = false var INSTALL = false var UNINSTALL = false var libfile = ""

@@ -281,14 +292,15 @@

Arguments: filename A $1 file to interpret (default: STDIN). Options: - -—install:<lib> Install dynamic library file <lib> - —-uninstall:<lib> Uninstall dynamic library file <lib> - -l, --log Set log level (debug|info|notice|warn|error|fatal) - Default: notice - -e, --evaluate Evaluate a $1 program inline - -h, —-help Print this help - -v, —-version Print the program version - -i, —-interactive Start $1 shell""" % [pkgName, pkgVersion] + -—install:<lib> Install dynamic library file <lib> + —-uninstall:<lib> Uninstall dynamic library file <lib> + -l, --log Set log level (debug|info|notice|warn|error|fatal) + Default: notice + -e, --evaluate Evaluate a $1 program inline + -h, —-help Print this help + -v, —-version Print the program version + -i, —-interactive Start $1 shell (with advanced prompt) + -j, --interactive-simple Start $1 shell (without advanced prompt)""" % [pkgName, pkgVersion] var file, s: string = "" var args = newSeq[string](0)

@@ -320,6 +332,9 @@ quit(0)

of "interactive", "i": if file == "": REPL = true + of "interactive-simple", "j": + if file == "": + SIMPLEREPL = true of "install": if file == "": INSTALL = true

@@ -359,8 +374,8 @@ fatal("Unable to uninstall library file: " & libfile)

quit(6) notice("Dynamic linbrary uninstalled successfully: " & libfile.extractFilename) quit(0) - elif REPL: - minRepl() + elif REPL or SIMPLEREPL: + minRepl(SIMPLEREPL) quit(0) else: minFile stdin, "stdin"
M site/contents/download.mdsite/contents/download.md

@@ -66,6 +66,10 @@ > [[/Users/h3rald/test]$](class:prompt)

To exit min shell, press [CTRL+C](class:kbd) or type [0 exit](class:cmd) and press [ENTER](class:kbd). +> %tip% +> +> By default, the min shell provides advanced features like tab-completion, history, etc. If however you run into problems, you can disable these features by running [min -i](class:cmd) instead, and run min shell with a bare-bones REPL. + ## Executing a min Program To execute a min script, you can: