all repos — min @ 8bddc431d3ce4113641ff4bb0d32de6086e468f4

A small but practical concatenative programming language.

refactor(scope) Moved SIGILS and SYMBOLS under ROOT scope.
h3rald h3rald@h3rald.com
Fri, 20 May 2016 21:50:10 +0200
commit

8bddc431d3ce4113641ff4bb0d32de6086e468f4

parent

b6e64f361b0774eee95720df2ab98bd14125d051

5 files changed, 20 insertions(+), 22 deletions(-)

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

@@ -13,8 +13,7 @@ "Two numbers are required on the stack",

"Division by zero" ] -var SYMBOLS*: CritBitTree[MinOperator] -var SIGILS*: CritBitTree[MinOperator] +var ROOT*: MinScope proc newMinInterpreter*(debugging = false): MinInterpreter = var s:MinStack = newSeq[MinValue](0)

@@ -54,17 +53,17 @@ if not i.evaluating:

i.currSym = val let symbol = val.symVal let sigil = "" & symbol[0] - if SYMBOLS.hasKey(val.symVal): + if ROOT.symbols.hasKey(val.symVal): try: - SYMBOLS[val.symVal](i) + ROOT.symbols[val.symVal](i) except: i.error(errSystem, getCurrentExceptionMsg()) else: - if SIGILS.hasKey(sigil) and symbol.len > 1: + if ROOT.sigils.hasKey(sigil) and symbol.len > 1: let sym = symbol[1..symbol.len-1] try: i.stack.add(MinValue(kind: minString, strVal: sym)) - SIGILS[sigil](i) + ROOT.sigils[sigil](i) except: i.error(errSystem, getCurrentExceptionMsg()) else:

@@ -120,7 +119,7 @@ finally:

i.filename = fn proc apply*(i: var MinInterpreter, symbol: string) = - SYMBOLS[symbol](i) + ROOT.symbols[symbol](i) proc copystack*(i: var MinInterpreter): MinStack = var s = newSeq[MinValue](0)
M core/types.nimcore/types.nim

@@ -19,12 +19,12 @@ minQuotation,

minString, minSymbol, minBool - MinScope = object - locals: CritBitTree[MinValue] - symbols: CritBitTree[MinValue] - sigils: CritBitTree[MinValue] - parent: ref MinScope - stack: MinStack + MinScope* = object + locals*: CritBitTree[MinValue] + symbols*: CritBitTree[MinOperator] + sigils*: CritBitTree[MinOperator] + parent*: ref MinScope + stack*: MinStack MinValue* = object line*: int column*: int
M core/utils.nimcore/utils.nim

@@ -3,12 +3,11 @@ import types, parser, interpreter

template minsym*(name: string, i: expr, body: stmt): stmt {.immediate.} = - bind SYMBOLS - SYMBOLS[name] = proc (i: var MinInterpreter) {.closure.} = + ROOT.symbols[name] = proc (i: var MinInterpreter) {.closure.} = body template minsigil*(name: char, i: expr, body: stmt): stmt {.immediate.} = - SIGILS[name] = proc (i: var MinInterpreter) = + ROOT.sigils[name] = proc (i: var MinInterpreter) = body proc isSymbol*(s: MinValue): bool =
M lib/lang.nimlib/lang.nim

@@ -10,13 +10,13 @@ quit(0)

minsym "symbols", i: var q = newSeq[MinValue](0) - for s in SYMBOLS.keys: + for s in ROOT.symbols.keys: q.add s.newVal i.push q.newVal minsym "sigils", i: var q = newSeq[MinValue](0) - for s in SIGILS.keys: + for s in ROOT.sigils.keys: q.add s.newVal i.push q.newVal

@@ -41,7 +41,7 @@ elif q2.isQuotation and q2.qVal.len == 1 and q2.qVal[0].kind == minSymbol:

symbol = q2.qVal[0].symVal else: i.error errIncorrect, "The top quotation must contain only one symbol value" - if SYMBOLS.hasKey(symbol): + if ROOT.symbols.hasKey(symbol): i.error errSystem, "Symbol '$1' already exists" % [symbol] minsym symbol, i: i.evaluating = true

@@ -52,7 +52,7 @@ minsym "unbind", i:

var q1 = i.pop if q1.qVal.len == 1 and q1.qVal[0].kind == minSymbol: var symbol = q1.qVal[0].symVal - SYMBOLS.excl symbol + ROOT.symbols.excl symbol else: i.error errIncorrect, "The top quotation must contain only one symbol value"

@@ -68,7 +68,7 @@ if q1.isQuotation and q2.isQuotation:

if q1.qVal.len == 1 and q1.qVal[0].kind == minSymbol: var symbol = q1.qVal[0].symVal if symbol.len == 1: - if SIGILS.hasKey(symbol): + if ROOT.sigils.hasKey(symbol): i.error errSystem, "Sigil '$1' already exists" % [symbol] minsigil symbol, i: i.evaluating = true
M minim.nimminim.nim

@@ -46,7 +46,7 @@ var w = if words.len > 0: words.pop else: ""

var sep = "" if words.len > 0: sep = " " - for s in SYMBOLS.keys: + for s in ROOT.symbols.keys: if startsWith(s, w): linenoiseAddCompletion completions, words.join(" ") & sep & s proc prompt(s: string): string =