diff options
author | cooldome <cdome@bk.ru> | 2018-10-18 19:21:25 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-18 20:21:25 +0200 |
commit | eaca5be9d6e205e8aa7055306122a6c053ef35a6 (patch) | |
tree | 784c5f2726a94b656e3f85ab231c4dfc377cc167 /compiler/lambdalifting.nim | |
parent | 15dbd973dec848f1c429fe7043e53254a501812b (diff) | |
download | Nim-eaca5be9d6e205e8aa7055306122a6c053ef35a6.tar.gz |
Change the order of compilation passes, transformation is made lazy at code gen (#8489)
* Ast no transformation * Add getImplNoTransform to the macros module * progress on delaying transf * Fix methods tranformation * Fix lazy lambdalifting * fix create thread wrapper * transform for lambda lifting * improve getImplTransformed * Fix destructor tests * try to fix nimprof for linux
Diffstat (limited to 'compiler/lambdalifting.nim')
-rw-r--r-- | compiler/lambdalifting.nim | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 79b44319f..c318421fa 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -11,7 +11,8 @@ import intsets, strutils, options, ast, astalgo, trees, treetab, msgs, - idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos + idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos, + transf discard """ The basic approach is that captured vars need to be put on the heap and @@ -257,7 +258,7 @@ proc liftIterSym*(g: ModuleGraph; n: PNode; owner: PSym): PNode = # add 'new' statement: result.add newCall(getSysSym(g, n.info, "internalNew"), env) result.add makeClosure(g, iter, env, n.info) - + proc freshVarForClosureIter*(g: ModuleGraph; s, owner: PSym): PNode = let envParam = getHiddenParam(g, owner) let obj = envParam.typ.lastSon @@ -390,7 +391,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = if innerProc: if s.isIterator: c.somethingToDo = true if not c.processed.containsOrIncl(s.id): - detectCapturedVars(s.getBody, s, c) + let body = transformBody(c.graph, s) + detectCapturedVars(body, s, c) let ow = s.skipGenericOwner if ow == owner: if owner.isIterator: @@ -651,14 +653,17 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass; # echo renderTree(s.getBody, {renderIds}) let oldInContainer = c.inContainer c.inContainer = 0 - var body = liftCapturedVars(s.getBody, s, d, c) + var body = transformBody(d.graph, s) + body = liftCapturedVars(body, s, d, c) if c.envvars.getOrDefault(s.id).isNil: - s.ast.sons[bodyPos] = body + s.transformedBody = body else: - s.ast.sons[bodyPos] = newTree(nkStmtList, rawClosureCreation(s, d, c), body) + s.transformedBody = newTree(nkStmtList, rawClosureCreation(s, d, c), body) c.inContainer = oldInContainer + if s.typ.callConv == ccClosure: result = symToClosure(n, owner, d, c) + elif s.id in d.capturedVars: if s.owner != owner: result = accessViaEnvParam(d.graph, n, owner) |