fix(emitter): avoid clj_ prefix on nim/ interop identifiers

The clj_ prefix added in fb8928e broke nim/module/proc interop because
native Nim identifiers were being mangled to clj_foo instead of foo.

- Extract sanitizeNimIdent from mangleName (does all cleanups except prefix)
- Use sanitizeNimIdent for nim/ interop function chains
- Regular Clojure symbols still get clj_ prefix via mangleName

Fixes BRing bringRunServer and other native Nim proc calls.
This commit is contained in:
2026-05-12 11:16:16 +03:00
parent fb8928e830
commit 3aaf3c0548
+8 -5
View File
@@ -35,7 +35,8 @@ proc resolveNsAlias*(name: string): string =
type
EmitterError* = object of CatchableError
proc mangleName*(name: string): string =
proc sanitizeNimIdent*(name: string): string =
## Sanitize a string to be a valid Nim identifier, without the clj_ prefix.
result = ""
for c in name:
case c
@@ -79,8 +80,9 @@ proc mangleName*(name: string): string =
"interface", "lambda", "open", "quit", "result", "nil", "end"]
if result in nimKeywords:
result = result & "1"
# Prefix to avoid conflicts with Nim identifiers (case-insensitive + underscore ignoring)
result = "clj_" & result
proc mangleName*(name: string): string =
result = "clj_" & sanitizeNimIdent(name)
proc pushScope() =
scopeStack.add(initHashSet[string]())
@@ -1958,10 +1960,11 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
let parts = op.replace(".", "/").split("/")
if parts.len >= 3:
let module = parts[1]
# Mangle each part of the function chain for Nim identifier validity
# Sanitize each part of the function chain for Nim identifier validity
# (native Nim identifiers must NOT get the clj_ prefix)
var mangledParts: seq[string] = @[]
for p in parts[2..^1]:
mangledParts.add(mangleName(p))
mangledParts.add(sanitizeNimIdent(p))
var funcChain = mangledParts.join(".")
# Strip ? suffix (Clojure convention) — not valid in Nim
if funcChain.endsWith("?"):