all repos — min @ 4795acea41ef66159486949d378d30ea5d62a147

A small but practical concatenative programming language.

Other dict-related fixes; added type? symbol.
h3rald h3rald@h3rald.com
Sun, 03 Jun 2018 11:43:50 +0200
commit

4795acea41ef66159486949d378d30ea5d62a147

parent

2a3c96ec4e6c42a9a54c82a17fb5da9b23ec3414

M core/parser.nimcore/parser.nim

@@ -76,8 +76,8 @@ of minFloat: floatVal*: BiggestFloat

of minQuotation, minDictionary: qVal*: seq[MinValue] scope*: ref MinScope - obj*: pointer - objType*: string + obj*: pointer # Used only for dicts + objType*: string # Used only for dicts of minString: strVal*: string of minSymbol: symVal*: string of minBool: boolVal*: bool
M core/utils.nimcore/utils.nim

@@ -186,6 +186,37 @@ return res.newVal(i.scope)

# Validators +proc validate(value: MinValue, t: string): bool {.extern:"min_exported_symbol_$1".}= + case t: + of "bool": + return value.isBool + of "int": + return value.isInt + of "num": + return value.isNumber + of "quot": + return value.isQuotation + of "dict": + return value.isDictionary + of "'sym": + return value.isStringLike + of "sym": + return value.isSymbol + of "float": + return value.isFloat + of "string": + return value.isString + of "a": + return true + else: + var split = t.split(":") + # Typed dictionaries + if split[0] == "dict": + if value.isTypedDictionary(split[1]): + return true + return false + + proc expect*(i: var MinInterpreter, elements: varargs[string]): seq[MinValue] {.extern:"min_exported_symbol_$1".}= let stack = elements.reverse.join(" ") let sym = i.currSym.getString

@@ -201,43 +232,19 @@ result &= "- got: " & invalid & " " & other & sym

for element in elements: let value = i.pop result.add value - case element: - of "bool": - if not value.isBool: - raiseInvalid(message(value.typeName)) - of "int": - if not value.isInt: - raiseInvalid(message(value.typeName)) - of "num": - if not value.isNumber: - raiseInvalid(message(value.typeName)) - of "quot": - if not value.isQuotation: - raiseInvalid(message(value.typeName)) - of "dict": - if not value.isDictionary: - raiseInvalid(message(value.typeName)) - of "'sym": - if not value.isStringLike: - raiseInvalid(message(value.typeName)) - of "sym": - if not value.isSymbol: - raiseInvalid(message(value.typeName)) - of "float": - if not value.isFloat: - raiseInvalid(message(value.typeName)) - of "string": - if not value.isString: - raiseInvalid(message(value.typeName)) - of "a": - discard # any type + var split = element.split("|") + if split.len > 1: + var res = false + for t in split: + if validate(value, t): + res = true + break + if res: + valid.add element else: - var split = element.split(":") - if split[0] == "dict": - if not value.isTypedDictionary(split[1]): - raiseInvalid(message(value.typeName)) - else: - raiseInvalid("Invalid type description: " & element) + raiseInvalid(message(value.typeName)) + elif not validate(value, element): + raiseInvalid(message(value.typeName)) valid.add element proc reqQuotationOfQuotations*(i: var MinInterpreter, a: var MinValue) {.extern:"min_exported_symbol_$1".}=
M core/value.nimcore/value.nim

@@ -10,15 +10,13 @@ of minInt:

return "int" of minFloat: return "float" - of minQuotation: #TODO review + of minDictionary: if v.isTypedDictionary: return "dict:" & v.objType - elif v.isDictionary: + else: return "dict" - else: - return "quot" - of minDictionary: - return "dict" + of minQuotation: + return "quot" of minString: return "string" of minSymbol:
M lib/min_lang.nimlib/min_lang.nim

@@ -51,16 +51,16 @@ q.add s.newVal

scope = scope.parent i.push q.newVal(i.scope) - def.symbol("module-symbols") do (i: In): - let vals = i.expect("dict:module") + def.symbol("scope-symbols") do (i: In): + let vals = i.expect("quot|dict") let m = vals[0] 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): - let vals = i.expect("dict:module") + def.symbol("scope-sigils") do (i: In): + let vals = i.expect("quot|dict") let m = vals[0] var q = newSeq[MinValue](0) for s in m.scope.sigils.keys:

@@ -134,9 +134,10 @@ def.symbol("module") do (i: In):

let vals = i.expect("'sym", "dict") let name = vals[0] var code = vals[1] + code.objType = "module" code.filename = i.filename info("[module] $1 ($2 symbols)" % [name.getString, $code.scope.symbols.len]) - i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal(i.scope), quotation: true) + i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: code) def.symbol("import") do (i: In): var vals = i.expect("'sym")

@@ -145,7 +146,7 @@ var name: string

name = rawName.getString var op = i.scope.getSymbol(name) i.apply(op) - vals = i.expect("dict") + vals = i.expect("dict:module") let mdl = vals[0] 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:

@@ -196,15 +197,12 @@ def.symbol("with") do (i: In):

let vals = i.expect("dict", "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 dequoted - # i.dequote(qscope) i.withScope(qscope): for v in qprog.qVal: i.push v def.symbol("publish") do (i: In): - let vals = i.expect("dict:module", "'sym") + let vals = i.expect("dict", "'sym") let qscope = vals[0] let str = vals[1] let sym = str.getString
M lib/min_logic.nimlib/min_logic.nim

@@ -215,5 +215,12 @@ if i.pop.isDictionary:

i.push true.newVal else: i.push false.newVal - + + def.symbol("type?") do (i: In): + let vals = i.expect("'sym", "a") + if vals[1].isTypedDictionary(vals[0].getString): + i.push true.newVal + else: + i.push false.newVal + def.finalize("logic")
M min.vimmin.vim

@@ -1,8 +1,8 @@

" Vim syntax file " Language: min " Maintainer: Fabio Cevasco -" Last Change: 25 March 2017 -" Version: 0.5.0 +" Last Change: 03 June 2018 +" Version: 0.17.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 ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -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 ddup 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 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 ddup 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 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 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? scope-symbols scope-sigils 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 tests/lang.mintests/lang.min

@@ -138,9 +138,11 @@ ((3 >) (true))

) case ) assert - (time module-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp" "to-timestamp") ==) assert + (time scope-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp" "to-timestamp") ==) assert - (sys module-sigils ("!" "$" "&") ==) assert + (sys scope-sigils ("!" "$" "&") ==) assert + + ({3 :a 5 :b} ("a" "b") ==) assert (opts {} ==) assert
M tests/logic.mintests/logic.min

@@ -132,6 +132,11 @@ (true quotation? false ==) assert

(false quotation? false ==) assert (("a" 2 c) quotation?) assert + ({} 'module type? false ==) assert + ((1 2 3) 'module type? false ==) assert + (4 'module type? false ==) assert + (logic 'module type?) assert + (7 0 / inf ==) assert (-7 0 / -inf ==) assert (0 0 / nan ==) assert