all repos — min @ f8269cf24b8f42a1d008046d6f4786bc1dea20b0

A small but practical concatenative programming language.

Debugging/REPL improvements.
h3rald h3rald@h3rald.com
Sun, 23 Nov 2014 16:30:39 +0100
commit

f8269cf24b8f42a1d008046d6f4786bc1dea20b0

parent

adb07b0894a9fadef787589ec7d8773f85107fab

3 files changed, 16 insertions(+), 8 deletions(-)

jump to
M interpreter.niminterpreter.nim

@@ -7,7 +7,8 @@ stack: TMinStack

parser*: TMinParser currSym: TMinValue filename: string - debugging: bool + debugging: bool + evaluating*: bool TMinOperator* = proc (i: var TMinInterpreter) TMinError* = enum errSystem,

@@ -43,7 +44,11 @@ return i

proc error*(i: TMinInterpreter, status: TMinError, message = "") = var msg = if message == "": ERRORS[status] else: message - stderr.writeln("$1[$2,$3] `$4`: Error - $5" %[i.filename, $i.currSym.line, $i.currSym.last, i.currSym.symVal, msg]) + var start = "" + if i.filename != "": + stderr.writeln("$1[$2,$3] `$4`: Error - $5" %[i.filename, $i.currSym.line, $i.currSym.last, i.currSym.symVal, msg]) + else: + stderr.writeln("`$1`: Error - $2" %[i.currSym.symVal, msg]) quit(int(status)) proc open*(i: var TMinInterpreter, stream:PStream, filename: string) =

@@ -57,16 +62,17 @@ proc dump*(i: TMinInterpreter): string =

var s = "" for item in i.stack: s = s & $item & " " - return s.strip + return s -proc debug(i: var TMinInterpreter, value: string = "") = +proc debug(i: var TMinInterpreter, value: TMinValue) = if i.debugging: - stderr.writeln("DEBUG: " &i.dump & value) + stderr.writeln("-- " &i.dump & $value) proc push*(i: var TMinInterpreter, val: TMinValue) = + i.debug val if val.kind == minSymbol: - i.currSym = val - i.debug " "&val.symVal + if not i.evaluating: + i.currSym = val if SYMBOLS.hasKey(val.symVal): try: SYMBOLS[val.symVal](i)
M minim.nimminim.nim

@@ -53,7 +53,7 @@

proc minimRepl*() = var i = newMinInterpreter(debugging) var s = newStringStream("") - i.open(s, "repl") + i.open(s, "") setControlCHook(handleReplCtrlC) echo "MiNiM v"&version&" - REPL initialized." echo "-> Press Ctrl+C to exit."
M primitives.nimprimitives.nim

@@ -174,8 +174,10 @@ let q2 = i.pop

if q1.isQuotation and q2.isQuotation: if q1.qVal.len == 1 and q1.qVal[0].kind == minSymbol: minsym q1.qVal[0].symVal: + i.evaluating = true for item in q2.qVal: i.push item + i.evaluating = false else: i.error(errIncorrect, "The top quotation must contain only one symbol value") else: