all repos — min @ acc808b4cc0a022d8468d42490cd76eb59b033cb

A small but practical concatenative programming language.

Made == and != more permissive; added # and = symbols.
h3rald h3rald@h3rald.com
Sat, 18 Nov 2017 13:46:59 +0100
commit

acc808b4cc0a022d8468d42490cd76eb59b033cb

parent

68afd109380f16ab785c252341a8a5420bd82423

M core/parser.nimcore/parser.nim

@@ -553,7 +553,45 @@

proc print*(a: MinValue) {.extern:"min_exported_symbol_$1".}= stdout.write($$a) +# Predicates + +proc isSymbol*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minSymbol + +proc isQuotation*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minQuotation + +proc isString*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minString + +proc isFloat*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minFloat + +proc isInt*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minInt + +proc isNumber*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.kind == minInt or s.kind == minFloat + +proc isBool*(s: MinValue): bool = + return s.kind == minBool + +proc isStringLike*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= + return s.isSymbol or s.isString or (s.isQuotation and s.qVal.len == 1 and s.qVal[0].isSymbol) + +proc isDictionary*(q: MinValue): bool {.extern:"min_exported_symbol_$1".}= + if not q.isQuotation: + return false + if q.qVal.len == 0: + return true + for val in q.qVal: + if not val.isQuotation or val.qVal.len != 2 or not val.qVal[0].isString: + return false + return true + proc `==`*(a: MinValue, b: MinValue): bool {.extern:"min_exported_symbol_eqeq".}= + if not (a.kind == b.kind or (a.isNumber and b.isNumber)): + return false if a.kind == minSymbol and b.kind == minSymbol: return a.symVal == b.symVal elif a.kind == minInt and b.kind == minInt:
M core/utils.nimcore/utils.nim

@@ -250,9 +250,3 @@ a = i.pop

b = i.pop if not (a.isQuotation and b.isQuotation or a.isString and b.isString): raiseInvalid("Two quotations or two strings are required on the stack") - -proc reqTwoSimilarTypesNonSymbol*(i: var MinInterpreter, a, b: var MinValue) {.extern:"min_exported_symbol_$1".}= - a = i.pop - b = i.pop - if not ((a.kind == b.kind or (a.isNumber and b.isNumber)) and not a.isSymbol): - raiseInvalid("Two non-symbol values of similar type are required on the stack")
M core/value.nimcore/value.nim

@@ -19,42 +19,6 @@ return "sym"

of minBool: return "bool" -# Predicates - -proc isSymbol*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minSymbol - -proc isQuotation*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minQuotation - -proc isString*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minString - -proc isFloat*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minFloat - -proc isInt*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minInt - -proc isNumber*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.kind == minInt or s.kind == minFloat - -proc isBool*(s: MinValue): bool = - return s.kind == minBool - -proc isStringLike*(s: MinValue): bool {.extern:"min_exported_symbol_$1".}= - return s.isSymbol or s.isString or (s.isQuotation and s.qVal.len == 1 and s.qVal[0].isSymbol) - -proc isDictionary*(q: MinValue): bool {.extern:"min_exported_symbol_$1".}= - if not q.isQuotation: - return false - if q.qVal.len == 0: - return true - for val in q.qVal: - if not val.isQuotation or val.qVal.len != 2 or not val.qVal[0].isString: - return false - return true - # Constructors proc newVal*(s: string): MinValue {.extern:"min_exported_symbol_$1".}=
M lib/min_lang.nimlib/min_lang.nim

@@ -657,6 +657,13 @@ i.push("quote-define".newSym)

# Shorthand symbol aliases + + def.symbol("#") do (i: In): + i.push("quote-bind".newSym) + + def.symbol("=") do (i: In): + i.push("quote-define".newSym) + def.symbol(":") do (i: In): i.push("define".newSym)
M lib/min_logic.nimlib/min_logic.nim

@@ -97,16 +97,20 @@ i.push newVal(n1.strVal >= n2.strVal)

def.symbol("==") do (i: In): var n1, n2: MinValue - i.reqTwoSimilarTypesNonSymbol n2, n1 - if n1.kind == minFloat or n2.kind == minFloat: + let vals = i.expect("a", "a") + n1 = vals[0] + n2 = vals[1] + if (n1.kind == minFloat or n2.kind == minFloat) and n1.isNumber and n2.isNumber: i.push newVal(floatCompare(n1, n2)) else: i.push newVal(n1 == n2) def.symbol("!=") do (i: In): var n1, n2: MinValue - i.reqTwoSimilarTypesNonSymbol n2, n1 - if n1.kind == minFloat or n2.kind == minFloat: + let vals = i.expect("a", "a") + n1 = vals[0] + n2 = vals[1] + if (n1.kind == minFloat or n2.kind == minFloat) and n1.isNumber and n2.isNumber: i.push newVal(not floatCompare(n1, n2)) i.push newVal(not (n1 == n2))
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 ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ -inf ROOT 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 column-print concat confirm cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dget dhas? dkeys dictionary? dip dir? dirname div dpick dprint dprint! 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 gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec 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 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 r2d random raise read reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir round run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice sort source split spread sqrt stack startup 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 dequote uppercase unzip version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : = # < <= == => =~ > >= @ -inf ROOT 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 column-print concat confirm cons cos cosh cp cpu crypto ctime d2r datetime ddel debug decode define defined? delete dget dhas? dkeys dictionary? dip dir? dirname div dpick dprint dprint! 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 gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec 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 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 r2d random raise read reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir round run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice sort source split spread sqrt stack startup 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 dequote uppercase unzip version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!?$%&$=<>#^*#+/]; contained syntax match minSpecialSymbols ;[:@'~!?$%&$=<>#^*#+/]; contained
M site/contents/_includes/_reference-lang.mdsite/contents/_includes/_reference-lang.md

@@ -30,7 +30,11 @@ {#alias||=>||apply#}

{#sig||#||quote-bind#} +{#alias||#||quote-bind#} + {#sig||=||quote-define#} + +{#alias||=||quote-define#} {#op||apply||{{q}}||({{a0p}})|| Returns a new quotation {{q}} obtained by evaluating each element of {{q}} in a separate stack.#}
M tests/logic.mintests/logic.min

@@ -137,5 +137,9 @@ (-7 0 / -inf ==) assert

(0 0 / nan ==) assert (10 3 / 3.33333 ==) assert + (3 "a" == not) assert + (1 () != true) assert + (3.3 'test == not) assert + report clear-stack