Merge pull request #3322 from yglukhov/fix-uint64-str-vm
Uint64 to string in pure nim. array[char] to string fixed in vm.
This commit is contained in:
commit
be43467037
2 changed files with 28 additions and 5 deletions
|
|
@ -320,7 +320,18 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool =
|
||||||
dest.node.strVal = if src.intVal == 0: "false" else: "true"
|
dest.node.strVal = if src.intVal == 0: "false" else: "true"
|
||||||
of tyFloat..tyFloat128:
|
of tyFloat..tyFloat128:
|
||||||
dest.node.strVal = $src.floatVal
|
dest.node.strVal = $src.floatVal
|
||||||
of tyString, tyCString:
|
of tyString:
|
||||||
|
dest.node.strVal = src.node.strVal
|
||||||
|
of tyCString:
|
||||||
|
if src.node.kind == nkBracket:
|
||||||
|
# Array of chars
|
||||||
|
var strVal = ""
|
||||||
|
for son in src.node.sons:
|
||||||
|
let c = char(son.intVal)
|
||||||
|
if c == '\0': break
|
||||||
|
strVal.add(c)
|
||||||
|
dest.node.strVal = strVal
|
||||||
|
else:
|
||||||
dest.node.strVal = src.node.strVal
|
dest.node.strVal = src.node.strVal
|
||||||
of tyChar:
|
of tyChar:
|
||||||
dest.node.strVal = $chr(src.intVal)
|
dest.node.strVal = $chr(src.intVal)
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,22 @@ proc reprPointer(x: pointer): string {.compilerproc.} =
|
||||||
return $buf
|
return $buf
|
||||||
|
|
||||||
proc `$`(x: uint64): string =
|
proc `$`(x: uint64): string =
|
||||||
var buf: array [0..59, char]
|
if x == 0:
|
||||||
discard c_sprintf(buf, "%llu", x)
|
result = "0"
|
||||||
return $buf
|
else:
|
||||||
|
var buf: array [60, char]
|
||||||
|
var i = 0
|
||||||
|
var n = x
|
||||||
|
while n != 0:
|
||||||
|
let nn = n div 10'u64
|
||||||
|
buf[i] = char(n - 10'u64 * nn + ord('0'))
|
||||||
|
inc i
|
||||||
|
n = nn
|
||||||
|
|
||||||
|
let half = i div 2
|
||||||
|
# Reverse
|
||||||
|
for t in 0 .. < half: swap(buf[t], buf[i-t-1])
|
||||||
|
result = $buf
|
||||||
|
|
||||||
proc reprStrAux(result: var string, s: string) =
|
proc reprStrAux(result: var string, s: string) =
|
||||||
if cast[pointer](s) == nil:
|
if cast[pointer](s) == nil:
|
||||||
|
|
@ -294,4 +307,3 @@ when not defined(useNimRtl):
|
||||||
reprAux(result, addr(p), typ, cl)
|
reprAux(result, addr(p), typ, cl)
|
||||||
add result, "\n"
|
add result, "\n"
|
||||||
deinitReprClosure(cl)
|
deinitReprClosure(cl)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue