New constructors for record and sequence

This commit is contained in:
Emery Hemingway 2021-09-23 14:29:31 +02:00
parent cd5dd7dd03
commit 75c176ddb6
1 changed files with 9 additions and 0 deletions

View File

@ -228,6 +228,11 @@ proc symbol*(s: string; E = void): Preserve {.inline.} =
## Create a Preserves symbol value.
Preserve(kind: pkSymbol, symbol: s)
proc initRecord*(label: Preserve; arity = 0): Preserve =
## Create a Preserves record value.
result = Preserve(kind: pkRecord, record: newSeq[Preserve](arity.succ))
result.record[arity] = label
proc initRecord*(label: Preserve; args: varargs[Preserve]): Preserve =
## Create a Preserves record value.
result = Preserve(kind: pkRecord,
@ -242,6 +247,10 @@ proc initRecord*(label: string; args: varargs[Preserve, toPreserve]): Preserve =
assert($initRecord("foo", 1, 2.0) == "<foo 1 2.0f>")
initRecord(symbol(label), args)
proc initSequence*(len = 0): Preserve =
## Create a Preserves sequence value.
Preserve(kind: pkSequence, record: newSeq[Preserve](len))
proc initSet*(): Preserve = Preserve(kind: pkSet)
## Create a Preserves set value.