gc:destructors: make system/repr compile
This commit is contained in:
parent
6c10d331db
commit
43d570c178
3 changed files with 43 additions and 3 deletions
|
|
@ -2607,6 +2607,28 @@ proc genConstSeq(p: BProc, n: PNode, t: PType): Rope =
|
||||||
|
|
||||||
result = "(($1)&$2)" % [getTypeDesc(p.module, t), result]
|
result = "(($1)&$2)" % [getTypeDesc(p.module, t), result]
|
||||||
|
|
||||||
|
proc genConstSeqV2(p: BProc, n: PNode, t: PType): Rope =
|
||||||
|
var data = rope"{"
|
||||||
|
for i in countup(0, n.len - 1):
|
||||||
|
if i > 0: data.addf(",$n", [])
|
||||||
|
data.add genConstExpr(p, n.sons[i])
|
||||||
|
data.add("}")
|
||||||
|
|
||||||
|
result = getTempName(p.module)
|
||||||
|
let payload = getTempName(p.module)
|
||||||
|
let base = t.skipTypes(abstractInst).sons[0]
|
||||||
|
|
||||||
|
appcg(p.module, cfsData,
|
||||||
|
"static const struct {$n" &
|
||||||
|
" NI cap; void* allocator; $1 data[$2];$n" &
|
||||||
|
"} $3 = {$2, NIM_NIL, $4};$n" &
|
||||||
|
"static NIM_CONST struct {$n" &
|
||||||
|
" NI len;$n" &
|
||||||
|
" $6 p;$n" &
|
||||||
|
"} $5 = {$2, ($6)&$3};$n", [
|
||||||
|
getTypeDesc(p.module, base), rope(len(n)), payload, data,
|
||||||
|
result, getTypeDesc(p.module, t)])
|
||||||
|
|
||||||
proc genConstExpr(p: BProc, n: PNode): Rope =
|
proc genConstExpr(p: BProc, n: PNode): Rope =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkHiddenStdConv, nkHiddenSubConv:
|
of nkHiddenStdConv, nkHiddenSubConv:
|
||||||
|
|
@ -2618,6 +2640,9 @@ proc genConstExpr(p: BProc, n: PNode): Rope =
|
||||||
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
||||||
var t = skipTypes(n.typ, abstractInst)
|
var t = skipTypes(n.typ, abstractInst)
|
||||||
if t.kind == tySequence:
|
if t.kind == tySequence:
|
||||||
|
if p.config.selectedGc == gcDestructors:
|
||||||
|
result = genConstSeqV2(p, n, n.typ)
|
||||||
|
else:
|
||||||
result = genConstSeq(p, n, n.typ)
|
result = genConstSeq(p, n, n.typ)
|
||||||
elif t.kind == tyProc and t.callConv == ccClosure and n.len > 1 and
|
elif t.kind == tyProc and t.callConv == ccClosure and n.len > 1 and
|
||||||
n.sons[1].kind == nkNilLit:
|
n.sons[1].kind == nkNilLit:
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,21 @@ when not defined(useNimRtl):
|
||||||
reprAux(result, cast[pointer](cast[ByteAddress](p) + i*bs), typ.base, cl)
|
reprAux(result, cast[pointer](cast[ByteAddress](p) + i*bs), typ.base, cl)
|
||||||
add result, "]"
|
add result, "]"
|
||||||
|
|
||||||
|
when defined(gcDestructors):
|
||||||
|
type
|
||||||
|
GenericSeq = object
|
||||||
|
len: int
|
||||||
|
p: pointer
|
||||||
|
PGenericSeq = ptr GenericSeq
|
||||||
|
const payloadOffset = sizeof(int) + sizeof(pointer)
|
||||||
|
# see seqs.nim: cap: int
|
||||||
|
# region: Allocator
|
||||||
|
|
||||||
|
template payloadPtr(x: untyped): untyped = cast[PGenericSeq](x).p
|
||||||
|
else:
|
||||||
|
const payloadOffset = GenericSeqSize
|
||||||
|
template payloadPtr(x: untyped): untyped = x
|
||||||
|
|
||||||
proc reprSequence(result: var string, p: pointer, typ: PNimType,
|
proc reprSequence(result: var string, p: pointer, typ: PNimType,
|
||||||
cl: var ReprClosure) =
|
cl: var ReprClosure) =
|
||||||
if p == nil:
|
if p == nil:
|
||||||
|
|
@ -170,7 +185,7 @@ when not defined(useNimRtl):
|
||||||
var bs = typ.base.size
|
var bs = typ.base.size
|
||||||
for i in 0..cast[PGenericSeq](p).len-1:
|
for i in 0..cast[PGenericSeq](p).len-1:
|
||||||
if i > 0: add result, ", "
|
if i > 0: add result, ", "
|
||||||
reprAux(result, cast[pointer](cast[ByteAddress](p) + GenericSeqSize + i*bs),
|
reprAux(result, cast[pointer](cast[ByteAddress](payloadPtr(p)) + payloadOffset + i*bs),
|
||||||
typ.base, cl)
|
typ.base, cl)
|
||||||
add result, "]"
|
add result, "]"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue