all repos — min @ b12d6698fb941ca8be8719221e5a5032c47847ae

A small but practical concatenative programming language.

Fixed errors when compiling with nim 0.17.0
h3rald h3rald@h3rald.com
Sat, 03 Jun 2017 18:38:04 +0200
commit

b12d6698fb941ca8be8719221e5a5032c47847ae

parent

8dc873a6adb297076184b979dbb1427a81476c07

M core/utils.nimcore/utils.nim

@@ -17,21 +17,17 @@ var scope = new MinScope

scope.parent = i.scope return scope -proc symbol*(scope: ref MinScope, sym: string, p: MinOperatorProc): ref MinScope = +proc symbol*(scope: ref MinScope, sym: string, p: MinOperatorProc) = scope.symbols[sym] = MinOperator(prc: p, kind: minProcOp, sealed: true) - return scope -proc symbol*(scope: ref MinScope, sym: string, v: MinValue): ref MinScope = +proc symbol*(scope: ref MinScope, sym: string, v: MinValue) = scope.symbols[sym] = MinOperator(val: v, kind: minValOp, sealed: true) - return scope -proc sigil*(scope: ref MinScope, sym: string, p: MinOperatorProc): ref MinScope = +proc sigil*(scope: ref MinScope, sym: string, p: MinOperatorProc) = scope.sigils[sym] = MinOperator(prc: p, kind: minProcOp, sealed: true) - return scope -proc sigil*(scope: ref MinScope, sym: string, v: MinValue): ref MinScope = +proc sigil*(scope: ref MinScope, sym: string, v: MinValue) = scope.sigils[sym] = MinOperator(val: v, kind: minValOp, sealed: true) - return scope proc finalize*(scope: ref MinScope, name: string = "") = var mdl = newSeq[MinValue](0).newVal(nil)
M lib/min_crypto.nimlib/min_crypto.nim

@@ -14,60 +14,60 @@ ../packages/nimSHA2/nimSHA2,

../packages/nimAES/nimAES proc crypto_module*(i: In)= - i.define() + let def = i.define() - .symbol("md5") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getMD5.newVal + def.symbol("md5") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getMD5.newVal - .symbol("sha1") do (i: In): - var s: MinValue - i.reqStringLike s - i.push compute(s.getString).toHex.newVal + def.symbol("sha1") do (i: In): + var s: MinValue + i.reqStringLike s + i.push compute(s.getString).toHex.newVal - .symbol("sha224") do (i: In): - var s: MinValue - i.reqStringLike s - i.push computeSHA224(s.getString).hex.toLowerAscii.newVal + def.symbol("sha224") do (i: In): + var s: MinValue + i.reqStringLike s + i.push computeSHA224(s.getString).hex.toLowerAscii.newVal - .symbol("sha256") do (i: In): - var s: MinValue - i.reqStringLike s - i.push computeSHA256(s.getString).hex.toLowerAscii.newVal + def.symbol("sha256") do (i: In): + var s: MinValue + i.reqStringLike s + i.push computeSHA256(s.getString).hex.toLowerAscii.newVal - .symbol("sha384") do (i: In): - var s: MinValue - i.reqStringLike s - i.push computeSHA384(s.getString).hex.toLowerAscii.newVal + def.symbol("sha384") do (i: In): + var s: MinValue + i.reqStringLike s + i.push computeSHA384(s.getString).hex.toLowerAscii.newVal - .symbol("sha512") do (i: In): - var s: MinValue - i.reqStringLike s - i.push computeSHA512(s.getString).hex.toLowerAscii.newVal + def.symbol("sha512") do (i: In): + var s: MinValue + i.reqStringLike s + i.push computeSHA512(s.getString).hex.toLowerAscii.newVal - .symbol("encode") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.encode.newVal - - .symbol("decode") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.decode.newVal + def.symbol("encode") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.encode.newVal + + def.symbol("decode") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.decode.newVal - .symbol("aes") do (i: In): - var s, k: MinValue - i.reqTwoStrings k, s - var ctx: AESContext - var text = s.getString - var length = text.len - if length div 16 == 0: - text &= " ".repeat(16 - length) - elif length mod 16 != 0 and length div 16 >= 1: - text &= " ".repeat((length div 16 + 1) * 16 - length) - var key = k.getString.compute.toHex # SHA1 of key, to make sure it's long enough - var nonce = key[0..15] - i.push ctx.cryptOFB(nonce, text).newVal + def.symbol("aes") do (i: In): + var s, k: MinValue + i.reqTwoStrings k, s + var ctx: AESContext + var text = s.getString + var length = text.len + if length div 16 == 0: + text &= " ".repeat(16 - length) + elif length mod 16 != 0 and length div 16 >= 1: + text &= " ".repeat((length div 16 + 1) * 16 - length) + var key = k.getString.compute.toHex # SHA1 of key, to make sure it's long enough + var nonce = key[0..15] + i.push ctx.cryptOFB(nonce, text).newVal - .finalize("crypto") + def.finalize("crypto")
M lib/min_fs.nimlib/min_fs.nim

@@ -10,57 +10,57 @@ ../core/utils,

../core/fileutils proc fs_module*(i: In) = - i.define() - .symbol("mtime") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getLastModificationTime.toSeconds.newVal + let def = i.define() + def.symbol("mtime") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getLastModificationTime.toSeconds.newVal - .symbol("atime") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getLastAccessTime.toSeconds.newVal + def.symbol("atime") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getLastAccessTime.toSeconds.newVal - .symbol("ctime") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getCreationTime.toSeconds.newVal + def.symbol("ctime") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getCreationTime.toSeconds.newVal - .symbol("hidden?") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.isHidden.newVal + def.symbol("hidden?") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.isHidden.newVal - .symbol("fsize") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getFileSize.newVal + def.symbol("fsize") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getFileSize.newVal - .symbol("fstats") do (i: In): - var s: MinValue - i.reqStringLike s - let fi = s.getString.getFileInfo - var info = newSeq[MinValue](0).newVal(i.scope) - info.qVal.add @["name".newSym, s].newVal(i.scope) - info.qVal.add @["device".newSym, fi.id.device.newVal].newVal(i.scope) - info.qVal.add @["file".newSym, fi.id.file.newVal].newVal(i.scope) - info.qVal.add @["type".newSym, fi.kind.filetype.newVal].newVal(i.scope) - info.qVal.add @["size".newSym, fi.size.newVal].newVal(i.scope) - info.qVal.add @["permissions".newSym, fi.permissions.unixPermissions.newVal].newVal(i.scope) - info.qVal.add @["nlinks".newSym, fi.linkCount.newVal].newVal(i.scope) - info.qVal.add @["ctime".newSym, fi.creationTime.toSeconds.newVal].newVal(i.scope) - info.qVal.add @["atime".newSym, fi.lastAccessTime.toSeconds.newVal].newVal(i.scope) - info.qVal.add @["mtime".newSym, fi.lastWriteTime.toSeconds.newVal].newVal(i.scope) - i.push info + def.symbol("fstats") do (i: In): + var s: MinValue + i.reqStringLike s + let fi = s.getString.getFileInfo + var info = newSeq[MinValue](0).newVal(i.scope) + info.qVal.add @["name".newSym, s].newVal(i.scope) + info.qVal.add @["device".newSym, fi.id.device.newVal].newVal(i.scope) + info.qVal.add @["file".newSym, fi.id.file.newVal].newVal(i.scope) + info.qVal.add @["type".newSym, fi.kind.filetype.newVal].newVal(i.scope) + info.qVal.add @["size".newSym, fi.size.newVal].newVal(i.scope) + info.qVal.add @["permissions".newSym, fi.permissions.unixPermissions.newVal].newVal(i.scope) + info.qVal.add @["nlinks".newSym, fi.linkCount.newVal].newVal(i.scope) + info.qVal.add @["ctime".newSym, fi.creationTime.toSeconds.newVal].newVal(i.scope) + info.qVal.add @["atime".newSym, fi.lastAccessTime.toSeconds.newVal].newVal(i.scope) + info.qVal.add @["mtime".newSym, fi.lastWriteTime.toSeconds.newVal].newVal(i.scope) + i.push info - .symbol("ftype") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getFileInfo.kind.filetype.newVal + def.symbol("ftype") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getFileInfo.kind.filetype.newVal - .symbol("fperms") do (i: In): - var s: MinValue - i.reqStringLike s - i.push s.getString.getFilePermissions.unixPermissions.newVal + def.symbol("fperms") do (i: In): + var s: MinValue + i.reqStringLike s + i.push s.getString.getFilePermissions.unixPermissions.newVal - .finalize("fs") + def.finalize("fs")
M lib/min_io.nimlib/min_io.nim

@@ -14,135 +14,134 @@ # I/O

proc io_module*(i: In) = - i.define() - - .symbol("newline") do (i: In): - echo "" + let def = i.define() - .symbol("puts") do (i: In): - let a = i.peek - echo $$a + def.symbol("newline") do (i: In): + echo "" - .symbol("puts!") do (i: In): - echo $$i.pop + def.symbol("puts") do (i: In): + let a = i.peek + echo $$a + + def.symbol("puts!") do (i: In): + echo $$i.pop - .symbol("notice") do (i: In): - let a = i.peek - notice $$a + def.symbol("notice") do (i: In): + let a = i.peek + notice $$a - .symbol("info") do (i: In): - let a = i.peek - info $$a + def.symbol("info") do (i: In): + let a = i.peek + info $$a - .symbol("error") do (i: In): - let a = i.peek - error $$a + def.symbol("error") do (i: In): + let a = i.peek + error $$a - .symbol("warn") do (i: In): - let a = i.peek - warn $$a + def.symbol("warn") do (i: In): + let a = i.peek + warn $$a - .symbol("debug") do (i: In): - let a = i.peek - debug $$a + def.symbol("debug") do (i: In): + let a = i.peek + debug $$a - .symbol("fatal") do (i: In): - let a = i.peek - fatal $$a - termRestore() - quit(100) + def.symbol("fatal") do (i: In): + let a = i.peek + fatal $$a + quit(100) - .symbol("column-print") do (i: In): - var n, q: MinValue - i.reqIntAndQuotation n, q - var c = 0 - for s in q.qVal: - c.inc - stdout.write $$s & spaces(max(0, 15 - ($$s).len)) - if c mod n.intVal == 0: - echo "" - echo "" + def.symbol("column-print") do (i: In): + var n, q: MinValue + i.reqIntAndQuotation n, q + var c = 0 + for s in q.qVal: + c.inc + stdout.write $$s & spaces(max(0, 15 - ($$s).len)) + if c mod n.intVal == 0: + echo "" + echo "" - .symbol("gets") do (i: In): - var ed = initEditor() - i.push ed.readLine().newVal + def.symbol("gets") do (i: In): + var ed = initEditor() + i.push ed.readLine().newVal - .symbol("password") do (i: In): - var ed = initEditor() - i.push ed.password("Enter Password: ").newVal + def.symbol("password") do (i: In): + var ed = initEditor() + i.push ed.password("Enter Password: ").newVal - .symbol("ask") do (i: In): - var s: MinValue - var ed = initEditor() - i.reqString s - i.push ed.readLine(s.getString & ": ").newVal + def.symbol("ask") do (i: In): + var s: MinValue + var ed = initEditor() + i.reqString s + i.push ed.readLine(s.getString & ": ").newVal - .symbol("confirm") do (i: In): - var s: MinValue - var ed = initEditor() - i.reqString s - proc confirm(): bool = - let answer = ed.readLine(s.getString & " [yes/no]: ") - if answer.match("^y(es)?$", "i"): - return true - elif answer.match("^no?$", "i"): - return false - else: - stdout.write "Invalid answer. Please enter 'yes' or 'no': " - return confirm() - i.push confirm().newVal + def.symbol("confirm") do (i: In): + var s: MinValue + var ed = initEditor() + i.reqString s + proc confirm(): bool = + let answer = ed.readLine(s.getString & " [yes/no]: ") + if answer.match("^y(es)?$", "i"): + return true + elif answer.match("^no?$", "i"): + return false + else: + stdout.write "Invalid answer. Please enter 'yes' or 'no': " + return confirm() + i.push confirm().newVal - .symbol("choose") do (i: In): - var q, s: MinValue - var ed = initEditor() - i.reqStringLikeAndQuotation s, q - if q.qVal.len <= 0: - raiseInvalid("No choices to display") - stdout.writeLine(s.getString) - proc choose(): int = - var c = 0 - for item in q.qVal: - if not item.isQuotation or not item.qVal.len == 2 or not item.qVal[0].isString or not item.qVal[1].isQuotation: - raiseInvalid("Each item of the quotation must be a quotation containing a string and a quotation") - c.inc - echo "$1 - $2" % [$c, item.qVal[0].getString] - let answer = ed.readLine("Enter your choice ($1 - $2): " % ["1", $c]) - var choice: int - try: - choice = answer.parseInt - except: - choice = 0 - if choice <= 0 or choice > c: - echo "Invalid choice." - return choose() - else: - return choice - let choice = choose() - i.unquote(q.qVal[choice-1].qVal[1]) + def.symbol("choose") do (i: In): + var q, s: MinValue + var ed = initEditor() + i.reqStringLikeAndQuotation s, q + if q.qVal.len <= 0: + raiseInvalid("No choices to display") + stdout.writeLine(s.getString) + proc choose(): int = + var c = 0 + for item in q.qVal: + if not item.isQuotation or not item.qVal.len == 2 or not item.qVal[0].isString or not item.qVal[1].isQuotation: + raiseInvalid("Each item of the quotation must be a quotation containing a string and a quotation") + c.inc + echo "$1 - $2" % [$c, item.qVal[0].getString] + let answer = ed.readLine("Enter your choice ($1 - $2): " % ["1", $c]) + var choice: int + try: + choice = answer.parseInt + except: + choice = 0 + if choice <= 0 or choice > c: + echo "Invalid choice." + return choose() + else: + return choice + let choice = choose() + i.unquote(q.qVal[choice-1].qVal[1]) - .symbol("print") do (i: In): - let a = i.peek - a.print + def.symbol("print") do (i: In): + let a = i.peek + a.print - .symbol("print!") do (i: In): - i.pop.print + def.symbol("print!") do (i: In): + i.pop.print - .symbol("fread") do (i: In): - var a: MinValue - i.reqString a - i.push newVal(a.strVal.readFile) + def.symbol("fread") do (i: In): + var a: MinValue + i.reqString a + i.push newVal(a.strVal.readFile) - .symbol("fwrite") do (i: In): - var a, b: MinValue - i.reqTwoStrings a, b - a.strVal.writeFile(b.strVal) + def.symbol("fwrite") do (i: In): + var a, b: MinValue + i.reqTwoStrings a, b + a.strVal.writeFile(b.strVal) - .symbol("fappend") do (i: In): - var a, b: MinValue - i.reqTwoStrings a, b - var f:File - discard f.open(a.strVal, fmAppend) - f.write(b.strVal) - f.close() + def.symbol("fappend") do (i: In): + var a, b: MinValue + i.reqTwoStrings a, b + var f:File + discard f.open(a.strVal, fmAppend) + f.write(b.strVal) + f.close() - .finalize("io") + def.finalize("io")
M lib/min_lang.nimlib/min_lang.nim

@@ -16,524 +16,523 @@ ../packages/nimline/nimline,

../core/scope proc lang_module*(i: In) = - i.scope - .symbol("exit") do (i: In): - termRestore() - quit(0) - - .symbol("symbols") do (i: In): - var q = newSeq[MinValue](0) - var scope = i.scope - while not scope.isNil: - for s in scope.symbols.keys: - q.add s.newVal - scope = scope.parent - i.push q.newVal(i.scope) + let def = i.scope + def.symbol("exit") do (i: In): + quit(0) + + def.symbol("symbols") do (i: In): + var q = newSeq[MinValue](0) + var scope = i.scope + while not scope.isNil: + for s in scope.symbols.keys: + q.add s.newVal + scope = scope.parent + i.push q.newVal(i.scope) + + def.symbol("sigils") do (i: In): + var q = newSeq[MinValue](0) + var scope = i.scope + while not scope.isNil: + for s in scope.sigils.keys: + q.add s.newVal + scope = scope.parent + i.push q.newVal(i.scope) + + def.symbol("module-symbols") do (i: In): + var m: MinValue + i.reqQuotation m + var q = newSeq[MinValue](0) + for s in m.scope.symbols.keys: + q.add s.newVal + i.push q.newVal(i.scope) + + def.symbol("module-sigils") do (i: In): + var m: MinValue + i.reqQuotation m + var q = newSeq[MinValue](0) + for s in m.scope.sigils.keys: + q.add s.newVal + i.push q.newVal(i.scope) + + def.symbol("from-json") do (i: In): + var s: MinValue + i.reqString s + i.push i.fromJson(s.getString.parseJson) - .symbol("sigils") do (i: In): - var q = newSeq[MinValue](0) - var scope = i.scope - while not scope.isNil: - for s in scope.sigils.keys: - q.add s.newVal - scope = scope.parent - i.push q.newVal(i.scope) + def.symbol("to-json") do (i: In): + var q: MinValue + i.reqQuotation q + i.push(($((%q).pretty)).newVal) + + def.symbol("loglevel") do (i: In): + var s: MinValue + i.reqStringLike s + var str = s.getString + echo "Log level: ", setLogLevel(str) + + def.symbol("loglevel?") do (i: In): + echo "Log level: ", getLogLevel() + + # Language constructs + + def.symbol("define") do (i: In): + var sym: MinValue + i.reqStringLike sym + var q1 = i.pop # existing (auto-quoted) + var symbol: string + if not q1.isQuotation: + q1 = @[q1].newVal(i.scope) + symbol = sym.getString + if not symbol.match "^[a-zA-Z_][a-zA-Z0-9/!?+*._-]*$": + raiseInvalid("Symbol identifier '$1' contains invalid characters." % symbol) + info "[define] $1 = $2" % [symbol, $q1] + if i.scope.symbols.hasKey(symbol) and i.scope.symbols[symbol].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1'" % [symbol]) + i.scope.symbols[symbol] = MinOperator(kind: minValOp, val: q1, sealed: false) + + def.symbol("bind") do (i: In): + var sym: MinValue + i.reqStringLike sym + var q1 = i.pop # existing (auto-quoted) + var symbol: string + if not q1.isQuotation: + q1 = @[q1].newVal(i.scope) + symbol = sym.getString + info "[bind] $1 = $2" % [symbol, $q1] + let res = i.scope.setSymbol(symbol, MinOperator(kind: minValOp, val: q1)) + if not res: + raiseUndefined("Attempting to bind undefined symbol: " & symbol) + + def.symbol("delete") do (i: In): + var sym: MinValue + i.reqStringLike sym + let res = i.scope.delSymbol(sym.getString) + if not res: + raiseUndefined("Attempting to delete undefined symbol: " & sym.getString) + + def.symbol("module") do (i: In): + var code, name: MinValue + i.reqStringLike name + i.reqQuotation code + code.filename = i.filename + i.unquote(code) + info("[module] $1 ($2 symbols)" % [name.getString, $code.scope.symbols.len]) + i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal(i.scope)) - .symbol("module-symbols") do (i: In): - var m: MinValue - i.reqQuotation m - var q = newSeq[MinValue](0) - for s in m.scope.symbols.keys: - q.add s.newVal - i.push q.newVal(i.scope) + def.symbol("import") do (i: In): + var mdl, rawName: MinValue + var name: string + i.reqStringLike rawName + name = rawName.getString + var op = i.scope.getSymbol(name) + i.apply(op) + i.reqQuotation mdl + info("[import] Importing: $1 ($2 symbols, $3 sigils)" % [name, $mdl.scope.symbols.len, $mdl.scope.sigils.len]) + for sym, val in mdl.scope.symbols.pairs: + if i.scope.symbols.hasKey(sym) and i.scope.symbols[sym].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1'" % [sym]) + i.debug "[import] $1" % [sym] + i.scope.symbols[sym] = val + for sig, val in mdl.scope.sigils.pairs: + if i.scope.sigils.hasKey(sig) and i.scope.sigils[sig].sealed: + raiseUndefined("Attempting to redefine sealed sigil '$1'" % [sig]) + i.debug "[import] $1" % [sig] + i.scope.sigils[sig] = val - .symbol("module-sigils") do (i: In): - var m: MinValue - i.reqQuotation m - var q = newSeq[MinValue](0) - for s in m.scope.sigils.keys: - q.add s.newVal - i.push q.newVal(i.scope) - - .symbol("from-json") do (i: In): - var s: MinValue - i.reqString s - i.push i.fromJson(s.getString.parseJson) + def.symbol("eval") do (i: In): + var s: MinValue + i.reqString s + i.eval s.strVal - .symbol("to-json") do (i: In): - var q: MinValue - i.reqQuotation q - i.push(($((%q).pretty)).newVal) - - .symbol("loglevel") do (i: In): - var s: MinValue - i.reqStringLike s - var str = s.getString - echo "Log level: ", setLogLevel(str) - - .symbol("loglevel?") do (i: In): - echo "Log level: ", getLogLevel() - - # Language constructs - - .symbol("define") do (i: In): - var sym: MinValue - i.reqStringLike sym - var q1 = i.pop # existing (auto-quoted) - var symbol: string - if not q1.isQuotation: - q1 = @[q1].newVal(i.scope) - symbol = sym.getString - if not symbol.match "^[a-zA-Z_][a-zA-Z0-9/!?+*._-]*$": - raiseInvalid("Symbol identifier '$1' contains invalid characters." % symbol) - info "[define] $1 = $2" % [symbol, $q1] - if i.scope.symbols.hasKey(symbol) and i.scope.symbols[symbol].sealed: - raiseUndefined("Attempting to redefine sealed symbol '$1'" % [symbol]) - i.scope.symbols[symbol] = MinOperator(kind: minValOp, val: q1, sealed: false) - - .symbol("bind") do (i: In): - var sym: MinValue - i.reqStringLike sym - var q1 = i.pop # existing (auto-quoted) - var symbol: string - if not q1.isQuotation: - q1 = @[q1].newVal(i.scope) - symbol = sym.getString - info "[bind] $1 = $2" % [symbol, $q1] - let res = i.scope.setSymbol(symbol, MinOperator(kind: minValOp, val: q1)) - if not res: - raiseUndefined("Attempting to bind undefined symbol: " & symbol) - - .symbol("delete") do (i: In): - var sym: MinValue - i.reqStringLike sym - let res = i.scope.delSymbol(sym.getString) - if not res: - raiseUndefined("Attempting to delete undefined symbol: " & sym.getString) - - .symbol("module") do (i: In): - var code, name: MinValue - i.reqStringLike name - i.reqQuotation code - code.filename = i.filename - i.unquote(code) - info("[module] $1 ($2 symbols)" % [name.getString, $code.scope.symbols.len]) - i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal(i.scope)) + def.symbol("load") do (i: In): + var s: MinValue + i.reqStringLike s + var file = s.getString + if not file.endsWith(".min"): + file = file & ".min" + file = i.pwd.joinPath(file) + info("[load] File: ", file) + if not file.fileExists: + raiseInvalid("File '$1' does not exists." % file) + i.load file - .symbol("import") do (i: In): - var mdl, rawName: MinValue - var name: string - i.reqStringLike rawName - name = rawName.getString - var op = i.scope.getSymbol(name) - i.apply(op) - i.reqQuotation mdl - info("[import] Importing: $1 ($2 symbols, $3 sigils)" % [name, $mdl.scope.symbols.len, $mdl.scope.sigils.len]) - for sym, val in mdl.scope.symbols.pairs: - if i.scope.symbols.hasKey(sym) and i.scope.symbols[sym].sealed: - raiseUndefined("Attempting to redefine sealed symbol '$1'" % [sym]) - i.debug "[import] $1" % [sym] - i.scope.symbols[sym] = val - for sig, val in mdl.scope.sigils.pairs: - if i.scope.sigils.hasKey(sig) and i.scope.sigils[sig].sealed: - raiseUndefined("Attempting to redefine sealed sigil '$1'" % [sig]) - i.debug "[import] $1" % [sig] - i.scope.sigils[sig] = val - - .symbol("eval") do (i: In): - var s: MinValue - i.reqString s - i.eval s.strVal - - .symbol("load") do (i: In): - var s: MinValue - i.reqStringLike s - var file = s.getString - if not file.endsWith(".min"): - file = file & ".min" - file = i.pwd.joinPath(file) - info("[load] File: ", file) - if not file.fileExists: - raiseInvalid("File '$1' does not exists." % file) - i.load file - - .symbol("with") do (i: In): - var qscope, qprog: MinValue - i.reqTwoQuotations qscope, qprog - if qscope.qVal.len > 0: - # System modules are empty quotes and don't need to be unquoted - i.unquote(qscope) - i.withScope(qscope, qscope.scope): + def.symbol("with") do (i: In): + var qscope, qprog: MinValue + i.reqTwoQuotations qscope, qprog + if qscope.qVal.len > 0: + # System modules are empty quotes and don't need to be unquoted + i.unquote(qscope) + i.withScope(qscope, qscope.scope): for v in qprog.qVal: i.push v - .symbol("publish") do (i: In): - var qscope, str: MinValue - i.reqQuotationAndStringLike qscope, str - let sym = str.getString - if qscope.scope.symbols.hasKey(sym) and qscope.scope.symbols[sym].sealed: - raiseUndefined("Attempting to redefine sealed symbol '$1'" % [sym]) - let scope = i.scope - info("[publish] Symbol: $2" % [sym]) - let op = proc(i: In) {.gcsafe, closure.} = - let origscope = i.scope - i.scope = scope - i.evaluating = true - i.push sym.newSym - i.evaluating = false - i.scope = origscope - qscope.scope.symbols[sym] = MinOperator(kind: minProcOp, prc: op) + def.symbol("publish") do (i: In): + var qscope, str: MinValue + i.reqQuotationAndStringLike qscope, str + let sym = str.getString + if qscope.scope.symbols.hasKey(sym) and qscope.scope.symbols[sym].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1'" % [sym]) + let scope = i.scope + info("[publish] Symbol: $2" % [sym]) + let op = proc(i: In) {.gcsafe, closure.} = + let origscope = i.scope + i.scope = scope + i.evaluating = true + i.push sym.newSym + i.evaluating = false + i.scope = origscope + qscope.scope.symbols[sym] = MinOperator(kind: minProcOp, prc: op) - .symbol("source") do (i: In): - var s: MinValue - i.reqStringLike s - let str = s.getString - let sym = i.scope.getSymbol(str) - if sym.kind == minValOp: - i.push sym.val + def.symbol("source") do (i: In): + var s: MinValue + i.reqStringLike s + let str = s.getString + let sym = i.scope.getSymbol(str) + if sym.kind == minValOp: + i.push sym.val + else: + raiseInvalid("No source available for native symbol '$1'." % str) + + def.symbol("call") do (i: In): + var symbol, q: MinValue + i.reqStringLike symbol + i.reqQuotation q + let s = symbol.getString + let origScope = i.scope + i.scope = q.scope + let sym = i.scope.getSymbol(s) + i.apply(sym) + i.scope = origScope + + def.symbol("raise") do (i: In): + var err: MinValue + i.reqDictionary err + if err.dhas("error".newSym) and err.dhas("message".newSym): + raiseRuntime("($1) $2" % [err.dget("error".newVal).getString, err.dget("message".newVal).getString], err.qVal) + else: + raiseInvalid("Invalid error dictionary") + + def.symbol("format-error") do (i: In): + var err: MinValue + i.reqDictionary err + if err.dhas("error".newSym) and err.dhas("message".newSym): + var msg: string + var list = newSeq[MinValue]() + list.add err.dget("message".newVal) + if err.qVal.contains("symbol".newVal): + list.add err.dget("symbol".newVal) + if err.qVal.contains("filename".newVal): + list.add err.dget("filename".newVal) + if err.qVal.contains("line".newVal): + 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] else: - raiseInvalid("No source available for native symbol '$1'." % str) + 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") + + def.symbol("try") do (i: In): + var prog: MinValue + i.reqQuotation prog + if prog.qVal.len == 0: + raiseInvalid("Quotation must contain at least one element") + var code = prog.qVal[0] + var final, catch: MinValue + var hasFinally = false + var hasCatch = false + if prog.qVal.len > 1: + catch = prog.qVal[1] + hasCatch = true + if prog.qVal.len > 2: + final = prog.qVal[2] + hasFinally = true + if (not code.isQuotation) or (hasCatch and not catch.isQuotation) or (hasFinally and not final.isQuotation): + raiseInvalid("Quotation must contain at one quotation") + try: + i.unquote(code) + except MinRuntimeError: + if not hasCatch: + return + let e = (MinRuntimeError)getCurrentException() + i.push e.qVal.newVal(i.scope) + i.unquote(catch) + except: + if not hasCatch: + return + let e = getCurrentException() + var res = newSeq[MinValue](0) + let err = sgregex.replace($e.name, ":.+$", "") + res.add @["error".newSym, err.newVal].newVal(i.scope) + res.add @["message".newSym, e.msg.newVal].newVal(i.scope) + res.add @["symbol".newSym, i.currSym].newVal(i.scope) + res.add @["filename".newSym, i.currSym.filename.newVal].newVal(i.scope) + res.add @["line".newSym, i.currSym.line.newVal].newVal(i.scope) + res.add @["column".newSym, i.currSym.column.newVal].newVal(i.scope) + i.push res.newVal(i.scope) + i.unquote(catch) + finally: + if hasFinally: + i.unquote(final) + + def.symbol("quote") do (i: In): + let a = i.pop + i.push @[a].newVal(i.scope) - .symbol("call") do (i: In): - var symbol, q: MinValue - i.reqStringLike symbol - i.reqQuotation q - let s = symbol.getString - let origScope = i.scope - i.scope = q.scope - let sym = i.scope.getSymbol(s) - i.apply(sym) - i.scope = origScope - - .symbol("raise") do (i: In): - var err: MinValue - i.reqDictionary err - if err.dhas("error".newSym) and err.dhas("message".newSym): - raiseRuntime("($1) $2" % [err.dget("error".newVal).getString, err.dget("message".newVal).getString], err.qVal) - else: - raiseInvalid("Invalid error dictionary") + def.symbol("unquote") do (i: In): + var q: MinValue + i.reqQuotation q + i.unquote(q) - .symbol("format-error") do (i: In): - var err: MinValue - i.reqDictionary err - if err.dhas("error".newSym) and err.dhas("message".newSym): - var msg: string - var list = newSeq[MinValue]() - list.add err.dget("message".newVal) - if err.qVal.contains("symbol".newVal): - list.add err.dget("symbol".newVal) - if err.qVal.contains("filename".newVal): - list.add err.dget("filename".newVal) - if err.qVal.contains("line".newVal): - 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] - else: - 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") + # Conditionals + + def.symbol("if") do (i: In): + var fpath, tpath, check: MinValue + i.reqThreeQuotations fpath, tpath, check + var stack = i.stack + i.unquote(check) + let res = i.pop + i.stack = stack + if not res.isBool: + raiseInvalid("Result of check is not a boolean value") + if res.boolVal == true: + i.unquote(tpath) + else: + i.unquote(fpath) - .symbol("try") do (i: In): - var prog: MinValue - i.reqQuotation prog - if prog.qVal.len == 0: - raiseInvalid("Quotation must contain at least one element") - var code = prog.qVal[0] - var final, catch: MinValue - var hasFinally = false - var hasCatch = false - if prog.qVal.len > 1: - catch = prog.qVal[1] - hasCatch = true - if prog.qVal.len > 2: - final = prog.qVal[2] - hasFinally = true - if (not code.isQuotation) or (hasCatch and not catch.isQuotation) or (hasFinally and not final.isQuotation): - raiseInvalid("Quotation must contain at one quotation") - try: - i.unquote(code) - except MinRuntimeError: - if not hasCatch: - return - let e = (MinRuntimeError)getCurrentException() - i.push e.qVal.newVal(i.scope) - i.unquote(catch) - except: - if not hasCatch: - return - let e = getCurrentException() - var res = newSeq[MinValue](0) - let err = sgregex.replace($e.name, ":.+$", "") - res.add @["error".newSym, err.newVal].newVal(i.scope) - res.add @["message".newSym, e.msg.newVal].newVal(i.scope) - res.add @["symbol".newSym, i.currSym].newVal(i.scope) - res.add @["filename".newSym, i.currSym.filename.newVal].newVal(i.scope) - res.add @["line".newSym, i.currSym.line.newVal].newVal(i.scope) - res.add @["column".newSym, i.currSym.column.newVal].newVal(i.scope) - i.push res.newVal(i.scope) - i.unquote(catch) - finally: - if hasFinally: - i.unquote(final) + def.symbol("when") do (i: In): + var tpath, check: MinValue + i.reqTwoQuotations tpath, check + var stack = i.stack + i.unquote(check) + let res = i.pop + i.stack = stack + if not res.isBool: + raiseInvalid("Result of check is not a boolean value") + if res.boolVal == true: + i.unquote(tpath) - .symbol("quote") do (i: In): - let a = i.pop - i.push @[a].newVal(i.scope) - - .symbol("unquote") do (i: In): - var q: MinValue - i.reqQuotation q - i.unquote(q) - - # Conditionals + def.symbol("unless") do (i: In): + var tpath, check: MinValue + i.reqTwoQuotations tpath, check + var stack = i.stack + i.unquote(check) + let res = i.pop + i.stack = stack + if not res.isBool: + raiseInvalid("Result of check is not a boolean value") + if res.boolVal == false: + i.unquote(tpath) - .symbol("if") do (i: In): - var fpath, tpath, check: MinValue - i.reqThreeQuotations fpath, tpath, check - var stack = i.stack - i.unquote(check) - let res = i.pop + # 4 ( + # ((> 3) ("Greater than 3" put!)) + # ((< 3) ("Smaller than 3" put!)) + # ((true) ("Exactly 3" put!)) + # ) case + def.symbol("case") do (i: In): + var cases: MinValue + i.reqQuotation cases + if cases.qVal.len == 0: + raiseInvalid("Empty case operator") + var k = 0 + let stack = i.stack + for c in cases.qVal: i.stack = stack - if not res.isBool: - raiseInvalid("Result of check is not a boolean value") - if res.boolVal == true: - i.unquote(tpath) - else: - i.unquote(fpath) - - .symbol("when") do (i: In): - var tpath, check: MinValue - i.reqTwoQuotations tpath, check - var stack = i.stack - i.unquote(check) + if not c.isQuotation: + raiseInvalid("A quotation of quotations is required") + k.inc + if c.qVal.len != 2 or not c.qVal[0].isQuotation or not c.qVal[1].isQuotation: + raiseInvalid("Inner quotations in case operator must contain two quotations") + var q = c.qVal[0] + i.unquote(q) let res = i.pop - i.stack = stack - if not res.isBool: - raiseInvalid("Result of check is not a boolean value") + if not res.isBool(): + raiseInvalid("Result of case #$1 is not a boolean value" % $k) if res.boolVal == true: - i.unquote(tpath) + var t = c.qVal[1] + i.unquote(t) + break - .symbol("unless") do (i: In): - var tpath, check: MinValue - i.reqTwoQuotations tpath, check - var stack = i.stack - i.unquote(check) - let res = i.pop - i.stack = stack - if not res.isBool: - raiseInvalid("Result of check is not a boolean value") - if res.boolVal == false: - i.unquote(tpath) + # Loops - # 4 ( - # ((> 3) ("Greater than 3" put!)) - # ((< 3) ("Smaller than 3" put!)) - # ((true) ("Exactly 3" put!)) - # ) case - .symbol("case") do (i: In): - var cases: MinValue - i.reqQuotation cases - if cases.qVal.len == 0: - raiseInvalid("Empty case operator") - var k = 0 - let stack = i.stack - for c in cases.qVal: - i.stack = stack - if not c.isQuotation: - raiseInvalid("A quotation of quotations is required") - k.inc - if c.qVal.len != 2 or not c.qVal[0].isQuotation or not c.qVal[1].isQuotation: - raiseInvalid("Inner quotations in case operator must contain two quotations") - var q = c.qVal[0] - i.unquote(q) - let res = i.pop - if not res.isBool(): - raiseInvalid("Result of case #$1 is not a boolean value" % $k) - if res.boolVal == true: - var t = c.qVal[1] - i.unquote(t) - break - - # Loops - - .symbol("foreach") do (i: In): - var prog, list: MinValue - i.reqTwoQuotations prog, list - for litem in list.qVal: - i.push litem - i.unquote(prog) - - .symbol("times") do (i: In): - var t, prog: MinValue - i.reqIntAndQuotation t, prog - if t.intVal < 1: - raiseInvalid("A non-zero natural number is required") - for c in 1..t.intVal: - i.unquote(prog) - - .symbol("while") do (i: In): - var d, b: MinValue - i.reqTwoQuotations d, b - for e in b.qVal: - i.push e + def.symbol("foreach") do (i: In): + var prog, list: MinValue + i.reqTwoQuotations prog, list + for litem in list.qVal: + i.push litem + i.unquote(prog) + + def.symbol("times") do (i: In): + var t, prog: MinValue + i.reqIntAndQuotation t, prog + if t.intVal < 1: + raiseInvalid("A non-zero natural number is required") + for c in 1..t.intVal: + i.unquote(prog) + + def.symbol("while") do (i: In): + var d, b: MinValue + i.reqTwoQuotations d, b + for e in b.qVal: + i.push e + i.unquote(b) + var check = i.pop + while check.isBool and check.boolVal == true: + i.unquote(d) i.unquote(b) - var check = i.pop - while check.isBool and check.boolVal == true: - i.unquote(d) - i.unquote(b) - check = i.pop - discard i.pop + check = i.pop + discard i.pop - # Other - - .symbol("linrec") do (i: In): - var r2, r1, t, p: MinValue - i.reqFourQuotations r2, r1, t, p - proc linrec(i: In, p, t, r1, r2: var MinValue) = - i.unquote(p) - var check = i.pop - if check.isBool and check.boolVal == true: - i.unquote(t) - else: - i.unquote(r1) - i.linrec(p, t, r1, r2) - i.unquote(r2) - i.linrec(p, t, r1, r2) + # Other + + def.symbol("linrec") do (i: In): + var r2, r1, t, p: MinValue + i.reqFourQuotations r2, r1, t, p + proc linrec(i: In, p, t, r1, r2: var MinValue) = + i.unquote(p) + var check = i.pop + if check.isBool and check.boolVal == true: + i.unquote(t) + else: + i.unquote(r1) + i.linrec(p, t, r1, r2) + i.unquote(r2) + i.linrec(p, t, r1, r2) - .symbol("version") do (i: In): - i.push version.newVal + def.symbol("version") do (i: In): + i.push version.newVal - # Save/load symbols - - .symbol("save-symbol") do (i: In): - var s:MinValue - i.reqStringLike s - let sym = s.getString - let op = i.scope.getSymbol(sym) - if op.kind == minProcOp: - raiseInvalid("Symbol '$1' cannot be serialized." % sym) - let json = MINSYMBOLS.readFile.parseJson - json[sym] = %op.val - MINSYMBOLS.writeFile(json.pretty) + # Save/load symbols + + def.symbol("save-symbol") do (i: In): + var s:MinValue + i.reqStringLike s + let sym = s.getString + let op = i.scope.getSymbol(sym) + if op.kind == minProcOp: + raiseInvalid("Symbol '$1' cannot be serialized." % sym) + let json = MINSYMBOLS.readFile.parseJson + json[sym] = %op.val + MINSYMBOLS.writeFile(json.pretty) - .symbol("load-symbol") do (i: In): - var s:MinValue - i.reqStringLike s - let sym = s.getString - let json = MINSYMBOLS.readFile.parseJson - if not json.hasKey(sym): - raiseUndefined("Symbol '$1' not found." % sym) - let val = i.fromJson(json[sym]) - i.scope.symbols[sym] = MinOperator(kind: minValOp, val: val) + def.symbol("load-symbol") do (i: In): + var s:MinValue + i.reqStringLike s + let sym = s.getString + let json = MINSYMBOLS.readFile.parseJson + if not json.hasKey(sym): + raiseUndefined("Symbol '$1' not found." % sym) + let val = i.fromJson(json[sym]) + i.scope.symbols[sym] = MinOperator(kind: minValOp, val: val) - .symbol("stored-symbols") do (i: In): - var q = newSeq[MinValue](0) - let json = MINSYMBOLS.readFile.parseJson - for k,v in json.pairs: - q.add k.newVal - i.push q.newVal(i.scope) + def.symbol("stored-symbols") do (i: In): + var q = newSeq[MinValue](0) + let json = MINSYMBOLS.readFile.parseJson + for k,v in json.pairs: + q.add k.newVal + i.push q.newVal(i.scope) - .symbol("remove-symbol") do (i: In): - var s:MinValue - i.reqStringLike s - let sym = s.getString - var json = MINSYMBOLS.readFile.parseJson - if not json.hasKey(sym): - raiseUndefined("Symbol '$1' not found." % sym) - json.delete(sym) - MINSYMBOLS.writeFile(json.pretty) + def.symbol("remove-symbol") do (i: In): + var s:MinValue + i.reqStringLike s + let sym = s.getString + var json = MINSYMBOLS.readFile.parseJson + if not json.hasKey(sym): + raiseUndefined("Symbol '$1' not found." % sym) + json.delete(sym) + MINSYMBOLS.writeFile(json.pretty) - .symbol("seal") do (i: In): - var sym: MinValue - i.reqStringLike sym - var s = i.scope.getSymbol(sym.getString) - s.sealed = true - i.scope.setSymbol(sym.getString, s) + def.symbol("seal") do (i: In): + var sym: MinValue + i.reqStringLike sym + var s = i.scope.getSymbol(sym.getString) + s.sealed = true + i.scope.setSymbol(sym.getString, s) - .symbol("unseal") do (i: In): - var sym: MinValue - i.reqStringLike sym - var s = i.scope.getSymbol(sym.getString) - s.sealed = false - i.scope.setSymbol(sym.getString, s, true) + def.symbol("unseal") do (i: In): + var sym: MinValue + i.reqStringLike sym + var s = i.scope.getSymbol(sym.getString) + s.sealed = false + i.scope.setSymbol(sym.getString, s, true) - .symbol("quote-bind") do (i: In): - var s, m: MinValue - i.reqString(s) - m = i.pop - i.push @[m].newVal(i.scope) - i.push s - i.push "bind".newSym + def.symbol("quote-bind") do (i: In): + var s, m: MinValue + i.reqString(s) + m = i.pop + i.push @[m].newVal(i.scope) + i.push s + i.push "bind".newSym - .symbol("quote-define") do (i: In): - var s, m: MinValue - i.reqString(s) - m = i.pop - i.push @[m].newVal(i.scope) - i.push s - i.push "define".newSym + def.symbol("quote-define") do (i: In): + var s, m: MinValue + i.reqString(s) + m = i.pop + i.push @[m].newVal(i.scope) + i.push s + i.push "define".newSym - # Sigils + # Sigils - .sigil("'") do (i: In): - var s: MinValue - i.reqString s - i.push(@[s.strVal.newSym].newVal(i.scope)) + def.sigil("'") do (i: In): + var s: MinValue + i.reqString s + i.push(@[s.strVal.newSym].newVal(i.scope)) - .sigil(":") do (i: In): - i.push("define".newSym) + def.sigil(":") do (i: In): + i.push("define".newSym) - .sigil("~") do (i: In): - i.push("delete".newSym) + def.sigil("~") do (i: In): + i.push("delete".newSym) - .sigil("@") do (i: In): - i.push("bind".newSym) + def.sigil("@") do (i: In): + i.push("bind".newSym) - .sigil("+") do (i: In): - i.push("module".newSym) + def.sigil("+") do (i: In): + i.push("module".newSym) - .sigil("^") do (i: In): - i.push("call".newSym) + def.sigil("^") do (i: In): + i.push("call".newSym) - .sigil("/") do (i: In): - i.push("dget".newSym) + def.sigil("/") do (i: In): + i.push("dget".newSym) - .sigil("%") do (i: In): - i.push("dset".newSym) + def.sigil("%") do (i: In): + i.push("dset".newSym) - .sigil(">") do (i: In): - i.push("save-symbol".newSym) + def.sigil(">") do (i: In): + i.push("save-symbol".newSym) - .sigil("<") do (i: In): - i.push("load-symbol".newSym) + def.sigil("<") do (i: In): + i.push("load-symbol".newSym) - .sigil("#") do (i: In): - i.push("quote-bind".newSym) + def.sigil("#") do (i: In): + i.push("quote-bind".newSym) - .sigil("=") do (i: In): - i.push("quote-define".newSym) + def.sigil("=") do (i: In): + i.push("quote-define".newSym) - # Shorthand symbol aliases + # Shorthand symbol aliases - .symbol(":") do (i: In): - i.push("define".newSym) + def.symbol(":") do (i: In): + i.push("define".newSym) - .symbol("@") do (i: In): - i.push("bind".newSym) + def.symbol("@") do (i: In): + i.push("bind".newSym) - .symbol("^") do (i: In): - i.push("call".newSym) + def.symbol("^") do (i: In): + i.push("call".newSym) - .symbol("'") do (i: In): - i.push("quote".newSym) + def.symbol("'") do (i: In): + i.push("quote".newSym) - .symbol("->") do (i: In): - i.push("unquote".newSym) + def.symbol("->") do (i: In): + i.push("unquote".newSym) - .symbol("=>") do (i: In): - i.push("apply".newSym) + def.symbol("=>") do (i: In): + i.push("apply".newSym) - .finalize("ROOT") + def.finalize("ROOT")
M lib/min_logic.nimlib/min_logic.nim

@@ -10,140 +10,140 @@ # Comparison operators

proc logic_module*(i: In)= - i.define() + let def = i.define() - .symbol(">") do (i: In): - var n2, n1: MinValue - i.reqTwoNumbersOrStrings n2, n1 - if n1.isNumber and n2.isNumber: - if n1.isInt and n2.isInt: - i.push newVal(n1.intVal > n2.intVal) - elif n1.isInt and n2.isFloat: - i.push newVal(n1.intVal.float > n2.floatVal) - elif n1.isFloat and n2.isFloat: - i.push newVal(n1.floatVal > n2.floatVal) - elif n1.isFloat and n2.isInt: - i.push newVal(n1.floatVal > n2.intVal.float) - else: - i.push newVal(n1.strVal > n2.strVal) + def.symbol(">") do (i: In): + var n2, n1: MinValue + i.reqTwoNumbersOrStrings n2, n1 + if n1.isNumber and n2.isNumber: + if n1.isInt and n2.isInt: + i.push newVal(n1.intVal > n2.intVal) + elif n1.isInt and n2.isFloat: + i.push newVal(n1.intVal.float > n2.floatVal) + elif n1.isFloat and n2.isFloat: + i.push newVal(n1.floatVal > n2.floatVal) + elif n1.isFloat and n2.isInt: + i.push newVal(n1.floatVal > n2.intVal.float) + else: + i.push newVal(n1.strVal > n2.strVal) - .symbol(">=") do (i: In): - var n2, n1: MinValue - i.reqTwoNumbersOrStrings n2, n1 - if n1.isNumber and n2.isNumber: - if n1.isInt and n2.isInt: - i.push newVal(n1.intVal >= n2.intVal) - elif n1.isInt and n2.isFloat: - i.push newVal(n1.intVal.float >= n2.floatVal) - elif n1.isFloat and n2.isFloat: - i.push newVal(n1.floatVal >= n2.floatVal) - elif n1.isFloat and n2.isInt: - i.push newVal(n1.floatVal >= n2.intVal.float) - else: - i.push newVal(n1.strVal >= n2.strVal) - - .symbol("<") do (i: In): - var n2, n1: MinValue - i.reqTwoNumbersOrStrings n1, n2 - if n1.isNumber and n2.isNumber: - if n1.isInt and n2.isInt: - i.push newVal(n1.intVal > n2.intVal) - elif n1.isInt and n2.isFloat: - i.push newVal(n1.intVal.float > n2.floatVal) - elif n1.isFloat and n2.isFloat: - i.push newVal(n1.floatVal > n2.floatVal) - elif n1.isFloat and n2.isInt: - i.push newVal(n1.floatVal > n2.intVal.float) - else: - i.push newVal(n1.strVal > n2.strVal) - - .symbol("<=") do (i: In): - var n2, n1: MinValue - i.reqTwoNumbersOrStrings n1, n2 - if n1.isNumber and n2.isNumber: - if n1.isInt and n2.isInt: - i.push newVal(n1.intVal >= n2.intVal) - elif n1.isInt and n2.isFloat: - i.push newVal(n1.intVal.float >= n2.floatVal) - elif n1.isFloat and n2.isFloat: - i.push newVal(n1.floatVal >= n2.floatVal) - elif n1.isFloat and n2.isInt: - i.push newVal(n1.floatVal >= n2.intVal.float) - else: - i.push newVal(n1.strVal >= n2.strVal) - - .symbol("==") do (i: In): - var n1, n2: MinValue - i.reqTwoSimilarTypesNonSymbol n2, n1 - i.push newVal(n1 == n2) - - .symbol("!=") do (i: In): - var n1, n2: MinValue - i.reqTwoSimilarTypesNonSymbol n2, n1 - i.push newVal(not (n1 == n2)) - - # Boolean Logic - - .symbol("not") do (i: In): - var b: MinValue - i.reqBool b - i.push newVal(not b.boolVal) - - .symbol("and") do (i: In): - var a, b: MinValue - i.reqTwoBools a, b - i.push newVal(a.boolVal and b.boolVal) - - .symbol("or") do (i: In): - var a, b: MinValue - i.reqTwoBools a, b - i.push newVal(a.boolVal or b.boolVal) - - .symbol("xor") do (i: In): - var a, b: MinValue - i.reqTwoBools a, b - i.push newVal(a.boolVal xor b.boolVal) - - .symbol("string?") do (i: In): - if i.peek.kind == minString: - i.push true.newVal - else: - i.push false.newVal - - .symbol("int?") do (i: In): - if i.peek.kind == minInt: - i.push true.newVal - else: - i.push false.newVal - - .symbol("float?") do (i: In): - if i.peek.kind == minFloat: - i.push true.newVal - else: - i.push false.newVal - - .symbol("number?") do (i: In): - if i.peek.kind == minFloat or i.peek.kind == minInt: - i.push true.newVal - else: - i.push false.newVal - - .symbol("bool?") do (i: In): - if i.peek.kind == minBool: - i.push true.newVal - else: - i.push false.newVal - - .symbol("quotation?") do (i: In): - if i.peek.kind == minQuotation: - i.push true.newVal - else: - i.push false.newVal + def.symbol(">=") do (i: In): + var n2, n1: MinValue + i.reqTwoNumbersOrStrings n2, n1 + if n1.isNumber and n2.isNumber: + if n1.isInt and n2.isInt: + i.push newVal(n1.intVal >= n2.intVal) + elif n1.isInt and n2.isFloat: + i.push newVal(n1.intVal.float >= n2.floatVal) + elif n1.isFloat and n2.isFloat: + i.push newVal(n1.floatVal >= n2.floatVal) + elif n1.isFloat and n2.isInt: + i.push newVal(n1.floatVal >= n2.intVal.float) + else: + i.push newVal(n1.strVal >= n2.strVal) + + def.symbol("<") do (i: In): + var n2, n1: MinValue + i.reqTwoNumbersOrStrings n1, n2 + if n1.isNumber and n2.isNumber: + if n1.isInt and n2.isInt: + i.push newVal(n1.intVal > n2.intVal) + elif n1.isInt and n2.isFloat: + i.push newVal(n1.intVal.float > n2.floatVal) + elif n1.isFloat and n2.isFloat: + i.push newVal(n1.floatVal > n2.floatVal) + elif n1.isFloat and n2.isInt: + i.push newVal(n1.floatVal > n2.intVal.float) + else: + i.push newVal(n1.strVal > n2.strVal) + + def.symbol("<=") do (i: In): + var n2, n1: MinValue + i.reqTwoNumbersOrStrings n1, n2 + if n1.isNumber and n2.isNumber: + if n1.isInt and n2.isInt: + i.push newVal(n1.intVal >= n2.intVal) + elif n1.isInt and n2.isFloat: + i.push newVal(n1.intVal.float >= n2.floatVal) + elif n1.isFloat and n2.isFloat: + i.push newVal(n1.floatVal >= n2.floatVal) + elif n1.isFloat and n2.isInt: + i.push newVal(n1.floatVal >= n2.intVal.float) + else: + i.push newVal(n1.strVal >= n2.strVal) + + def.symbol("==") do (i: In): + var n1, n2: MinValue + i.reqTwoSimilarTypesNonSymbol n2, n1 + i.push newVal(n1 == n2) + + def.symbol("!=") do (i: In): + var n1, n2: MinValue + i.reqTwoSimilarTypesNonSymbol n2, n1 + i.push newVal(not (n1 == n2)) + + # Boolean Logic + + def.symbol("not") do (i: In): + var b: MinValue + i.reqBool b + i.push newVal(not b.boolVal) + + def.symbol("and") do (i: In): + var a, b: MinValue + i.reqTwoBools a, b + i.push newVal(a.boolVal and b.boolVal) + + def.symbol("or") do (i: In): + var a, b: MinValue + i.reqTwoBools a, b + i.push newVal(a.boolVal or b.boolVal) + + def.symbol("xor") do (i: In): + var a, b: MinValue + i.reqTwoBools a, b + i.push newVal(a.boolVal xor b.boolVal) - .symbol("dictionary?") do (i: In): - if i.peek.isDictionary: - i.push true.newVal - else: - i.push false.newVal + def.symbol("string?") do (i: In): + if i.peek.kind == minString: + i.push true.newVal + else: + i.push false.newVal - .finalize("logic") + def.symbol("int?") do (i: In): + if i.peek.kind == minInt: + i.push true.newVal + else: + i.push false.newVal + + def.symbol("float?") do (i: In): + if i.peek.kind == minFloat: + i.push true.newVal + else: + i.push false.newVal + + def.symbol("number?") do (i: In): + if i.peek.kind == minFloat or i.peek.kind == minInt: + i.push true.newVal + else: + i.push false.newVal + + def.symbol("bool?") do (i: In): + if i.peek.kind == minBool: + i.push true.newVal + else: + i.push false.newVal + + def.symbol("quotation?") do (i: In): + if i.peek.kind == minQuotation: + i.push true.newVal + else: + i.push false.newVal + + def.symbol("dictionary?") do (i: In): + if i.peek.isDictionary: + i.push true.newVal + else: + i.push false.newVal + + def.finalize("logic")
M lib/min_num.nimlib/min_num.nim

@@ -11,113 +11,113 @@ # Arithmetic

proc num_module*(i: In)= - i.define() + let def = i.define() + + def.symbol("+") do (i: In): + var a, b: MinValue + i.reqTwoNumbers a, b + if a.isInt: + if b.isInt: + i.push newVal(a.intVal + b.intVal) + else: + i.push newVal(a.intVal.float + b.floatVal) + else: + if b.isFloat: + i.push newVal(a.floatVal + b.floatVal) + else: + i.push newVal(a.floatVal + b.intVal.float) - .symbol("+") do (i: In): - var a, b: MinValue - i.reqTwoNumbers a, b - if a.isInt: - if b.isInt: - i.push newVal(a.intVal + b.intVal) - else: - i.push newVal(a.intVal.float + b.floatVal) + def.symbol("-") do (i: In): + var a, b: MinValue + i.reqTwoNumbers a, b + if a.isInt: + if b.isInt: + i.push newVal(b.intVal - a.intVal) else: - if b.isFloat: - i.push newVal(a.floatVal + b.floatVal) - else: - i.push newVal(a.floatVal + b.intVal.float) - - .symbol("-") do (i: In): - var a, b: MinValue - i.reqTwoNumbers a, b - if a.isInt: - if b.isInt: - i.push newVal(b.intVal - a.intVal) - else: - i.push newVal(b.floatVal - a.intVal.float) + i.push newVal(b.floatVal - a.intVal.float) + else: + if b.isFloat: + i.push newVal(b.floatVal - a.floatVal) else: - if b.isFloat: - i.push newVal(b.floatVal - a.floatVal) - else: - i.push newVal(b.intVal.float - a.floatVal) - - .symbol("*") do (i: In): - var a, b: MinValue - i.reqTwoNumbers a, b - if a.isInt: - if b.isInt: - i.push newVal(a.intVal * b.intVal) - else: - i.push newVal(a.intVal.float * b.floatVal) + i.push newVal(b.intVal.float - a.floatVal) + + def.symbol("*") do (i: In): + var a, b: MinValue + i.reqTwoNumbers a, b + if a.isInt: + if b.isInt: + i.push newVal(a.intVal * b.intVal) else: - if b.isFloat: - i.push newVal(a.floatVal * b.floatVal) - else: - i.push newVal(a.floatVal * b.intVal.float) - - .symbol("/") do (i: In): - var a, b: MinValue - i.reqTwoNumbers a, b - if a.isInt: - if b.isInt: - i.push newVal(b.intVal.int / a.intVal.int) - else: - i.push newVal(b.floatVal / a.intVal.float) + i.push newVal(a.intVal.float * b.floatVal) + else: + if b.isFloat: + i.push newVal(a.floatVal * b.floatVal) else: - if b.isFloat: - i.push newVal(b.floatVal / a.floatVal) - else: - i.push newVal(b.intVal.float / a.floatVal) - - .symbol("random") do (i: In): - var n: MinValue - i.reqInt n - i.push n.intVal.int.random.newVal + i.push newVal(a.floatVal * b.intVal.float) + + def.symbol("/") do (i: In): + var a, b: MinValue + i.reqTwoNumbers a, b + if a.isInt: + if b.isInt: + i.push newVal(b.intVal.int / a.intVal.int) + else: + i.push newVal(b.floatVal / a.intVal.float) + else: + if b.isFloat: + i.push newVal(b.floatVal / a.floatVal) + else: + i.push newVal(b.intVal.float / a.floatVal) + + def.symbol("random") do (i: In): + var n: MinValue + i.reqInt n + i.push n.intVal.int.random.newVal - .symbol("div") do (i: In): - var a, b: MinValue - i.reqTwoInts b, a - i.push(newVal(a.intVal div b.intVal)) - - .symbol("mod") do (i: In): - var a, b: MinValue - i.reqTwoInts b, a - i.push(newVal(a.intVal mod b.intVal)) + def.symbol("div") do (i: In): + var a, b: MinValue + i.reqTwoInts b, a + i.push(newVal(a.intVal div b.intVal)) + + def.symbol("mod") do (i: In): + var a, b: MinValue + i.reqTwoInts b, a + i.push(newVal(a.intVal mod b.intVal)) - .symbol("succ") do (i: In): - var n: MinValue - i.reqInt n - i.push newVal(n.intVal + 1) + def.symbol("succ") do (i: In): + var n: MinValue + i.reqInt n + i.push newVal(n.intVal + 1) - .symbol("pred") do (i: In): - var n: MinValue - i.reqInt n - i.push newVal(n.intVal - 1) + def.symbol("pred") do (i: In): + var n: MinValue + i.reqInt n + i.push newVal(n.intVal - 1) - .symbol("even?") do (i: In): - var n: MinValue - i.reqInt n - i.push newVal(n.intVal mod 2 == 0) + def.symbol("even?") do (i: In): + var n: MinValue + i.reqInt n + i.push newVal(n.intVal mod 2 == 0) - .symbol("odd?") do (i: In): - var n: MinValue - i.reqInt n - i.push newVal(n.intVal mod 2 != 0) + def.symbol("odd?") do (i: In): + var n: MinValue + i.reqInt n + i.push newVal(n.intVal mod 2 != 0) - .symbol("sum") do (i: In): - var s: MinValue - i.reqQuotationOfNumbers s - var c = 0.float - var isInt = true - for n in s.qVal: - if n.isFloat: - isInt = false - c = + n.floatVal - else: - c = c + n.intVal.float - if isInt: - i.push c.int.newVal + def.symbol("sum") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + var c = 0.float + var isInt = true + for n in s.qVal: + if n.isFloat: + isInt = false + c = + n.floatVal else: - i.push c.newVal + c = c + n.intVal.float + if isInt: + i.push c.int.newVal + else: + i.push c.newVal - .finalize("num") + def.finalize("num")
M lib/min_seq.nimlib/min_seq.nim

@@ -12,329 +12,329 @@

# Operations on sequences (data quotations) proc seq_module*(i: In)= - i.define() + let def = i.define() - .symbol("concat") do (i: In): - var q1, q2: MinValue - i.reqTwoQuotations q1, q2 - let q = q2.qVal & q1.qVal - i.push q.newVal(i.scope) + def.symbol("concat") do (i: In): + var q1, q2: MinValue + i.reqTwoQuotations q1, q2 + let q = q2.qVal & q1.qVal + i.push q.newVal(i.scope) - .symbol("first") do (i: In): - var q: MinValue - i.reqQuotation q - if q.qVal.len == 0: - raiseOutOfBounds("Quotation is empty") - i.push q.qVal[0] + def.symbol("first") do (i: In): + var q: MinValue + i.reqQuotation q + if q.qVal.len == 0: + raiseOutOfBounds("Quotation is empty") + i.push q.qVal[0] - .symbol("rest") do (i: In): - var q: MinValue - i.reqQuotation q - if q.qVal.len == 0: - raiseOutOfBounds("Quotation is empty") - i.push q.qVal[1..q.qVal.len-1].newVal(i.scope) + def.symbol("rest") do (i: In): + var q: MinValue + i.reqQuotation q + if q.qVal.len == 0: + raiseOutOfBounds("Quotation is empty") + i.push q.qVal[1..q.qVal.len-1].newVal(i.scope) - .symbol("append") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - i.push newVal(q.qVal & v, i.scope) - - .symbol("prepend") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - i.push newVal(v & q.qVal, i.scope) - - .symbol("get") do (i: In): - var index, q: MinValue - i.reqIntAndQuotation index, q - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - i.push q.qVal[ix.int] + def.symbol("append") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + i.push newVal(q.qVal & v, i.scope) - .symbol("set") do (i: In): - var val, index, q: MinValue - i.reqInt index - val = i.pop - i.reqQuotation q - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - q.qVal[ix.int] = val - i.push q + def.symbol("prepend") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + i.push newVal(v & q.qVal, i.scope) - .symbol("remove") do (i: In): - var index, q: MinValue - i.reqIntAndQuotation index, q - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - var res = newSeq[MinValue](0) - for x in 0..q.qVal.len-1: - if x == ix: - continue - res.add q.qVal[x] - i.push res.newVal(i.scope) + def.symbol("get") do (i: In): + var index, q: MinValue + i.reqIntAndQuotation index, q + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + i.push q.qVal[ix.int] + + def.symbol("set") do (i: In): + var val, index, q: MinValue + i.reqInt index + val = i.pop + i.reqQuotation q + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + q.qVal[ix.int] = val + i.push q + + def.symbol("remove") do (i: In): + var index, q: MinValue + i.reqIntAndQuotation index, q + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + var res = newSeq[MinValue](0) + for x in 0..q.qVal.len-1: + if x == ix: + continue + res.add q.qVal[x] + i.push res.newVal(i.scope) - .symbol("insert") do (i: In): - var val, index, q: MinValue - i.reqInt index - val = i.pop - i.reqQuotation q - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - var res = newSeq[MinValue](0) - for x in 0..q.qVal.len-1: - if x == ix: - res.add val - res.add q.qVal[x] - i.push res.newVal(i.scope) + def.symbol("insert") do (i: In): + var val, index, q: MinValue + i.reqInt index + val = i.pop + i.reqQuotation q + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + var res = newSeq[MinValue](0) + for x in 0..q.qVal.len-1: + if x == ix: + res.add val + res.add q.qVal[x] + i.push res.newVal(i.scope) - .symbol("size") do (i: In): - var q: MinValue - i.reqQuotation q - i.push q.qVal.len.newVal + def.symbol("size") do (i: In): + var q: MinValue + i.reqQuotation q + i.push q.qVal.len.newVal + + def.symbol("in?") do (i: In): + i.reqStackSize(2) + let v = i.pop + var q: MinValue + i.reqQuotation q + i.push q.qVal.contains(v).newVal - .symbol("in?") do (i: In): - i.reqStackSize(2) - let v = i.pop - var q: MinValue - i.reqQuotation q - i.push q.qVal.contains(v).newVal - - .symbol("map") do (i: In): - var prog, list: MinValue - i.reqTwoQuotations prog, list - var res = newSeq[MinValue](0) - for litem in list.qVal: - i.push litem - i.unquote(prog) - res.add i.pop - i.push res.newVal(i.scope) + def.symbol("map") do (i: In): + var prog, list: MinValue + i.reqTwoQuotations prog, list + var res = newSeq[MinValue](0) + for litem in list.qVal: + i.push litem + i.unquote(prog) + res.add i.pop + i.push res.newVal(i.scope) - .symbol("apply") do (i: In): - var prog: MinValue - i.reqQuotation prog - i.apply prog + def.symbol("apply") do (i: In): + var prog: MinValue + i.reqQuotation prog + i.apply prog - .symbol("reverse") do (i: In): - var q: MinValue - i.reqQuotation q - var res = newSeq[MinValue](0) - for c in countdown(q.qVal.len-1, 0): - res.add q.qVal[c] - i.push res.newVal(i.scope) + def.symbol("reverse") do (i: In): + var q: MinValue + i.reqQuotation q + var res = newSeq[MinValue](0) + for c in countdown(q.qVal.len-1, 0): + res.add q.qVal[c] + i.push res.newVal(i.scope) - .symbol("filter") do (i: In): - var filter, list: MinValue - i.reqTwoQuotations filter, list - var res = newSeq[MinValue](0) - for e in list.qVal: - i.push e - i.unquote(filter) - var check = i.pop - if check.isBool and check.boolVal == true: - res.add e - i.push res.newVal(i.scope) + def.symbol("filter") do (i: In): + var filter, list: MinValue + i.reqTwoQuotations filter, list + var res = newSeq[MinValue](0) + for e in list.qVal: + i.push e + i.unquote(filter) + var check = i.pop + if check.isBool and check.boolVal == true: + res.add e + i.push res.newVal(i.scope) - .symbol("reject") do (i: In): - var filter, list: MinValue - i.reqTwoQuotations filter, list - var res = newSeq[MinValue](0) - for e in list.qVal: - i.push e - i.unquote(filter) - var check = i.pop - if check.isBool and check.boolVal == false: - res.add e - i.push res.newVal(i.scope) + def.symbol("reject") do (i: In): + var filter, list: MinValue + i.reqTwoQuotations filter, list + var res = newSeq[MinValue](0) + for e in list.qVal: + i.push e + i.unquote(filter) + var check = i.pop + if check.isBool and check.boolVal == false: + res.add e + i.push res.newVal(i.scope) - .symbol("any?") do (i: In): - var filter, list: MinValue - i.reqTwoQuotations filter, list - for e in list.qVal: - i.push e - i.unquote(filter) - var check = i.pop - if check.isBool and check.boolVal == true: - i.push true.newVal - return - i.push false.newVal + def.symbol("any?") do (i: In): + var filter, list: MinValue + i.reqTwoQuotations filter, list + for e in list.qVal: + i.push e + i.unquote(filter) + var check = i.pop + if check.isBool and check.boolVal == true: + i.push true.newVal + return + i.push false.newVal - .symbol("all?") do (i: In): - var filter, list: MinValue - i.reqTwoQuotations filter, list - for e in list.qVal: - i.push e - i.unquote(filter) - var check = i.pop - if check.isBool and check.boolVal == false: - i.push false.newVal - break - i.push true.newVal + def.symbol("all?") do (i: In): + var filter, list: MinValue + i.reqTwoQuotations filter, list + for e in list.qVal: + i.push e + i.unquote(filter) + var check = i.pop + if check.isBool and check.boolVal == false: + i.push false.newVal + break + i.push true.newVal - .symbol("sort") do (i: In): - var cmp, list: MinValue - i.reqTwoQuotations cmp, list - var i2 = i - var minCmp = proc(a, b: MinValue): int {.closure.}= - i2.push a - i2.push b - i2.unquote(cmp) - let r = i2.pop - if r.isBool: - if r.isBool and r.boolVal == true: - return 1 - else: - return -1 + def.symbol("sort") do (i: In): + var cmp, list: MinValue + i.reqTwoQuotations cmp, list + var i2 = i + var minCmp = proc(a, b: MinValue): int {.closure.}= + i2.push a + i2.push b + i2.unquote(cmp) + let r = i2.pop + if r.isBool: + if r.isBool and r.boolVal == true: + return 1 else: - raiseInvalid("Predicate quotation must return a boolean value") - var qList = list.qVal - sort[MinValue](qList, minCmp) - i.push qList.newVal(i.scope) - - .symbol("shorten") do (i: In): - var n, q: MinValue - i.reqIntAndQuotation n, q - if n.intVal > q.qVal.len: - raiseInvalid("Quotation is too short") - i.push q.qVal[0..n.intVal.int-1].newVal(i.scope) + return -1 + else: + raiseInvalid("Predicate quotation must return a boolean value") + var qList = list.qVal + sort[MinValue](qList, minCmp) + i.push qList.newVal(i.scope) + + def.symbol("shorten") do (i: In): + var n, q: MinValue + i.reqIntAndQuotation n, q + if n.intVal > q.qVal.len: + raiseInvalid("Quotation is too short") + i.push q.qVal[0..n.intVal.int-1].newVal(i.scope) - .symbol("find") do (i: In): - var s, test, result: MinValue - i.reqTwoQuotations test, s - var res = -1 - var c = 0 - for el in s.qVal: - i.push el - i.unquote test - result = i.pop - if result.isBool and result.boolVal == true: - res = c - break - c.inc - i.push res.newVal + def.symbol("find") do (i: In): + var s, test, result: MinValue + i.reqTwoQuotations test, s + var res = -1 + var c = 0 + for el in s.qVal: + i.push el + i.unquote test + result = i.pop + if result.isBool and result.boolVal == true: + res = c + break + c.inc + i.push res.newVal - .symbol("reduce") do (i: In): - var s, q, acc: MinValue - i.reqQuotation q + def.symbol("reduce") do (i: In): + var s, q, acc: MinValue + i.reqQuotation q + acc = i.pop + i.reqQuotation s + for el in s.qVal: + i.push acc + i.push el + i.unquote q acc = i.pop - i.reqQuotation s - for el in s.qVal: - i.push acc - i.push el - i.unquote q - acc = i.pop - i.push acc + i.push acc - .symbol("map-reduce") do (i: In): - var s, map, red, acc: MinValue - i.reqThreeQuotations red, map, s - if s.qVal.len == 0: - raiseInvalid("Quotation must have at least one element") - i.push s.qVal[0] + def.symbol("map-reduce") do (i: In): + var s, map, red, acc: MinValue + i.reqThreeQuotations red, map, s + if s.qVal.len == 0: + raiseInvalid("Quotation must have at least one element") + i.push s.qVal[0] + i.unquote map + acc = i.pop + for ix in 1..s.qVal.len-1: + i.push s.qVal[ix] i.unquote map + i.push acc + i.unquote red acc = i.pop - for ix in 1..s.qVal.len-1: - i.push s.qVal[ix] - i.unquote map - i.push acc - i.unquote red - acc = i.pop - i.push acc + i.push acc - .symbol("partition") do (i: In): - var s, test: MinValue - i.reqTwoQuotations test, s - var tseq = newSeq[MinValue](0) - var fseq = newSeq[MinValue](0) - for el in s.qVal: - i.push el - i.unquote test - let res = i.pop - if res.isBool and res.boolVal == true: - tseq.add el - else: - fseq.add el - i.push tseq.newVal(i.scope) - i.push fseq.newVal(i.scope) + def.symbol("partition") do (i: In): + var s, test: MinValue + i.reqTwoQuotations test, s + var tseq = newSeq[MinValue](0) + var fseq = newSeq[MinValue](0) + for el in s.qVal: + i.push el + i.unquote test + let res = i.pop + if res.isBool and res.boolVal == true: + tseq.add el + else: + fseq.add el + i.push tseq.newVal(i.scope) + i.push fseq.newVal(i.scope) + + def.symbol("slice") do (i: In): + var start, finish, q: MinValue + i.reqInt finish + i.reqInt start + i.reqQuotation q + let st = start.intVal + let fn = finish.intVal + if st < 0 or fn > q.qVal.len-1: + raiseOutOfBounds("Index out of bounds") + elif fn < st: + raiseInvalid("End index must be greater than start index") + let rng = q.qVal[st.int..fn.int] + i.push rng.newVal(i.scope) - .symbol("slice") do (i: In): - var start, finish, q: MinValue - i.reqInt finish - i.reqInt start - i.reqQuotation q - let st = start.intVal - let fn = finish.intVal - if st < 0 or fn > q.qVal.len-1: - raiseOutOfBounds("Index out of bounds") - elif fn < st: - raiseInvalid("End index must be greater than start index") - let rng = q.qVal[st.int..fn.int] - i.push rng.newVal(i.scope) + def.symbol("harvest") do (i: In): + var q: MinValue + i.reqQuotation q + var res = newSeq[MinValue](0) + for el in q.qVal: + if el.isQuotation and el.qVal.len == 0: + continue + res.add el + i.push res.newVal(i.scope) - .symbol("harvest") do (i: In): - var q: MinValue - i.reqQuotation q - var res = newSeq[MinValue](0) - for el in q.qVal: - if el.isQuotation and el.qVal.len == 0: - continue + def.symbol("flatten") do (i: In): + var q: MinValue + i.reqQuotation q + var res = newSeq[MinValue](0) + for el in q.qVal: + if el.isQuotation: + for el2 in el.qVal: + res.add el2 + else: res.add el - i.push res.newVal(i.scope) + i.push res.newVal(i.scope) - .symbol("flatten") do (i: In): - var q: MinValue - i.reqQuotation q - var res = newSeq[MinValue](0) - for el in q.qVal: - if el.isQuotation: - for el2 in el.qVal: - res.add el2 - else: - res.add el - i.push res.newVal(i.scope) + # Operations on dictionaries - # Operations on dictionaries - - .symbol("dhas?") do (i: In): - var d, k: MinValue - i.reqStringLike k - i.reqDictionary d - i.push d.dhas(k).newVal + def.symbol("dhas?") do (i: In): + var d, k: MinValue + i.reqStringLike k + i.reqDictionary d + i.push d.dhas(k).newVal - .symbol("dget") do (i: In): - var d, k: MinValue - i.reqStringLike k - i.reqDictionary d - i.push d.dget(k) - - .symbol("dset") do (i: In): - var d, k: MinValue - i.reqStringLike k - let m = i.pop - i.reqDictionary d - i.push i.dset(d, k, m) + def.symbol("dget") do (i: In): + var d, k: MinValue + i.reqStringLike k + i.reqDictionary d + i.push d.dget(k) + + def.symbol("dset") do (i: In): + var d, k: MinValue + i.reqStringLike k + let m = i.pop + i.reqDictionary d + i.push i.dset(d, k, m) - .symbol("ddel") do (i: In): - var d, k: MinValue - i.reqStringLike k - i.reqDictionary d - i.push i.ddel(d, k) + def.symbol("ddel") do (i: In): + var d, k: MinValue + i.reqStringLike k + i.reqDictionary d + i.push i.ddel(d, k) - .symbol("keys") do (i: In): - var d: MinValue - i.reqDictionary d - i.push i.keys(d) + def.symbol("keys") do (i: In): + var d: MinValue + i.reqDictionary d + i.push i.keys(d) - .symbol("values") do (i: In): - var d: MinValue - i.reqDictionary d - i.push i.values(d) + def.symbol("values") do (i: In): + var d: MinValue + i.reqDictionary d + i.push i.values(d) - + - .finalize("seq") + def.finalize("seq")
M lib/min_stack.nimlib/min_stack.nim

@@ -6,137 +6,137 @@ ../core/parser,

../core/value, ../core/interpreter, ../core/utils - + # Operations on the whole stack proc stack_module*(i: In)= - i.define() + let def = i.define() + + def.symbol("clear-stack") do (i: In): + while i.stack.len > 0: + discard i.pop + + def.symbol("get-stack") do (i: In): + i.push i.stack.newVal(i.scope) - .symbol("clear-stack") do (i: In): - while i.stack.len > 0: - discard i.pop + def.symbol("set-stack") do (i: In): + var q: MinValue + i.reqQuotation q + i.stack = q.qVal - .symbol("get-stack") do (i: In): - i.push i.stack.newVal(i.scope) + def.symbol("id") do (i: In): + discard + + def.symbol("pop") do (i: In): + if i.stack.len < 1: + raiseEmptyStack() + discard i.pop - .symbol("set-stack") do (i: In): - var q: MinValue - i.reqQuotation q - i.stack = q.qVal - - .symbol("id") do (i: In): - discard - - .symbol("pop") do (i: In): - if i.stack.len < 1: - raiseEmptyStack() - discard i.pop - - .symbol("dup") do (i: In): - i.push i.peek + def.symbol("dup") do (i: In): + i.push i.peek - .symbol("dip") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - i.unquote(q) - i.push v + def.symbol("dip") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + i.unquote(q) + i.push v - .symbol("nip") do (i: In): - var a, b: MinValue - a = i.pop - b = i.pop - i.push a - - .symbol("cleave") do (i: In): - var q: MinValue - i.reqQuotationOfQuotations q - let v = i.pop - for s in q.qVal: - var s1 = s - i.push v - i.unquote(s1) - - .symbol("spread") do (i: In): - var q: MinValue - i.reqQuotationOfQuotations q - var els = newSeq[MinValue](0) - for el in 0..q.qVal.len-1: - els.add i.pop - var count = els.len-1 - for s in q.qVal: - var s1 = s - i.push els[count] - i.unquote(s1) - count.dec - - .symbol("keep") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop + def.symbol("nip") do (i: In): + var a, b: MinValue + a = i.pop + b = i.pop + i.push a + + def.symbol("cleave") do (i: In): + var q: MinValue + i.reqQuotationOfQuotations q + let v = i.pop + for s in q.qVal: + var s1 = s i.push v - i.unquote(q) - i.push v - - .symbol("swap") do (i: In): - i.reqStackSize 2 - let a = i.pop - let b = i.pop - i.push a - i.push b + i.unquote(s1) + + def.symbol("spread") do (i: In): + var q: MinValue + i.reqQuotationOfQuotations q + var els = newSeq[MinValue](0) + for el in 0..q.qVal.len-1: + els.add i.pop + var count = els.len-1 + for s in q.qVal: + var s1 = s + i.push els[count] + i.unquote(s1) + count.dec + + def.symbol("keep") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + i.push v + i.unquote(q) + i.push v + + def.symbol("swap") do (i: In): + i.reqStackSize 2 + let a = i.pop + let b = i.pop + i.push a + i.push b - .symbol("over") do (i: In): - i.reqStackSize 2 - let a = i.pop - let b = i.pop - i.push b - i.push a - i.push b + def.symbol("over") do (i: In): + i.reqStackSize 2 + let a = i.pop + let b = i.pop + i.push b + i.push a + i.push b - .symbol("pick") do (i: In): - i.reqStackSize 3 - let a = i.pop - let b = i.pop - let c = i.pop - i.push c - i.push b - i.push a - i.push c + def.symbol("pick") do (i: In): + i.reqStackSize 3 + let a = i.pop + let b = i.pop + let c = i.pop + i.push c + i.push b + i.push a + i.push c - .symbol("rollup") do (i: In): - i.reqStackSize 3 - let first = i.pop - let second = i.pop - let third = i.pop - i.push first - i.push second - i.push third + def.symbol("rollup") do (i: In): + i.reqStackSize 3 + let first = i.pop + let second = i.pop + let third = i.pop + i.push first + i.push second + i.push third - .symbol("rolldown") do (i: In): - i.reqStackSize 3 - let first = i.pop - let second = i.pop - let third = i.pop - i.push second - i.push first - i.push third + def.symbol("rolldown") do (i: In): + i.reqStackSize 3 + let first = i.pop + let second = i.pop + let third = i.pop + i.push second + i.push first + i.push third - .symbol("cons") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - q.qVal = @[v] & q.qVal - i.push q + def.symbol("cons") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + q.qVal = @[v] & q.qVal + i.push q - .symbol("swons") do (i: In): - i.push "swap".newSym - i.push "cons".newSym - - .symbol("sip") do (i: In): - var a, b: MinValue - i.reqTwoQuotations a, b - i.push b - i.unquote(a) - i.push b + def.symbol("swons") do (i: In): + i.push "swap".newSym + i.push "cons".newSym - .finalize("stack") + def.symbol("sip") do (i: In): + var a, b: MinValue + i.reqTwoQuotations a, b + i.push b + i.unquote(a) + i.push b + + def.finalize("stack")
M lib/min_str.nimlib/min_str.nim

@@ -11,9 +11,9 @@ ../packages/nim-sgregex/sgregex

proc str_module*(i: In) = - i.define() + let def = i.define() - .symbol("interpolate") do (i: In): + def.symbol("interpolate") do (i: In): var s, q: MinValue i.reqQuotationAndString q, s var strings = newSeq[string](0)

@@ -22,12 +22,12 @@ strings.add $$el

let res = s.strVal % strings i.push res.newVal - .symbol("strip") do (i: In): + def.symbol("strip") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.strip.newVal - .symbol("split") do (i: In): + def.symbol("split") do (i: In): var sep, s: MinValue i.reqTwoStrings sep, s var q = newSeq[MinValue](0)

@@ -35,51 +35,51 @@ for e in s.strVal.split(sep.strVal):

q.add e.newVal i.push q.newVal(i.scope) - .symbol("join") do (i: In): + def.symbol("join") do (i: In): var q, s: MinValue i.reqStringLikeAndQuotation s, q i.push q.qVal.mapIt($$it).join(s.getString).newVal - .symbol("length") do (i: In): + def.symbol("length") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.len.newVal - .symbol("lowercase") do (i: In): + def.symbol("lowercase") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.toLowerAscii.newVal - .symbol("uppercase") do (i: In): + def.symbol("uppercase") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.toUpperAscii.newVal - .symbol("capitalize") do (i: In): + def.symbol("capitalize") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.capitalizeAscii.newVal - .symbol("titleize") do (i: In): + def.symbol("titleize") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.split(" ").mapIt(it.capitalizeAscii).join(" ").newVal - .symbol("repeat") do (i: In): + def.symbol("repeat") do (i: In): var s, n: MinValue i.reqIntAndString n, s i.push s.getString.repeat(n.intVal).newVal - .symbol("indent") do (i: In): + def.symbol("indent") do (i: In): var s, n: MinValue i.reqIntAndString n, s i.push s.getString.indent(n.intVal).newVal - .symbol("string") do (i: In): + def.symbol("string") do (i: In): var s = i.pop i.push(($$s).newVal) - .symbol("bool") do (i: In): + def.symbol("bool") do (i: In): var v = i.pop let strcheck = (v.isString and (v.getString == "false" or v.getString == "")) let intcheck = v.isInt and v.intVal == 0

@@ -91,7 +91,7 @@ i.push false.newVal

else: i.push true.newVal - .symbol("int") do (i: In): + def.symbol("int") do (i: In): var s = i.pop if s.isString: i.push s.getString.parseInt.newVal

@@ -107,7 +107,7 @@ i.push 0.int.newVal

else: raiseInvalid("Cannot convert a quotation to an integer.") - .symbol("float") do (i: In): + def.symbol("float") do (i: In): var s = i.pop if s.isString: i.push s.getString.parseFloat.newVal

@@ -123,7 +123,7 @@ i.push 0.float.newVal

else: raiseInvalid("Cannot convert a quotation to float.") - .symbol("search") do (i: In): + def.symbol("search") do (i: In): var reg, str: MinValue i.reqTwoStrings reg, str var matches = str.strVal.search(reg.strVal)

@@ -132,7 +132,7 @@ for i in 0..matches.len-1:

res[i] = matches[i].newVal i.push res.newVal(i.scope) - .symbol("match") do (i: In): + def.symbol("match") do (i: In): var reg, str: MinValue i.reqTwoStrings reg, str if str.strVal.match(reg.strVal):

@@ -140,12 +140,12 @@ i.push true.newVal

else: i.push false.newVal - .symbol("replace") do (i: In): + def.symbol("replace") do (i: In): var s_replace, reg, s_find: MinValue i.reqThreeStrings s_replace, reg, s_find i.push sgregex.replace(s_find.strVal, reg.strVal, s_replace.strVal).newVal - .symbol("regex") do (i: In): + def.symbol("regex") do (i: In): var reg, str: MinValue i.reqTwoStrings reg, str let results = str.strVal =~ reg.strVal

@@ -154,10 +154,10 @@ for r in results:

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

@@ -18,20 +18,20 @@ proc unix(s: string): string =

return s.replace("\\", "/") proc sys_module*(i: In)= - var sys = i.define() + let def = i.define() - sys = sys.symbol(".") do (i: In): + def.symbol(".") do (i: In): i.push newVal(getCurrentDir().unix) - .symbol("..") do (i: In): + def.symbol("..") do (i: In): i.push newVal(getCurrentDir().parentDir.unix) - .symbol("cd") do (i: In): + def.symbol("cd") do (i: In): var f: MinValue i.reqStringLike f f.getString.setCurrentDir - .symbol("ls") do (i: In): + def.symbol("ls") do (i: In): var a: MinValue i.reqStringLike a var list = newSeq[MinValue](0)

@@ -39,7 +39,7 @@ for i in walkDir(a.getString):

list.add newVal(i.path.unix) i.push list.newVal(i.scope) - .symbol("ls-r") do (i: In): + def.symbol("ls-r") do (i: In): var a: MinValue i.reqStringLike a var list = newSeq[MinValue](0)

@@ -47,59 +47,59 @@ for i in walkDirRec(a.getString):

list.add newVal(i.unix) i.push list.newVal(i.scope) - .symbol("system") do (i: In): + def.symbol("system") do (i: In): var a: MinValue i.reqStringLike a i.push execShellCmd(a.getString).newVal - .symbol("run") do (i: In): + def.symbol("run") do (i: In): var cmd: MinValue i.reqStringLike cmd let res = execCmdEx(cmd.getString) i.push @[@["output".newSym, res.output.newVal].newVal(i.scope), @["code".newSym, res.exitCode.newVal].newVal(i.scope)].newVal(i.scope) - .symbol("get-env") do (i: In): + def.symbol("get-env") do (i: In): var a: MinValue i.reqStringLike a i.push a.getString.getEnv.newVal - .symbol("put-env") do (i: In): + def.symbol("put-env") do (i: In): var key, value: MinValue i.reqTwoStringLike key, value key.getString.putEnv value.getString - .symbol("env?") do (i: In): + def.symbol("env?") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.existsEnv.newVal - .symbol("which") do (i: In): + def.symbol("which") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.findExe.newVal - .symbol("os") do (i: In): + def.symbol("os") do (i: In): i.push hostOS.newVal - .symbol("cpu") do (i: In): + def.symbol("cpu") do (i: In): i.push hostCPU.newVal - .symbol("exists?") do (i: In): + def.symbol("exists?") do (i: In): var f: MinValue i.reqStringLike f i.push newVal(f.getString.fileExists or f.getString.dirExists) - .symbol("file?") do (i: In): + def.symbol("file?") do (i: In): var f: MinValue i.reqStringLike f i.push f.getString.fileExists.newVal - .symbol("dir?") do (i: In): + def.symbol("dir?") do (i: In): var f: MinValue i.reqStringLike f i.push f.getString.dirExists.newVal - .symbol("rm") do (i: In): + def.symbol("rm") do (i: In): var v: MinValue i.reqStringLike v let f = v.getString

@@ -110,7 +110,7 @@ f.removeDir

else: raiseInvalid("File '$1' does not exist." % f) - .symbol("cp") do (i: In): + def.symbol("cp") do (i: In): var a, b: MinValue i.reqTwoStringLike a, b let src = b.getString

@@ -125,7 +125,7 @@ copyFileWithPermissions src, dest / src.extractFilename

else: copyFileWithPermissions src, dest - .symbol("mv") do (i: In): + def.symbol("mv") do (i: In): var a, b: MinValue i.reqTwoStringLike a, b let src = b.getString

@@ -134,79 +134,79 @@ if dest.dirExists:

dest = dest / src.extractFilename moveFile src, dest - .symbol("rmdir") do (i: In): + def.symbol("rmdir") do (i: In): var f: MinValue i.reqStringLike f f.getString.removeDir - .symbol("mkdir") do (i: In): + def.symbol("mkdir") do (i: In): var f: MinValue i.reqStringLike f f.getString.createDir - .symbol("sleep") do (i: In): - var ms: MinValue - i.reqInt ms - sleep ms.intVal.int + def.symbol("sleep") do (i: In): + var ms: MinValue + i.reqInt ms + sleep ms.intVal.int - .symbol("chmod") do (i: In): + def.symbol("chmod") do (i: In): var s, perms: MinValue i.reqIntAndString perms, s s.getString.setFilePermissions(perms.intVal.toFilePermissions) - .symbol("symlink?") do (i: In): + def.symbol("symlink?") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.symlinkExists.newVal - .symbol("symlink") do (i: In): + def.symbol("symlink") do (i: In): var src, dest: MinValue i.reqTwoStringLike dest, src src.getString.createSymlink dest.getString - .symbol("hardlink") do (i: In): + def.symbol("hardlink") do (i: In): var src, dest: MinValue i.reqTwoStringLike dest, src src.getString.createHardlink dest.getString - .symbol("filename") do (i: In): + def.symbol("filename") do (i: In): var f: MinValue i.reqStringLike f i.push f.getString.extractFilename.unix.newVal - .symbol("dirname") do (i: In): + def.symbol("dirname") do (i: In): var f: MinValue i.reqStringLike f i.push f.getString.parentDir.unix.newVal - .symbol("$") do (i: In): + def.symbol("$") do (i: In): i.push("get-env".newSym) - .symbol("!") do (i: In): + def.symbol("!") do (i: In): i.push("system".newSym) - .symbol("&") do (i: In): + def.symbol("&") do (i: In): i.push("run".newSym) - .sigil("$") do (i: In): + def.sigil("$") do (i: In): i.push("get-env".newSym) - .sigil("!") do (i: In): + def.sigil("!") do (i: In): i.push("system".newSym) - .sigil("&") do (i: In): + def.sigil("&") do (i: In): i.push("run".newSym) when not defined(lite): - sys = sys.symbol("unzip") do (i: In): + def.symbol("unzip") do (i: In): var f, dir: MinValue i.reqTwoStringLike dir, f miniz.unzip(f.getString, dir.getString) - .symbol("zip") do (i: In): + def.symbol("zip") do (i: In): var files, file: MinValue i.reqStringLikeAndQuotation file, files miniz.zip(files.qVal.mapIt(it.getString), file.getString) - sys.finalize("sys") + def.finalize("sys")
M lib/min_time.nimlib/min_time.nim

@@ -11,53 +11,53 @@ # Time

proc time_module*(i: In)= - i.define() + let def = i.define() - .symbol("timestamp") do (i: In): - i.push getTime().int.newVal - - .symbol("now") do (i: In): - i.push epochTime().newVal + def.symbol("timestamp") do (i: In): + i.push getTime().int.newVal - .symbol("timeinfo") do (i: In): - var t: MinValue - i.reqNumber t - var time: Time - if t.kind == minInt: - time = t.intVal.fromSeconds - else: - time = t.floatVal.fromSeconds - let tinfo = time.getLocalTime - var info = newSeq[MinValue](0).newVal(i.scope) - info.qVal.add @["year".newSym, tinfo.year.newVal].newVal(i.scope) - info.qVal.add @["month".newSym, (tinfo.month.int+1).newVal].newVal(i.scope) - info.qVal.add @["day".newSym, tinfo.monthday.newVal].newVal(i.scope) - info.qVal.add @["weekday".newSym, (tinfo.weekday.int+1).newVal].newVal(i.scope) - info.qVal.add @["yearday".newSym, tinfo.yearday.newVal].newVal(i.scope) - info.qVal.add @["hour".newSym, tinfo.hour.newVal].newVal(i.scope) - info.qVal.add @["minute".newSym, tinfo.minute.newVal].newVal(i.scope) - info.qVal.add @["second".newSym, tinfo.second.newVal].newVal(i.scope) - i.push info + def.symbol("now") do (i: In): + i.push epochTime().newVal + + def.symbol("timeinfo") do (i: In): + var t: MinValue + i.reqNumber t + var time: Time + if t.kind == minInt: + time = t.intVal.fromSeconds + else: + time = t.floatVal.fromSeconds + let tinfo = time.getLocalTime + var info = newSeq[MinValue](0).newVal(i.scope) + info.qVal.add @["year".newSym, tinfo.year.newVal].newVal(i.scope) + info.qVal.add @["month".newSym, (tinfo.month.int+1).newVal].newVal(i.scope) + info.qVal.add @["day".newSym, tinfo.monthday.newVal].newVal(i.scope) + info.qVal.add @["weekday".newSym, (tinfo.weekday.int+1).newVal].newVal(i.scope) + info.qVal.add @["yearday".newSym, tinfo.yearday.newVal].newVal(i.scope) + info.qVal.add @["hour".newSym, tinfo.hour.newVal].newVal(i.scope) + info.qVal.add @["minute".newSym, tinfo.minute.newVal].newVal(i.scope) + info.qVal.add @["second".newSym, tinfo.second.newVal].newVal(i.scope) + i.push info - .symbol("datetime") do (i: In): - var t: MinValue - i.reqNumber t - var time: Time - if t.kind == minInt: - time = t.intVal.fromSeconds - else: - time = t.floatVal.fromSeconds - i.push time.getLocalTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal + def.symbol("datetime") do (i: In): + var t: MinValue + i.reqNumber t + var time: Time + if t.kind == minInt: + time = t.intVal.fromSeconds + else: + time = t.floatVal.fromSeconds + i.push time.getLocalTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal - .symbol("tformat") do (i: In): - var t, s: MinValue - i.reqString s - i.reqNumber t - var time: Time - if t.kind == minInt: - time = t.intVal.fromSeconds - else: - time = t.floatVal.fromSeconds - i.push time.getLocalTime.format(s.getString).newVal - - .finalize("time") + def.symbol("tformat") do (i: In): + var t, s: MinValue + i.reqString s + i.reqNumber t + var time: Time + if t.kind == minInt: + time = t.intVal.fromSeconds + else: + time = t.floatVal.fromSeconds + i.push time.getLocalTime.format(s.getString).newVal + + def.finalize("time")