This commit is contained in:
araq
2025-12-02 10:44:00 +01:00
parent 5fc7feacd1
commit 3710d48a68
4 changed files with 30 additions and 13 deletions

View File

@@ -854,14 +854,6 @@ proc newFloatNode*(kind: TNodeKind, floatVal: BiggestFloat): PNode =
result = newNode(kind)
result.floatVal = floatVal
proc newStrNode*(kind: TNodeKind, strVal: string): PNode =
result = newNode(kind)
result.strVal = strVal
proc newStrNode*(strVal: string; info: TLineInfo): PNode =
result = newNodeI(nkStrLit, info)
result.strVal = strVal
proc newProcNode*(kind: TNodeKind, info: TLineInfo, body: PNode,
params,
name, pattern, genericParams,

View File

@@ -361,19 +361,23 @@ proc addLocalSyms(w: var Writer; n: PNode) =
proc trInclude(w: var Writer; n: PNode) =
w.deps.addParLe pool.tags.getOrIncl(toNifTag(n.kind)), trLineInfo(w, n.info)
w.deps.addDotToken # flags
w.deps.addDotToken # type
for child in n:
assert child.kind == nkStrLit
w.deps.addStrLit child.strVal
w.deps.addStrLit child.strVal # raw string literal, no wrapper needed
w.deps.addParRi
proc trImport(w: var Writer; n: PNode) =
for child in n:
if child.kind == nkSym:
w.deps.addParLe pool.tags.getOrIncl(toNifTag(n.kind)), trLineInfo(w, n.info)
w.deps.addDotToken # flags
w.deps.addDotToken # type
let s = child.sym
assert s.kindImpl == skModule
let fp = toFullPath(w.infos.config, s.positionImpl.FileIndex)
w.deps.addStrLit fp
w.deps.addStrLit fp # raw string literal, no wrapper needed
w.deps.addParRi
proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode) =
@@ -845,6 +849,9 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string): PNode =
of DotToken:
result = nil
inc n
of StringLit:
result = newStrNode(pool.strings[n.litId], c.infos.oldLineInfo(n.info))
inc n
of ParLe:
let kind = n.nodeKind
case kind
@@ -938,7 +945,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string): PNode =
while n.kind != ParRi:
result.sons.add c.loadNode(n, thisModule)
else:
raiseAssert "Not yet implemented " & $n.kind
raiseAssert "expected string literal but got " & $n.kind
proc moduleSuffix(conf: ConfigRef; f: FileIndex): string =
moduleSuffix(toFullPath(conf, f), cast[seq[string]](conf.searchPaths))

View File

@@ -981,6 +981,14 @@ proc newSymNode*(sym: PSym, info: TLineInfo): PNode =
result.typField = sym.typImpl
result.info = info
proc newStrNode*(kind: TNodeKind, strVal: string): PNode =
result = newNode(kind)
result.strVal = strVal
proc newStrNode*(strVal: string; info: TLineInfo): PNode =
result = newNodeI(nkStrLit, info)
result.strVal = strVal
proc forcePartial*(s: PSym) =
## Resets all impl-fields to their default values and sets state to Partial.
## This is useful for creating a stub symbol that can be lazily loaded later.

View File

@@ -365,8 +365,18 @@ proc compilePipelineProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIdx
discard graph.compilePipelineModule(projectFile, {sfMainModule, sfSystemModule})
graph.withinSystem = false
elif graph.config.cmd == cmdM:
# For cmdM: load system.nim from NIF, don't recompile it
# The import mechanism will load it via moduleFromNifFile
# For cmdM: load system.nim from NIF first, then compile the main module
connectPipelineCallbacks(graph)
graph.config.m.systemFileIdx = fileInfoIdx(graph.config,
graph.config.libpath / RelativeFile"system.nim")
var cachedModules: seq[FileIndex] = @[]
when not defined(nimKochBootstrap):
graph.systemModule = moduleFromNifFile(graph, graph.config.m.systemFileIdx, cachedModules)
if graph.systemModule == nil:
let nifPath = toNifFilename(graph.config, graph.config.m.systemFileIdx)
localError(graph.config, unknownLineInfo,
"nim m requires precompiled NIF for system module (expected: " & nifPath & ")")
return
discard graph.compilePipelineModule(projectFile, {sfMainModule})
else:
graph.compilePipelineSystemModule()