Added stack tests; Added ift symbol; modified vim syntax file.
@@ -44,7 +44,7 @@ HOME = getenv("USERPROFILE")
if not defined(windows): HOME = getenv("HOME") -let MINIMRC* = HOME / ".minrc" -let MINIMSYMBOLS* = HOME / ".min_symbols" -let MINIMHISTORY* = HOME / ".min_history" -let MINIMLOG* = HOME / "min.log" +let MINRC* = HOME / ".minrc" +let MINSYMBOLS* = HOME / ".min_symbols" +let MINHISTORY* = HOME / ".min_history" +let MINLOG* = HOME / "min.log"
@@ -501,6 +501,18 @@ i.unquote("<ifte-true>", tpath)
else: i.unquote("<ifte-false>", fpath) + .symbol("ift") do (i: In): + var fpath, tpath, check: MinValue + i.reqTwoQuotations tpath, check + var stack = i.stack + i.unquote("<ift-check>", 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("<ift-true>", tpath) + # 4 ( # ((> 3) ("Greater than 3" put!)) # ((< 3) ("Smaller than 3" put!))@@ -649,15 +661,15 @@ let sym = s.getString
let op = i.scope.getSymbol(sym) if op.kind == minProcOp: raiseInvalid("Symbol '$1' cannot be serialized." % sym) - let json = MINIMSYMBOLS.readFile.parseJson + let json = MINSYMBOLS.readFile.parseJson json[sym] = %op.val - MINIMSYMBOLS.writeFile(json.pretty) + MINSYMBOLS.writeFile(json.pretty) .symbol("load-symbol") do (i: In): var s:MinValue i.reqStringLike s let sym = s.getString - let json = MINIMSYMBOLS.readFile.parseJson + let json = MINSYMBOLS.readFile.parseJson if not json.hasKey(sym): raiseUndefined("Symbol '$1' not found." % sym) let val = i.fromJson(json[sym])@@ -665,7 +677,7 @@ i.scope.symbols[sym] = MinOperator(kind: minValOp, val: val)
.symbol("stored-symbols") do (i: In): var q = newSeq[MinValue](0) - let json = MINIMSYMBOLS.readFile.parseJson + let json = MINSYMBOLS.readFile.parseJson for k,v in json.pairs: q.add k.newVal i.push q.newVal(i.scope)@@ -674,11 +686,11 @@ .symbol("remove-symbol") do (i: In):
var s:MinValue i.reqStringLike s let sym = s.getString - var json = MINIMSYMBOLS.readFile.parseJson + var json = MINSYMBOLS.readFile.parseJson if not json.hasKey(sym): raiseUndefined("Symbol '$1' not found." % sym) json.delete(sym) - MINIMSYMBOLS.writeFile(json.pretty) + MINSYMBOLS.writeFile(json.pretty) .symbol("seal") do (i: In): var sym: MinValue@@ -709,6 +721,21 @@ m = i.pop
i.push @[m].newVal(i.scope) i.push s i.push "define".newSym + + .symbol("clear-stack") do (i: In): + while i.stack.len > 0: + discard i.pop + + .symbol("dump-stack") do (i: In): + echo i.dump + + .symbol("get-stack") do (i: In): + i.push i.stack.newVal(i.scope) + + .symbol("set-stack") do (i: In): + var q: MinValue + i.reqQuotation q + i.stack = q.qVal # Sigils
@@ -140,20 +140,4 @@ i.push b
i.unquote("<sip>", a) i.push b - .symbol("clear-stack") do (i: In): - while i.stack.len > 0: - discard i.pop - - .symbol("dump-stack") do (i: In): - echo i.dump - - .symbol("get-stack") do (i: In): - i.push i.stack.newVal(i.scope) - - .symbol("set-stack") do (i: In): - var q: MinValue - i.reqQuotation q - i.stack = q.qVal - - .finalize()
@@ -41,7 +41,7 @@
const PRELUDE* = "prelude.min".slurp.strip newNiftyLogger().addHandler() -newRollingFileLogger(MINIMLOG, fmtStr = verboseFmtStr).addHandler() +newRollingFileLogger(MINLOG, fmtStr = verboseFmtStr).addHandler() proc getExecs(): seq[string] = var res = newSeq[string](0)@@ -77,7 +77,7 @@ return symbols.mapIt("*" & $it)
if word.startsWith("("): return symbols.mapIt("(" & $it) if word.startsWith("<"): - return toSeq(MINIMSYMBOLS.readFile.parseJson.pairs).mapIt("<" & $it[0]) + return toSeq(MINSYMBOLS.readFile.parseJson.pairs).mapIt("<" & $it[0]) if word.startsWith("$"): return toSeq(envPairs()).mapIt("$" & $it[0]) if word.startsWith("!"):@@ -106,12 +106,19 @@ return toSeq(walkDir(dir, true)).filterIt(it.path.toLowerAscii.startsWith(f.toLowerAscii)).mapIt("\"$1" % [it.path.replace("\\", "/")])
return symbols proc stdLib*(i: In) = - if not MINIMSYMBOLS.fileExists: - MINIMSYMBOLS.writeFile("{}") - if not MINIMHISTORY.fileExists: - MINIMHISTORY.writeFile("") - if not MINIMRC.fileExists: - MINIMRC.writeFile("") + if not MINSYMBOLS.fileExists: + MINSYMBOLS.writeFile("{}") + if not MINHISTORY.fileExists: + MINHISTORY.writeFile("") + if not MINRC.fileExists: + let minrc = """ +; Load all stored symbols +stored-symbols ('load-symbol ROOT with) foreach + +; Execute startup symbol within ROOT scope +'startup ROOT with +""" + MINRC.writeFile(minrc) i.lang_module i.stack_module i.io_module@@ -123,7 +130,7 @@ i.time_module
i.fs_module i.crypto_module i.eval PRELUDE, "<prelude>" - i.eval MINIMRC.readFile() + i.eval MINRC.readFile() proc interpret*(i: In, s: Stream) = i.stdLib()@@ -176,7 +183,7 @@ var s = newStringStream("")
i.open(s, "<repl>") var line: string #echo "$1 v$2" % [appname, version] - var ed = initEditor(historyFile = MINIMHISTORY) + var ed = initEditor(historyFile = MINHISTORY) while true: let symbols = toSeq(i.scope.symbols.keys) ed.completionCallback = proc(ed: LineEditor): seq[string] =
@@ -1,8 +1,8 @@
" Vim syntax file " Language: min " Maintainer: Fabio Cevasco -" Last Change: 11 November 2016 -" Version: 0.3.0 +" Last Change: 25 March 2017 +" Version: 0.5.0 if exists("b:current_syntax") finish@@ -11,7 +11,7 @@
setl iskeyword=@,36-39,+,-,/,*,.,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd encode encrypt env? error eval even? exit fappend fatal file? filename filter first float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite gets get-stack getenv hardlink hidden? ifte import indent info inspect int int? interpolate interval io join k keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map match md5 mkdir mod module mtime mv newline not notice now num number? odd? os password pop popd pred print print! prompt publish puts puts! putenv q quotation? quote quote-bind quote-define raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search set-stack sha1 sha224 sha256 sha384 sha512 sigils sip sleep sort source split startup stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version warn which while with xor zip contains +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd encode encrypt env? error eval even? exit fappend fatal file? filename filter first float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite gets get-stack getenv hardlink hidden? i id ift ifte import indent info inspect int int? interpolate interval io join k keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map match md5 mkdir mod module mtime mv newline not notice now num number? odd? os password pop popd pred print print! prompt publish puts puts! putenv q quotation? quote quote-bind quote-define raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search set-stack sha1 sha224 sha256 sha384 sha512 sigils sip sleep sort source split startup stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version warn which while with xor zip contains syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
@@ -12,9 +12,3 @@
; Unsealed symbols () :startup ("[$1]$$ " (.) %) :prompt - -; Load all stored symbols -stored-symbols ('load-symbol ROOT with) foreach - -; Execute startup symbol within ROOT scope -'startup ROOT with
@@ -1,5 +1,5 @@
'lang load -;'stack load +'stack load 'io load 'logic load 'num load
@@ -10,16 +10,6 @@ newline
"lang" describe - (1 id 1 ==) assert - - (1 pop get-stack () ==) assert - - (1 dup get-stack (1 1) ==) assert - - (3 2 (1 +) dip + 6 ==) assert - - ((1) (2 swap append) sip concat (1 2 1 2) ==) assert - (2 'a define (3 a + (5 'a define a) -> +) -> a + 12 ==) assert@@ -94,8 +84,6 @@ ((2 3) unquote get-stack (2 3) ==) assert
(4 (1 2 3) append (1 2 3 4) ==) assert - (1 (2 3) cons (1 2 3) ==) assert - ((1 2 3 4) 2 at 3 ==) assert ((1 2 3) length 3 ==) assert@@ -108,6 +96,9 @@ (3 (succ) 3 times 6 ==) assert
((2 3 >) ("YES") ("NO") ifte "NO" ==) assert ((2 3 <) ("YES") ("NO") ifte "YES" ==) assert + + ("NO" (2 3 >) ("YES") ift "NO" ==) assert + ((2 3 <) ("YES") ift "YES" ==) assert (0 :c (c 10 <) (c succ @c) while
@@ -0,0 +1,23 @@
+'test load +'test import + +"stack" describe + + (1 id 1 ==) assert + + (2 (2 +) i 4 ==) assert + + (2 id 2 ==) assert + + (2 pop get-stack () ==) assert + + (1 dup get-stack (1 1) ==) assert + + (3 2 (1 +) dip + 6 ==) assert + + ((1) (2 swap append) sip concat (1 2 1 2) ==) assert + + (1 (2 3) cons (1 2 3) ==) assert + + report + clear-stack