diff options
Diffstat (limited to 'compiler/liftlocals.nim')
-rw-r--r-- | compiler/liftlocals.nim | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/compiler/liftlocals.nim b/compiler/liftlocals.nim index ae789cd88..aaa0707e0 100644 --- a/compiler/liftlocals.nim +++ b/compiler/liftlocals.nim @@ -10,9 +10,11 @@ ## This module implements the '.liftLocals' pragma. import - intsets, strutils, options, ast, astalgo, msgs, + options, ast, msgs, idents, renderer, types, lowerings, lineinfos +import std/strutils + from pragmas import getPragmaVal from wordrecg import wLiftLocals @@ -21,19 +23,20 @@ type partialParam: PSym objType: PType cache: IdentCache + idgen: IdGenerator proc interestingVar(s: PSym): bool {.inline.} = result = s.kind in {skVar, skLet, skTemp, skForVar, skResult} and sfGlobal notin s.flags proc lookupOrAdd(c: var Ctx; s: PSym; info: TLineInfo): PNode = - let field = addUniqueField(c.objType, s, c.cache) + let field = addUniqueField(c.objType, s, c.cache, c.idgen) var deref = newNodeI(nkHiddenDeref, info) deref.typ = c.objType - add(deref, newSymNode(c.partialParam, info)) + deref.add(newSymNode(c.partialParam, info)) result = newNodeI(nkDotExpr, info) - add(result, deref) - add(result, newSymNode(field)) + result.add(deref) + result.add(newSymNode(field)) result.typ = field.typ proc liftLocals(n: PNode; i: int; c: var Ctx) = @@ -42,18 +45,20 @@ proc liftLocals(n: PNode; i: int; c: var Ctx) = of nkSym: if interestingVar(it.sym): n[i] = lookupOrAdd(c, it.sym, it.info) - of procDefs, nkTypeSection: discard + of procDefs, nkTypeSection, nkMixinStmt, nkBindStmt: discard else: - for i in 0 ..< it.safeLen: + for i in 0..<it.safeLen: liftLocals(it, i, c) proc lookupParam(params, dest: PNode): PSym = + result = nil if dest.kind != nkIdent: return nil - for i in 1 ..< params.len: + for i in 1..<params.len: if params[i].kind == nkSym and params[i].sym.name.id == dest.ident.id: return params[i].sym -proc liftLocalsIfRequested*(prc: PSym; n: PNode; cache: IdentCache; conf: ConfigRef): PNode = +proc liftLocalsIfRequested*(prc: PSym; n: PNode; cache: IdentCache; conf: ConfigRef; + idgen: IdGenerator): PNode = let liftDest = getPragmaVal(prc.ast, wLiftLocals) if liftDest == nil: return n let partialParam = lookupParam(prc.typ.n, liftDest) @@ -65,7 +70,7 @@ proc liftLocalsIfRequested*(prc: PSym; n: PNode; cache: IdentCache; conf: Config if objType.kind != tyObject or tfPartial notin objType.flags: localError(conf, liftDest.info, "parameter '$1' is not a pointer to a partial object" % $liftDest) return n - var c = Ctx(partialParam: partialParam, objType: objType, cache: cache) + var c = Ctx(partialParam: partialParam, objType: objType, cache: cache, idgen: idgen) let w = newTree(nkStmtList, n) liftLocals(w, 0, c) result = w[0] |