refactor(validation) Added reqStringOrQuotation.
h3rald h3rald@h3rald.com
Sat, 04 Jun 2016 22:43:33 +0200
2 files changed,
11 insertions(+),
12 deletions(-)
M
core/utils.nim
→
core/utils.nim
@@ -96,6 +96,11 @@ a = i.pop
if not a.isQuotation: raise MinInvalidError(msg: "A quotation is required on the stack") +proc reqStringOrQuotation*(i: var MinInterpreter, a: var MinValue) = + a = i.pop + if not a.isQuotation or not a.isString: + raise MinInvalidError(msg: "A quotation or a string is required on the stack") + proc reqTwoQuotations*(i: var MinInterpreter, a, b: var MinValue) = a = i.pop b = i.pop
M
lib/lang.nim
→
lib/lang.nim
@@ -260,24 +260,20 @@ i.error(errIncorrect, "Two quotations or two strings are required on the stack")
return .symbol("first") do (i: In): - var q = i.pop + var q: MinValue + i.reqStringOrQuotation q if q.isQuotation: i.push q.qVal[0] elif q.isString: i.push newVal($q.strVal[0]) - else: - i.error(errIncorrect, "A quotation or a string is required on the stack") - return .symbol("rest") do (i: In): - var q = i.pop + var q: MinValue + i.reqStringOrQuotation q if q.isQuotation: i.push newVal(q.qVal[1..q.qVal.len-1]) elif q.isString: i.push newVal(q.strVal[1..q.strVal.len-1]) - else: - i.error(errIncorrect, "A quotation or a string is required on the stack") - return .symbol("quote") do (i: In): let a = i.pop@@ -312,14 +308,12 @@ i.error errIncorrect, "An integer and a quotation are required on the stack"
return .symbol("size") do (i: In): - let q = i.pop + var q: MinValue + i.reqStringOrQuotation q if q.isQuotation: i.push q.qVal.len.newVal elif q.isString: i.push q.strVal.len.newVal - else: - i.error(errIncorrect, "A quotation or a string is required on the stack") - return .symbol("contains") do (i: In): let v = i.pop