all repos — min @ 7c059e97dd7fe78562730a9c70958057adc35d1b

A small but practical concatenative programming language.

Added cache for filenames; removed unneded scope creation.
h3rald h3rald@h3rald.com
Wed, 03 Jun 2026 10:32:37 +0200
commit

7c059e97dd7fe78562730a9c70958057adc35d1b

parent

df73f1743bcb8f37ce030fa66d69eba8a0d9368c

M minpkg/core/env.nimminpkg/core/env.nim

@@ -1,5 +1,6 @@

import std/os, + std/critbits, minline var HOME* {.threadvar.}: string

@@ -26,3 +27,4 @@ var COLOR* {.threadvar.}: bool

COLOR = true var ERRORS_HANDLED* {.threadvar.}: bool ERRORS_HANDLED = false +var FILECACHE* {.threadvar.}: CritBitTree[string]
M minpkg/core/interpreter.nimminpkg/core/interpreter.nim

@@ -212,8 +212,7 @@ else:

op.prc(i) else: if op.val.kind == minQuotation and op.lambda: - var newscope = newScopeRef(i.scope) - i.withScope(newscope): + i.withScope(): for e in op.val.qVal: if e.isSymbol and e.symVal == sym: raiseInvalid("Symbol '$#' evaluates to itself" % sym)
M minpkg/core/parser.nimminpkg/core/parser.nim

@@ -9,6 +9,7 @@ logging,

json] import + env, baseutils import std/unicode except strip

@@ -167,6 +168,12 @@ raiseInvalid("dVal - Dictionary expected, got " & $v.kind)

if v.scope.isNil: return CritBitTree[MinOperator]() return v.scope.symbols + +proc internFile*(s: string): string = + if FILECACHE.hasKey(s): + return FILECACHE[s] + FILECACHE[s] = s + return s const errorMessages: array[MinParserError, string] = [

@@ -792,7 +799,7 @@ raiseInvalid("Invalid dictionary")

result = MinValue(kind: minDictionary, scope: scope) of tkSymbol: result = MinValue(kind: minSymbol, symVal: p.a, column: p.getColumn, - line: p.lineNumber, filename: p.filename) + line: p.lineNumber, filename: internFile(p.filename)) p.a = "" p.currSym = result discard getToken(p)
M minpkg/lib/min_global.nimminpkg/lib/min_global.nim

@@ -356,7 +356,8 @@ var endSnapshot: seq[MinValue]

var snapShot: seq[MinValue] try: snapshot = deepCopy(i.stack) - i.dequote bv + for v in bv.qVal: # execute directly in the existing scope (withScope) + i.push v endSnapshot = i.stack let d = snapshot.diff(endSnapshot) if d.len > 0:

@@ -365,7 +366,8 @@ except MinReturnException:

discard else: try: - i.dequote bv + for v in bv.qVal: # execute directly in the existing scope (withScope) + i.push v except MinReturnException: discard # Validate output
M next-release.mdnext-release.md

@@ -7,5 +7,7 @@

* Ensure the relevant procs are gcsafe. * No longer using ref for `MinValue` objects. * No longer performing a deep copy when dequoting. +* Optimized the way debug information is stored to reduce memory usage. +* Avoiding creating unnecessary scopes when possible (withScope macro already creates a scope).