Make compatible with nimNoLibc
This commit is contained in:
parent
9ae435a83c
commit
8d48ae60e9
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# 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/algorithm import sort
|
||||||
from std/json import escapeJson, escapeJsonUnquoted
|
from std/json import escapeJson, escapeJsonUnquoted
|
||||||
import bigints
|
import bigints
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[endians, options, streams, strutils]
|
import std/[assertions, endians, options, streams, strutils]
|
||||||
import bigints
|
import bigints
|
||||||
import ./decoding, ./parsing, ./values
|
import ./decoding, ./parsing, ./values
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[endians, streams]
|
import std/[assertions, endians, streams]
|
||||||
import bigints
|
import bigints
|
||||||
import ./values
|
import ./values
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
import std/macros
|
import std/[assertions, macros]
|
||||||
|
|
||||||
const
|
const
|
||||||
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}
|
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[base64, options, parseutils, strutils, unicode]
|
import std/[assertions, base64, options, parseutils, strutils, unicode]
|
||||||
from std/sequtils import insert
|
from std/sequtils import insert
|
||||||
|
|
||||||
import bigints, npeg
|
import bigints, npeg
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# 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 bigints
|
||||||
import ./values
|
import ./values
|
||||||
|
|
||||||
|
@ -42,6 +44,15 @@ proc writeSymbol(stream: Stream; sym: string) =
|
||||||
writeEscaped(stream, sym, '|')
|
writeEscaped(stream, sym, '|')
|
||||||
write(stream, '|')
|
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) =
|
proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
|
||||||
## Encode Preserves to a `Stream` as text.
|
## Encode Preserves to a `Stream` as text.
|
||||||
if pr.embedded: write(stream, "#:")
|
if pr.embedded: write(stream, "#:")
|
||||||
|
@ -51,17 +62,14 @@ proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
|
||||||
of false: write(stream, "#f")
|
of false: write(stream, "#f")
|
||||||
of true: write(stream, "#t")
|
of true: write(stream, "#t")
|
||||||
of pkFloat:
|
of pkFloat:
|
||||||
case pr.float.classify:
|
when defined(nimNoLibc):
|
||||||
of fcNormal, fcZero, fcNegZero:
|
writeFloatBytes(stream, pr.float)
|
||||||
|
# IEE754-to-decimal is non-trivial
|
||||||
|
else:
|
||||||
|
if pr.float.classify in {fcNormal, fcZero, fcNegZero}:
|
||||||
write(stream, $pr.float)
|
write(stream, $pr.float)
|
||||||
else:
|
else:
|
||||||
var buf: array[8, byte]
|
writeFloatBytes(stream, pr.float)
|
||||||
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, '"')
|
|
||||||
of pkRegister:
|
of pkRegister:
|
||||||
write(stream, $pr.register)
|
write(stream, $pr.register)
|
||||||
of pkBigInt:
|
of pkBigInt:
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# 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
|
import bigints
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -80,11 +81,6 @@ type
|
||||||
## Object refs embedded in Preserves `Value`s must inherit from `EmbeddedObj`.
|
## 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.
|
## 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 =
|
func `==`*(x, y: Value): bool =
|
||||||
## Check `x` and `y` for equivalence.
|
## Check `x` and `y` for equivalence.
|
||||||
if x.kind == y.kind and x.embedded == y.embedded:
|
if x.kind == y.kind and x.embedded == y.embedded:
|
||||||
|
@ -92,7 +88,7 @@ func `==`*(x, y: Value): bool =
|
||||||
of pkBoolean:
|
of pkBoolean:
|
||||||
result = x.bool == y.bool
|
result = x.bool == y.bool
|
||||||
of pkFloat:
|
of pkFloat:
|
||||||
result = x.float === y.float
|
result = cast[uint64](x.float) == cast[uint64](y.float)
|
||||||
of pkRegister:
|
of pkRegister:
|
||||||
result = x.register == y.register
|
result = x.register == y.register
|
||||||
of pkBigInt:
|
of pkBigInt:
|
||||||
|
|
Loading…
Reference in New Issue