all repos — min @ 2a8fca89b977629994e15993c1d72886836c606d

A small but practical concatenative programming language.

Improved error handling in tests.
h3rald h3rald@h3rald.com
Sat, 15 Oct 2016 22:39:50 +0200
commit

2a8fca89b977629994e15993c1d72886836c606d

parent

6924adcb0ecfb0e37832b24ec05e3effb91b365a

4 files changed, 23 insertions(+), 16 deletions(-)

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

@@ -154,7 +154,7 @@ result.scope = i.scope

result.currSym = MinValue(column: 1, line: 1, kind: minSymbol, symVal: "") proc error(i: MinInterpreter, message: string) = - if i.currSym.filename == "": + if i.currSym.filename.isNil or i.currSym.filename == "": stderr.writeLine("`$1`: Error - $2" % [i.currSym.symVal, message]) else: stderr.writeLine("$1 [$2,$3] `$4`: Error - $5" % [i.currSym.filename, $i.currSym.line, $i.currSym.column, i.currSym.symVal, message])
M lib/min_lang.nimlib/min_lang.nim

@@ -255,7 +255,10 @@ i.reqStringLike s

var file = s.getString if not file.endsWith(".min"): file = file & ".min" - i.load i.pwd.joinPath(file) + file = i.pwd.joinPath(file) + if not file.fileExists: + raiseInvalid("File '$1' does not exists." % file) + i.load file .symbol("with") do (i: In): var qscope, qprog: MinValue
M tests/lang.mintests/lang.min

@@ -30,30 +30,29 @@ ~five

(symbols "five" contains false ==) assert ( - ( - (+) :myplus - ) =mymath - ) :defmod + (+) :myplus + ) =mymath + + (symbols "mymath" contains) assert - (defmod symbols "mymath" contains) assert - (defmod mymath scope?) assert + (mymath scope?) assert (() scope? false ==) assert (() inspect () ==) assert - (defmod 'mymath import symbols "myplus" contains) assert + ('mymath import symbols "myplus" contains) assert - (defmod 'mymath import 2 3 myplus 5 ==) assert + ('mymath import 2 3 myplus 5 ==) assert ; Extend an existing scope - (defmod + ( ('mymath import (-) :myminus) => @mymath 5 2 mymath ^myminus 3 ==) assert - (defmod mymath inspect ("myplus") ==) assert + (mymath inspect ("myminus" "myplus") ==) assert ;((":mysigil" concat) ', sigil ,test "test:mysigil" ==) assert

@@ -62,7 +61,7 @@

("2 2 +" "tests/testload.min" fwrite 'testload load 4 ==) assert "tests/testload.min" rm - (defmod 2 2 mymath ^myplus 4 ==) assert + (2 2 mymath ^myplus 4 ==) assert (1 2 3 4 get-stack (1 2 3 4) ==) assert

@@ -110,7 +109,7 @@ (first)

("Caught a " swap concat) ) try "Caught a MinEmptyStackError" ==) assert - ("aaaa" :. . "aaaa" ==) assert ;It is possible to shadow sealed symbols in child scopes + ("aaaa" :cd cd "aaaa" ==) assert ;It is possible to shadow sealed symbols in child scopes (((2 :a1 *a1 3 :a1) ("failed")) try "failed" ==) assert

@@ -175,5 +174,4 @@ ((3 4 7 2 4 6 5 6) '< sort (7 6 6 5 4 4 3 2) ==) assert

report ; Tidy up - ~defmod clear-stack
M tests/test.mintests/test.min

@@ -15,7 +15,13 @@ ;; assert

( ' :check ; save the check quotation to validate ' :results ; save the result symbol to update - (check -> true ==) + ( + ( + (check -> true ==) + (1 at :err "\nError: $1" (err) % puts false) + ) try + + ) ( ok results append quote @results "." print!