fixes #3221
This commit is contained in:
parent
3fc95ce69e
commit
9c9a7b6520
2 changed files with 44 additions and 1 deletions
|
|
@ -474,12 +474,14 @@ proc transformConv(c: PTransf, n: PNode): PTransNode =
|
||||||
|
|
||||||
type
|
type
|
||||||
TPutArgInto = enum
|
TPutArgInto = enum
|
||||||
paDirectMapping, paFastAsgn, paVarAsgn
|
paDirectMapping, paFastAsgn, paVarAsgn, paComplexOpenarray
|
||||||
|
|
||||||
proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
||||||
# This analyses how to treat the mapping "formal <-> arg" in an
|
# This analyses how to treat the mapping "formal <-> arg" in an
|
||||||
# inline context.
|
# inline context.
|
||||||
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
|
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
|
||||||
|
if arg.kind == nkStmtListExpr:
|
||||||
|
return paComplexOpenarray
|
||||||
return paDirectMapping # XXX really correct?
|
return paDirectMapping # XXX really correct?
|
||||||
# what if ``arg`` has side-effects?
|
# what if ``arg`` has side-effects?
|
||||||
case arg.kind
|
case arg.kind
|
||||||
|
|
@ -569,6 +571,14 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
assert(skipTypes(formal.typ, abstractInst).kind == tyVar)
|
assert(skipTypes(formal.typ, abstractInst).kind == tyVar)
|
||||||
idNodeTablePut(newC.mapping, formal, arg)
|
idNodeTablePut(newC.mapping, formal, arg)
|
||||||
# XXX BUG still not correct if the arg has a side effect!
|
# XXX BUG still not correct if the arg has a side effect!
|
||||||
|
of paComplexOpenarray:
|
||||||
|
let typ = newType(tySequence, formal.owner)
|
||||||
|
addSonSkipIntLit(typ, formal.typ.sons[0])
|
||||||
|
var temp = newTemp(c, typ, formal.info)
|
||||||
|
addVar(v, temp)
|
||||||
|
add(stmtList, newAsgnStmt(c, temp, arg.PTransNode))
|
||||||
|
idNodeTablePut(newC.mapping, formal, temp)
|
||||||
|
|
||||||
var body = iter.getBody.copyTree
|
var body = iter.getBody.copyTree
|
||||||
pushInfoContext(n.info)
|
pushInfoContext(n.info)
|
||||||
# XXX optimize this somehow. But the check "c.inlining" is not correct:
|
# XXX optimize this somehow. But the check "c.inlining" is not correct:
|
||||||
|
|
|
||||||
33
tests/iter/tcomplex_openarray.nim
Normal file
33
tests/iter/tcomplex_openarray.nim
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
# bug #3221
|
||||||
|
|
||||||
|
import algorithm, math, sequtils
|
||||||
|
|
||||||
|
|
||||||
|
iterator permutations[T](ys: openarray[T]): seq[T] =
|
||||||
|
var
|
||||||
|
d = 1
|
||||||
|
c = newSeq[int](ys.len)
|
||||||
|
xs = newSeq[T](ys.len)
|
||||||
|
for i, y in ys: xs[i] = y
|
||||||
|
yield xs
|
||||||
|
block outer:
|
||||||
|
while true:
|
||||||
|
while d > 1:
|
||||||
|
dec d
|
||||||
|
c[d] = 0
|
||||||
|
while c[d] >= d:
|
||||||
|
inc d
|
||||||
|
if d >= ys.len: break outer
|
||||||
|
let i = if (d and 1) == 1: c[d] else: 0
|
||||||
|
swap xs[i], xs[d]
|
||||||
|
yield xs
|
||||||
|
inc c[d]
|
||||||
|
|
||||||
|
proc dig_vectors(): void =
|
||||||
|
var v_nums: seq[int]
|
||||||
|
v_nums = newSeq[int](1)
|
||||||
|
for perm in permutations(toSeq(0 .. 1)):
|
||||||
|
v_nums[0] = 1
|
||||||
|
|
||||||
|
dig_vectors()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue