all repos — min @ 99b1b316d5c49c3bdbe5b52972b07d7a730d7999

A small but practical concatenative programming language.

Reviewed scope names; improved logging.
h3rald h3rald@h3rald.com
Wed, 09 Nov 2016 12:29:59 +0100
commit

99b1b316d5c49c3bdbe5b52972b07d7a730d7999

parent

41457007e36ed75329baafa3c10b3392cf88be8a

M core/consts.nimcore/consts.nim

@@ -2,7 +2,8 @@ import

os, parsecfg, streams, - strutils + strutils, + logging const cfgfile = "../minim.nimble".slurp

@@ -27,13 +28,13 @@ version = e.value

else: discard of cfgError: - stderr.writeLine("Configuration error.") + error("Configuration error.") quit(1) else: discard close(p) else: - stderr.writeLine("Cannot process configuration file.") + error("Cannot process configuration file.") quit(2)

@@ -45,5 +46,4 @@ HOME = getenv("HOME")

let MINIMRC* = HOME / ".minimrc" let MINIMSYMBOLS* = HOME / ".minim_symbols" -let MINIMHISTORY* = HOME / ".minim_history" - +let MINIMHISTORY* = HOME / ".minim_history"
M core/fileutils.nimcore/fileutils.nim

@@ -97,5 +97,4 @@ result.incl fpOthersWrite

if others == 7: result.incl fpOthersRead result.incl fpOthersWrite - result.incl fpOthersExec - + result.incl fpOthersExec
M core/interpreter.nimcore/interpreter.nim

@@ -40,7 +40,7 @@ res = i.scope

i.scope = origScope template withScope*(i: In, q: MinValue, body: untyped): untyped = - var scope = newScopeRef(i.scope) + var scope = newScopeRef(i.scope, "with") i.withScope(q, scope): body

@@ -89,7 +89,7 @@ proc stackTrace(i: In) =

var trace = i.trace trace.reverse() for sym in trace: - stderr.writeLine sym.formatTrace + info sym.formatTrace proc error(i: In, message: string) = error(i.currSym.formatError(message))

@@ -117,7 +117,7 @@ else:

i.push(op.val) proc apply*(i: In, op: MinOperator, name="apply") = - var scope = newScopeRef(i.scope) + var scope = newScopeRef(i.scope, name) i.apply(op, scope) proc push*(i: In, val: MinValue) =

@@ -167,7 +167,7 @@ i.push val

except MinRuntimeError: let msg = getCurrentExceptionMsg() i.stack = i.stackcopy - stderr.writeLine("(!) $1:$2,$3 $4" % [i.currSym.filename, $i.currSym.line, $i.currSym.column, msg]) + error("$1:$2,$3 $4" % [i.currSym.filename, $i.currSym.line, $i.currSym.column, msg]) i.stackTrace raise MinTrappedException(msg: msg) except MinTrappedException:

@@ -187,7 +187,7 @@ for v in q.qVal:

i.push v proc unquote*(i: In, name: string, q: var MinValue) = - var scope = newScopeRef(i.scope) + var scope = newScopeRef(i.scope, "unquote") i.unquote(name, q, scope) proc eval*(i: In, s: string, name="<eval>") =

@@ -208,4 +208,4 @@ i2.interpret()

i.trace = i2.trace i.stackcopy = i2.stackcopy i.stack = i2.stack - i.scope = i2.scope + i.scope = i2.scope
M core/linedit.nimcore/linedit.nim

@@ -496,5 +496,4 @@ while true:

var ed = initEditor(historyFile = nil) echo "---", ed.readLine("-> "), "---" - testChar() - + testChar()
M core/parser.nimcore/parser.nim

@@ -146,7 +146,7 @@ "false"

] proc newScope*(parent: ref MinScope, name="scope"): MinScope = - result = MinScope(name: "<$1:$2>" % [name, $genOid()], parent: parent) + result = MinScope(name: "$1/$2" % [name, $genOid()], parent: parent) proc newScopeRef*(parent: ref MinScope, name="scope"): ref MinScope = new(result)
M core/regex.nimcore/regex.nim

@@ -74,6 +74,4 @@ "127.0.0.1".treplace("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$", "$4.$3.$1.$2")

"127.0.0.1".treplace("[0-9]+", "255") "Hello".tsearch("HELLO", "i") "Hello\nWorld!".tsearch("HELLO.WORLD", "mis") - "Testing".toperator("s/test/eat/i") - - + "Testing".toperator("s/test/eat/i")
M core/scope.nimcore/scope.nim

@@ -10,7 +10,7 @@ if not scope.parent.isNil:

result = scope.parent.fullname & ":" & result proc copy*(s: ref MinScope): ref MinScope = - var scope = newScope(s.parent, "copy($1)" % s.name) + var scope = newScope(s.parent, "copy/$1" % s.name) scope.symbols = s.symbols new(result) result[] = scope

@@ -76,4 +76,4 @@ proc previous*(scope: ref MinScope): ref MinScope =

if scope.parent.isNil: return scope else: - return scope.parent + return scope.parent
M core/utils.nimcore/utils.nim

@@ -210,4 +210,4 @@

proc reqDictionary*(i: In, q: var MinValue) = q = i.pop if not q.isDictionary: - raiseInvalid("An dictionary is required on the stack") + raiseInvalid("An dictionary is required on the stack")
M core/value.nimcore/value.nim

@@ -77,5 +77,4 @@ let sym = v.qVal[0]

if sym.isSymbol: return sym.symVal else: - raiseInvalid("Quotation is not a quoted symbol") - + raiseInvalid("Quotation is not a quoted symbol")
M core/zip.nimcore/zip.nim

@@ -4,7 +4,6 @@

import ../vendor/miniz - proc zip*(files: seq[string], filepath: string) = var pZip: ptr mz_zip_archive = cast[ptr mz_zip_archive](alloc0(sizeof(mz_zip_archive))) discard pZip.mz_zip_writer_init_file(filepath.cstring, 0)

@@ -33,4 +32,4 @@ dest.parentDir.createDir()

dest.writeFile("") discard pZip.mz_zip_reader_extract_to_file(i, dest, 0) discard pZip.mz_zip_reader_end() - dealloc(pZip) + dealloc(pZip)
M doc/MiNiM_UserGuide.mddoc/MiNiM_UserGuide.md

@@ -87,7 +87,7 @@ > The following:

> > `((error "MyError") (message "This is a test error")) format-error` > -> produces: `"(!) This is a test error"` +> produces: `"This is a test error"` #} {#op||from-json||S||\*||
M doc/reference.mddoc/reference.md

@@ -81,7 +81,7 @@ > The following:

> > `((error "MyError") (message "This is a test error")) format-error` > -> produces: `"(!) This is a test error"` +> produces: `"This is a test error"` #} {#op||from-json||S||\*||
M lib/min_lang.nimlib/min_lang.nim

@@ -323,9 +323,9 @@ list.add err.dget("line".newVal)

if err.qVal.contains("column".newVal): list.add err.dget("column".newVal) if list.len <= 1: - msg = "(!) $1" % $$list[0] + msg = "$1" % $$list[0] else: - msg = "(!) $3($4,$5) `$2`: $1" % [$$list[0], $$list[1], $$list[2], $$list[3], $$list[4]] + msg = "$3($4,$5) `$2`: $1" % [$$list[0], $$list[1], $$list[2], $$list[3], $$list[4]] i.push msg.newVal else: raiseInvalid("Invalid error dictionary")
M minim.nimminim.nim

@@ -141,15 +141,15 @@

proc minimFile*(filename: string) = var stream = newFileStream(filename, fmRead) if stream == nil: - stderr.writeLine("Error - Cannot read from file: "& filename) - stderr.flushFile() + error("Cannot read from file: "& filename) + quit(100) minimStream(stream, filename) proc minimFile*(file: File, filename="stdin") = var stream = newFileStream(stdin) if stream == nil: - stderr.writeLine("Error - Cannot read from "& filename) - stderr.flushFile() + error("Cannot read from file: "& filename) + quit(100) minimStream(stream, filename) proc printResult(i: In, res: MinValue) =