all repos — min @ b3059e9053474931e2524e9ac66a3d00d212a1e5

A small but practical concatenative programming language.

Changed unquote into dequote; fixed tests on windows.
h3rald h3rald@h3rald.com
Sun, 16 Jul 2017 13:39:34 +0200
commit

b3059e9053474931e2524e9ac66a3d00d212a1e5

parent

fb6c67931ae0268f769387da85e4879c23684c35

M core/interpreter.nimcore/interpreter.nim

@@ -110,7 +110,7 @@ i.push e

else: i.push(op.val) -proc unquote*(i: In, q: var MinValue) = +proc dequote*(i: In, q: var MinValue) = i.withScope(q, q.scope): for v in q.qVal: i.push v

@@ -124,7 +124,7 @@ i2.withScope(q, q.scope):

for v in q.qVal: if (v.kind == minQuotation): var v2 = v - i2.unquote(v2) + i2.dequote(v2) else: i2.push v except:
M lib/min_io.nimlib/min_io.nim

@@ -119,7 +119,7 @@ return choose()

else: return choice let choice = choose() - i.unquote(q.qVal[choice-1].qVal[1]) + i.dequote(q.qVal[choice-1].qVal[1]) def.symbol("print") do (i: In): let a = i.peek
M lib/min_lang.nimlib/min_lang.nim

@@ -122,7 +122,7 @@ let vals = i.expect("'sym", "quot")

let name = vals[0] var code = vals[1] code.filename = i.filename - i.unquote(code) + i.dequote(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))

@@ -169,8 +169,8 @@ let vals = i.expect("quot", "quot")

var qscope = vals[0] let qprog = vals[1] if qscope.qVal.len > 0: - # System modules are empty quotes and don't need to be unquoted - i.unquote(qscope) + # System modules are empty quotes and don't need to be dequoted + i.dequote(qscope) i.withScope(qscope, qscope.scope): for v in qprog.qVal: i.push v

@@ -263,13 +263,13 @@ 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) + i.dequote(code) except MinRuntimeError: if not hasCatch: return let e = (MinRuntimeError)getCurrentException() i.push e.qVal.newVal(i.scope) - i.unquote(catch) + i.dequote(catch) except: if not hasCatch: return

@@ -283,20 +283,20 @@ 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) + i.dequote(catch) finally: if hasFinally: - i.unquote(final) + i.dequote(final) def.symbol("quote") do (i: In): let vals = i.expect("a") let a = vals[0] i.push @[a].newVal(i.scope) - def.symbol("unquote") do (i: In): + def.symbol("dequote") do (i: In): let vals = i.expect("quot") var q = vals[0] - i.unquote(q) + i.dequote(q) # Conditionals

@@ -306,41 +306,41 @@ var fpath = vals[0]

var tpath = vals[1] var check = vals[2] var stack = i.stack - i.unquote(check) + i.dequote(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) + i.dequote(tpath) else: - i.unquote(fpath) + i.dequote(fpath) def.symbol("when") do (i: In): let vals = i.expect("quot", "quot") var tpath = vals[0] var check = vals[1] var stack = i.stack - i.unquote(check) + i.dequote(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) + i.dequote(tpath) def.symbol("unless") do (i: In): let vals = i.expect("quot", "quot") var tpath = vals[0] var check = vals[1] var stack = i.stack - i.unquote(check) + i.dequote(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) + i.dequote(tpath) # 4 ( # ((> 3) ("Greater than 3" put!))

@@ -362,13 +362,13 @@ 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) + i.dequote(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) + i.dequote(t) break # Loops

@@ -379,7 +379,7 @@ var prog = vals[0]

var list = vals[1] for litem in list.qVal: i.push litem - i.unquote(prog) + i.dequote(prog) def.symbol("times") do (i: In): let vals = i.expect("int", "quot")

@@ -388,7 +388,7 @@ var prog = vals[1]

if t.intVal < 1: raiseInvalid("A non-zero natural number is required") for c in 1..t.intVal: - i.unquote(prog) + i.dequote(prog) def.symbol("while") do (i: In): let vals = i.expect("quot", "quot")

@@ -396,11 +396,11 @@ var d = vals[0]

var b = vals[1] for e in b.qVal: i.push e - i.unquote(b) + i.dequote(b) var check = i.pop while check.isBool and check.boolVal == true: - i.unquote(d) - i.unquote(b) + i.dequote(d) + i.dequote(b) check = i.pop discard i.pop

@@ -413,14 +413,14 @@ var r1 = vals[1]

var t = vals[2] var p = vals[3] proc linrec(i: In, p, t, r1, r2: var MinValue) = - i.unquote(p) + i.dequote(p) var check = i.pop if check.isBool and check.boolVal == true: - i.unquote(t) + i.dequote(t) else: - i.unquote(r1) + i.dequote(r1) i.linrec(p, t, r1, r2) - i.unquote(r2) + i.dequote(r2) i.linrec(p, t, r1, r2) def.symbol("version") do (i: In):

@@ -630,7 +630,7 @@ def.symbol("'") do (i: In):

i.push("quote".newSym) def.symbol("->") do (i: In): - i.push("unquote".newSym) + i.push("dequote".newSym) def.symbol("=>") do (i: In): i.push("apply".newSym)
M lib/min_seq.nimlib/min_seq.nim

@@ -114,7 +114,7 @@ let list = vals[1]

var res = newSeq[MinValue](0) for litem in list.qVal: i.push litem - i.unquote(prog) + i.dequote(prog) res.add i.pop i.push res.newVal(i.scope)

@@ -138,7 +138,7 @@ let list = vals[1]

var res = newSeq[MinValue](0) for e in list.qVal: i.push e - i.unquote(filter) + i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == true: res.add e

@@ -151,7 +151,7 @@ let list = vals[1]

var res = newSeq[MinValue](0) for e in list.qVal: i.push e - i.unquote(filter) + i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == false: res.add e

@@ -163,7 +163,7 @@ var filter = vals[0]

let list = vals[1] for e in list.qVal: i.push e - i.unquote(filter) + i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == true: i.push true.newVal

@@ -176,7 +176,7 @@ var filter = vals[0]

let list = vals[1] for e in list.qVal: i.push e - i.unquote(filter) + i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == false: i.push false.newVal

@@ -191,7 +191,7 @@ var i2 = i

var minCmp = proc(a, b: MinValue): int {.closure.}= i2.push a i2.push b - i2.unquote(cmp) + i2.dequote(cmp) let r = i2.pop if r.isBool: if r.isBool and r.boolVal == true:

@@ -221,7 +221,7 @@ var res = -1

var c = 0 for el in s.qVal: i.push el - i.unquote test + i.dequote test result = i.pop if result.isBool and result.boolVal == true: res = c

@@ -237,7 +237,7 @@ let s = vals[2]

for el in s.qVal: i.push acc i.push el - i.unquote q + i.dequote q acc = i.pop i.push acc

@@ -249,13 +249,13 @@ let s = vals[2]

if s.qVal.len == 0: raiseInvalid("Quotation must have at least one element") i.push s.qVal[0] - i.unquote map + i.dequote map var acc = i.pop for ix in 1..s.qVal.len-1: i.push s.qVal[ix] - i.unquote map + i.dequote map i.push acc - i.unquote red + i.dequote red acc = i.pop i.push acc

@@ -267,7 +267,7 @@ var tseq = newSeq[MinValue](0)

var fseq = newSeq[MinValue](0) for el in s.qVal: i.push el - i.unquote test + i.dequote test let res = i.pop if res.isBool and res.boolVal == true: tseq.add el
M lib/min_stack.nimlib/min_stack.nim

@@ -37,7 +37,7 @@ def.symbol("dip") do (i: In):

let vals = i.expect("quot", "a") var q = vals[0] let v = vals[1] - i.unquote(q) + i.dequote(q) i.push v def.symbol("nip") do (i: In):

@@ -52,7 +52,7 @@ let v = i.pop

for s in q.qVal: var s1 = s i.push v - i.unquote(s1) + i.dequote(s1) def.symbol("spread") do (i: In): var q: MinValue

@@ -64,7 +64,7 @@ var count = els.len-1

for s in q.qVal: var s1 = s i.push els[count] - i.unquote(s1) + i.dequote(s1) count.dec def.symbol("keep") do (i: In):

@@ -72,7 +72,7 @@ let vals = i.expect("quot", "a")

var q = vals[0] let v = vals[1] i.push v - i.unquote(q) + i.dequote(q) i.push v def.symbol("swap") do (i: In):

@@ -134,7 +134,7 @@ let vals = i.expect("quot", "quot")

var a = vals[0] let b = vals[1] i.push b - i.unquote(a) + i.dequote(a) i.push b def.finalize("stack")
M min.vimmin.vim

@@ -11,7 +11,7 @@

setl iskeyword=@,36-39,+,-,/,*,.,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define defined? delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json to-timestamp try unquote uppercase unzip values version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define defined? delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json to-timestamp try dequote uppercase unzip values version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
M site/contents/_includes/_reference-lang.mdsite/contents/_includes/_reference-lang.md

@@ -28,7 +28,7 @@ {#sig||>||save-symbol#}

{#sig||<||load-symbol#} -{#alias||->||unquote#} +{#alias||->||dequote#} {#alias||=>||apply#}

@@ -270,7 +270,7 @@

{#op||unless||{{q1}} {{q2}}||{{a0p}}|| If {{1}} evaluates to {{f}} then evaluates {{2}}.#} -{#op||unquote||{{q}}||{{a0p}}|| +{#op||dequote||{{q}}||{{a0p}}|| Pushes the contents of quotation {{q}} on the stack. #} {#op||unseal||{{sl}}||{{null}}||
M site/contents/_includes/_reference-stack.mdsite/contents/_includes/_reference-stack.md

@@ -16,7 +16,7 @@ {#op||cons||{{a1}} ({{a0p}})||({{a1}} {{a0p}})||

Prepends {{a1}} to the quotation on top of the stack.#} {#op||dip||{{a1}} ({{a2}})||{{a0p}} {{a1}}|| -Removes the first and second element from the stack, unquotes the first element, and restores the second element.#} +Removes the first and second element from the stack, dequotes the first element, and restores the second element.#} {#op||dup||{{a1}}||{{a1}} {{a1}}|| Duplicates the first element on the stack.#}

@@ -58,7 +58,7 @@ {#op||set-stack||{{q}}||{{a0p}}||

Substitute the existing stack with the contents of {{q}}.#} {#op||sip||{{a1}} ({{a2}})||{{a0p}} {{a1}}|| -Saves the {{a1}}, unquotes {{a2}}, and restores {{a1}}.#} +Saves the {{a1}}, dequotes {{a2}}, and restores {{a1}}.#} {#op||spread||{{a0p}} ({{q}}{{0p}})||{{a0p}}|| > Applies each quotation contained in the first element to each subsequent corresponding element.
M site/rules.minsite/rules.min

@@ -43,7 +43,7 @@

( =meta meta /path :path - " - Preprocessing $1" (path) => % notice + " - Processing stylesheet: $1" (path) => % notice meta input-fread :contents contents preprocess-css @contents meta contents %contents #meta
M tests/lang.mintests/lang.min

@@ -63,7 +63,7 @@

(2 quote (2) ==) assert - ((2 3) unquote get-stack (2 3) ==) assert + ((2 3) dequote get-stack (2 3) ==) assert (3 (succ) 3 times 6 ==) assert

@@ -116,7 +116,7 @@ ((a b +) (4 :a 5 :b) with 9 ==) assert

("{\"a\": 1, \"b\": 2.3}" from-json ((a 1) (b 2.3)) ==) assert - ((1 2 3 "aaa" 'q q true) to-json "\n" "" replace " " "" replace "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]" ==) assert + ((1 2 3 "aaa" 'q q true) to-json "\r\n" "" replace "\n" "" replace " " "" replace "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]" ==) assert ((1 2 3 "aaa" 'q q true) to-json from-json (1 2 3 "aaa" 'q q true) ==) assert

@@ -144,7 +144,7 @@ (sys module-sigils ("!" "$" "&") ==) assert

(opts () ==) assert - (args ("tests/all.min") ==) assert + (args first "all.min$" match) assert (3 string "3" ==) assert