all repos — min @ 8c09fa0f8202f9080158bb3a5bfa5e7597a5d2f1

A small but practical concatenative programming language.

Fixed any? and all?
* Closes #34.
h3rald h3rald@h3rald.com
Sun, 08 Jul 2018 12:39:14 +0200
commit

8c09fa0f8202f9080158bb3a5bfa5e7597a5d2f1

parent

62767eddb2e00b56af0ff48855a5b944cdd90927

5 files changed, 29 insertions(+), 12 deletions(-)

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

@@ -68,7 +68,7 @@ var stack:MinStack = newSeq[MinValue](0)

var trace:MinStack = newSeq[MinValue](0) var stackcopy:MinStack = newSeq[MinValue](0) var pr:MinParser - var scope = new MinScope + var scope = newScopeRef(nil) var i:MinInterpreter = MinInterpreter( filename: filename, pwd: path,
M core/parser.nimcore/parser.nim

@@ -85,10 +85,17 @@ qVal*: seq[MinValue]

of minString: strVal*: string of minSymbol: symVal*: string of minBool: boolVal*: bool + MinScopeKind* = enum + minNativeScope, + minLangScope MinScope* = object + parent*: ref MinScope symbols*: CritBitTree[MinOperator] - sigils*: CritBitTree[MinOperator] - parent*: ref MinScope + case kind: MinScopeKind + of minNativeScope: + sigils*: CritBitTree[MinOperator] + of minLangScope: + discard MinOperatorProc* = proc (i: In) {.closure.} MinOperatorKind* = enum minProcOp

@@ -183,12 +190,12 @@ "true",

"false" ] -proc newScope*(parent: ref MinScope): MinScope {.extern:"min_exported_symbol_$1".}= - result = MinScope(parent: parent) +proc newScope*(parent: ref MinScope, kind = minLangScope): MinScope {.extern:"min_exported_symbol_$1".}= + result = MinScope(parent: parent, kind: kind) -proc newScopeRef*(parent: ref MinScope): ref MinScope {.extern:"min_exported_symbol_$1".}= +proc newScopeRef*(parent: ref MinScope, kind = minLangScope): ref MinScope {.extern:"min_exported_symbol_$1".}= new(result) - result[] = newScope(parent) + result[] = newScope(parent, kind) proc open*(my: var MinParser, input: Stream, filename: string) {.extern:"min_exported_symbol_$1".}= lexbase.open(my, input)
M core/utils.nimcore/utils.nim

@@ -19,7 +19,7 @@

# Library methods proc define*(i: In): ref MinScope {.extern:"min_exported_symbol_$1".}= - var scope = new MinScope + var scope = newScopeRef(i.scope, minNativeScope) scope.parent = i.scope return scope
M lib/min_seq.nimlib/min_seq.nim

@@ -170,27 +170,29 @@ def.symbol("any?") do (i: In):

let vals = i.expect("quot", "quot") var filter = vals[0] let list = vals[1] + var res = false.newVal for e in list.qVal: i.push e i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == true: - i.push true.newVal + res = true.newVal return - i.push false.newVal + i.push res def.symbol("all?") do (i: In): let vals = i.expect("quot", "quot") var filter = vals[0] let list = vals[1] + var res = true.newVal for e in list.qVal: i.push e i.dequote(filter) var check = i.pop if check.isBool and check.boolVal == false: - i.push false.newVal + res = false.newVal break - i.push true.newVal + i.push res def.symbol("sort") do (i: In): let vals = i.expect("quot", "quot")
M tests/seq.mintests/seq.min

@@ -65,5 +65,13 @@ ((1 2 3 (4 5 6) 7 (8 9)) flatten (1 2 3 4 5 6 7 8 9) ==) assert

((2 3 + 4 *) quote-map ('+ ==) find 2 ==) assert + ((2 4 6 8) 'even? all?) assert + + ((2 4 3 6 8) 'even? all? not) assert + + ((1 2 3 4) 'odd? any?) assert + + ((2 4 6 8) 'odd? any? not) assert + report clear-stack