diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-10-20 05:26:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 14:26:37 +0200 |
commit | 3cbe8d2c53cec1f41de116f3d3a9a7678a62da11 (patch) | |
tree | b1582301c9e5627d47f488132494d7251fb96208 | |
parent | ed0f8a497333c75b9035c4e7837ee1158d53aa20 (diff) | |
download | Nim-3cbe8d2c53cec1f41de116f3d3a9a7678a62da11.tar.gz |
$(uint|uint64) now works with nimscript (#15644)
* $(uint|uint64) now works with nimscript * fixup
-rw-r--r-- | lib/system/dollars.nim | 20 | ||||
-rw-r--r-- | lib/system/mm/go.nim | 2 | ||||
-rw-r--r-- | lib/system/strmantle.nim | 20 | ||||
-rw-r--r-- | tests/test_nimscript.nims | 3 |
4 files changed, 23 insertions, 22 deletions
diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index b2f0186b3..e87c237ad 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -19,6 +19,26 @@ when defined(js): ## 64bit ints. # pending https://github.com/nim-lang/RFCs/issues/187 $(cast[int](x)) +else: + proc `$`*(x: uint64): string {.noSideEffect, raises: [].} = + ## The stringify operator for an unsigned integer argument. Returns `x` + ## converted to a decimal string. + if x == 0: + result = "0" + else: + result = newString(60) + var i = 0 + var n = x + while n != 0: + let nn = n div 10'u64 + result[i] = char(n - 10'u64 * nn + ord('0')) + inc i + n = nn + result.setLen i + + let half = i div 2 + # Reverse + for t in 0 .. half-1: swap(result[t], result[i-t-1]) proc `$`*(x: int64): string {.magic: "Int64ToStr", noSideEffect.} ## The stringify operator for an integer argument. Returns `x` diff --git a/lib/system/mm/go.nim b/lib/system/mm/go.nim index b6d5a1a44..9a8c47ea5 100644 --- a/lib/system/mm/go.nim +++ b/lib/system/mm/go.nim @@ -35,8 +35,6 @@ proc goMalloc(size: uint): pointer {.importc: "go_malloc", dynlib: goLib.} proc goSetFinalizer(obj: pointer, f: pointer) {.importc: "set_finalizer", codegenDecl:"$1 $2$3 __asm__ (\"main.Set_finalizer\");\n$1 $2$3", dynlib: goLib.} proc writebarrierptr(dest: PPointer, src: pointer) {.importc: "writebarrierptr", codegenDecl:"$1 $2$3 __asm__ (\"main.Atomic_store_pointer\");\n$1 $2$3", dynlib: goLib.} -proc `$`*(x: uint64): string {.noSideEffect, raises: [].} - proc GC_getStatistics(): string = var mstats = goMemStats() result = "[GC] total allocated memory: " & $(mstats.total_alloc) & "\n" & diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim index 43a769b5f..21b790603 100644 --- a/lib/system/strmantle.nim +++ b/lib/system/strmantle.nim @@ -283,26 +283,6 @@ proc nimCharToStr(x: char): string {.compilerRtl.} = result = newString(1) result[0] = x -proc `$`*(x: uint64): string {.noSideEffect, raises: [].} = - ## The stringify operator for an unsigned integer argument. Returns `x` - ## converted to a decimal string. - if x == 0: - result = "0" - else: - result = newString(60) - var i = 0 - var n = x - while n != 0: - let nn = n div 10'u64 - result[i] = char(n - 10'u64 * nn + ord('0')) - inc i - n = nn - result.setLen i - - let half = i div 2 - # Reverse - for t in 0 .. half-1: swap(result[t], result[i-t-1]) - when defined(gcDestructors): proc GC_getStatistics*(): string = result = "[GC] total memory: " diff --git a/tests/test_nimscript.nims b/tests/test_nimscript.nims index d9f477366..b94146b1e 100644 --- a/tests/test_nimscript.nims +++ b/tests/test_nimscript.nims @@ -73,6 +73,9 @@ echo "Nimscript imports are successful." block: doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath +block: + doAssert $3'u == "3" + doAssert $3'u64 == "3" block: # #14142 discard dirExists("/usr") |