mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
more fixes
This commit is contained in:
@@ -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 ---------------------------------------------------
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user