gc:destructors: make strutils compile (but still crashes)
This commit is contained in:
parent
417d27c544
commit
a4543c1aac
1 changed files with 12 additions and 7 deletions
|
|
@ -51,8 +51,7 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope =
|
||||||
|
|
||||||
# ------ Version 2: destructor based strings and seqs -----------------------
|
# ------ Version 2: destructor based strings and seqs -----------------------
|
||||||
|
|
||||||
proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope =
|
proc genStringLiteralDataOnlyV2(m: BModule, s: string; result: Rope) =
|
||||||
result = getTempName(m)
|
|
||||||
addf(m.s[cfsData], "static const struct {$n" &
|
addf(m.s[cfsData], "static const struct {$n" &
|
||||||
" NI cap; void* allocator; NIM_CHAR data[$2+1];$n" &
|
" NI cap; void* allocator; NIM_CHAR data[$2+1];$n" &
|
||||||
"} $1 = { $2, NIM_NIL, $3 };$n",
|
"} $1 = { $2, NIM_NIL, $3 };$n",
|
||||||
|
|
@ -61,24 +60,28 @@ proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope =
|
||||||
proc genStringLiteralV2(m: BModule; n: PNode): Rope =
|
proc genStringLiteralV2(m: BModule; n: PNode): Rope =
|
||||||
let id = nodeTableTestOrSet(m.dataCache, n, m.labels)
|
let id = nodeTableTestOrSet(m.dataCache, n, m.labels)
|
||||||
if id == m.labels:
|
if id == m.labels:
|
||||||
|
let pureLit = getTempName(m)
|
||||||
|
genStringLiteralDataOnlyV2(m, n.strVal, pureLit)
|
||||||
|
result = getTempName(m)
|
||||||
discard cgsym(m, "NimStrPayload")
|
discard cgsym(m, "NimStrPayload")
|
||||||
discard cgsym(m, "NimStringV2")
|
discard cgsym(m, "NimStringV2")
|
||||||
# string literal not found in the cache:
|
# string literal not found in the cache:
|
||||||
let pureLit = genStringLiteralDataOnlyV2(m, n.strVal)
|
|
||||||
result = getTempName(m)
|
|
||||||
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+1)
|
result = getTempName(m)
|
||||||
|
addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n",
|
||||||
|
[result, rope(len(n.strVal)), m.tmpBase & rope(id)])
|
||||||
|
|
||||||
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)
|
||||||
var pureLit: Rope
|
var pureLit: Rope
|
||||||
if id == m.labels:
|
if id == m.labels:
|
||||||
|
pureLit = getTempName(m)
|
||||||
discard cgsym(m, "NimStrPayload")
|
discard cgsym(m, "NimStrPayload")
|
||||||
discard cgsym(m, "NimStringV2")
|
discard cgsym(m, "NimStringV2")
|
||||||
# string literal not found in the cache:
|
# string literal not found in the cache:
|
||||||
pureLit = genStringLiteralDataOnlyV2(m, n.strVal)
|
genStringLiteralDataOnlyV2(m, n.strVal, pureLit)
|
||||||
else:
|
else:
|
||||||
pureLit = m.tmpBase & rope(id)
|
pureLit = m.tmpBase & rope(id)
|
||||||
result = "{$1, (NimStrPayload*)&$2}" % [rope(len(n.strVal)), pureLit]
|
result = "{$1, (NimStrPayload*)&$2}" % [rope(len(n.strVal)), pureLit]
|
||||||
|
|
@ -88,7 +91,9 @@ proc genStringLiteralV2Const(m: BModule; n: PNode): Rope =
|
||||||
proc genStringLiteralDataOnly(m: BModule; s: string; info: TLineInfo): Rope =
|
proc genStringLiteralDataOnly(m: BModule; s: string; info: TLineInfo): Rope =
|
||||||
case detectStrVersion(m)
|
case detectStrVersion(m)
|
||||||
of 0, 1: result = genStringLiteralDataOnlyV1(m, s)
|
of 0, 1: result = genStringLiteralDataOnlyV1(m, s)
|
||||||
of 2: result = genStringLiteralDataOnlyV2(m, s)
|
of 2:
|
||||||
|
result = getTempName(m)
|
||||||
|
genStringLiteralDataOnlyV2(m, s, result)
|
||||||
else:
|
else:
|
||||||
localError(m.config, info, "cannot determine how to produce code for string literal")
|
localError(m.config, info, "cannot determine how to produce code for string literal")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue