mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 05:20:31 +00:00
make nested custom seqs work
This commit is contained in:
@@ -165,15 +165,18 @@ template interestingSym(s: PSym): bool =
|
||||
s.owner == c.owner and s.kind in InterestingSyms and hasDestructor(s.typ)
|
||||
|
||||
proc genSink(t: PType; dest: PNode): PNode =
|
||||
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||
let op = if t.sink != nil: t.sink else: t.assignment
|
||||
assert op != nil
|
||||
result = newTree(nkCall, newSymNode(op), newTree(nkHiddenAddr, dest))
|
||||
|
||||
proc genCopy(t: PType; dest: PNode): PNode =
|
||||
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||
assert t.assignment != nil
|
||||
result = newTree(nkCall, newSymNode(t.assignment), newTree(nkHiddenAddr, dest))
|
||||
|
||||
proc genDestroy(t: PType; dest: PNode): PNode =
|
||||
let t = t.skipTypes({tyGenericInst, tyAlias})
|
||||
assert t.destructor != nil
|
||||
result = newTree(nkCall, newSymNode(t.destructor), newTree(nkHiddenAddr, dest))
|
||||
|
||||
@@ -289,6 +292,7 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
|
||||
result.add body
|
||||
|
||||
when defined(nimDebugDestroys):
|
||||
echo "------------------------------------"
|
||||
echo owner.name.s, " transformed to: "
|
||||
echo result
|
||||
if owner.name.s == "createSeq":
|
||||
echo "------------------------------------"
|
||||
echo owner.name.s, " transformed to: "
|
||||
echo result
|
||||
|
||||
@@ -320,6 +320,7 @@ proc liftTypeBoundOps*(c: PContext; typ: PType; info: TLineInfo) =
|
||||
## to ensure we lift assignment, destructors and moves properly.
|
||||
## The later 'destroyer' pass depends on it.
|
||||
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:
|
||||
if typ.destructor == nil: liftBody(c, typ, attachedDestructor, info)
|
||||
if typ.assignment == nil: liftBody(c, typ, attachedAsgn, info)
|
||||
|
||||
@@ -8,7 +8,14 @@ discard """
|
||||
89
|
||||
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'''
|
||||
"""
|
||||
|
||||
@@ -127,5 +134,10 @@ proc main =
|
||||
for i in 0 ..< s.len:
|
||||
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()
|
||||
echo "after ", allocCount, " ", deallocCount
|
||||
|
||||
Reference in New Issue
Block a user