all repos — min @ 36b32c0288102ecf3b89d435965e3897f4b05e26

A small but practical concatenative programming language.

Improving diagnostics.
h3rald h3rald@h3rald.com
Sun, 03 Jan 2021 15:44:21 +0100
commit

36b32c0288102ecf3b89d435965e3897f4b05e26

parent

7b5a7e98670d260e6411bd50b6661128fe57d36a

M core/interpreter.nimcore/interpreter.nim

@@ -109,16 +109,19 @@ result.scope = i.scope

result.currSym = MinValue(column: 1, line: 1, kind: minSymbol, symVal: "") proc formatError(sym: MinValue, message: string): string = - if sym.filename == "": - return "[$1]: $2" % [sym.symVal, message] - else: - return "$1($2,$3) [$4]: $5" % [sym.filename, $sym.line, $sym.column, sym.symVal, message] + var name = sym.symVal + if sym.parentSym != "": + name = sym.parentSym + return "$1($2,$3) [$4]: $5" % [sym.filename, $sym.line, $sym.column, name, message] proc formatTrace(sym: MinValue): string = + var name = sym.symVal + if sym.parentSym != "": + name = sym.parentSym if sym.filename == "": - return "<native> in symbol: $1" % [sym.symVal] + return "<native> in symbol: $1" % [name] else: - return "$1($2,$3) in symbol: $4" % [sym.filename, $sym.line, $sym.column, sym.symVal] + return "$1($2,$3) in symbol: $4" % [sym.filename, $sym.line, $sym.column, name] proc stackTrace*(i: In) = var trace = i.trace

@@ -230,17 +233,7 @@ proc push*(i: In, val: MinValue) {.gcsafe, extern:"min_exported_symbol_$1".}=

if val.kind == minSymbol: i.debug(val) if not i.evaluating: - if val.line == 0 and val.column == 0 and val.filename == "": - # Simbol was added via min code, get data from previous min symbol - var nval = deepCopy(val) - let pval = i.trace[i.trace.len-1] - nval.symVal = pval.symVal & " > " & nval.symVal - nval.filename = pval.filename - nval.column = pval.column - nval.line = pval.line - i.currSym = nval - else: - i.currSym = val + i.currSym = val i.trace.add val let symbol = val.symVal if symbol == "return":

@@ -416,3 +409,10 @@ return i.eval(s, name, true)

proc read*(i: In, s: string): MinValue = return i.load(s, true) + +# Inherit file/line/column from current symbol +proc pushSym*(i: In, s: string) = + i.push MinValue(kind: minSymbol, symVal: s, filename: i.currSym.filename, line: i.currSym.line, column: i.currSym.column, parentSym: i.currSym.symVal) + +proc newSym*(i: In, s: string): MinValue = + return MinValue(kind: minSymbol, symVal: s, filename: i.currSym.filename, line: i.currSym.line, column: i.currSym.column, parentSym: i.currSym.symVal)
M core/parser.nimcore/parser.nim

@@ -71,6 +71,7 @@ MinValueObject* {.acyclic, final.} = object

line*: int column*: int filename*: string + parentSym*: string case kind*: MinKind of minNull: discard of minInt: intVal*: BiggestInt
M core/value.nimcore/value.nim

@@ -52,9 +52,6 @@

proc newSym*(s: string): MinValue = return MinValue(kind: minSymbol, symVal: s) -proc newSym*(s: string, fn: string): MinValue = - return MinValue(kind: minSymbol, symVal: s, filename: fn) - # Get string value from string or quoted symbol proc getFloat*(v: MinValue): float =
M lib/min_dict.nimlib/min_dict.nim

@@ -73,12 +73,12 @@ let vals = i.expect("dict")

i.push vals[0].objType.newVal def.sigil("?") do (i: In): - i.push("dhas?".newSym) + i.pushSym("dhas?") def.sigil("/") do (i: In): - i.push("dget".newSym) + i.pushSym("dget") def.sigil("%") do (i: In): - i.push("dset".newSym) + i.pushSym("dset") def.finalize("dict")
M lib/min_lang.nimlib/min_lang.nim

@@ -156,7 +156,7 @@ let op = proc(i: In) {.closure.} =

let origscope = i.scope i.scope = scope i.evaluating = true - i.push sym.newSym + i.pushSym sym i.evaluating = false i.scope = origscope qscope.scope.symbols[sym] = MinOperator(kind: minProcOp, prc: op)

@@ -255,7 +255,7 @@ except MinReturnException:

discard # Validate output for k in 0..outVars.len-1: - i.push outVars[k].newSym + i.pushSym outVars[k] let x = i.peek let o = outExpects[k] var r = false;

@@ -521,7 +521,7 @@ i.eval s.strVal

def.symbol("quit") do (i: In): i.push 0.newVal - i.push "exit".newSym + i.pushSym "exit" def.symbol("parse") do (i: In): let vals = i.expect("string")

@@ -556,19 +556,14 @@ let s = vals[0].getString

let parts = s.split("/") if parts.len < 2: raiseInvalid("Dictionary identifier not specified") - i.push parts[0].newSym + i.pushSym parts[0] for p in 0..parts.len-2: let vals = i.expect("dict") let mdl = vals[0] let symId = parts[p+1] - #var q = newSeq[MinValue](0) - #q.add symId.newSym i.push mdl i.push symId.newVal - i.push "call".newSym - #i.push q.newVal - #i.push mdl - #i.push "with".newSym + i.pushSym "call" def.symbol("set-type") do (i: In): let vals = i.expect("'sym", "dict")

@@ -854,7 +849,7 @@ let s = vals[0]

let m = vals[1] i.push @[m].newVal i.push s - i.push "bind".newSym + i.pushSym "bind" def.symbol("quote-define") do (i: In): let vals = i.expect("string", "a")

@@ -862,7 +857,7 @@ let s = vals[0]

let m = vals[1] i.push @[m].newVal i.push s - i.push "define".newSym + i.pushSym "define" def.symbol("args") do (i: In):

@@ -994,72 +989,72 @@

def.sigil("'") do (i: In): let vals = i.expect("string") let s = vals[0] - i.push(@[s.strVal.newSym].newVal) + i.push(@[i.newSym(s.strVal)].newVal) def.sigil(":") do (i: In): - i.push("define".newSym) + i.pushSym("define") def.sigil("~") do (i: In): - i.push("delete".newSym) + i.pushSym("delete") def.sigil("@") do (i: In): - i.push("bind".newSym) + i.pushSym("bind") def.sigil("+") do (i: In): - i.push("module".newSym) + i.pushSym("module") def.sigil("^") do (i: In): - i.push("call".newSym) + i.pushSym("call") def.sigil("*") do (i: In): - i.push("invoke".newSym) + i.pushSym("invoke") def.sigil(">") do (i: In): - i.push("save-symbol".newSym) + i.pushSym("save-symbol") def.sigil("<") do (i: In): - i.push("load-symbol".newSym) + i.pushSym("load-symbol") def.sigil("#") do (i: In): - i.push("quote-bind".newSym) + i.pushSym("quote-bind") def.sigil("=") do (i: In): - i.push("quote-define".newSym) + i.pushSym("quote-define") # Shorthand symbol aliases def.symbol("#") do (i: In): - i.push("quote-bind".newSym) + i.pushSym("quote-bind") def.symbol("=") do (i: In): - i.push("quote-define".newSym) + i.pushSym("quote-define") def.symbol("=-=") do (i: In): - i.push("expect-empty-stack".newSym) + i.pushSym("expect-empty-stack") def.symbol(":") do (i: In): - i.push("define".newSym) + i.pushSym("define") def.symbol("@") do (i: In): - i.push("bind".newSym) + i.pushSym("bind") def.symbol("^") do (i: In): - i.push("call".newSym) + i.pushSym("call") def.symbol("'") do (i: In): - i.push("quote".newSym) + i.pushSym("quote") def.symbol("->") do (i: In): - i.push("dequote".newSym) + i.pushSym("dequote") def.symbol("--") do (i: In): - i.push("reverse-expect-dequote".newSym) + i.pushSym("reverse-expect-dequote") def.symbol("::") do (i: In): - i.push("operator".newSym) + i.pushSym("operator") def.symbol("=>") do (i: In): - i.push("apply".newSym) + i.pushSym("apply") def.symbol("==>") do (i: In): discard # used within operator defs

@@ -1068,9 +1063,9 @@ def.symbol("return") do (i: In):

discard # used within operator defs def.symbol(">>") do (i: In): - i.push("prefix-dequote".newSym) + i.pushSym("prefix-dequote") def.symbol("><") do (i: In): - i.push("infix-dequote".newSym) + i.pushSym("infix-dequote") def.finalize("ROOT")
M lib/min_logic.nimlib/min_logic.nim

@@ -261,9 +261,9 @@ else:

i.push (vals[1].typename == vals[0].getString).newVal def.symbol("&&") do (i: In): - i.push("expect-all".newSym) + i.pushSym("expect-all") def.symbol("||") do (i: In): - i.push("expect-any".newSym) + i.pushSym("expect-any") def.finalize("logic")
M lib/min_stack.nimlib/min_stack.nim

@@ -122,8 +122,8 @@ q.qVal = @[v] & q.qVal

i.push q def.symbol("swons") do (i: In): - i.push "swap".newSym - i.push "cons".newSym + i.pushSym "swap" + i.pushSym "cons" def.symbol("sip") do (i: In): let vals = i.expect("quot", "quot")
M lib/min_str.nimlib/min_str.nim

@@ -27,8 +27,8 @@ let res = s.strVal % strings

i.push res.newVal def.symbol("apply-interpolate") do (i: In): - i.push "apply".newSym - i.push "interpolate".newSym + i.pushSym "apply" + i.pushSym "interpolate" def.symbol("strip") do (i: In): let vals = i.expect("'sym")

@@ -212,7 +212,7 @@ raiseInvalid("major, minor, and patch values are not integers")

i.push(newVal("$#.$#.$#" % [$major, $minor, $patch])) def.symbol("semver-inc-major") do (i: In): - i.push("from-semver".newSym) + i.pushSym("from-semver") var d = i.pop let cv = i.dget(d, "major") let v = cv.intVal + 1

@@ -220,26 +220,26 @@ i.dset(d, "major", v.newVal)

i.dset(d, "minor", 0.newVal) i.dset(d, "patch", 0.newVal) i.push(d) - i.push("to-semver".newSym) + i.pushSym("to-semver") def.symbol("semver-inc-minor") do (i: In): - i.push("from-semver".newSym) + i.pushSym("from-semver") var d = i.pop let cv = i.dget(d, "minor") let v = cv.intVal + 1 i.dset(d, "minor", v.newVal) i.dset(d, "patch", 0.newVal) i.push(d) - i.push("to-semver".newSym) + i.pushSym("to-semver") def.symbol("semver-inc-patch") do (i: In): - i.push("from-semver".newSym) + i.pushSym("from-semver") var d = i.pop let cv = i.dget(d, "patch") let v = cv.intVal + 1 i.dset(d, "patch", v.newVal) i.push(d) - i.push("to-semver".newSym) + i.pushSym("to-semver") def.symbol("escape") do (i: In): let vals = i.expect("'sym")

@@ -261,12 +261,12 @@ var s = a & b

i.push s.newVal def.symbol("=~") do (i: In): - i.push("regex".newSym) + i.pushSym("regex") def.symbol("%") do (i: In): - i.push("interpolate".newSym) + i.pushSym("interpolate") def.symbol("=%") do (i: In): - i.push("apply-interpolate".newSym) + i.pushSym("apply-interpolate") def.finalize("str")
M lib/min_sys.nimlib/min_sys.nim

@@ -213,25 +213,25 @@ let f = vals[0]

i.push f.getString.parentDir.unix.newVal def.symbol("$") do (i: In): - i.push("get-env".newSym) + i.pushSym("get-env") def.symbol("!") do (i: In): - i.push("system".newSym) + i.pushSym("system") def.symbol("!!") do (i: In): - i.push("system!".newSym) + i.pushSym("system!") def.symbol("&") do (i: In): - i.push("run".newSym) + i.pushSym("run") def.sigil("$") do (i: In): - i.push("get-env".newSym) + i.pushSym("get-env") def.sigil("!") do (i: In): - i.push("system".newSym) + i.pushSym("system") def.sigil("&") do (i: In): - i.push("run".newSym) + i.pushSym("run") when not defined(lite): def.symbol("unzip") do (i: In):
M min.nimmin.nim

@@ -332,7 +332,7 @@ var s = newStringStream("")

i.open(s, "<repl>") var line: string while true: - i.push("prompt".newSym(i.filename)) + i.push(i.newSym("prompt")) let vals = i.expect("string") let v = vals[0] let prompt = v.getString()

@@ -355,7 +355,7 @@ let symbols = toSeq(i.scope.symbols.keys)

EDITOR.completionCallback = proc(ed: LineEditor): seq[string] = return ed.getCompletions(symbols) # evaluate prompt - i.push("prompt".newSym(i.filename)) + i.push(i.newSym("prompt")) let vals = i.expect("string") let v = vals[0] let prompt = v.getString()
M min.ymlmin.yml

@@ -1,5 +1,5 @@

author: Fabio Cevasco description: A tiny concatenative programming language and shell. -id: 35901301 +id: 35924740 name: min -version: 0.27.1+version: 0.27.2
M next-release.mdnext-release.md

@@ -1,2 +1,1 @@

-* Fixed handling if escaped / characters in regex operator -* Fixed fatal error in REPL +* Improved diagnostics for native symbols calling other symbols.
M site/settings.jsonsite/settings.json

@@ -6,5 +6,5 @@ "rules": "rules.min",

"temp": "temp", "templates": "templates", "title": "min language", - "version": "0.27.1" + "version": "0.27.2" }