all repos — min @ c354ea10b0ade24b5734ad7269d0b643c28fd5fc

A small but practical concatenative programming language.

Modified scope name generation.
h3rald h3rald@h3rald.com
Sun, 19 Feb 2017 13:50:19 +0100
commit

c354ea10b0ade24b5734ad7269d0b643c28fd5fc

parent

6183a01a5e1d8d2b9d959c9ebce63d536220cb0a

4 files changed, 24 insertions(+), 8 deletions(-)

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

@@ -1,12 +1,13 @@

# Adapted from: https://github.com/Araq/Nimrod/blob/v0.9.6/lib/pure/json.nim import lexbase, + sequtils, strutils, streams, unicode, tables, critbits, - oids, + math, logging type

@@ -145,8 +146,21 @@ "true",

"false" ] +var SCOPES = 0 + +proc b64(n: int): string = + let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + var residual = n + result = "" + while true: + result = alphabet[residual mod 64] & result + residual = residual div 64 + if residual == 0: + break + proc newScope*(parent: ref MinScope, name="scope"): MinScope = - result = MinScope(name: "$1/$2" % [name, $genOid()], parent: parent) + let id = atomicInc(SCOPES).b64 + result = MinScope(name: "$1-$2" % [name, id], parent: parent) proc newScopeRef*(parent: ref MinScope, name="scope"): ref MinScope = new(result)

@@ -494,7 +508,7 @@ discard getToken(p)

of tkBracketLe: var q = newSeq[MinValue](0) var oldscope = i.scope - var newscope = newScopeRef(i.scope, "quotation") + var newscope = newScopeRef(i.scope, "q") i.scope = newscope discard getToken(p) while p.token != tkBracketRi:
M core/scope.nimcore/scope.nim

@@ -10,7 +10,7 @@ if not scope.parent.isNil:

result = scope.parent.fullname & ":" & result proc copy*(s: ref MinScope): ref MinScope = - var scope = newScope(s.parent, "copy/$1" % s.name) + var scope = newScope(s.parent, "_$1" % s.name) scope.symbols = s.symbols new(result) result[] = scope

@@ -76,4 +76,4 @@ proc previous*(scope: ref MinScope): ref MinScope =

if scope.parent.isNil: return scope else: - return scope.parent+ return scope.parent
M lib/min_lang.nimlib/min_lang.nim

@@ -229,6 +229,8 @@ i.reqQuotation mdl

info("[import] Importing: $1 ($2 symbols)" % [name, $mdl.scope.symbols.len]) debug("[import] Scope: $1" % i.scope.fullname) for sym, val in mdl.scope.symbols.pairs: + if i.scope.symbols.hasKey(sym) and i.scope.symbols[sym].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1' on scope '$2'" % [sym, i.scope.name]) i.debug "[import] $1:$2" % [i.scope.fullname, sym] i.scope.symbols[sym] = val
M nifty.jsonnifty.json

@@ -11,7 +11,7 @@ },

"git+src+tag": { "cmd": "git clone --branch {{tag}} {{src}} --depth 1" - }, + }, "curl+src+name": { "cmd": "curl {{src}} -o {{name}}"

@@ -23,7 +23,7 @@ "git+name":

{ "cmd": "git pull", "pwd": "{{name}}" - }, + }, "curl+src+name": { "cmd": "curl {{src}} -o {{name}}"

@@ -73,6 +73,6 @@ {

"name": "styled_console_logger.nim", "src": "https://raw.githubusercontent.com/h3rald/nifty/master/lib/styled_console_logger.nim", "curl": true - } + } } }