Rework the initX[E]() procs to initX(E = void)

This commit is contained in:
Emery Hemingway 2023-03-29 17:32:54 -05:00
parent 5d3f7b94a3
commit 71b6d4c017
4 changed files with 11 additions and 11 deletions

View File

@ -313,14 +313,14 @@ proc initRecord*[E](label: string; args: varargs[Preserve[E]]): Preserve[E] {.in
## Create a Preserves record value.
initRecord(toSymbol(label, E), args)
proc initSequence*[E](len: Natural = 0): Preserve[E] =
proc initSequence*(len: Natural = 0; E = void): Preserve[E] =
## Create a Preserves sequence value.
Preserve[E](kind: pkSequence, sequence: newSeq[Preserve[E]](len))
proc initSet*[E](): Preserve[E] = Preserve[E](kind: pkSet)
proc initSet*(E = void): Preserve[E] = Preserve[E](kind: pkSet)
## Create a Preserves set value.
proc initDictionary*[E](): Preserve[E] = Preserve[E](kind: pkDictionary)
proc initDictionary*(E = void): Preserve[E] = Preserve[E](kind: pkDictionary)
## Create a Preserves dictionary value.
proc embed*[E](pr: sink Preserve[E]): Preserve[E] =
@ -827,7 +827,7 @@ proc toPreserve*[T](x: T; E = void): Preserve[E] =
result.record.add(pr)
result.record.add(tosymbol(T.getCustomPragmaVal(preservesRecord), E))
elif T.hasCustomPragma(preservesTuple):
result = initSequence[E]()
result = initSequence(0, E)
for label, field in x.fieldPairs:
when x.dot(label).hasCustomPragma(preservesTupleTail):
for y in field.items:
@ -838,7 +838,7 @@ proc toPreserve*[T](x: T; E = void): Preserve[E] =
applyEmbed(label, pr)
result.sequence.add(pr)
elif T.hasCustomPragma(preservesDictionary):
result = initDictionary[E]()
result = initDictionary(E)
for key, val in x.fieldPairs:
var pr = fieldToPreserve(key, val)
applyEmbed(key, pr)
@ -859,7 +859,7 @@ proc toPreserveHook*[T](set: HashSet[T]; E: typedesc): Preserve[E] =
proc toPreserveHook*[A, B](table: Table[A, B]|TableRef[A, B], E: typedesc): Preserve[E] =
## Hook for preserving ``Table``.
result = initDictionary[E]()
result = initDictionary(E)
for k, v in table.pairs:
result[toPreserve(k, E)] = toPreserve(v, E)

View File

@ -202,7 +202,7 @@ const parser = peg("Schema", p: ParseState):
pushStack n
Ref <- >(Alpha * *Alnum) * *('.' * >(*Alnum)):
var path = initSequence[void]()
var path = initSequence()
for i in 1..<capture.len: path.sequence.add(toSymbol capture[i].s)
var name = pop(path.sequence)
var n = initRecord(toSymbol"ref", path, name)
@ -240,7 +240,7 @@ const parser = peg("Schema", p: ParseState):
pushStack node
DictionaryPattern <- '{' * S * *(>Value * S * ':' * S * NamedSimplePattern * S) * '}':
var dict = initDictionary[void]()
var dict = initDictionary(void)
for i in countDown(pred capture.len, 1):
let key = toSymbol capture[i].s
dict[key] = initRecord("named", key, popStack())

View File

@ -89,10 +89,10 @@ proc toPreserveHook*(node: Node; E: typedesc): Preserve[E] =
result = toPreserve(cast[seq[byte]](ByteStringNode(node).value), E)
elif node of Blok:
var blk = Blok(node)
result = initSequence[E](blk.nodes.len)
result = initSequence(blk.nodes.len, E)
for i, child in blk.nodes: result.sequence[i] = toPreserve(child, E)
elif node of Map:
result = initDictionary[E]()
result = initDictionary(E)
for key, val in Map(node).bindings:
result[toPreserve(key, E)] = toPreserve(val, E)
elif node of StringVal:

View File

@ -28,7 +28,7 @@ proc toPreserveHook*(xn: XmlNode; E: typedesc): Preserve[E] =
if xn.kind == xnElement:
result = Preserve[E](kind: pkRecord)
if not xn.attrs.isNil:
var attrs = initDictionary[E]()
var attrs = initDictionary(E)
for xk, xv in xn.attrs.pairs:
attrs[toSymbol(xk, E)] = toPreserveFromString(xv, E)
result.record.add(attrs)