Export depattern proc
This commit is contained in:
parent
8bc0ee2ae5
commit
23c69f63a5
|
@ -289,31 +289,40 @@ proc grabDictionary*(bindings: sink openArray[(string, Pattern)]): Pattern =
|
|||
for (key, val) in bindings.items:
|
||||
result.dcompound.dict.entries[key.toSymbol(Cap)] = val
|
||||
|
||||
func depattern(comp: DCompound): Preserve[Cap]
|
||||
proc depattern(comp: DCompound; values: var seq[Value]; index: var int): Value {.gcsafe.}
|
||||
|
||||
func depattern(pat: Pattern): Preserve[Cap] =
|
||||
proc depattern(pat: Pattern; values: var seq[Value]; index: var int): Value =
|
||||
case pat.orKind
|
||||
of PatternKind.DDiscard, PatternKind.DBind:
|
||||
of PatternKind.DDiscard:
|
||||
discard
|
||||
of PatternKind.DBind:
|
||||
if index < values.len:
|
||||
result = move values[index]
|
||||
inc index
|
||||
of PatternKind.DLit:
|
||||
result = pat.dlit.value.toPreserve(Cap)
|
||||
of PatternKind.DCompound:
|
||||
result = depattern(pat.dcompound)
|
||||
result = depattern(pat.dcompound, values, index)
|
||||
|
||||
func depattern(comp: DCompound): Preserve[Cap] =
|
||||
proc depattern(comp: DCompound; values: var seq[Value]; index: var int): Value {.gcsafe.} =
|
||||
case comp.orKind
|
||||
of DCompoundKind.rec:
|
||||
result = initRecord(comp.rec.label, comp.rec.fields.len)
|
||||
for i, f in comp.rec.fields:
|
||||
result[i] = depattern(f)
|
||||
result[i] = depattern(f, values, index)
|
||||
of DCompoundKind.arr:
|
||||
result = initSequence(comp.arr.items.len, Cap)
|
||||
for i, e in comp.arr.items:
|
||||
result[i] = depattern(e)
|
||||
result[i] = depattern(e, values, index)
|
||||
of DCompoundKind.dict:
|
||||
result = initDictionary(Cap)
|
||||
for key, val in comp.dict.entries:
|
||||
result[key] = depattern(val)
|
||||
result[key] = depattern(val, values, index)
|
||||
|
||||
proc depattern*(pat: Pattern; values: sink seq[Value]): Value =
|
||||
## Convert a `Pattern` to a `Value` while replacing binds with `values`.
|
||||
var index: int
|
||||
depattern(pat, values, index)
|
||||
|
||||
type Literal*[T] = object
|
||||
## A wrapper type to deserialize patterns to native values.
|
||||
|
@ -321,7 +330,7 @@ type Literal*[T] = object
|
|||
|
||||
proc fromPreserveHook*[T, E](lit: var Literal[T]; pr: Preserve[E]): bool =
|
||||
var pat: Pattern
|
||||
pat.fromPreserve(pr) and lit.value.fromPreserve(depattern pat)
|
||||
pat.fromPreserve(pr) and lit.value.fromPreserve(depattern(pat, @[]))
|
||||
|
||||
proc toPreserveHook*[T](lit: Literal[T]; E: typedesc): Preserve[E] =
|
||||
lit.value.grab.toPreserve(E)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20231102"
|
||||
version = "20231107"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated actors for conversational concurrency"
|
||||
license = "Unlicense"
|
||||
|
|
Loading…
Reference in New Issue