all repos — min @ 41a367c2ef810139724e5df1b65b01d47990830f

A small but practical concatenative programming language.

refactor(errors) Improved error handling.
h3rald h3rald@h3rald.com
Sun, 29 May 2016 21:13:48 +0200
commit

41a367c2ef810139724e5df1b65b01d47990830f

parent

6570dc0b3eee7f89194d405d680da6e7647997a5

5 files changed, 19 insertions(+), 11 deletions(-)

jump to
M core/interpreter.nimcore/interpreter.nim

@@ -12,6 +12,7 @@ "Insufficient items on the stack",

"Quotation not found on the stack", "Symbol undefined", "Incorrect items on the stack", + "Runtime error", "Two numbers are required on the stack", "Division by zero" ]
M core/types.nimcore/types.nim

@@ -91,5 +91,6 @@ errEmptyStack,

errNoQuotation, errUndefined, errIncorrect, + errRuntime, errTwoNumbersRequired, errDivisionByZero
M lib/io.nimlib/io.nim

@@ -31,9 +31,9 @@ if a.strVal.fileExists:

try: i.push newVal(a.strVal.readFile) except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: - warn "File '$1' not found" % [a.strVal] + i.error errRuntime, "File '$1' not found" % [a.strVal] else: i.error(errIncorrect, "A string is required on the stack")

@@ -44,7 +44,7 @@ if a.isString and b.isString:

try: a.strVal.writeFile(b.strVal) except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error(errIncorrect, "Two strings are required on the stack")

@@ -58,7 +58,7 @@ discard f.open(a.strVal, fmAppend)

f.write(b.strVal) f.close() except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error(errIncorrect, "Two strings are required on the stack")
M lib/lang.nimlib/lang.nim

@@ -49,6 +49,7 @@ elif q2.isQuotation and q2.qVal.len == 1 and q2.qVal[0].kind == minSymbol:

symbol = q2.qVal[0].symVal else: i.error errIncorrect, "The top quotation must contain only one symbol value" + return i.debug "[let] " & symbol & " = " & $q1 i.scope.parent.symbols[symbol] = proc(i: var MinInterpreter) = #i.evaluating = true

@@ -68,6 +69,7 @@ elif q2.isQuotation and q2.qVal.len == 1 and q2.qVal[0].kind == minSymbol:

symbol = q2.qVal[0].symVal else: i.error errIncorrect, "The top quotation must contain only one symbol value" + return i.debug "[bind] " & symbol & " = " & $q1 #if not i.filename.isNil and i.filename != "eval": # echo "BIND $1 - fn: $2" % [symbol, i.filename]

@@ -93,6 +95,7 @@ let name = i.pop

var code = i.pop if not name.isString or not code.isQuotation: i.error(errIncorrect, "A string and a quotation are require on the stack") + return let id = name.strVal let scope = i.scope let stack = i.copystack

@@ -140,6 +143,7 @@ var symbol = q1.qVal[0].symVal

if symbol.len == 1: if i.scope.parent.sigils.hasKey(symbol): i.error errSystem, "Sigil '$1' already exists" % [symbol] + return #q2.filename = i.filename # Save filename for diagnostic purposes i.scope.parent.sigils[symbol] = proc(i: var MinInterpreter) = i.evaluating = true

@@ -269,6 +273,7 @@ .symbol("unquote") do (i: In):

var q = i.pop if not q.isQuotation: i.error errNoQuotation + return i.newScope("<unquote-push>", q): for item in q.qVal: i.push item

@@ -287,6 +292,7 @@ var q = i.pop

let v = i.pop if not q.isQuotation: i.error errNoQuotation + return q.qVal = @[v] & q.qVal i.push q
M lib/sys.nimlib/sys.nim

@@ -18,7 +18,7 @@ if f.isString:

try: f.strVal.setCurrentDir except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "A string is required on the stack"

@@ -31,7 +31,7 @@ for i in walkdir(a.strVal):

list.add newVal(i.path) i.push list.newVal else: - warn "Directory '$1' not found" % [a.strVal] + i.error errRuntime, "Directory '$1' not found" % [a.strVal] else: i.error(errIncorrect, "A string is required on the stack")

@@ -95,7 +95,7 @@ if f.isString:

try: f.strVal.removeFile except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "A string is required on the stack"

@@ -106,7 +106,7 @@ if a.isString and b.isString:

try: copyFile a.strVal, b.strVal except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "Two strings are required on the stack"

@@ -117,7 +117,7 @@ if a.isString and b.isString:

try: moveFile a.strVal, b.strVal except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "Two strings are required on the stack"

@@ -127,7 +127,7 @@ if f.isString:

try: f.strVal.removeDir except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "A string is required on the stack"

@@ -137,7 +137,7 @@ if f.isString:

try: f.strVal.createDir except: - warn getCurrentExceptionMsg() + i.error errRuntime, getCurrentExceptionMsg() else: i.error errIncorrect, "A string is required on the stack"