Implemented operations on native dicts & created new dict module.
h3rald h3rald@h3rald.com
Sat, 26 May 2018 18:27:56 +0200
6 files changed,
76 insertions(+),
64 deletions(-)
M
core/value.nim
→
core/value.nim
@@ -49,6 +49,9 @@
proc newVal*(s: bool): MinValue {.extern:"min_exported_symbol_$1_6".}= return MinValue(kind: minBool, boolVal: s) +proc newDict*(parentScope: ref MinScope): MinValue {.extern:"min_exported_symbol_$1".}= + return MinValue(kind: minDictionary, qVal: newSeq[MinValue](0), scope: newScopeRef(parentScope)) + proc newSym*(s: string): MinValue {.extern:"min_exported_symbol_$1".}= return MinValue(kind: minSymbol, symVal: s)
A
lib/min_dict.nim
@@ -0,0 +1,69 @@
+import + critbits +import + ../core/parser, + ../core/value, + ../core/interpreter, + ../core/utils + +# Operations on dictionaries +proc dict_module*(i: In)= + + let def = i.define() + + def.symbol("dhas?") do (i: In): + let vals = i.expect("'sym", "dict") + let k = vals[0] + let d = vals[1] + i.push d.dhas(k).newVal + + def.symbol("dget") do (i: In): + let vals = i.expect("'sym", "dict") + let k = vals[0] + let d = vals[1] + var val = d.dget(k) + i.dequote val # Dictionary values are always quoted + + def.symbol("dset") do (i: In): + let vals = i.expect("'sym", "a", "dict") + let k = vals[0] + let m = vals[1] + let d = vals[2] + i.push i.dset(d, k, m) + + def.symbol("ddel") do (i: In): + let vals = i.expect("'sym", "dict") + let k = vals[0] + var d = vals[1] + i.push i.ddel(d, k) + + def.symbol("dkeys") do (i: In): + let vals = i.expect("dict") + let d = vals[0] + i.push i.keys(d) + + def.symbol("dvalues") do (i: In): + let vals = i.expect("dict") + let d = vals[0] + i.push i.values(d) + + def.symbol("dpick") do (i: In): + let vals = i.expect("quot", "dict") + var q = vals[0] + var d = vals[1] + var res = newDict(i.scope) + for k in q.qVal: + if d.dhas(k): + i.dset(res, k, d.dget(k)) + i.push res + + def.sigil("?") do (i: In): + i.push("dhas?".newSym) + + def.sigil("/") do (i: In): + i.push("dget".newSym) + + def.sigil("%") do (i: In): + i.push("dset".newSym) + + def.finalize("dict")
M
lib/min_seq.nim
→
lib/min_seq.nim
@@ -1,5 +1,4 @@
import - critbits, tables, sequtils, algorithm@@ -339,67 +338,5 @@ res.add el2
else: res.add el i.push res.newVal(i.scope) - - # Operations on dictionaries - - def.symbol("dhas?") do (i: In): - let vals = i.expect("'sym", "dict") - let k = vals[0] - let d = vals[1] - i.push d.dhas(k).newVal - - def.symbol("dget") do (i: In): - let vals = i.expect("'sym", "dict") - let k = vals[0] - let d = vals[1] - var val = d.dget(k) - i.dequote val # Dictionary values are always quoted - - def.symbol("dset") do (i: In): - let vals = i.expect("'sym", "a", "dict") - let k = vals[0] - let m = vals[1] - let d = vals[2] - i.push i.dset(d, k, m) - - def.symbol("ddel") do (i: In): - let vals = i.expect("'sym", "dict") - let k = vals[0] - var d = vals[1] - i.push i.ddel(d, k) - - def.symbol("dkeys") do (i: In): - let vals = i.expect("dict") - let d = vals[0] - i.push i.keys(d) - - def.symbol("dvalues") do (i: In): - let vals = i.expect("dict") - let d = vals[0] - i.push i.values(d) - - def.symbol("dsort") do (i: In): - let vals = i.expect("dict") - var d = vals[0] - i.push d.qVal.sortedByIt(it.qVal[0].getString).newVal(i.scope) - - def.symbol("dpick") do (i: In): - let vals = i.expect("quot", "dict") - var q = vals[0] - var d = vals[1] - var res = newSeq[MinValue](0) - for v in d.qVal: - if q.qVal.contains v.qVal[0]: - res.add v - i.push res.newVal(i.scope) - - def.sigil("?") do (i: In): - i.push("dhas?".newSym) - - def.sigil("/") do (i: In): - i.push("dget".newSym) - - def.sigil("%") do (i: In): - i.push("dset".newSym) def.finalize("seq")
M
min.vim
→
min.vim
@@ -11,7 +11,7 @@
setl iskeyword=@,36-39,+,-,*,.,/,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dictionary? dip dir? dirname div download dpick dprint dprint! drop dset dsort dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module module-symbols module-sigils mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random randomize raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? seal search send seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc unless substr unseal unzip uppercase version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dict dictionary? dip dir? dirname div download dpick dprint dprint! drop dset dsort dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module module-symbols module-sigils mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random randomize raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? seal search send seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc unless substr unseal unzip uppercase version warn when which while with xor zip syntax match minDefaultSigil ;\<[/:@'~!?$%&$=<>#^*#+]; contained syntax match minQuote ;\<['];
M
prelude.min
→
prelude.min
@@ -6,6 +6,7 @@ 'num import
'sys import 'stack import 'seq import +'dict import 'time import 'fs import 'lite? (