all repos — min @ 302caeb12e8e5ee93bbec3e656c6b6bc89c508a6

A small but practical concatenative programming language.

Started fixing tests.
h3rald h3rald@h3rald.com
Sat, 02 Jun 2018 21:37:12 +0200
commit

302caeb12e8e5ee93bbec3e656c6b6bc89c508a6

parent

bccfe44249ad4f4b827a0031a627abfa6327c447

7 files changed, 24 insertions(+), 36 deletions(-)

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

@@ -14,10 +14,10 @@

type MinTrappedException* = ref object of SystemError MinRuntimeError* = ref object of SystemError - qVal*: seq[MinValue] + data*: MinValue -proc raiseRuntime*(msg: string, qVal: var seq[MinValue]) {.extern:"min_exported_symbol_$1".}= - raise MinRuntimeError(msg: msg, qVal: qVal) +proc raiseRuntime*(msg: string, data: MinValue) {.extern:"min_exported_symbol_$1".}= + raise MinRuntimeError(msg: msg, data: data) proc dump*(i: MinInterpreter): string {.extern:"min_exported_symbol_$1".}= var s = ""
M core/parser.nimcore/parser.nim

@@ -600,7 +600,7 @@ var d = "{"

for i in a.dVal.pairs: var v = "" if i.val.kind == minProcOp: - v = "<compiled>" + v = "<native>" else: v = $i.val.val if (not i.val.quotation):

@@ -636,7 +636,7 @@ var d = "{"

for i in a.dVal.pairs: var v = "" if i.val.kind == minProcOp: - v = "<compiled>" + v = "<native>" else: v = $i.val.val if (not i.val.quotation):
M core/utils.nimcore/utils.nim

@@ -52,7 +52,7 @@ proc dget*(i: In, q: MinValue, s: MinValue): MinValue {.extern:"min_exported_symbol_$1".}=

if not q.isDictionary: raiseInvalid("Value is not a dictionary") if q.dVal[s.getString].kind == minProcOp: - raiseInvalid("Key '$1' is set to a compiled value that cannot be retrieved." % [s.getString]) + raiseInvalid("Key '$1' is set to a native value that cannot be retrieved." % [s.getString]) var val = q.dVal[s.getString].val result = i.call(val) if result.qVal.len == 1:

@@ -62,7 +62,7 @@ proc dget*(i: In, q: MinValue, s: string): MinValue {.extern:"min_exported_symbol_$1_2".}=

if not q.isDictionary: raiseInvalid("Value is not a dictionary") if q.dVal[s].kind == minProcOp: - raiseInvalid("Key $1 is set to a compiled value that cannot be retrieved." % [s]) + raiseInvalid("Key $1 is set to a native value that cannot be retrieved." % [s]) var val = q.dVal[s].val result = i.call(val) if result.qVal.len == 1 and result.qVal[0].kind != minQuotation:

@@ -120,7 +120,7 @@ # Assumes q is a dictionary

var r = newSeq[MinValue](0) for item in q.dVal.values: if item.kind == minProcOp: - raiseInvalid("Dictionary contains compiled values that cannot be accessed.") + raiseInvalid("Dictionary contains native values that cannot be accessed.") var v = item.val var val = i.call(v) if val.qVal.len == 1 and val.qVal[0].kind != minQuotation:
M lib/min_lang.nimlib/min_lang.nim

@@ -246,7 +246,7 @@ def.symbol("raise") do (i: In):

let vals = i.expect("dict") let err = vals[0] if err.dhas("error".newVal) and err.dhas("message".newVal): - raiseRuntime("($1) $2" % [i.dget(err, "error".newVal).getString, i.dget(err, "message").getString], err.qVal) + raiseRuntime("($1) $2" % [i.dget(err, "error".newVal).getString, i.dget(err, "message").getString], err) else: raiseInvalid("Invalid error dictionary")

@@ -296,21 +296,22 @@ except MinRuntimeError:

if not hasCatch: return let e = (MinRuntimeError)getCurrentException() - i.push e.qVal.newVal(i.scope) + e.data = newDict(i.scope) + i.push e.data i.dequote(catch) except: if not hasCatch: return let e = getCurrentException() - var res = newSeq[MinValue](0) + var res = newDict(i.scope) let err = sgregex.replace($e.name, ":.+$", "") - res.add @["error".newVal, err.newVal].newVal(i.scope) - res.add @["message".newVal, e.msg.newVal].newVal(i.scope) - res.add @["symbol".newVal, i.currSym].newVal(i.scope) - res.add @["filename".newVal, i.currSym.filename.newVal].newVal(i.scope) - res.add @["line".newVal, i.currSym.line.newVal].newVal(i.scope) - res.add @["column".newVal, i.currSym.column.newVal].newVal(i.scope) - i.push res.newVal(i.scope) + i.dset(res, "error", err.newVal) + i.dset(res, "message", e.msg.newVal) + i.dset(res, "symbol", i.currSym) + i.dset(res, "filename", i.currSym.filename.newVal) + i.dset(res, "line", i.currSym.line.newVal) + i.dset(res, "column", i.currSym.column.newVal) + i.push res i.dequote(catch) finally: if hasFinally:
M lib/min_sys.nimlib/min_sys.nim

@@ -59,7 +59,10 @@ def.symbol("run") do (i: In):

let vals = i.expect("'sym") let cmd = vals[0] let res = execCmdEx(cmd.getString) - i.push @[@["output".newVal, res.output.newVal].newVal(i.scope), @["code".newVal, res.exitCode.newVal].newVal(i.scope)].newVal(i.scope) + var d = newDict(i.scope) + i.dset(d, "output", res.output.newVal) + i.dset(d, "code", res.exitCode.newVal) + i.push(d) def.symbol("get-env") do (i: In): let vals = i.expect("'sym")
M min.nimmin.nim

@@ -225,7 +225,7 @@ echo "{$1} -> {" % n

for item in res.dVal.pairs: var v = "" if item.val.kind == minProcOp: - v = "<compiled>" + v = "<native>" else: v = $item.val.val if (not item.val.quotation):
M tests/seq.mintests/seq.min

@@ -33,22 +33,6 @@ ((1 2 3 4) (2 +) map (3 4 5 6) ==) assert

((5 4 3 2 1) reverse (1 2 3 4 5) ==) assert - ((("a" 1)("b" 2)("c" 3)) dictionary?) assert - - ((("a" 1)("b" 2)("c" 3)) 'b dget 2 ==) assert - - ((("a" 1)("b" 2)("c" 3)) ' :dict dict 5 'b dset 7 %d =newdict newdict (("a" 1)("b" 5)("c" 3)("d" 7)) == dict (("a" 1)("b" 2)("c" 3)) == and) assert - - ((("a" 1)("b" 2)("c" 3)) ' :dict dict 'b ddel =newdict newdict (("a" 1)("c" 3)) == dict (("a" 1)("b" 2)("c" 3)) == and) assert - - ((("a" 1)("b" 2)("c" 3)) dkeys ("a" "b" "c") ==) assert - - ((("a" 1)("b" 2)("c" 3)) dvalues (1 2 3) ==) assert - - ((("a" 4) ("c" 8) ("f" 2) ("b" 0)) dsort (("a" 4)("b" 0)("c" 8)("f" 2)) ==) assert - - ((("a" 1) ("b" 2) ("c" 3) ("d" 4)) ("b" "c") dpick (("b" 2) ("c" 3)) ==) assert - ((3 4 7 2 4 6 5 6) '> sort (2 3 4 4 5 6 6 7) ==) assert ((3 4 7 2 4 6 5 6) '< sort (7 6 6 5 4 4 3 2) ==) assert