WIP: strings/seqs based on destructors

This commit is contained in:
Andreas Rumpf 2018-07-17 13:19:42 +02:00
commit 32afdc09c6
13 changed files with 240 additions and 141 deletions

View file

@ -53,16 +53,20 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope =
proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope =
result = getTempName(m)
addf(m.s[cfsData], " static const NIM_CHAR $1[$2] = $3;$n",
addf(m.s[cfsData], "static const struct {$n" &
" NI cap; void* allocator; NIM_CHAR[$2] data;$n" &
"} $1 = { $2, NIM_NIL, $3 };$n",
[result, rope(len(s)+1), makeCString(s)])
proc genStringLiteralV2(m: BModule; n: PNode): Rope =
let id = nodeTableTestOrSet(m.dataCache, n, m.labels)
if id == m.labels:
discard cgsym(m, "NimStrPayload")
discard cgsym(m, "NimStringV2")
# 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, $2, $3};$n",
addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n",
[result, rope(len(n.strVal)+1), pureLit])
else:
result = m.tmpBase & rope(id)