genSym for library macros, whose symbols can land in the caller's closure environment. This keeps the library's names from meeting the caller's; the caller's own locals can still meet each other.
Procs
proc macroSym(kind: NimSymKind; ident: string): NimNode {....raises: [], tags: [], forbids: [].}
- genSym with a name no identifier can spell. Nim names a lifted local name & $fieldIndex, so a plain conn at index 14 and the caller's conn1 at index 4 are both emitted as the C member conn14. C codegen escapes the backtick and appends _, which no Nim identifier ends with; the pg suffix leaves the index as the only trailing number. A routine is never an env field and its name shows in async tracebacks, so it keeps the plain name. An {.async.} proc's params sit in its own env, apart from its body's locals, so callback params can stay plain. Templates that declare locals in the caller use macroSymLocals.
Macros
macro macroSymLocals(def: untyped): untyped
-
Template pragma: give the locals the template declares in its caller macroSym names. The body moves to a private <name>Core template that takes those names as parameters, and <name> becomes a macro with the same signature and doc that passes them. Parameters (the caller's names), {.inject.} locals and nested routines' own names are left alone.
A local's name replaces every identifier spelled the same in the body, so a field (a.f, T(f: x)), named argument or outer symbol (var n = n) spelled like one fails to compile. Other pragmas, varargs params, a name declared with two kinds, and a nested routine's param or local sharing a name are rejected here.