all repos — min @ 0a749f71406b1cac0b2b39e9c7c9bb5f749984ae

A small but practical concatenative programming language.

Fixed with operator.
h3rald h3rald@h3rald.com
Sat, 29 Oct 2016 19:14:43 +0200
commit

0a749f71406b1cac0b2b39e9c7c9bb5f749984ae

parent

c478fdeffa7bb703c9995eafebcbcebf3177205a

4 files changed, 2 insertions(+), 43 deletions(-)

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

@@ -34,7 +34,6 @@ if i.debugging:

stderr.writeLine("-- " & value) template withScope*(i: In, q: MinValue, res:ref MinScope, body: untyped): untyped = - #i.debug "[scope] " & q.scope.fullname let origScope = i.scope i.scope = q.scope.copy i.scope.parent = origScope

@@ -116,7 +115,6 @@ of minValOp:

if op.val.kind == minQuotation: var q = op.val i.withScope(q, s): - #echo "a1: ", i.scope.fullname for e in q.qVal: i.push e else:
M core/utils.nimcore/utils.nim

@@ -9,10 +9,6 @@ interpreter

# Library methods -proc printKeys*(syms: CritBitTree[MinOperator]) = - for key, value in syms.pairs: - echo " - $1" % key - proc define*(i: In, name: string): ref MinScope = var scope = new MinScope scope.name = name

@@ -36,22 +32,13 @@ scope.sigils[sym] = MinOperator(val: v, kind: minValOp, sealed: true)

return scope proc finalize*(scope: ref MinScope) = - # TODO verify scope var mdl = newSeq[MinValue](0).newVal(nil) mdl.scope = scope let op = proc(i: In) {.gcsafe, closure.} = i.evaluating = true i.push mdl i.evaluating = false - #echo scope.previous.fullname, " - ", scope.name - #echo scope.previous.symbols.len, " - ", scope.symbols.len - #scope.previous.symbols[scope.name] = MinOperator(kind: minProcOp, prc: op) - # TODO echos - #echo "Finalizing: $1" % scope.name - #echo scope.previous.fullname, " - ", scope.previous.symbols.len - #scope.previous.symbols.printKeys scope.previous.symbols[scope.name] = MinOperator(kind: minProcOp, prc: op) - #echo scope.previous.symbols.len, " - ", scope.symbols.len # Validators
M lib/min_lang.nimlib/min_lang.nim

@@ -177,7 +177,6 @@ raiseInvalid("Symbol identifier '$1' contains invalid characters." % symbol)

i.debug "[define] (scope: $1) $2 = $3" % [i.scope.fullname, symbol, $q1] if i.scope.symbols.hasKey(symbol) and i.scope.symbols[symbol].sealed: raiseUndefined("Attempting to redefine sealed symbol '$1' on scope '$2'" % [symbol, i.scope.name]) - #i.newScope("$1#$2" % [symbol, $genOid()], q1) i.scope.symbols[symbol] = MinOperator(kind: minValOp, val: q1, sealed: false) .symbol("bind") do (i: In):

@@ -200,16 +199,6 @@ let res = i.scope.delSymbol(sym.getString)

if not res: raiseUndefined("Attempting to delete undefined symbol: " & sym.getString) - #.symbol("scope") do (i: In): - # var code: MinValue - # i.reqQuotation code - # code.filename = i.filename - # i.unquote("<scope>", code) - # i.push @[code].newVal(i.scope) - - .symbol("current-scope") do (i: In): - i.push i.scope.fullname.newVal - .symbol("module") do (i: In): var code, name: MinValue i.reqStringLike name

@@ -219,15 +208,6 @@ i.unquote("<module>", code, code.scope)

i.debug("[module] $1 ($2 symbols)" % [name.getString, $code.scope.symbols.len]) i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal(i.scope)) - #.symbol("scope?") do (i: In): - # var q: MinValue - # i.reqQuotation q - # if not q.scope.isNil: - # i.push true.newVal - # else: - # i.push false.newVal - - .symbol("import") do (i: In): var mdl, rawName: MinValue var name: string

@@ -236,13 +216,9 @@ name = rawName.getString

var op = i.scope.getSymbol(name) i.apply(op) i.reqQuotation mdl - #echo "Import: $1" % name - #echo ">>", mdl, "<<" - # TODO Remove echos i.debug("[import] Importing: $1 ($2 symbols)" % [name, $mdl.scope.symbols.len]) for sym, val in mdl.scope.symbols.pairs: i.debug "[import] $1:$2" % [i.scope.fullname, sym] - #echo "[import] $1:$2" % [i.scope.name, sym] i.scope.symbols[sym] = val #.symbol("sigil") do (i: In):

@@ -280,7 +256,7 @@ var qscope, qprog: MinValue

i.reqTwoQuotations qscope, qprog if qscope.qVal.len > 0: # System modules are empty quotes and don't need to be unquoted - i.unquote("<with-scope>", qscope) + i.unquote("<with-scope>", qscope, qscope.scope) i.withScope(qscope): for v in qprog.qVal: i.push v
M tests/lang.mintests/lang.min

@@ -72,8 +72,6 @@ ; ) @mymath 5 2 mymath ^myminus 3 ==) assert

; ;(mymath inspect ("myminus" "myplus") ==) assert - ;((":mysigil" concat) ', sigil ,test "test:mysigil" ==) assert - ("3 4 +" eval 7 ==) assert ("2 2 +" "tests/testload.min" fwrite 'testload load 4 ==) assert

@@ -147,7 +145,7 @@ (() 1 at)

(1) ) try 1 ==) assert - ;((a b +) (4 :a 5 :b) with 9 ==) assert + ((a b +) (4 :a 5 :b) with 9 ==) assert ("{\"a\": 1, \"b\": 2.3}" from-json ((a 1) (b 2.3)) ==) assert