Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate the move analyser into duplifier.nim #521

Merged
merged 2 commits into from
Feb 12, 2025
Merged
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
12 changes: 7 additions & 5 deletions src/hexer/duplifier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type
reportLastUse: bool
typeCache: TypeCache
tmpCounter: int
source: ptr TokenBuf

Expects = enum
DontCare,
Expand All @@ -50,9 +51,9 @@ type

# -------------- helpers ----------------------------------------

proc isLastRead(c: Context; n: Cursor): bool =
# XXX We don't have a move analyser yet.
false
proc isLastRead(c: var Context; n: Cursor): bool =
var otherUsage = NoLineInfo
result = isLastUse(n, c.source[], otherUsage)

const
ConstructingExprs = {CallX, CallStrLitX, InfixX, PrefixX, CmdX, OconstrX, NewOconstrX,
Expand Down Expand Up @@ -606,6 +607,7 @@ proc trEnsureMove(c: var Context; n: var Cursor; e: Expects) =
let m = "not the last usage of: " & toString(n, false)
c.dest.buildTree ErrT, info:
c.dest.add strToken(pool.strings.getOrIncl(m), info)
skip n

proc tr(c: var Context; n: var Cursor; e: Expects) =
if n.kind == Symbol:
Expand Down Expand Up @@ -671,9 +673,9 @@ proc tr(c: var Context; n: var Cursor; e: Expects) =
else:
trSons c, n, WantNonOwner

proc injectDups*(n: Cursor; lifter: ref LiftingCtx): TokenBuf =
proc injectDups*(n: Cursor; source: var TokenBuf; lifter: ref LiftingCtx): TokenBuf =
var c = Context(lifter: lifter, typeCache: createTypeCache(),
dest: createTokenBuf(400))
dest: createTokenBuf(400), source: addr source)
c.typeCache.openScope()
var n = n
tr(c, n, WantNonOwner)
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/mover.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ when isMainModule:
while true:
case result.kind
of ParLe:
if result.exprKind == EnsureMoveX:
if result.exprKind == EMoveX:
inc result
return result
inc nested
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/pipeline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc transform*(c: var EContext; n: Cursor; moduleSuffix: string): TokenBuf =

var c2 = beginRead(n1)
let ctx = createLiftingCtx()
var n2 = injectDups(c2, ctx)
var n2 = injectDups(c2, n1, ctx)
endRead(n1)

var c3 = beginRead(n2)
Expand Down
Loading