From d165364aac3cf62ca8bb8ef3ad957f7a03a45580 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf <rumpf_a@web.de> Date: Mon, 12 Sep 2016 23:04:11 +0200 Subject: minor steps to make closure iterators work with the JS backend --- compiler/lambdalifting.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 753602c80..36ad2e0a6 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -226,8 +226,14 @@ proc interestingIterVar(s: PSym): bool {.inline.} = template isIterator*(owner: PSym): bool = owner.kind == skIterator and owner.typ.callConv == ccClosure +proc liftingHarmful(owner: PSym): bool {.inline.} = + ## lambda lifting can be harmful for JS-like code generators. + let isCompileTime = sfCompileTime in owner.flags or owner.kind == skMacro + result = gCmd in {cmdCompileToPHP, cmdCompileToJS} and not isCompileTime + proc liftIterSym*(n: PNode; owner: PSym): PNode = # transforms (iter) to (let env = newClosure[iter](); (iter, env)) + if liftingHarmful(owner): return n let iter = n.sym assert iter.isIterator @@ -838,6 +844,7 @@ proc liftForLoop*(body: PNode; owner: PSym): PNode = nkBreakState(cl.state) ... """ + if liftingHarmful(owner): return body var L = body.len if not (body.kind == nkForStmt and body[L-2].kind in nkCallKinds): localError(body.info, "ignored invalid for loop") -- cgit 1.4.1-2-gfad0