--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) =
|
||||
let op = opr
|
||||
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:
|
||||
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator is generic")
|
||||
patchHead op
|
||||
|
|
|
|||
|
|
@ -1427,6 +1427,12 @@ proc maybeAddResult(c: PContext, s: PSym, n: PNode) =
|
|||
addResult(c, s.typ.sons[0], n.info, s.kind)
|
||||
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) =
|
||||
case s.name.s.normalize
|
||||
of "=destroy":
|
||||
|
|
@ -1440,6 +1446,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
|||
elif obj.kind == tyGenericInvocation: obj = obj.sons[0]
|
||||
else: break
|
||||
if obj.kind in {tyObject, tyDistinct, tySequence, tyString}:
|
||||
obj = canonType(c, obj)
|
||||
if obj.destructor.isNil:
|
||||
obj.destructor = s
|
||||
else:
|
||||
|
|
@ -1491,6 +1498,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
|||
objB = objB.sons[0]
|
||||
else: break
|
||||
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)
|
||||
if opr[].isNil:
|
||||
opr[] = s
|
||||
|
|
|
|||
|
|
@ -1551,10 +1551,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
|||
# XXX figure out why this has children already...
|
||||
result.sons.setLen 0
|
||||
result.n = nil
|
||||
if c.config.selectedGc == gcDestructors:
|
||||
result.flags = {tfHasAsgn}
|
||||
else:
|
||||
result.flags = {}
|
||||
result.flags = {tfHasAsgn}
|
||||
semContainerArg(c, n, "seq", result)
|
||||
else:
|
||||
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.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
|
||||
PayloadBase = object
|
||||
|
|
|
|||
|
|
@ -3431,6 +3431,10 @@ when not defined(JS): #and not defined(nimscript):
|
|||
when defined(memtracker):
|
||||
include "system/memtracker"
|
||||
|
||||
when defined(gcDestructors):
|
||||
include "core/strs"
|
||||
include "core/seqs"
|
||||
|
||||
when hostOS == "standalone":
|
||||
include "system/embedded"
|
||||
else:
|
||||
|
|
@ -3479,10 +3483,7 @@ when not defined(JS): #and not defined(nimscript):
|
|||
{.pop.}
|
||||
{.push stack_trace: off, profiler:off.}
|
||||
when hasAlloc:
|
||||
when defined(gcDestructors):
|
||||
include "core/strs"
|
||||
include "core/seqs"
|
||||
else:
|
||||
when not defined(gcDestructors):
|
||||
include "system/sysstr"
|
||||
{.pop.}
|
||||
when hasAlloc: include "system/strmantle"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue