Skip to content

Commit

Permalink
Integrate the move analyser into duplifier.nim (#521)
Browse files Browse the repository at this point in the history
* Integrate the move analyser into duplifier.nim

* fixes `ensureMove`
  • Loading branch information
ringabout authored Feb 12, 2025
1 parent 4de49db commit f0d86e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
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

0 comments on commit f0d86e3

Please sign in to comment.