Debugging/REPL improvements.
h3rald h3rald@h3rald.com
Sun, 23 Nov 2014 16:30:39 +0100
3 files changed,
16 insertions(+),
8 deletions(-)
M
interpreter.nim
→
interpreter.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
primitives.nim
→
primitives.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: