allows a destructor to be attached to a tyString/tySequence
This commit is contained in:
parent
4ec91a30c4
commit
ef4b755183
4 changed files with 28 additions and 17 deletions
|
|
@ -1088,9 +1088,9 @@ proc newSym*(symKind: TSymKind, name: PIdent, owner: PSym,
|
||||||
result.id = getID()
|
result.id = getID()
|
||||||
when debugIds:
|
when debugIds:
|
||||||
registerId(result)
|
registerId(result)
|
||||||
#if result.id == 93289:
|
#if result.id == 77131:
|
||||||
# writeStacktrace()
|
# writeStacktrace()
|
||||||
# MessageOut(name.s & " has id: " & toString(result.id))
|
# echo name.s
|
||||||
|
|
||||||
proc isMetaType*(t: PType): bool =
|
proc isMetaType*(t: PType): bool =
|
||||||
return t.kind in tyMetaTypes or
|
return t.kind in tyMetaTypes or
|
||||||
|
|
@ -1272,7 +1272,7 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
|
||||||
when debugIds:
|
when debugIds:
|
||||||
registerId(result)
|
registerId(result)
|
||||||
when false:
|
when false:
|
||||||
if result.id == 205734:
|
if result.id == 76426:
|
||||||
echo "KNID ", kind
|
echo "KNID ", kind
|
||||||
writeStackTrace()
|
writeStackTrace()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1017,8 +1017,8 @@ proc checkForMetaFields(c: PContext; n: PNode) =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyLent, tyPtr, tyRef,
|
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyLent, tyPtr, tyRef,
|
||||||
tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink:
|
tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink:
|
||||||
let start = int ord(t.kind in {tyGenericInvocation, tyGenericInst})
|
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
|
||||||
for i in start ..< t.sons.len:
|
for i in start ..< t.len:
|
||||||
checkMeta(t.sons[i])
|
checkMeta(t.sons[i])
|
||||||
else:
|
else:
|
||||||
checkMeta(t)
|
checkMeta(t)
|
||||||
|
|
@ -1337,7 +1337,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
if obj.kind in {tyGenericBody, tyGenericInst}: obj = obj.lastSon
|
if obj.kind in {tyGenericBody, tyGenericInst}: obj = obj.lastSon
|
||||||
elif obj.kind == tyGenericInvocation: obj = obj.sons[0]
|
elif obj.kind == tyGenericInvocation: obj = obj.sons[0]
|
||||||
else: break
|
else: break
|
||||||
if obj.kind in {tyObject, tyDistinct}:
|
if obj.kind in {tyObject, tyDistinct, tySequence, tyString}:
|
||||||
if obj.destructor.isNil:
|
if obj.destructor.isNil:
|
||||||
obj.destructor = s
|
obj.destructor = s
|
||||||
else:
|
else:
|
||||||
|
|
@ -1359,7 +1359,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
if t.kind == tyGenericBody: t = t.lastSon
|
if t.kind == tyGenericBody: t = t.lastSon
|
||||||
elif t.kind == tyGenericInvocation: t = t.sons[0]
|
elif t.kind == tyGenericInvocation: t = t.sons[0]
|
||||||
else: break
|
else: break
|
||||||
if t.kind in {tyObject, tyDistinct, tyEnum}:
|
if t.kind in {tyObject, tyDistinct, tyEnum, tySequence, tyString}:
|
||||||
if t.deepCopy.isNil: t.deepCopy = s
|
if t.deepCopy.isNil: t.deepCopy = s
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.info, errGenerated,
|
localError(c.config, n.info, errGenerated,
|
||||||
|
|
@ -1388,7 +1388,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
elif objB.kind in {tyGenericInvocation, tyGenericInst}:
|
elif objB.kind in {tyGenericInvocation, tyGenericInst}:
|
||||||
objB = objB.sons[0]
|
objB = objB.sons[0]
|
||||||
else: break
|
else: break
|
||||||
if obj.kind in {tyObject, tyDistinct} and sameType(obj, objB):
|
if obj.kind in {tyObject, tyDistinct, tySequence, tyString} and sameType(obj, objB):
|
||||||
let opr = if s.name.s == "=": addr(obj.assignment) else: addr(obj.sink)
|
let opr = if s.name.s == "=": addr(obj.assignment) else: addr(obj.sink)
|
||||||
if opr[].isNil:
|
if opr[].isNil:
|
||||||
opr[] = s
|
opr[] = s
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ when false:
|
||||||
proc `=trace`[T](s: NimSeqV2[T]) =
|
proc `=trace`[T](s: NimSeqV2[T]) =
|
||||||
for i in 0 ..< s.len: `=trace`(s.data[i])
|
for i in 0 ..< s.len: `=trace`(s.data[i])
|
||||||
|
|
||||||
proc `=destroy`[T](x: var NimSeqV2[T]) =
|
proc `=destroy`[T](s: var seq[T]) =
|
||||||
|
var x = cast[ptr NimSeqV2[T]](addr s)
|
||||||
var p = x.p
|
var p = x.p
|
||||||
if p != nil:
|
if p != nil:
|
||||||
when not supportsCopyMem(T):
|
when not supportsCopyMem(T):
|
||||||
|
|
@ -43,7 +44,10 @@ proc `=destroy`[T](x: var NimSeqV2[T]) =
|
||||||
x.p = nil
|
x.p = nil
|
||||||
x.len = 0
|
x.len = 0
|
||||||
|
|
||||||
proc `=`[T](a: var NimSeqV2[T]; b: NimSeqV2[T]) =
|
proc `=`[T](x: var seq[T]; y: seq[T]) =
|
||||||
|
var a = cast[ptr NimSeqV2[T]](addr x)
|
||||||
|
var b = cast[ptr NimSeqV2[T]](unsafeAddr y)
|
||||||
|
|
||||||
if a.p == b.p: return
|
if a.p == b.p: return
|
||||||
`=destroy`(a)
|
`=destroy`(a)
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
|
|
@ -56,7 +60,9 @@ proc `=`[T](a: var NimSeqV2[T]; b: NimSeqV2[T]) =
|
||||||
for i in 0..<a.len:
|
for i in 0..<a.len:
|
||||||
a.p.data[i] = b.p.data[i]
|
a.p.data[i] = b.p.data[i]
|
||||||
|
|
||||||
proc `=sink`[T](a: var NimSeqV2[T]; b: NimSeqV2[T]) =
|
proc `=sink`[T](x: var seq[T]; y: seq[T]) =
|
||||||
|
var a = cast[ptr NimSeqV2[T]](addr x)
|
||||||
|
var b = cast[ptr NimSeqV2[T]](unsafeAddr y)
|
||||||
if a.p != nil and a.p != b.p:
|
if a.p != nil and a.p != b.p:
|
||||||
`=destroy`(a)
|
`=destroy`(a)
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
|
|
|
||||||
|
|
@ -45,22 +45,27 @@ template frees(s) =
|
||||||
if not isLiteral(s):
|
if not isLiteral(s):
|
||||||
s.p.region.dealloc(s.p.region, s.p, contentSize(s.p.cap))
|
s.p.region.dealloc(s.p.region, s.p, contentSize(s.p.cap))
|
||||||
|
|
||||||
proc `=destroy`(s: var NimStringV2) =
|
proc `=destroy`(s: var string) =
|
||||||
frees(s)
|
var a = cast[ptr NimStringV2[T]](addr s)
|
||||||
s.len = 0
|
frees(a)
|
||||||
s.p = nil
|
a.len = 0
|
||||||
|
a.p = nil
|
||||||
|
|
||||||
template lose(a) =
|
template lose(a) =
|
||||||
frees(a)
|
frees(a)
|
||||||
|
|
||||||
proc `=sink`(a: var NimStringV2, b: NimStringV2) =
|
proc `=sink`(x: var string, y: string) =
|
||||||
|
var a = cast[ptr NimStringV2](addr x)
|
||||||
|
var b = cast[ptr NimStringV2](unsafeAddr y)
|
||||||
# we hope this is optimized away for not yet alive objects:
|
# we hope this is optimized away for not yet alive objects:
|
||||||
if unlikely(a.p == b.p): return
|
if unlikely(a.p == b.p): return
|
||||||
lose(a)
|
lose(a)
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
a.p = b.p
|
a.p = b.p
|
||||||
|
|
||||||
proc `=`(a: var NimStringV2; b: NimStringV2) =
|
proc `=`(x: var string, y: string) =
|
||||||
|
var a = cast[ptr NimStringV2](addr x)
|
||||||
|
var b = cast[ptr NimStringV2](unsafeAddr y)
|
||||||
if unlikely(a.p == b.p): return
|
if unlikely(a.p == b.p): return
|
||||||
lose(a)
|
lose(a)
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue