summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2015-08-28 18:28:54 +0200
committerAndreas Rumpf <rumpf_a@web.de>2015-08-28 18:28:54 +0200
commitc718e0eb2d57a68f6f3792dd28b5435a7b061345 (patch)
tree1cfd917ac952a90155104b380a8b305baff31ca7 /compiler
parent3452f6ce4195db096346935fec02eb03c5877788 (diff)
parenta66b968d3bc278a669e2350762eda894b100c511 (diff)
downloadNim-c718e0eb2d57a68f6f3792dd28b5435a7b061345.tar.gz
Merge pull request #3242 from yglukhov/byvar-fix
JS: Fixed passing byvar
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim28
1 files changed, 23 insertions, 5 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 4a0e22db7..c72365cce 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1032,7 +1032,7 @@ proc genDeref(p: PProc, n: PNode, r: var TCompRes) =
     if a.typ != etyBaseIndex: internalError(n.info, "genDeref")
     r.res = "$1[$2]" % [a.address, a.res]
 
-proc genArg(p: PProc, n: PNode, r: var TCompRes) =
+proc genArgNoParam(p: PProc, n: PNode, r: var TCompRes) =
   var a: TCompRes
   gen(p, n, a)
   if a.typ == etyBaseIndex:
@@ -1042,6 +1042,20 @@ proc genArg(p: PProc, n: PNode, r: var TCompRes) =
   else:
     add(r.res, a.res)
 
+proc genArg(p: PProc, n: PNode, param: PSym, r: var TCompRes) =
+  var a: TCompRes
+  gen(p, n, a)
+  if skipTypes(param.typ, abstractVar).kind in {tyOpenArray, tyVarargs} and
+      a.typ == etyBaseIndex:
+    add(r.res, "$1[$2]" % [a.address, a.res])
+  elif a.typ == etyBaseIndex:
+    add(r.res, a.address)
+    add(r.res, ", ")
+    add(r.res, a.res)
+  else:
+    add(r.res, a.res)
+
+
 proc genArgs(p: PProc, n: PNode, r: var TCompRes) =
   add(r.res, "(")
   var hasArgs = false
@@ -1052,13 +1066,17 @@ proc genArgs(p: PProc, n: PNode, r: var TCompRes) =
 
   for i in countup(1, sonsLen(n) - 1):
     let it = n.sons[i]
+    var paramType : PNode = nil
     if i < sonsLen(typ):
       assert(typ.n.sons[i].kind == nkSym)
-      let paramType = typ.n.sons[i]
+      paramType = typ.n.sons[i]
       if paramType.typ.isCompileTimeOnly: continue
 
     if hasArgs: add(r.res, ", ")
-    genArg(p, it, r)
+    if paramType.isNil:
+      genArgNoParam(p, it, r)
+    else:
+      genArg(p, it, paramType.sym, r)
     hasArgs = true
   add(r.res, ")")
   r.kind = resExpr
@@ -1083,7 +1101,7 @@ proc genInfixCall(p: PProc, n: PNode, r: var TCompRes) =
   add(r.res, "(")
   for i in countup(2, sonsLen(n) - 1):
     if i > 2: add(r.res, ", ")
-    genArg(p, n.sons[i], r)
+    genArgNoParam(p, n.sons[i], r)
   add(r.res, ")")
   r.kind = resExpr
 
@@ -1097,7 +1115,7 @@ proc genEcho(p: PProc, n: PNode, r: var TCompRes) =
     let it = n.sons[i]
     if it.typ.isCompileTimeOnly: continue
     if i > 0: add(r.res, ", ")
-    genArg(p, it, r)
+    genArgNoParam(p, it, r)
   add(r.res, ")")
   r.kind = resExpr