diff options
author | Andrii Riabushenko <cdome@bk.ru> | 2018-11-30 09:47:55 +0000 |
---|---|---|
committer | Andrii Riabushenko <cdome@bk.ru> | 2018-11-30 09:47:55 +0000 |
commit | ca473d0f94cc27cd318b69b9f4ff63f842d4ebec (patch) | |
tree | 6737e21233a36e212ffae3d100d1a388fae9a87e /compiler | |
parent | 6459d4ec728462850660c1723c9a871c6670307d (diff) | |
download | Nim-ca473d0f94cc27cd318b69b9f4ff63f842d4ebec.tar.gz |
add array constructors
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/destroyer.nim | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index a4bed4674..a26a4d379 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -426,7 +426,7 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = result.add arg[0] for i in 1..<arg.len: result.add pArg(arg[i], c, i < L and parameters[i].kind == tySink) - elif arg.kind in {nkObjConstr, nkTupleConstr, nkCharLit..nkFloat128Lit}: + elif arg.kind in {nkBracket, nkObjConstr, nkTupleConstr, nkBracket, nkCharLit..nkFloat128Lit}: discard "object construction to sink parameter: nothing to do" result = arg elif arg.kind == nkSym and arg.sym.kind in InterestingSyms and isLastRead(arg, c): @@ -535,25 +535,31 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = branch = copyNode(ri[i]) branch.add moveOrCopyIfTyped(ri[i][0]) result.add branch + of nkBracket: + # array constructor + let ri2 = copyTree(ri) + for i in 0..<ri.len: + # everything that is passed to an array constructor is consumed, + # so these all act like 'sink' parameters: + ri2[i] = pArg(ri[i], c, isSink = true) + result = genSink(c, dest.typ, dest, ri2) of nkObjConstr: - result = genSink(c, dest.typ, dest, ri) let ri2 = copyTree(ri) for i in 1..<ri.len: # everything that is passed to an object constructor is consumed, # so these all act like 'sink' parameters: - ri2[i].sons[1] = pArg(ri[i][1], c, isSink = true) - result.add ri2 + ri2[i][1] = pArg(ri[i][1], c, isSink = true) + result = genSink(c, dest.typ, dest, ri2) of nkTupleConstr: - result = genSink(c, dest.typ, dest, ri) let ri2 = copyTree(ri) for i in 0..<ri.len: # everything that is passed to an tuple constructor is consumed, # so these all act like 'sink' parameters: if ri[i].kind == nkExprColonExpr: - ri2[i].sons[1] = pArg(ri[i][1], c, isSink = true) + ri2[i][1] = pArg(ri[i][1], c, isSink = true) else: ri2[i] = pArg(ri[i], c, isSink = true) - result.add ri2 + result = genSink(c, dest.typ, dest, ri2) of nkSym: if ri.sym.kind != skParam and isLastRead(ri, c): # Rule 3: `=sink`(x, z); wasMoved(z) |