From d18256dff228b85f10c22ab1817b7da05cc48dc6 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 21 Dec 2025 17:30:27 +0100 Subject: [PATCH] more faithful NIF representation of the AST --- compiler/ast2nif.nim | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index db3fce6683..9902f542c0 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -164,7 +164,7 @@ type const # Symbol kinds that are always local to a proc and should never have module suffix - skLocalSymKinds = {skParam, skGenericParam, skForVar, skResult, skTemp} + skLocalSymKinds = {skParam, skForVar, skResult, skTemp} proc isLocalSym(sym: PSym): bool {.inline.} = sym.kindImpl in skLocalSymKinds or @@ -362,10 +362,7 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) = writeSym(w, dest, sym.ownerFieldImpl) # Store the AST for routine symbols and constants # Constants need their AST for astdef() to return the constant's value - if sym.kindImpl in routineKinds + {skConst}: - writeNode(w, dest, sym.astImpl, forAst = true) - else: - dest.addDotToken + writeNode(w, dest, sym.astImpl, forAst = true) writeLoc w, dest, sym.locImpl writeNode(w, dest, sym.constraintImpl) writeSym(w, dest, sym.instantiatedFromImpl) @@ -512,14 +509,14 @@ proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode; forAst = false) = of nkNilLit: w.withNode dest, n: discard - of nkLetSection, nkVarSection, nkConstSection, nkGenericParams: + of nkLetSection, nkVarSection, nkConstSection: # Track local variables declared in let/var sections w.withNode dest, n: for child in n: addLocalSyms w, child # Process the child node writeNode(w, dest, child, forAst) - of nkForStmt, nkTypeDef: + of nkForStmt: # Track for loop variable (first child is the loop variable) w.withNode dest, n: if n.len > 0: @@ -1112,12 +1109,7 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule: s.ownerFieldImpl = loadSymStub(c, n, thisModule, localSyms) # Load the AST for routine symbols and constants # Constants need their AST for astdef() to return the constant's value - if s.kindImpl in routineKinds + {skConst}: - s.astImpl = loadNode(c, n, thisModule, localSyms) - elif n.kind == DotToken: - inc n - else: - raiseAssert "expected '.' for non-routine symbol AST but got " & $n.kind + s.astImpl = loadNode(c, n, thisModule, localSyms) loadLoc c, n, s.locImpl s.constraintImpl = loadNode(c, n, thisModule, localSyms) s.instantiatedFromImpl = loadSymStub(c, n, thisModule, localSyms)