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

This commit is contained in:
Araq 2018-11-16 00:13:39 +01:00
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: putIntoDest(p, d, e, rope(lengthOrd(p.config, typ)))
else: internalError(p.config, e.info, "genArrayLen()") 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) = proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
if p.config.selectedGc == gcDestructors: if p.config.selectedGc == gcDestructors:
e.sons[1] = makeAddr(e[1])
genCall(p, e, d) genCall(p, e, d)
return return
var a, b, call: TLoc 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 mAppendStrStr: genStrAppend(p, e, d)
of mAppendSeqElem: of mAppendSeqElem:
if p.config.selectedGc == gcDestructors: if p.config.selectedGc == gcDestructors:
e.sons[1] = makeAddr(e[1])
genCall(p, e, d) genCall(p, e, d)
else: else:
genSeqElemAppend(p, e, d) 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", addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n",
[result, rope(len(n.strVal)), pureLit]) [result, rope(len(n.strVal)), pureLit])
else: else:
result = m.tmpBase & rope(id) result = m.tmpBase & rope(id+1)
proc genStringLiteralV2Const(m: BModule; n: PNode): Rope = proc genStringLiteralV2Const(m: BModule; n: PNode): Rope =
let id = nodeTableTestOrSet(m.dataCache, n, m.labels) 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) let x = fakeClosureType(m, t.owner)
genTupleInfo(m, x, x, result, info) genTupleInfo(m, x, x, result, info)
of tySequence: of tySequence:
if m.config.selectedGC != gcDestructors:
genTypeInfoAux(m, t, t, result, info) genTypeInfoAux(m, t, t, result, info)
if m.config.selectedGC != gcDestructors:
if m.config.selectedGC >= gcMarkAndSweep: if m.config.selectedGC >= gcMarkAndSweep:
let markerProc = genTraverseProc(m, origType, sig) let markerProc = genTraverseProc(m, origType, sig)
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc]) 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 if newLen <= oldLen: return
var xu = cast[ptr NimSeqV2[T]](addr x) 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 xu.len = newLen
for i in oldLen .. newLen-1: for i in oldLen .. newLen-1:
x.data[i] = value x.data[i] = value