--gc:destructors: hello world example compiles and runs

This commit is contained in:
Araq
2018-11-16 00:13:39 +01:00
parent 2eb14bdd41
commit 4bd9f32f33
4 changed files with 13 additions and 3 deletions

View File

@@ -1580,8 +1580,17 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
else: putIntoDest(p, d, e, rope(lengthOrd(p.config, typ)))
else: internalError(p.config, e.info, "genArrayLen()")
proc makePtrType(baseType: PType): PType =
result = newType(tyPtr, baseType.owner)
addSonSkipIntLit(result, baseType)
proc makeAddr(n: PNode): PNode =
result = newTree(nkHiddenAddr, n)
result.typ = makePtrType(n.typ)
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
if p.config.selectedGc == gcDestructors:
e.sons[1] = makeAddr(e[1])
genCall(p, e, d)
return
var a, b, call: TLoc
@@ -1963,6 +1972,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mAppendStrStr: genStrAppend(p, e, d)
of mAppendSeqElem:
if p.config.selectedGc == gcDestructors:
e.sons[1] = makeAddr(e[1])
genCall(p, e, d)
else:
genSeqElemAppend(p, e, d)

View File

@@ -69,7 +69,7 @@ proc genStringLiteralV2(m: BModule; n: PNode): Rope =
addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n",
[result, rope(len(n.strVal)), pureLit])
else:
result = m.tmpBase & rope(id)
result = m.tmpBase & rope(id+1)
proc genStringLiteralV2Const(m: BModule; n: PNode): Rope =
let id = nodeTableTestOrSet(m.dataCache, n, m.labels)

View File

@@ -1213,8 +1213,8 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope =
let x = fakeClosureType(m, t.owner)
genTupleInfo(m, x, x, result, info)
of tySequence:
genTypeInfoAux(m, t, t, result, info)
if m.config.selectedGC != gcDestructors:
genTypeInfoAux(m, t, t, result, info)
if m.config.selectedGC >= gcMarkAndSweep:
let markerProc = genTraverseProc(m, origType, sig)
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])

View File

@@ -125,7 +125,7 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) =
if newLen <= oldLen: return
var xu = cast[ptr NimSeqV2[T]](addr x)
xu.p = prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T))
xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T)))
xu.len = newLen
for i in oldLen .. newLen-1:
x.data[i] = value