Make compatible with nimNoLibc

This commit is contained in:
Emery Hemingway 2024-04-22 11:07:52 +02:00
parent 9ae435a83c
commit 8d48ae60e9
7 changed files with 28 additions and 24 deletions

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[options, sets, sequtils, strutils, tables, typetraits]
import std/[assertions, options, sets, sequtils, strutils, tables, typetraits]
from std/algorithm import sort
from std/json import escapeJson, escapeJsonUnquoted
import bigints

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[endians, options, streams, strutils]
import std/[assertions, endians, options, streams, strutils]
import bigints
import ./decoding, ./parsing, ./values

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[endians, streams]
import std/[assertions, endians, streams]
import bigints
import ./values

View File

@ -7,7 +7,7 @@
# distribution, for details about the copyright.
#
import std/macros
import std/[assertions, macros]
const
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[base64, options, parseutils, strutils, unicode]
import std/[assertions, base64, options, parseutils, strutils, unicode]
from std/sequtils import insert
import bigints, npeg

View File

@ -1,7 +1,9 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[base64, endians, math, sequtils, streams, strutils]
import std/[assertions, base64, endians, sequtils, streams, strutils]
when not defined(nimNoLibc):
import std/math
import bigints
import ./values
@ -42,6 +44,15 @@ proc writeSymbol(stream: Stream; sym: string) =
writeEscaped(stream, sym, '|')
write(stream, '|')
proc writeFloatBytes(stream: Stream; f: float) =
var buf: array[8, byte]
bigEndian64(addr buf[0], addr f)
write(stream, "#xd\"")
for b in buf:
write(stream, hexAlphabet[b shr 4])
write(stream, hexAlphabet[b and 0xf])
write(stream, '"')
proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
## Encode Preserves to a `Stream` as text.
if pr.embedded: write(stream, "#:")
@ -51,17 +62,14 @@ proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
of false: write(stream, "#f")
of true: write(stream, "#t")
of pkFloat:
case pr.float.classify:
of fcNormal, fcZero, fcNegZero:
write(stream, $pr.float)
when defined(nimNoLibc):
writeFloatBytes(stream, pr.float)
# IEE754-to-decimal is non-trivial
else:
var buf: array[8, byte]
bigEndian64(addr buf[0], addr pr.float)
write(stream, "#xd\"")
for b in buf:
write(stream, hexAlphabet[b shr 4])
write(stream, hexAlphabet[b and 0xf])
write(stream, '"')
if pr.float.classify in {fcNormal, fcZero, fcNegZero}:
write(stream, $pr.float)
else:
writeFloatBytes(stream, pr.float)
of pkRegister:
write(stream, $pr.register)
of pkBigInt:

View File

@ -1,8 +1,9 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[algorithm, hashes, math, options, sets, sequtils, tables]
import std/[algorithm, hashes, options, sets, sequtils, tables]
when not defined(nimNoLibc):
import std/math
import bigints
type
@ -80,11 +81,6 @@ type
## Object refs embedded in Preserves `Value`s must inherit from `EmbeddedObj`.
## At the moment this is just an alias to `RootObj` but this may change in the future.
func `===`[T: SomeFloat](a, b: T): bool =
## Compare where Nan == NaN.
let class = a.classify
(class == b.classify) and ((class notin {fcNormal,fcSubnormal}) or (a == b))
func `==`*(x, y: Value): bool =
## Check `x` and `y` for equivalence.
if x.kind == y.kind and x.embedded == y.embedded:
@ -92,7 +88,7 @@ func `==`*(x, y: Value): bool =
of pkBoolean:
result = x.bool == y.bool
of pkFloat:
result = x.float === y.float
result = cast[uint64](x.float) == cast[uint64](y.float)
of pkRegister:
result = x.register == y.register
of pkBigInt: