Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/arkham/analyser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ proc analyse(c: var Context; n: var Cursor) =
if frame.sawCall: c.loopStack[^1].sawCall = true
for pnm in frame.usedParams: c.loopStack[^1].usedParams.incl pnm
else:
when declared(ComesfromS):
if n.stmtKind == ComesfromS:
# `(comesfrom SYM S*)`: debug-info marker, walks like `stmts` but
# opens no scope frame. The leading child is the origin SYMBOL, not a
# statement, so `analyseChildren` would analyse it as a symbol *use*
# and record a read of the expanded routine at this position.
#
# Guarded so arkham still compiles against a nimony that predates the
# tag (nim-lang/nimony#2240); drop the `when` once that has merged.
n.into:
skip n # the origin symbol
while n.hasMore: analyse(c, n)
return
analyseChildren(c, n) # if/case/ret/... : recurse
else:
inc n
Expand Down
17 changes: 16 additions & 1 deletion src/arkham/codegen_a64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,22 @@ proc genStmt2(g: var CodeGen; c: Cursor) =
g.ovfReg2 = rB
g.ovfBridges = @[rA, rB]
while cc.hasMore: skip cc
else: raiseAssert "arkham a64n: genStmt2 " & $c.stmtKind
else:
when declared(ComesfromS):
if c.stmtKind == ComesfromS:
# `(comesfrom SYM S*)` — statements produced by expanding SYM (a
# template today). Debug-info only: no scope and no code of its own, so
# it behaves as `stmts` once the leading origin SYMBOL is stepped over.
# That first child is an operand, not a statement.
#
# Guarded so arkham still compiles against a nimony that predates the
# tag (nim-lang/nimony#2240); drop the `when` once that has merged.
var cc = c
cc.into:
skip cc # the origin symbol
while cc.hasMore: (g.genStmt2(cc); skip cc)
return
raiseAssert "arkham a64n: genStmt2 " & $c.stmtKind

# ── proc emission / driver (pure-emit path) ──────────────────────────────────

Expand Down
33 changes: 32 additions & 1 deletion src/arkham/codegen_x64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4590,7 +4590,25 @@ proc genStmt2(g: var CodeGen; c: Cursor) =
g.genStore2(opCur, memLoc(lhsCur, ScalarSlot))
g.noFoldPos = -1
while cc.hasMore: skip cc
else: raiseAssert "arkham x64n: genStmt2 " & $c.stmtKind
else:
when declared(ComesfromS):
if c.stmtKind == ComesfromS:
# `(comesfrom SYM S*)` — statements produced by expanding SYM (a
# template today). Debug-info only: no scope and no code of its own, so
# it behaves as `stmts` once the leading origin SYMBOL is stepped over.
# That first child is an operand, not a statement.
#
# Guarded so arkham still compiles against a nimony that predates the
# tag (nim-lang/nimony#2240); drop the `when` once that has merged.
var cc = c
cc.into:
skip cc # the origin symbol
while cc.hasMore:
var nx = cc; skip nx
g.tailStmt = myTail and not nx.hasMore
g.genStmt2(cc); skip cc
return
raiseAssert "arkham x64n: genStmt2 " & $c.stmtKind

# ── fused value core: unconverted-proc stubs (die as each case lands) ────────
proc emitBin2(g: var CodeGen; c: Cursor; dest: var Location) =
Expand Down Expand Up @@ -6838,6 +6856,19 @@ proc asmStmt(g: var CodeGen; c: Cursor) =
g.retLabelUsed2 = true
g.emJmp(g.retLabel2)
else:
when declared(ComesfromS):
if c.stmtKind == ComesfromS:
# See `genStmt2`: transparent debug-info marker, first child is an
# operand. Guarded so arkham still compiles against a nimony that
# predates the tag (nim-lang/nimony#2240).
var cc = c
cc.into:
skip cc # the origin symbol
while cc.hasMore:
var nx = cc; skip nx
g.tailStmt = myTail and not nx.hasMore
g.asmStmt(cc); skip cc
return
lengError c, "`" & $c.stmtKind & "` is not allowed in an `.assembler` proc", g.asmInfo

proc genAsmProc(g: var CodeGen; info: ProcInfo) =
Expand Down
14 changes: 14 additions & 0 deletions src/arkham/register_allocator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ proc walk(b: var Builder; n: var Cursor) =
n.into:
while n.hasMore: walk(b, n)
else:
when declared(ComesfromS):
if n.stmtKind == ComesfromS:
# `(comesfrom SYM S*)`: debug-info marker, walks like `stmts`. The
# leading child is the origin SYMBOL, not a statement, so the generic
# recursion below would count it as a use of the expanded routine here.
#
# Guarded so arkham still compiles against a nimony that predates the
# tag (nim-lang/nimony#2240); drop the `when` once that has merged.
n.into:
skip n # the origin symbol
while n.hasMore:
walk(b, n)
flushFree(b, b.posOf(n))
return
if n.kind == TagLit:
n.into:
while n.hasMore: walk(b, n) # recurse (var decls may nest)
Expand Down