diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-09-12 23:04:11 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-09-12 23:04:19 +0200 |
commit | d165364aac3cf62ca8bb8ef3ad957f7a03a45580 (patch) | |
tree | 3dfefbc02b84b6a3678206fe84ef0372d65bee4e | |
parent | 568de6013f3cb8ffb01438b860a7243b498f5059 (diff) | |
download | Nim-d165364aac3cf62ca8bb8ef3ad957f7a03a45580.tar.gz |
minor steps to make closure iterators work with the JS backend
-rw-r--r-- | compiler/lambdalifting.nim | 7 |
1 files changed, 7 insertions, 0 deletions
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") |