all repos — min @ bb5621bf2575abb079f6ba73081a67928de528bc

A small but practical concatenative programming language.

feat(delete, contains) Added delete and contains symbols.
h3rald h3rald@h3rald.com
Sun, 29 May 2016 16:47:27 +0200
commit

bb5621bf2575abb079f6ba73081a67928de528bc

parent

5dba95de551d5ababe228aee740db425bb3aa5c7

3 files changed, 27 insertions(+), 3 deletions(-)

jump to
M core/interpreter.nimcore/interpreter.nim

@@ -32,6 +32,13 @@ return scope.symbols[key]

elif not scope.parent.isNil: return scope.parent.getSymbol(key) +proc delSymbol*(scope: ref MinScope, key: string) = + #echo key, " - ", scope.symbols.hasKey(key) + if scope.symbols.hasKey(key): + scope.symbols.excl(key) + elif not scope.parent.isNil: + scope.parent.delSymbol(key) + proc setSymbol*(scope: ref MinScope, key: string, value: MinOperator): bool {.discardable.}= result = false # check if a symbol already exists in parent scope
M lib/lang.nimlib/lang.nim

@@ -21,8 +21,11 @@ i.push q.newVal

.symbol("sigils") do (i: In): var q = newSeq[MinValue](0) - for s in i.scope.parent.sigils.keys: - q.add s.newVal + var scope = i.scope.parent + while not scope.isNil: + for s in scope.sigils.keys: + q.add s.newVal + scope = scope.parent i.push q.newVal .symbol("debug?") do (i: In):

@@ -78,6 +81,12 @@ #echo "BIND '$1' FN: $2" % [symbol, i.filename]

i.push q1.qVal #i.filename = fn #i.evaluating = false + + .symbol("delete") do (i: In): + var sym = i.pop + if not sym.isStringLike: + i.error errIncorrect, "A string or a symbol are required on the stack" + i.scope.delSymbol(sym.getString) .symbol("module") do (i: In): let name = i.pop

@@ -290,6 +299,14 @@ if not q.isQuotation:

i.error errNoQuotation return i.push q.qVal.len.newVal + + .symbol("contains") do (i: In): + let v = i.pop + let q = i.pop + if not q.isQuotation: + i.error errNoQuotation + return + i.push q.qVal.contains(v).newVal .symbol("map") do (i: In): let prog = i.pop
M tests/test.mintests/test.min

@@ -6,7 +6,7 @@

;; describe ( .name - "Testing: " print! name put! + "Testing: [" print! name print! "]" put! padding () ) :describe