make nested custom seqs work
This commit is contained in:
parent
fa0f04968f
commit
4f633dde64
3 changed files with 21 additions and 4 deletions
|
|
@ -165,15 +165,18 @@ template interestingSym(s: PSym): bool =
|
||||||
s.owner == c.owner and s.kind in InterestingSyms and hasDestructor(s.typ)
|
s.owner == c.owner and s.kind in InterestingSyms and hasDestructor(s.typ)
|
||||||
|
|
||||||
proc genSink(t: PType; dest: PNode): PNode =
|
proc genSink(t: PType; dest: PNode): PNode =
|
||||||
|
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||||
let op = if t.sink != nil: t.sink else: t.assignment
|
let op = if t.sink != nil: t.sink else: t.assignment
|
||||||
assert op != nil
|
assert op != nil
|
||||||
result = newTree(nkCall, newSymNode(op), newTree(nkHiddenAddr, dest))
|
result = newTree(nkCall, newSymNode(op), newTree(nkHiddenAddr, dest))
|
||||||
|
|
||||||
proc genCopy(t: PType; dest: PNode): PNode =
|
proc genCopy(t: PType; dest: PNode): PNode =
|
||||||
|
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||||
assert t.assignment != nil
|
assert t.assignment != nil
|
||||||
result = newTree(nkCall, newSymNode(t.assignment), newTree(nkHiddenAddr, dest))
|
result = newTree(nkCall, newSymNode(t.assignment), newTree(nkHiddenAddr, dest))
|
||||||
|
|
||||||
proc genDestroy(t: PType; dest: PNode): PNode =
|
proc genDestroy(t: PType; dest: PNode): PNode =
|
||||||
|
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||||
assert t.destructor != nil
|
assert t.destructor != nil
|
||||||
result = newTree(nkCall, newSymNode(t.destructor), newTree(nkHiddenAddr, dest))
|
result = newTree(nkCall, newSymNode(t.destructor), newTree(nkHiddenAddr, dest))
|
||||||
|
|
||||||
|
|
@ -289,6 +292,7 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
|
||||||
result.add body
|
result.add body
|
||||||
|
|
||||||
when defined(nimDebugDestroys):
|
when defined(nimDebugDestroys):
|
||||||
|
if owner.name.s == "createSeq":
|
||||||
echo "------------------------------------"
|
echo "------------------------------------"
|
||||||
echo owner.name.s, " transformed to: "
|
echo owner.name.s, " transformed to: "
|
||||||
echo result
|
echo result
|
||||||
|
|
|
||||||
|
|
@ -320,6 +320,7 @@ proc liftTypeBoundOps*(c: PContext; typ: PType; info: TLineInfo) =
|
||||||
## to ensure we lift assignment, destructors and moves properly.
|
## to ensure we lift assignment, destructors and moves properly.
|
||||||
## The later 'destroyer' pass depends on it.
|
## The later 'destroyer' pass depends on it.
|
||||||
if not newDestructors or not hasDestructor(typ): return
|
if not newDestructors or not hasDestructor(typ): return
|
||||||
|
let typ = typ.skipTypes({tyGenericInst, tyAlias})
|
||||||
# we generate the destructor first so that other operators can depend on it:
|
# we generate the destructor first so that other operators can depend on it:
|
||||||
if typ.destructor == nil: liftBody(c, typ, attachedDestructor, info)
|
if typ.destructor == nil: liftBody(c, typ, attachedDestructor, info)
|
||||||
if typ.assignment == nil: liftBody(c, typ, attachedAsgn, info)
|
if typ.assignment == nil: liftBody(c, typ, attachedAsgn, info)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,14 @@ discard """
|
||||||
89
|
89
|
||||||
90
|
90
|
||||||
90
|
90
|
||||||
after 1 1'''
|
0 0 1
|
||||||
|
0 1 2
|
||||||
|
0 2 3
|
||||||
|
1 0 4
|
||||||
|
1 1 5
|
||||||
|
1 2 6
|
||||||
|
1 3 7
|
||||||
|
after 6 6'''
|
||||||
cmd: '''nim c --newruntime $file'''
|
cmd: '''nim c --newruntime $file'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -127,5 +134,10 @@ proc main =
|
||||||
for i in 0 ..< s.len:
|
for i in 0 ..< s.len:
|
||||||
echo s[i]
|
echo s[i]
|
||||||
|
|
||||||
|
var nested = createSeq(createSeq(1, 2, 3), createSeq(4, 5, 6, 7))
|
||||||
|
for i in 0 ..< nested.len:
|
||||||
|
for j in 0 ..< nested[i].len:
|
||||||
|
echo i, " ", j, " ", nested[i][j]
|
||||||
|
|
||||||
main()
|
main()
|
||||||
echo "after ", allocCount, " ", deallocCount
|
echo "after ", allocCount, " ", deallocCount
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue