From 3710d48a6825f795bde7e5c5709ed3ea840478ae Mon Sep 17 00:00:00 2001 From: araq Date: Tue, 2 Dec 2025 10:44:00 +0100 Subject: [PATCH] progres --- compiler/ast.nim | 8 -------- compiler/ast2nif.nim | 13 ++++++++++--- compiler/astdef.nim | 8 ++++++++ compiler/pipelines.nim | 14 ++++++++++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index eebe6f257e..444c51b199 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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, diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index b91dc4956e..c2e5ad5652 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -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)) diff --git a/compiler/astdef.nim b/compiler/astdef.nim index cc0c4c49a6..ffd02f3a96 100644 --- a/compiler/astdef.nim +++ b/compiler/astdef.nim @@ -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. diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 2ef0c60e22..358d0be5f0 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -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()