diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/endians.nim | 21 | ||||
-rw-r--r-- | lib/pure/terminal.nim | 8 | ||||
-rw-r--r-- | lib/system/nimscript.nim | 4 |
3 files changed, 20 insertions, 13 deletions
diff --git a/lib/pure/endians.nim b/lib/pure/endians.nim index 6f80d56ef..771ecaaca 100644 --- a/lib/pure/endians.nim +++ b/lib/pure/endians.nim @@ -44,20 +44,23 @@ else: const useBuiltinSwap = false when useBuiltinSwap: + template swapOpImpl(T: typedesc, op: untyped) = + ## We have to use `copyMem` here instead of a simple deference because they + ## may point to a unaligned address. A sufficiently smart compiler _should_ + ## be able to elide them when they're not necessary. + var tmp: T + copyMem(addr tmp, inp, sizeOf(T)) + tmp = op(tmp) + copyMem(outp, addr tmp, sizeOf(T)) + proc swapEndian64*(outp, inp: pointer) {.inline, nosideeffect.}= - var i = cast[ptr uint64](inp) - var o = cast[ptr uint64](outp) - o[] = builtin_bswap64(i[]) + swapOpImpl(uint64, builtin_bswap64) proc swapEndian32*(outp, inp: pointer) {.inline, nosideeffect.}= - var i = cast[ptr uint32](inp) - var o = cast[ptr uint32](outp) - o[] = builtin_bswap32(i[]) + swapOpImpl(uint32, builtin_bswap32) proc swapEndian16*(outp, inp: pointer) {.inline, nosideeffect.}= - var i = cast[ptr uint16](inp) - var o = cast[ptr uint16](outp) - o[] = builtin_bswap16(i[]) + swapOpImpl(uint16, builtin_bswap16) else: proc swapEndian64*(outp, inp: pointer) = diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 2e138b27e..974dc839d 100644 --- a/lib/pure/terminal.nim +++ b/lib/pure/terminal.nim @@ -18,7 +18,7 @@ import macros import strformat -from strutils import toLowerAscii +from strutils import toLowerAscii, `%` import colors, tables when defined(windows): @@ -635,7 +635,8 @@ proc ansiForegroundColorCode*(color: Color): string = template ansiForegroundColorCode*(color: static[Color]): string = const rgb = extractRGB(color) - (static(fmt"{fgPrefix}{rgb.r};{rgb.g};{rgb.b}m")) + # no usage of `fmt`, see issue #7632 + (static("$1$2;$3;$4m" % [$fgPrefix, $(rgb.r), $(rgb.g), $(rgb.b)])) proc ansiBackgroundColorCode*(color: Color): string = let rgb = extractRGB(color) @@ -643,7 +644,8 @@ proc ansiBackgroundColorCode*(color: Color): string = template ansiBackgroundColorCode*(color: static[Color]): string = const rgb = extractRGB(color) - (static(fmt"{bgPrefix}{rgb.r};{rgb.g};{rgb.b}m")) + # no usage of `fmt`, see issue #7632 + (static("$1$2;$3;$4m" % [$bgPrefix, $(rgb.r), $(rgb.g), $(rgb.b)])) proc setForegroundColor*(f: File, color: Color) = ## Sets the terminal's foreground true color. diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim index c876d6d06..0adc7a83c 100644 --- a/lib/system/nimscript.nim +++ b/lib/system/nimscript.nim @@ -282,7 +282,9 @@ proc projectPath*(): string = builtin proc thisDir*(): string = - ## Retrieves the location of the current ``nims`` script file. + ## Retrieves the directory of the current ``nims`` script file. Its path is + ## obtained via ``currentSourcePath`` (although, currently, + ## ``currentSourcePath`` resolves symlinks, unlike ``thisDir``). builtin proc cd*(dir: string) {.raises: [OSError].} = |