Implemented #144.
h3rald h3rald@h3rald.com
Sat, 06 Feb 2021 21:03:22 +0000
7 files changed,
23 insertions(+),
17 deletions(-)
M
minpkg/core/utils.nim
→
minpkg/core/utils.nim
@@ -198,6 +198,12 @@ if andr:
result = true break +proc validateValueType*(i: var MinInterpreter, element: string, value: MinValue): bool {.gcsafe.} = + var g: CritBitTree[string] + var s = newSeq[string](0) + var c = 0 + return i.validateValueType(element, value, g, s, c) + proc basicValidate*(i: In, value: MinValue, t: string): bool = case t: of "bool":@@ -235,10 +241,7 @@ return false
elif i.scope.hasSymbol(ta): # Custom type alias let element = i.scope.getSymbol(ta).val.getString - var fakeGenerics: CritBitTree[string] - var vTypes = newSeq[string](0) - var c = 0 - return i.validateValueType(element, value, fakeGenerics, vTypes, c) + return i.validateValueType(element, value) elif i.scope.hasSymbol(tc): # Custom type class var i2 = i.copy(i.filename)
M
minpkg/lib/min_lang.nim
→
minpkg/lib/min_lang.nim
@@ -277,7 +277,7 @@ iv = @[iv].newVal
i.scope.symbols[inVars[k]] = MinOperator(kind: minValOp, sealed: false, val: iv, quotation: inVals[k].isQuotation) # Inject variables for mapped outputs for k in 0..outVars.len-1: - i.scope.symbols[outVars[k]] = MinOperator(kind: minValOp, sealed: false, val: newNull(), quotation: false) + i.scope.symbols[outVars[k]] = MinOperator(kind: minValOp, sealed: false, val: @[newNull()].newVal, quotation: true) # Actually execute the body of the operator var endSnapshot: seq[MinValue] var snapShot: seq[MinValue]
M
minpkg/lib/min_logic.nim
→
minpkg/lib/min_logic.nim
@@ -227,10 +227,10 @@ 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 (vals[1].typename == vals[0].getString).newVal + let t = vals[0].getString + let v = vals[1] + let res = i.validateValueType(t, v) + i.push res.newVal def.symbol("&&") do (i: In): i.pushSym("expect-all")
M
next-release.md
→
next-release.md
@@ -0,0 +1,3 @@
+### New Features + +* The symbol **type?** is now able to check if a value satisfies a type expression, not only a simple type (#144). Note however that it is now necessary to prepend dictionary types with `dict:` (as in type expressions).
M
site/contents/reference-logic.md
→
site/contents/reference-logic.md
@@ -83,7 +83,7 @@ {#op||stringlike?||{{any}}||{{b}}||
Returns {{t}} if {{any}} is a string or a quoted symbol, {{f}} otherwise. #} {#op||type?||{{any}} {{sl}}||{{b}}|| -Returns {{t}} if the data type of {{any}} is the specified type {{sl}}, {{f}} otherwise. #} +Returns {{t}} if the data type of {{any}} satisfies the specified type expression {{sl}}, {{f}} otherwise. #} {#op||xor||{{b1}} {{b2}}||{{b3}}|| Returns {{t}} if {{b1}} and {{b2}} are different, {{f}} otherwise.#}
M
tests/lang.min
→
tests/lang.min
@@ -291,7 +291,7 @@ in %test
@out ) ) :: - ("aaa" test-c 'test-c type?) *test/assert + ("aaa" test-c 'dict:test-c type?) *test/assert ( symbol add
M
tests/logic.min
→
tests/logic.min
@@ -136,13 +136,13 @@ ("a" stringlike?) *test/assert
(1 stringlike? false ==) *test/assert ('test stringlike?) *test/assert - ({} 'module type? false ==) *test/assert - ((1 2 3) 'module type? false ==) *test/assert - (4 'module type? false ==) *test/assert - (logic 'module type?) *test/assert + ({} 'dict:module type? false ==) *test/assert + ((1 2 3) 'dict:module type? false ==) *test/assert + (4 'dict:module type? false ==) *test/assert + (logic 'dict:module type?) *test/assert (1 "int" type?) *test/assert ("test" "str" type?) *test/assert - (ROOT "module" type?) *test/assert + (ROOT "dict:module" type?) *test/assert (7 0 / inf ==) *test/assert (-7 0 / -inf ==) *test/assert@@ -173,4 +173,4 @@ ) ||
) *test/assert *test/report - clear-stack+ clear-stack