diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-06-23 01:44:08 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-06-23 01:45:10 +0200 |
commit | ad8784eef094cdcc4d8ac87837808239d0cb78f7 (patch) | |
tree | 01434b014a4b3ba02e6d2d9a93edff9c6aefd482 | |
parent | d68dec11cecdbb25dc0a42bde4474831d4333d18 (diff) | |
download | Nim-ad8784eef094cdcc4d8ac87837808239d0cb78f7.tar.gz |
PHP codegen: code works with PHP 5.3 (with some luck)
-rw-r--r-- | compiler/jsgen.nim | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 73b627f91..8a631bb66 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1690,7 +1690,29 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mMinusSet: binaryExpr(p, n, r, "SetMinus", "SetMinus($1, $2)") of mIncl: binaryExpr(p, n, r, "", "$1[$2] = true") of mExcl: binaryExpr(p, n, r, "", "delete $1[$2]" | "unset $1[$2]") - of mInSet: binaryExpr(p, n, r, "", "($1[$2] != undefined)" | "isset($1[$2])") + of mInSet: + if p.target == targetJS: + binaryExpr(p, n, r, "", "($1[$2] != undefined)") + else: + let s = n.sons[1] + if s.kind == nkCurly: + var a, b, x: TCompRes + gen(p, n.sons[2], x) + r.res = rope("(") + r.kind = resExpr + for i in countup(0, sonsLen(s) - 1): + if i > 0: add(r.res, " || ") + var it = s.sons[i] + if it.kind == nkRange: + gen(p, it.sons[0], a) + gen(p, it.sons[1], b) + addf(r.res, "($1 >= $2 && $1 <= $3)", [x.res, a.res, b.res,]) + else: + gen(p, it, a) + addf(r.res, "($1 == $2)", [x.res, a.res]) + add(r.res, ")") + else: + binaryExpr(p, n, r, "", "isset($1[$2])") of mNewSeq: genNewSeq(p, n) of mOf: genOf(p, n, r) of mReset: genReset(p, n) |