diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-12-27 00:17:48 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-12-27 00:17:48 +0100 |
commit | 9309f8101d5acf349611314267dbdf1f9a352022 (patch) | |
tree | 72425640792439f3cd666222063ab1a5def853d5 /compiler/lambdalifting.nim | |
parent | 7dc0bca53ae6727c67b899d979c5fe40b1deadd3 (diff) | |
download | Nim-9309f8101d5acf349611314267dbdf1f9a352022.tar.gz |
new-ll: further progress (bootstrapping still fails)
Diffstat (limited to 'compiler/lambdalifting.nim')
-rw-r--r-- | compiler/lambdalifting.nim | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 139a3f9ce..613fb8555 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -169,7 +169,7 @@ proc addHiddenParam(routine: PSym, param: PSym) = proc getHiddenParam(routine: PSym): PSym = let params = routine.ast.sons[paramsPos] let hidden = lastSon(params) - if hidden.kind == nkSym and hidden.sym.kind == skParam: + if hidden.kind == nkSym and hidden.sym.kind == skParam and hidden.sym.name.s == paramName: result = hidden.sym assert sfFromGeneric in result.flags else: @@ -194,7 +194,7 @@ proc illegalCapture(s: PSym): bool {.inline.} = s.kind == skResult proc isInnerProc(s: PSym): bool = - if s.kind in {skProc, skMethod, skConverter, skIterator}: + if s.kind in {skProc, skMethod, skConverter, skIterator} and s.magic == mNone: result = s.skipGenericOwner.kind in routineKinds proc createUpField(obj, fieldType: PType): PSym = @@ -327,7 +327,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = # ow != owner: return # direct or indirect dependency: - if innerProc or interestingVar(s): + if (innerProc and s.typ.callConv == ccClosure) or interestingVar(s): discard """ proc outer() = var x: int @@ -371,8 +371,11 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure, nkTemplateDef, nkTypeSection: discard - of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef, nkMacroDef: + of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef: discard + of nkLambdaKinds, nkIteratorDef: + if n.typ != nil: + detectCapturedVars(n[namePos], owner, c) else: for i in 0..<n.len: detectCapturedVars(n[i], owner, c) @@ -599,8 +602,11 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass; of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure, nkTemplateDef, nkTypeSection: discard - of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef, nkMacroDef: + of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef: discard + of nkLambdaKinds, nkIteratorDef: + if n.typ != nil: + discard liftCapturedVars(n[namePos], owner, d, c) else: if owner.isIterator and n.kind == nkYieldStmt: result = transformYield(n, owner, d, c) @@ -660,8 +666,8 @@ proc liftLambdas*(fn: PSym, body: PNode): PNode = result = wrapIterBody(newBody, fn) else: result = body - if fn.name.s == "outer": - echo renderTree(result, {renderIds}) + #if fn.name.s == "outer": + # echo renderTree(result, {renderIds}) proc liftLambdasForTopLevel*(module: PSym, body: PNode): PNode = if body.kind == nkEmpty or gCmd == cmdCompileToJS: |