Fixed passing byvar
This commit is contained in:
parent
3a01eab4df
commit
a66b968d3b
2 changed files with 33 additions and 5 deletions
|
|
@ -1032,7 +1032,7 @@ proc genDeref(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
if a.typ != etyBaseIndex: internalError(n.info, "genDeref")
|
if a.typ != etyBaseIndex: internalError(n.info, "genDeref")
|
||||||
r.res = "$1[$2]" % [a.address, a.res]
|
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
|
var a: TCompRes
|
||||||
gen(p, n, a)
|
gen(p, n, a)
|
||||||
if a.typ == etyBaseIndex:
|
if a.typ == etyBaseIndex:
|
||||||
|
|
@ -1042,6 +1042,20 @@ proc genArg(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
else:
|
else:
|
||||||
add(r.res, a.res)
|
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) =
|
proc genArgs(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
add(r.res, "(")
|
add(r.res, "(")
|
||||||
var hasArgs = false
|
var hasArgs = false
|
||||||
|
|
@ -1052,13 +1066,17 @@ proc genArgs(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
|
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
|
var paramType : PNode = nil
|
||||||
if i < sonsLen(typ):
|
if i < sonsLen(typ):
|
||||||
assert(typ.n.sons[i].kind == nkSym)
|
assert(typ.n.sons[i].kind == nkSym)
|
||||||
let paramType = typ.n.sons[i]
|
paramType = typ.n.sons[i]
|
||||||
if paramType.typ.isCompileTimeOnly: continue
|
if paramType.typ.isCompileTimeOnly: continue
|
||||||
|
|
||||||
if hasArgs: add(r.res, ", ")
|
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
|
hasArgs = true
|
||||||
add(r.res, ")")
|
add(r.res, ")")
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
|
|
@ -1083,7 +1101,7 @@ proc genInfixCall(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
add(r.res, "(")
|
add(r.res, "(")
|
||||||
for i in countup(2, sonsLen(n) - 1):
|
for i in countup(2, sonsLen(n) - 1):
|
||||||
if i > 2: add(r.res, ", ")
|
if i > 2: add(r.res, ", ")
|
||||||
genArg(p, n.sons[i], r)
|
genArgNoParam(p, n.sons[i], r)
|
||||||
add(r.res, ")")
|
add(r.res, ")")
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
|
|
||||||
|
|
@ -1097,7 +1115,7 @@ proc genEcho(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.typ.isCompileTimeOnly: continue
|
if it.typ.isCompileTimeOnly: continue
|
||||||
if i > 0: add(r.res, ", ")
|
if i > 0: add(r.res, ", ")
|
||||||
genArg(p, it, r)
|
genArgNoParam(p, it, r)
|
||||||
add(r.res, ")")
|
add(r.res, ")")
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,13 @@ proc main =
|
||||||
echo y
|
echo y
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# Test: pass var seq to var openarray
|
||||||
|
var s = @[2, 1]
|
||||||
|
proc foo(a: var openarray[int]) = a[0] = 123
|
||||||
|
|
||||||
|
proc bar(s: var seq[int], a: int) =
|
||||||
|
doAssert(a == 5)
|
||||||
|
foo(s)
|
||||||
|
s.bar(5)
|
||||||
|
doAssert(s == @[123, 1])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue