more fixes

This commit is contained in:
ringabout
2023-12-07 14:47:51 +00:00
committed by GitHub
parent cb172328ba
commit da277cf1b8
2 changed files with 10 additions and 6 deletions

View File

@@ -97,6 +97,9 @@ proc genStringLiteralV2Const(m: BModule; n: PNode; isConst: bool; result: var Ro
# ------ Version 3: destructor based strings and seqs -----------------------
# strings are enhanced by interned strings
proc toConstLenV3(len: int): string =
result = rope((len shl 1) or 1)
proc genStringLiteralDataOnlyV3(m: BModule, s: string; result: Rope; isConst: bool) =
m.s[cfsStrData].addf("static $4 NIM_CHAR $1[$2] = $3;$n",
[result, rope(s.len), makeCString(s),
@@ -112,12 +115,12 @@ proc genStringLiteralV3(m: BModule; n: PNode; isConst: bool; result: var Rope) =
cgsym(m, "NimStringV3")
# string literal not found in the cache:
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, &$3};$n",
[tmp, rope(n.strVal.len), pureLit, rope(if isConst: "const" else: "")])
[tmp, toConstLenV3(n.strVal.len), pureLit, rope(if isConst: "const" else: "")])
else:
let tmp = getTempName(m)
result.add tmp
m.s[cfsStrData].addf("static $4 NimStringV3 $1 = {$2, &$3};$n",
[tmp, rope(n.strVal.len), m.tmpBase & rope(id),
[tmp, toConstLenV3(n.strVal.len), m.tmpBase & rope(id),
rope(if isConst: "const" else: "")])
proc genStringLiteralV3Const(m: BModule; n: PNode; isConst: bool; result: var Rope) =
@@ -130,7 +133,7 @@ proc genStringLiteralV3Const(m: BModule; n: PNode; isConst: bool; result: var Ro
genStringLiteralDataOnlyV3(m, n.strVal, pureLit, isConst)
else:
pureLit = m.tmpBase & rope(id)
result.addf "{$1, &$2}", [rope(n.strVal.len), pureLit]
result.addf "{$1, &$2}", [toConstLenV3(n.strVal.len), pureLit]
# ------ Version selector ---------------------------------------------------

View File

@@ -39,7 +39,7 @@ template `strCap=`(p: pointer, size: int) =
proc nimStrLenV3(s: NimStringV3): int {.compilerRtl, inl.} = s.rawlen shr 1
template toRawLen(len: int): int = len shl 1
template incRawLen(s: var NimStringV3, value: int = 1) =
s.rawlen = s.rawlen + value shl 1
s.rawlen += value shl 1
template setRawLen(s: var NimStringV3, len: int) =
s.rawLen = toRawLen(len)
@@ -136,8 +136,9 @@ proc nimToCStringConv(s: NimStringV3): cstring {.compilerproc, nonReloadable, in
else:
## TODO: fixme: inject conversions somewhere else and be cleaned up
## but let it leak for now
result = cast[cstring](allocPayload0(s.nimStrLenV3+1))
copyMem(result, unsafeAddr s.p[0], s.nimStrLenV3)
let len = s.nimStrLenV3+1
result = cast[cstring](allocShared0(len+1))
copyMem(result, unsafeAddr s.p[0], len)
proc appendString(dest: var NimStringV3; src: NimStringV3) {.compilerproc, inline.} =
if src.nimStrLenV3 > 0: