all repos — min @ 854dc391e4724d549431001635e1523d8e42a672

A small but practical concatenative programming language.

refactor(validation) Added reqStringOrQuotation.
h3rald h3rald@h3rald.com
Sat, 04 Jun 2016 22:43:33 +0200
commit

854dc391e4724d549431001635e1523d8e42a672

parent

858875a85585b3454faad998cbd19119a8ebf011

2 files changed, 11 insertions(+), 12 deletions(-)

jump to
M core/utils.nimcore/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.nimlib/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