--gc:destructors: baby steps
This commit is contained in:
parent
446f911a17
commit
e3a668a33b
5 changed files with 27 additions and 25 deletions
|
|
@ -296,7 +296,8 @@ proc makePtrType(c: Con, baseType: PType): PType =
|
||||||
template genOp(opr, opname, ri) =
|
template genOp(opr, opname, ri) =
|
||||||
let op = opr
|
let op = opr
|
||||||
if op == nil:
|
if op == nil:
|
||||||
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator not found for type " & typeToString(t))
|
globalError(c.graph.config, dest.info, "internal error: '" & opname &
|
||||||
|
"' operator not found for type " & typeToString(t))
|
||||||
elif op.ast[genericParamsPos].kind != nkEmpty:
|
elif op.ast[genericParamsPos].kind != nkEmpty:
|
||||||
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator is generic")
|
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator is generic")
|
||||||
patchHead op
|
patchHead op
|
||||||
|
|
|
||||||
|
|
@ -1427,6 +1427,12 @@ proc maybeAddResult(c: PContext, s: PSym, n: PNode) =
|
||||||
addResult(c, s.typ.sons[0], n.info, s.kind)
|
addResult(c, s.typ.sons[0], n.info, s.kind)
|
||||||
addResultNode(c, n)
|
addResultNode(c, n)
|
||||||
|
|
||||||
|
proc canonType(c: PContext, t: PType): PType =
|
||||||
|
if t.kind == tySequence:
|
||||||
|
result = c.graph.sysTypes[tySequence]
|
||||||
|
else:
|
||||||
|
result = t
|
||||||
|
|
||||||
proc semOverride(c: PContext, s: PSym, n: PNode) =
|
proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
case s.name.s.normalize
|
case s.name.s.normalize
|
||||||
of "=destroy":
|
of "=destroy":
|
||||||
|
|
@ -1440,6 +1446,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
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, tySequence, tyString}:
|
if obj.kind in {tyObject, tyDistinct, tySequence, tyString}:
|
||||||
|
obj = canonType(c, obj)
|
||||||
if obj.destructor.isNil:
|
if obj.destructor.isNil:
|
||||||
obj.destructor = s
|
obj.destructor = s
|
||||||
else:
|
else:
|
||||||
|
|
@ -1491,6 +1498,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
objB = objB.sons[0]
|
objB = objB.sons[0]
|
||||||
else: break
|
else: break
|
||||||
if obj.kind in {tyObject, tyDistinct, tySequence, tyString} and sameType(obj, objB):
|
if obj.kind in {tyObject, tyDistinct, tySequence, tyString} and sameType(obj, objB):
|
||||||
|
# attach these ops to the canonical tySequence
|
||||||
|
obj = canonType(c, obj)
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -1551,10 +1551,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
# XXX figure out why this has children already...
|
# XXX figure out why this has children already...
|
||||||
result.sons.setLen 0
|
result.sons.setLen 0
|
||||||
result.n = nil
|
result.n = nil
|
||||||
if c.config.selectedGc == gcDestructors:
|
result.flags = {tfHasAsgn}
|
||||||
result.flags = {tfHasAsgn}
|
|
||||||
else:
|
|
||||||
result.flags = {}
|
|
||||||
semContainerArg(c, n, "seq", result)
|
semContainerArg(c, n, "seq", result)
|
||||||
else:
|
else:
|
||||||
result = semContainer(c, n, tySequence, "seq", prev)
|
result = semContainer(c, n, tySequence, "seq", prev)
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,6 @@ proc `=sink`[T](x: var seq[T]; y: seq[T]) =
|
||||||
a.len = b.len
|
a.len = b.len
|
||||||
a.p = b.p
|
a.p = b.p
|
||||||
|
|
||||||
when false:
|
|
||||||
proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.}
|
|
||||||
proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {.
|
|
||||||
compilerRtl.}
|
|
||||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.}
|
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
PayloadBase = object
|
PayloadBase = object
|
||||||
|
|
|
||||||
|
|
@ -3431,6 +3431,10 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
when defined(memtracker):
|
when defined(memtracker):
|
||||||
include "system/memtracker"
|
include "system/memtracker"
|
||||||
|
|
||||||
|
when defined(gcDestructors):
|
||||||
|
include "core/strs"
|
||||||
|
include "core/seqs"
|
||||||
|
|
||||||
when hostOS == "standalone":
|
when hostOS == "standalone":
|
||||||
include "system/embedded"
|
include "system/embedded"
|
||||||
else:
|
else:
|
||||||
|
|
@ -3479,10 +3483,7 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
{.pop.}
|
{.pop.}
|
||||||
{.push stack_trace: off, profiler:off.}
|
{.push stack_trace: off, profiler:off.}
|
||||||
when hasAlloc:
|
when hasAlloc:
|
||||||
when defined(gcDestructors):
|
when not defined(gcDestructors):
|
||||||
include "core/strs"
|
|
||||||
include "core/seqs"
|
|
||||||
else:
|
|
||||||
include "system/sysstr"
|
include "system/sysstr"
|
||||||
{.pop.}
|
{.pop.}
|
||||||
when hasAlloc: include "system/strmantle"
|
when hasAlloc: include "system/strmantle"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue