Remove records module

Redundant with toPreserve and fromPreserve.
This commit is contained in:
Emery Hemingway 2021-09-25 13:57:58 +02:00
parent 42a9b26458
commit 2dd63903f0
2 changed files with 1 additions and 50 deletions

View File

@ -1,48 +0,0 @@
# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[macros, typetraits]
import ../preserves
type RecordClass*[E = void] = object
## Type of a preserves record.
label*: Preserve[E]
arity*: Natural
proc `$`*(rec: RecordClass): string =
$rec.label & "/" & $rec.arity
proc isClassOf*(rec: RecordClass; val: Preserve): bool =
## Compare the label and arity of ``val`` to the record type ``rec``.
if val.kind == pkRecord:
assert(val.record.len > 0)
result = val.label == rec.label and rec.arity == val.arity
proc classOf*[E](val: Preserve[E]): RecordClass[E] =
## Derive the ``RecordClass`` of ``val``.
if val.kind != pkRecord:
raise newException(Defect, "cannot derive class of non-record value " & $val)
assert(val.record.len > 0)
RecordClass[E](label: val.label, arity: val.arity)
proc classOf*[T](x: T; E = void): RecordClass[E] =
## Derive the ``RecordClass`` of ``x``.
when not T.hasCustomPragma(record): {.error: "no {.record.} pragma on " & $T.}
result.label = preserves.symbol[E](T.getCustomPragmaVal(record))
for k, v in x.fieldPairs: inc(result.arity)
proc classOf*(T: typedesc[tuple]; E = void): RecordClass[E] =
## Derive the ``RecordClass`` of ``T``.
when not T.hasCustomPragma(record): {.error: "no {.record.} pragma on " & $T.}
RecordClass[E](
label: preserves.symbol[E](T.getCustomPragmaVal(record)),
arity: tupleLen(T))
proc init*[E](rec: RecordClass; fields: varargs[Preserve[E]]): Preserve[E] =
## Initialize a new record value.
assert(fields.len == rec.arity, $(fields.toPreserve) & " (arity " & $fields.len & ") is not of arity " & $rec.arity)
result = initRecord(rec.label, fields)
proc init*[E](T: typedesc[tuple]; fields: varargs[Preserve[E]]): Preserve[E] =
## Initialize a new record value.
init(classOf(T), fields)

View File

@ -2,7 +2,7 @@
# SPDX-License-Identifier: Unlicense
import std/[options, tables, unittest]
import bigints, preserves, preserves/records
import bigints, preserves
suite "conversions":
test "dictionary":
@ -30,7 +30,6 @@ suite "conversions":
check(prs.kind == pkRecord)
check($prs == """<foo 1 2 <bar "ku">>""")
check(preserveTo(prs, Foobar) == some(tup))
check(classOf(tup) == classOf(prs))
test "tables":
var a: Table[int, string]