C codegen: preparations for different seq and string implementations

This commit is contained in:
Andreas Rumpf 2018-04-03 10:25:20 +02:00
commit d837362216
8 changed files with 116 additions and 43 deletions

View file

@ -12,12 +12,11 @@
import allocators
type
string {.core.} = object
string {.core, exportc: "NimStringV2".} = object
len, cap: int
data: ptr UncheckedArray[char]
proc nimStringLiteral(x: cstring; len: int): string {.core.} =
string(len: len, cap: len, data: x)
const nimStrVersion {.core.} = 2
template frees(s) = dealloc(s.data, s.cap + 1)
@ -80,7 +79,7 @@ proc newString*(len: int): string =
if len > 0:
result.data = alloc0(len+1)
converter toCString(x: string): cstring {.core.} =
converter toCString(x: string): cstring {.core, inline.} =
if x.len == 0: cstring"" else: cast[cstring](x.data)
proc newStringOfCap*(cap: int): string =