summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorHans Raaf <hara@oderwat.de>2016-08-07 03:42:24 +0200
committerHans Raaf <hara@oderwat.de>2016-08-07 03:48:20 +0200
commitbb683cb9839633a1f58a9f44fa994d4c803dd124 (patch)
tree2320539478491eeabbcf1c3acfa04fe14ae120fe /compiler
parent872f3a4ab1fcc9f4467fa92e3e34e9f2afe9000b (diff)
downloadNim-bb683cb9839633a1f58a9f44fa994d4c803dd124.tar.gz
Fix using ptr to seq in js backend.
I suddenly got ReferenceError exceptions for some of the code which is
using etyBaseIndex ptr. Initialising the xxx_Idx part of the variable
fixes this problem.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 244bba681..a0b54812f 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1445,8 +1445,11 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) =
     a: TCompRes
     s: Rope
   if n.kind == nkEmpty:
+    let mname = mangleName(v, p.target)
     addf(p.body, "var $1 = $2;$n" | "$$$1 = $2;$n",
-         [mangleName(v, p.target), createVar(p, v.typ, isIndirect(v))])
+         [mname, createVar(p, v.typ, isIndirect(v))])
+    if v.typ.kind in { tyVar, tyPtr, tyRef } and mapType(p, v.typ) == etyBaseIndex:
+      addf(p.body, "var $1_Idx = 0;$n", [ mname ])
   else:
     discard mangleName(v, p.target)
     gen(p, n, a)
@@ -1948,9 +1951,13 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
   let header = generateHeader(p, prc.typ)
   if prc.typ.sons[0] != nil and sfPure notin prc.flags:
     resultSym = prc.ast.sons[resultPos].sym
+    let mname = mangleName(resultSym, p.target)
     resultAsgn = ("var $# = $#;$n" | "$$$# = $#;$n") % [
-        mangleName(resultSym, p.target),
+        mname,
         createVar(p, resultSym.typ, isIndirect(resultSym))]
+    if resultSym.typ.kind in { tyVar, tyPtr, tyRef } and mapType(p, resultSym.typ) == etyBaseIndex:
+      resultAsgn.add "var $#_Idx = 0;$n" % [
+        mname ];
     gen(p, prc.ast.sons[resultPos], a)
     if mapType(p, resultSym.typ) == etyBaseIndex:
       returnStmt = "return [$#, $#];$n" % [a.address, a.res]