From 802b7a29b4db922579bc17514edc2acc4fd639bc Mon Sep 17 00:00:00 2001 From: araq Date: Fri, 12 Dec 2025 13:56:25 +0100 Subject: [PATCH] moved code around --- compiler/ast2nif.nim | 56 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index a8e15ddfb2..38120a1554 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -26,6 +26,26 @@ import ic / [enum2nif] export nifindexes.AttachedOp, nifindexes.HookIndexEntry, nifindexes.HooksPerType export nifindexes.ClassIndexEntry, nifindexes.MethodIndexEntry +# -------------- Module name handling -------------------------------------------- + +proc cachedModuleSuffix*(config: ConfigRef; fileIdx: FileIndex): string = + ## Gets or computes the module suffix for a FileIndex. + ## For NIF modules, the suffix is already stored in the file info. + ## For source files, computes it from the path. + let fullPath = toFullPath(config, fileIdx) + if fileInfoKind(config, fileIdx) == fikNifModule: + result = fullPath # Already a suffix + else: + result = moduleSuffix(fullPath, cast[seq[string]](config.searchPaths)) + +proc modname(module: int; conf: ConfigRef): string = + cachedModuleSuffix(conf, module.FileIndex) + +proc modname(module: PSym; conf: ConfigRef): string = + assert module.kindImpl == skModule + modname(module.positionImpl, conf) + + proc toAttachedOp*(op: TTypeAttachedOp): AttachedOp = ## Maps Nim compiler's TTypeAttachedOp to nimony's AttachedOp. ## Returns attachedDestroy for attachedDeepCopy (caller should skip it). @@ -48,16 +68,13 @@ proc toTTypeAttachedOp*(op: AttachedOp): TTypeAttachedOp = of nifindexes.attachedSink: astdef.attachedSink of nifindexes.attachedTrace: astdef.attachedTrace - -proc cachedModuleSuffix*(config: ConfigRef; fileIdx: FileIndex): string = - ## Gets or computes the module suffix for a FileIndex. - ## For NIF modules, the suffix is already stored in the file info. - ## For source files, computes it from the path. - let fullPath = toFullPath(config, fileIdx) - if fileInfoKind(config, fileIdx) == fikNifModule: - result = fullPath # Already a suffix - else: - result = moduleSuffix(fullPath, cast[seq[string]](config.searchPaths)) +proc typeToNifSym(typ: PType; config: ConfigRef): string = + result = "`t" + result.addInt ord(typ.kind) + result.add '.' + result.addInt typ.uniqueId.item + result.add '.' + result.add modname(typ.uniqueId.module, config) proc toHookIndexEntry*(config: ConfigRef; typeId: ItemId; hookSym: PSym): HookIndexEntry = ## Converts a type ItemId and hook symbol to a HookIndexEntry for the NIF index. @@ -150,17 +167,6 @@ proc oldLineInfo(w: var LineInfoWriter; info: PackedLineInfo): TLineInfo = result = TLineInfo(line: x.line.uint16, col: x.col.int16, fileIndex: fileIdx) -# -------------- Module name handling -------------------------------------------- - -proc modname(module: int; conf: ConfigRef): string = - cachedModuleSuffix(conf, module.FileIndex) - -proc modname(module: PSym; conf: ConfigRef): string = - assert module.kindImpl == skModule - modname(module.positionImpl, conf) - - - # ------------- Writer --------------------------------------------------------------- #[ @@ -283,14 +289,6 @@ proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode; forAst = false) proc writeType(w: var Writer; dest: var TokenBuf; typ: PType) proc writeSym(w: var Writer; dest: var TokenBuf; sym: PSym) -proc typeToNifSym(typ: PType; config: ConfigRef): string = - result = "`t" - result.addInt ord(typ.kind) - result.add '.' - result.addInt typ.uniqueId.item - result.add '.' - result.add modname(typ.uniqueId.module, config) - proc writeLoc(w: var Writer; dest: var TokenBuf; loc: TLoc) = dest.addIdent toNifTag(loc.k) dest.addIdent toNifTag(loc.storage)