diff options
author | hlaaftana <10591326+hlaaftana@users.noreply.github.com> | 2020-04-29 09:59:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 08:59:08 +0200 |
commit | 800ce5b9507469d1d8e87d4e7730e2f1750dc8d7 (patch) | |
tree | 85c8073b4bcd01ef17056b6fae76d02846058005 /compiler | |
parent | 3b5a504692495324afdb7c20159122e66100f767 (diff) | |
download | Nim-800ce5b9507469d1d8e87d4e7730e2f1750dc8d7.tar.gz |
Fix negative indexed arrays for JS, refs #13966 (#14152)
* Fix negative arrays for JS, refs #13966 * small extra fix: no need to .slice() cstring in JS
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/jsgen.nim | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 27c4e0e2a..751c043c5 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1161,9 +1161,9 @@ proc genArrayAddr(p: PProc, n: PNode, r: var TCompRes) = first = firstOrd(p.config, typ[0]) if optBoundsCheck in p.options: useMagic(p, "chckIndx") - r.res = "chckIndx($1, $2, ($3 != null ? $3.length : 0)+$2-1)-$2" % [b.res, rope(first), tmp] + r.res = "chckIndx($1, $2, ($3 != null ? $3.length : 0)+$2-1)-($2)" % [b.res, rope(first), tmp] elif first != 0: - r.res = "($1)-$2" % [b.res, rope(first)] + r.res = "($1)-($2)" % [b.res, rope(first)] else: r.res = b.res r.kind = resExpr @@ -1897,8 +1897,8 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = let rhsIsLit = n[2].kind in nkStrKinds let (a, tmp) = maybeMakeTemp(p, n[1], lhs) if skipTypes(n[1].typ, abstractVarRange).kind == tyCString: - r.res = "if ($1 != null) { $4 += $2; } else { $4 = $2$3; }" % [ - a, rhs.rdLoc, if rhsIsLit: nil else: ~".slice()", tmp] + r.res = "if ($1 != null) { $3 += $2; } else { $3 = $2; }" % [ + a, rhs.rdLoc, tmp] else: r.res = "if ($1 != null) { $4 = ($4).concat($2); } else { $4 = $2$3; }" % [ lhs.rdLoc, rhs.rdLoc, if rhsIsLit: nil else: ~".slice()", tmp] |