Sigil/symbol sync.
h3rald h3rald@h3rald.com
Sun, 27 Oct 2024 11:15:07 +0100
3 files changed,
18 insertions(+),
0 deletions(-)
M
minpkg/lib/min_global.nim
→
minpkg/lib/min_global.nim
@@ -416,7 +416,11 @@ i.scope.symbols[n] = MinOperator(kind: minProcOp, prc: p, sealed: false, doc: doc)
else: if i.scope.sigils.hasKey(n) and i.scope.sigils[n].sealed: raiseUndefined("Attempting to redefine sealed sigil '$1'" % [n]) + if i.scope.symbols.hasKey(n) and i.scope.symbols[n].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1'" % [n]) i.scope.sigils[n] = MinOperator(kind: minProcOp, prc: p, sealed: true, doc: doc) + # Define a symbol with the same name as the sigil + i.scope.symbols[n] = MinOperator(kind: minProcOp, prc: p, sealed: false, doc: doc) def.symbol("expect-empty-stack") do (i: In): let l = i.stack.len@@ -590,8 +594,12 @@ raiseInvalid("Sigil identifier '$1' contains invalid characters." % symbol)
info "[define-sigil] $1 = $2" % [symbol, $q1] if i.scope.sigils.hasKey(symbol) and i.scope.sigils[symbol].sealed: raiseUndefined("Attempting to redefine sealed sigil '$1'" % [symbol]) + if i.scope.symbols.hasKey(symbol) and i.scope.symbols[symbol].sealed: + raiseUndefined("Attempting to redefine sealed symbol '$1'" % [symbol]) i.scope.sigils[symbol] = MinOperator(kind: minValOp, val: q1, sealed: false, quotation: true) + i.scope.symbols[symbol] = MinOperator(kind: minValOp, val: q1, + sealed: false, quotation: true) def.symbol("bind") do (i: In): let vals = i.expect("'sym", "a")@@ -625,6 +633,7 @@ let sym = vals[0]
let res = i.scope.delSymbol(sym.getString) if not res: raiseUndefined("Attempting to delete undefined symbol: " & sym.getString) + discard i.scope.delSigil(sym.getString) def.symbol("delete-sigil") do (i: In): let vals = i.expect("'sym")@@ -632,6 +641,7 @@ let sym = vals[0]
let res = i.scope.delSigil(sym.getString) if not res: raiseUndefined("Attempting to delete undefined sigil: " & sym.getString) + discard i.scope.delSymbol(sym.getString) def.symbol("scope") do (i: In): var dict = newDict(i.scope.parent)
M
next-release.md
→
next-release.md
@@ -2,6 +2,7 @@ ### BREAKING CHANGES
* Actually removed the `invoke` symbol and `*` sigil that were supposed to be removed in v0.44.0 but didn't. * Removed Dockerfile and Notepad++ highlighter (no longer maintained). +* When defining or deleting a sigil, a symbol with the same name is now defined/deleted as well. ### Fixes and Improvements
M
tests/global.min
→
tests/global.min
@@ -228,6 +228,13 @@ j"{\"test\": true}"
'j delete-sigil {true :test} == ) test.assert + + ( + 'from-json 'j define-sigil + "{\"test\": true}" j + 'j delete-symbol + {true :test} == + ) test.assert ( {{100 :b} :a} :test test.a.b 100 ==