Update protocols and pattern constructors
This commit is contained in:
parent
0bf6b684fe
commit
d8f6d82956
|
@ -1 +1 @@
|
||||||
Subproject commit b42230b96a6f8665fdd8e56a52a5e76072a6d182
|
Subproject commit ca92d99c524d99b6d3be04a0ba5383ec5a65b550
|
|
@ -10,11 +10,13 @@ from ./actors import Ref
|
||||||
export dataspacePatterns.`$`
|
export dataspacePatterns.`$`
|
||||||
|
|
||||||
type
|
type
|
||||||
CRec = dataspacePatterns.CRec[Ref]
|
AnyAtom = dataspacePatterns.AnyAtom[Ref]
|
||||||
DCompoundRec = dataspacePatterns.DCompoundRec[Ref]
|
DBind = dataspacePatterns.DBind[Ref]
|
||||||
DBind* = dataspacePatterns.DBind[Ref]
|
|
||||||
DLit* = dataspacePatterns.DLit[Ref]
|
|
||||||
DCompound* = dataspacePatterns.DCompound[Ref]
|
DCompound* = dataspacePatterns.DCompound[Ref]
|
||||||
|
DCompoundArr = dataspacePatterns.DCompoundArr[Ref]
|
||||||
|
DCompoundDict = dataspacePatterns.DCompoundDict[Ref]
|
||||||
|
DCompoundRec = dataspacePatterns.DCompoundRec[Ref]
|
||||||
|
DLit = dataspacePatterns.DLit[Ref]
|
||||||
Pattern* = dataspacePatterns.Pattern[Ref]
|
Pattern* = dataspacePatterns.Pattern[Ref]
|
||||||
|
|
||||||
proc `?`*(d: DBind): Pattern =
|
proc `?`*(d: DBind): Pattern =
|
||||||
|
@ -26,8 +28,26 @@ proc `?`*(d: DLit): Pattern =
|
||||||
proc `?`*(d: DCompound): Pattern =
|
proc `?`*(d: DCompound): Pattern =
|
||||||
Pattern(orKind: PatternKind.DCompound, dcompound: d)
|
Pattern(orKind: PatternKind.DCompound, dcompound: d)
|
||||||
|
|
||||||
|
proc `?`*(x: bool): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`bool`, bool: x))
|
||||||
|
|
||||||
|
proc `?`*(x: float32): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`float`, float: x))
|
||||||
|
|
||||||
|
proc `?`*(x: float64): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`double`, double: x))
|
||||||
|
|
||||||
|
proc `?`*(x: int): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`int`, int: x))
|
||||||
|
|
||||||
proc `?`*(s: string): Pattern =
|
proc `?`*(s: string): Pattern =
|
||||||
?DLit(value: toPreserve(s, Ref))
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`string`, string: s))
|
||||||
|
|
||||||
|
proc `?`*(x: seq[byte]): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`bytes`, bytes: x))
|
||||||
|
|
||||||
|
proc `?`*(x: Symbol): Pattern =
|
||||||
|
?DLit(value: AnyAtom(orKind: AnyAtomKind.`symbol`, symbol: x))
|
||||||
|
|
||||||
proc drop*(): Pattern = Pattern(orKind: PatternKind.DDiscard)
|
proc drop*(): Pattern = Pattern(orKind: PatternKind.DDiscard)
|
||||||
proc grab*(): Pattern = ?DBind(pattern: drop())
|
proc grab*(): Pattern = ?DBind(pattern: drop())
|
||||||
|
@ -35,24 +55,59 @@ proc grab*(): Pattern = ?DBind(pattern: drop())
|
||||||
proc `?_`*(): Pattern = drop()
|
proc `?_`*(): Pattern = drop()
|
||||||
proc `?*`*(): Pattern = grab()
|
proc `?*`*(): Pattern = grab()
|
||||||
|
|
||||||
proc `?`*(T: typedesc; bindings: openArray[(int, Pattern)]): Pattern =
|
proc `?`*(T: typedesc; bindings: sink openArray[(int, Pattern)]): Pattern =
|
||||||
## Pattern constructor operator.
|
## Pattern constructor operator.
|
||||||
|
# TODO: get a pattern for T and then replace the inner patterns with bindings.
|
||||||
when T.hasCustomPragma(preservesRecord):
|
when T.hasCustomPragma(preservesRecord):
|
||||||
var label = tosymbol(T.getCustomPragmaVal(preservesRecord), Ref)
|
var
|
||||||
|
label = tosymbol(T.getCustomPragmaVal(preservesRecord), Ref)
|
||||||
|
fields = newSeq[Pattern]()
|
||||||
|
for (i, pat) in bindings:
|
||||||
|
if i > fields.high: fields.setLen(succ i)
|
||||||
|
fields[i] = pat
|
||||||
result = ?DCompound(
|
result = ?DCompound(
|
||||||
orKind: DCompoundKind.rec,
|
orKind: DCompoundKind.rec,
|
||||||
rec: DCompoundRec(
|
rec: DCompoundRec(
|
||||||
ctor: CRec(label: label, arity: bindings.len),
|
label: label, fields: fields))
|
||||||
members: toTable bindings))
|
|
||||||
elif T is ref:
|
elif T is ref:
|
||||||
`?`(pointerBase(T), bindings)
|
`?`(pointerBase(T), bindings)
|
||||||
else:
|
else:
|
||||||
{.error: "no custom pragma on " & $T.}
|
{.error: "no preserves pragma on " & $T.}
|
||||||
|
|
||||||
proc observe*(pat: Pattern): Pattern =
|
proc `?`*(T: typedesc): Pattern =
|
||||||
# TODO: why doesn't Observe from ./protocols/dataspace.nim work?
|
## Derive a `Pattern` from type `T`.
|
||||||
?DCompound(
|
## This works for `tuple` and `object` types but in the
|
||||||
|
## general case will return a wildcard binding.
|
||||||
|
when T.hasCustomPragma(preservesRecord):
|
||||||
|
var
|
||||||
|
label = tosymbol(T.getCustomPragmaVal(preservesRecord), Ref)
|
||||||
|
fields = newSeq[Pattern]()
|
||||||
|
dummy: ptr T
|
||||||
|
for key, val in fieldPairs(dummy[]):
|
||||||
|
fields.add grab()
|
||||||
|
result = ?DCompound(
|
||||||
orKind: DCompoundKind.rec,
|
orKind: DCompoundKind.rec,
|
||||||
rec: DCompoundRec(
|
rec: DCompoundRec(
|
||||||
ctor: CRec(label: toSymbol("Observe", Ref), arity: 2),
|
label: label, fields: fields))
|
||||||
members: toTable {0 : pat, 1: `?_`()}))
|
elif T is tuple:
|
||||||
|
var
|
||||||
|
arr = DCompoundArr()
|
||||||
|
dummy: ptr T
|
||||||
|
for key, val in fieldPairs(dummy[]):
|
||||||
|
arr.items.add ?(typeOf val)
|
||||||
|
result = ?DCompound(
|
||||||
|
orKind: DCompoundKind.arr,
|
||||||
|
arr: arr)
|
||||||
|
elif T is object:
|
||||||
|
var
|
||||||
|
dict = DCompoundDict()
|
||||||
|
dummy: ptr T
|
||||||
|
for key, val in fieldPairs(dummy[]):
|
||||||
|
dict.entries[key.toSymbol(Ref)] = grab() #?(typeOf val)
|
||||||
|
result = ?DCompound(
|
||||||
|
orKind: DCompoundKind.dict,
|
||||||
|
dict: dict)
|
||||||
|
elif T is ref:
|
||||||
|
?pointerBase(T)
|
||||||
|
else:
|
||||||
|
grab() # capture any value
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
include_rules
|
export XDG_CACHE_HOME
|
||||||
|
|
||||||
|
!nim = |> nim compile -o:%o %f |>
|
||||||
|
|
||||||
: ../../../preserves/src/preserves/preserves_schema_nim.nim |> !nim |> preserves_schema_nim
|
: ../../../preserves/src/preserves/preserves_schema_nim.nim |> !nim |> preserves_schema_nim
|
||||||
|
|
||||||
|
@ -17,6 +19,7 @@ schemas = \
|
||||||
sturdy.nim \
|
sturdy.nim \
|
||||||
tcp.nim \
|
tcp.nim \
|
||||||
timer.nim \
|
timer.nim \
|
||||||
|
trace.nim \
|
||||||
transportAddress.nim \
|
transportAddress.nim \
|
||||||
worker.nim \
|
worker.nim \
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,64 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/typetraits, preserves, std/tables, std/tables, std/tables
|
std/typetraits, preserves, std/tables
|
||||||
|
|
||||||
type
|
type
|
||||||
CRec*[E] {.preservesRecord: "rec".} = ref object
|
AnyAtomKind* {.pure.} = enum
|
||||||
`label`*: Preserve[E]
|
`bool`, `float`, `double`, `int`, `string`, `bytes`, `symbol`, `embedded`
|
||||||
`arity`*: int
|
AnyAtomBool* = bool
|
||||||
|
AnyAtomFloat* = float32
|
||||||
|
AnyAtomDouble* = float64
|
||||||
|
AnyAtomInt* = int
|
||||||
|
AnyAtomString* = string
|
||||||
|
AnyAtomBytes* = seq[byte]
|
||||||
|
AnyAtomSymbol* = Symbol
|
||||||
|
AnyAtomEmbedded*[E] = Preserve[E]
|
||||||
|
`AnyAtom`*[E] {.preservesOr.} = ref object
|
||||||
|
case orKind*: AnyAtomKind
|
||||||
|
of AnyAtomKind.`bool`:
|
||||||
|
`bool`*: AnyAtomBool
|
||||||
|
|
||||||
|
of AnyAtomKind.`float`:
|
||||||
|
`float`*: AnyAtomFloat
|
||||||
|
|
||||||
|
of AnyAtomKind.`double`:
|
||||||
|
`double`*: AnyAtomDouble
|
||||||
|
|
||||||
|
of AnyAtomKind.`int`:
|
||||||
|
`int`*: AnyAtomInt
|
||||||
|
|
||||||
|
of AnyAtomKind.`string`:
|
||||||
|
`string`*: AnyAtomString
|
||||||
|
|
||||||
|
of AnyAtomKind.`bytes`:
|
||||||
|
`bytes`*: AnyAtomBytes
|
||||||
|
|
||||||
|
of AnyAtomKind.`symbol`:
|
||||||
|
`symbol`*: AnyAtomSymbol
|
||||||
|
|
||||||
|
of AnyAtomKind.`embedded`:
|
||||||
|
`embedded`*: AnyAtomEmbedded[E]
|
||||||
|
|
||||||
|
|
||||||
DLit*[E] {.preservesRecord: "lit".} = ref object
|
DLit*[E] {.preservesRecord: "lit".} = ref object
|
||||||
`value`*: Preserve[E]
|
`value`*: AnyAtom[E]
|
||||||
|
|
||||||
DBind*[E] {.preservesRecord: "bind".} = ref object
|
DBind*[E] {.preservesRecord: "bind".} = ref object
|
||||||
`pattern`*: Pattern[E]
|
`pattern`*: Pattern[E]
|
||||||
|
|
||||||
DDiscard* {.preservesRecord: "_".} = object
|
DDiscard* {.preservesRecord: "_".} = object
|
||||||
|
|
||||||
CArr* {.preservesRecord: "arr".} = object
|
|
||||||
`arity`*: int
|
|
||||||
|
|
||||||
DCompoundKind* {.pure.} = enum
|
DCompoundKind* {.pure.} = enum
|
||||||
`rec`, `arr`, `dict`
|
`rec`, `arr`, `dict`
|
||||||
DCompoundRec*[E] {.preservesRecord: "compound".} = ref object
|
DCompoundRec*[E] {.preservesRecord: "rec".} = ref object
|
||||||
`ctor`*: CRec[E]
|
`label`*: Preserve[E]
|
||||||
`members`*: Table[int, Pattern[E]]
|
`fields`*: seq[Pattern[E]]
|
||||||
|
|
||||||
DCompoundArr*[E] {.preservesRecord: "compound".} = ref object
|
DCompoundArr*[E] {.preservesRecord: "arr".} = ref object
|
||||||
`ctor`*: CArr
|
`items`*: seq[Pattern[E]]
|
||||||
`members`*: Table[int, Pattern[E]]
|
|
||||||
|
|
||||||
DCompoundDict*[E] {.preservesRecord: "compound".} = ref object
|
DCompoundDict*[E] {.preservesRecord: "dict".} = ref object
|
||||||
`ctor`*: CDict
|
`entries`*: Table[Preserve[E], Pattern[E]]
|
||||||
`members`*: Table[Preserve[E], Pattern[E]]
|
|
||||||
|
|
||||||
`DCompound`*[E] {.preservesOr.} = ref object
|
`DCompound`*[E] {.preservesOr.} = ref object
|
||||||
case orKind*: DCompoundKind
|
case orKind*: DCompoundKind
|
||||||
|
@ -44,8 +72,6 @@ type
|
||||||
`dict`*: DCompoundDict[E]
|
`dict`*: DCompoundDict[E]
|
||||||
|
|
||||||
|
|
||||||
CDict* {.preservesRecord: "dict".} = object
|
|
||||||
|
|
||||||
PatternKind* {.pure.} = enum
|
PatternKind* {.pure.} = enum
|
||||||
`DDiscard`, `DBind`, `DLit`, `DCompound`
|
`DDiscard`, `DBind`, `DLit`, `DCompound`
|
||||||
`Pattern`*[E] {.preservesOr.} = ref object
|
`Pattern`*[E] {.preservesOr.} = ref object
|
||||||
|
@ -63,15 +89,15 @@ type
|
||||||
`dcompound`*: DCompound[E]
|
`dcompound`*: DCompound[E]
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[E](x: CRec[E] | DLit[E] | DBind[E] | DCompound[E] | Pattern[E]): string =
|
proc `$`*[E](x: AnyAtom[E] | DLit[E] | DBind[E] | DCompound[E] | Pattern[E]): string =
|
||||||
`$`(toPreserve(x, E))
|
`$`(toPreserve(x, E))
|
||||||
|
|
||||||
proc encode*[E](x: CRec[E] | DLit[E] | DBind[E] | DCompound[E] | Pattern[E]): seq[
|
proc encode*[E](x: AnyAtom[E] | DLit[E] | DBind[E] | DCompound[E] | Pattern[E]): seq[
|
||||||
byte] =
|
byte] =
|
||||||
encode(toPreserve(x, E))
|
encode(toPreserve(x, E))
|
||||||
|
|
||||||
proc `$`*(x: DDiscard | CArr | CDict): string =
|
proc `$`*(x: DDiscard): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
proc encode*(x: DDiscard | CArr | CDict): seq[byte] =
|
proc encode*(x: DDiscard): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserve(x))
|
||||||
|
|
|
@ -18,6 +18,9 @@ type
|
||||||
`assertion`*: Assertion[E]
|
`assertion`*: Assertion[E]
|
||||||
`handle`*: Handle
|
`handle`*: Handle
|
||||||
|
|
||||||
|
Extension*[E] {.preservesRecord: "label".} = ref object
|
||||||
|
`addFieldsCalledWithSimplePattern`*: seq[Preserve[E]]
|
||||||
|
|
||||||
Sync*[E] {.preservesRecord: "sync".} = ref object
|
Sync*[E] {.preservesRecord: "sync".} = ref object
|
||||||
`peer`*: Preserve[E]
|
`peer`*: Preserve[E]
|
||||||
|
|
||||||
|
@ -29,7 +32,7 @@ type
|
||||||
Assertion*[E] = Preserve[E]
|
Assertion*[E] = Preserve[E]
|
||||||
Handle* = int
|
Handle* = int
|
||||||
PacketKind* {.pure.} = enum
|
PacketKind* {.pure.} = enum
|
||||||
`Turn`, `Error`
|
`Turn`, `Error`, `Extension`
|
||||||
`Packet`*[E] {.preservesOr.} = ref object
|
`Packet`*[E] {.preservesOr.} = ref object
|
||||||
case orKind*: PacketKind
|
case orKind*: PacketKind
|
||||||
of PacketKind.`Turn`:
|
of PacketKind.`Turn`:
|
||||||
|
@ -38,6 +41,9 @@ type
|
||||||
of PacketKind.`Error`:
|
of PacketKind.`Error`:
|
||||||
`error`*: Error[E]
|
`error`*: Error[E]
|
||||||
|
|
||||||
|
of PacketKind.`Extension`:
|
||||||
|
`extension`*: Extension[E]
|
||||||
|
|
||||||
|
|
||||||
EventKind* {.pure.} = enum
|
EventKind* {.pure.} = enum
|
||||||
`Assert`, `Retract`, `Message`, `Sync`
|
`Assert`, `Retract`, `Message`, `Sync`
|
||||||
|
@ -56,13 +62,15 @@ type
|
||||||
`sync`*: Sync[E]
|
`sync`*: Sync[E]
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[E](x: Error[E] | Turn[E] | Message[E] | Assert[E] | Sync[E] |
|
proc `$`*[E](x: Error[E] | Turn[E] | Message[E] | Assert[E] | Extension[E] |
|
||||||
|
Sync[E] |
|
||||||
TurnEvent[E] |
|
TurnEvent[E] |
|
||||||
Packet[E] |
|
Packet[E] |
|
||||||
Event[E]): string =
|
Event[E]): string =
|
||||||
`$`(toPreserve(x, E))
|
`$`(toPreserve(x, E))
|
||||||
|
|
||||||
proc encode*[E](x: Error[E] | Turn[E] | Message[E] | Assert[E] | Sync[E] |
|
proc encode*[E](x: Error[E] | Turn[E] | Message[E] | Assert[E] | Extension[E] |
|
||||||
|
Sync[E] |
|
||||||
TurnEvent[E] |
|
TurnEvent[E] |
|
||||||
Packet[E] |
|
Packet[E] |
|
||||||
Event[E]): seq[byte] =
|
Event[E]): seq[byte] =
|
||||||
|
|
|
@ -3,16 +3,35 @@ import
|
||||||
std/typetraits, preserves
|
std/typetraits, preserves
|
||||||
|
|
||||||
type
|
type
|
||||||
`State`* {.preservesOr.} = enum
|
StateKind* {.pure.} = enum
|
||||||
`started`, `ready`, `failed`, `complete`
|
`started`, `ready`, `failed`, `complete`, `userDefined`
|
||||||
|
StateUserDefined*[E] = Preserve[E]
|
||||||
|
`State`*[E] {.preservesOr.} = ref object
|
||||||
|
case orKind*: StateKind
|
||||||
|
of StateKind.`started`:
|
||||||
|
`started`* {.preservesLiteral: "started".}: bool
|
||||||
|
|
||||||
|
of StateKind.`ready`:
|
||||||
|
`ready`* {.preservesLiteral: "ready".}: bool
|
||||||
|
|
||||||
|
of StateKind.`failed`:
|
||||||
|
`failed`* {.preservesLiteral: "failed".}: bool
|
||||||
|
|
||||||
|
of StateKind.`complete`:
|
||||||
|
`complete`* {.preservesLiteral: "complete".}: bool
|
||||||
|
|
||||||
|
of StateKind.`userDefined`:
|
||||||
|
`userdefined`*: StateUserDefined[E]
|
||||||
|
|
||||||
|
|
||||||
ServiceObject*[E] {.preservesRecord: "service-object".} = ref object
|
ServiceObject*[E] {.preservesRecord: "service-object".} = ref object
|
||||||
`serviceName`*: Preserve[E]
|
`serviceName`*: Preserve[E]
|
||||||
`object`*: Preserve[E]
|
`object`*: Preserve[E]
|
||||||
|
|
||||||
CoreService*[E] {.preservesRecord: "core-service".} = ref object
|
RequireService*[E] {.preservesRecord: "require-service".} = ref object
|
||||||
`serviceName`*: Preserve[E]
|
`serviceName`*: Preserve[E]
|
||||||
|
|
||||||
RequireService*[E] {.preservesRecord: "require-service".} = ref object
|
RestartService*[E] {.preservesRecord: "restart-service".} = ref object
|
||||||
`serviceName`*: Preserve[E]
|
`serviceName`*: Preserve[E]
|
||||||
|
|
||||||
RunService*[E] {.preservesRecord: "run-service".} = ref object
|
RunService*[E] {.preservesRecord: "run-service".} = ref object
|
||||||
|
@ -20,19 +39,21 @@ type
|
||||||
|
|
||||||
ServiceState*[E] {.preservesRecord: "service-state".} = ref object
|
ServiceState*[E] {.preservesRecord: "service-state".} = ref object
|
||||||
`serviceName`*: Preserve[E]
|
`serviceName`*: Preserve[E]
|
||||||
`state`*: State
|
`state`*: State[E]
|
||||||
|
|
||||||
ServiceDependency*[E] {.preservesRecord: "depends-on".} = ref object
|
ServiceDependency*[E] {.preservesRecord: "depends-on".} = ref object
|
||||||
`depender`*: Preserve[E]
|
`depender`*: Preserve[E]
|
||||||
`dependee`*: ServiceState[E]
|
`dependee`*: ServiceState[E]
|
||||||
|
|
||||||
proc `$`*[E](x: ServiceObject[E] | CoreService[E] | RequireService[E] |
|
proc `$`*[E](x: State[E] | ServiceObject[E] | RequireService[E] |
|
||||||
|
RestartService[E] |
|
||||||
RunService[E] |
|
RunService[E] |
|
||||||
ServiceState[E] |
|
ServiceState[E] |
|
||||||
ServiceDependency[E]): string =
|
ServiceDependency[E]): string =
|
||||||
`$`(toPreserve(x, E))
|
`$`(toPreserve(x, E))
|
||||||
|
|
||||||
proc encode*[E](x: ServiceObject[E] | CoreService[E] | RequireService[E] |
|
proc encode*[E](x: State[E] | ServiceObject[E] | RequireService[E] |
|
||||||
|
RestartService[E] |
|
||||||
RunService[E] |
|
RunService[E] |
|
||||||
ServiceState[E] |
|
ServiceState[E] |
|
||||||
ServiceDependency[E]): seq[byte] =
|
ServiceDependency[E]): seq[byte] =
|
||||||
|
|
|
@ -27,7 +27,7 @@ type
|
||||||
`sink`*: Preserve[E]
|
`sink`*: Preserve[E]
|
||||||
`spec`*: Preserve[E]
|
`spec`*: Preserve[E]
|
||||||
|
|
||||||
`LineMode`* {.preservesOr.} = enum
|
`LineMode`* {.preservesOr, pure.} = enum
|
||||||
`lf`, `crlf`
|
`lf`, `crlf`
|
||||||
SourceKind* {.pure.} = enum
|
SourceKind* {.pure.} = enum
|
||||||
`sink`, `StreamError`, `credit`
|
`sink`, `StreamError`, `credit`
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/typetraits, preserves, std/tables, std/tables
|
std/typetraits, preserves, std/tables
|
||||||
|
|
||||||
type
|
type
|
||||||
CRec*[E] {.preservesRecord: "rec".} = ref object
|
PCompoundKind* {.pure.} = enum
|
||||||
|
`rec`, `arr`, `dict`
|
||||||
|
PCompoundRec*[E] {.preservesRecord: "rec".} = ref object
|
||||||
`label`*: Preserve[E]
|
`label`*: Preserve[E]
|
||||||
`arity`*: int
|
`fields`*: seq[Pattern[E]]
|
||||||
|
|
||||||
PCompound*[E] {.preservesRecord: "compound".} = ref object
|
PCompoundArr*[E] {.preservesRecord: "arr".} = ref object
|
||||||
`ctor`*: ConstructorSpec[E]
|
`items`*: seq[Pattern[E]]
|
||||||
`members`*: PCompoundMembers[E]
|
|
||||||
|
|
||||||
ConstructorSpecKind* {.pure.} = enum
|
PCompoundDict*[E] {.preservesRecord: "dict".} = ref object
|
||||||
`CRec`, `CArr`, `CDict`
|
`entries`*: Table[Preserve[E], Pattern[E]]
|
||||||
`ConstructorSpec`*[E] {.preservesOr.} = ref object
|
|
||||||
case orKind*: ConstructorSpecKind
|
|
||||||
of ConstructorSpecKind.`CRec`:
|
|
||||||
`crec`*: CRec[E]
|
|
||||||
|
|
||||||
of ConstructorSpecKind.`CArr`:
|
`PCompound`*[E] {.preservesOr.} = ref object
|
||||||
`carr`*: CArr
|
case orKind*: PCompoundKind
|
||||||
|
of PCompoundKind.`rec`:
|
||||||
|
`rec`*: PCompoundRec[E]
|
||||||
|
|
||||||
of ConstructorSpecKind.`CDict`:
|
of PCompoundKind.`arr`:
|
||||||
`cdict`*: CDict
|
`arr`*: PCompoundArr[E]
|
||||||
|
|
||||||
|
of PCompoundKind.`dict`:
|
||||||
|
`dict`*: PCompoundDict[E]
|
||||||
|
|
||||||
|
|
||||||
PAnd*[E] {.preservesRecord: "and".} = ref object
|
PAnd*[E] {.preservesRecord: "and".} = ref object
|
||||||
|
@ -32,7 +34,6 @@ type
|
||||||
`pattern`*: Pattern[E]
|
`pattern`*: Pattern[E]
|
||||||
`template`*: Template[E]
|
`template`*: Template[E]
|
||||||
|
|
||||||
TCompoundMembers*[E] = Table[Preserve[E], Template[E]]
|
|
||||||
TRef* {.preservesRecord: "ref".} = object
|
TRef* {.preservesRecord: "ref".} = object
|
||||||
`binding`*: int
|
`binding`*: int
|
||||||
|
|
||||||
|
@ -42,11 +43,31 @@ type
|
||||||
Lit*[E] {.preservesRecord: "lit".} = ref object
|
Lit*[E] {.preservesRecord: "lit".} = ref object
|
||||||
`value`*: Preserve[E]
|
`value`*: Preserve[E]
|
||||||
|
|
||||||
TCompound*[E] {.preservesRecord: "compound".} = ref object
|
TCompoundKind* {.pure.} = enum
|
||||||
`ctor`*: ConstructorSpec[E]
|
`rec`, `arr`, `dict`
|
||||||
`members`*: TCompoundMembers[E]
|
TCompoundRec*[E] {.preservesRecord: "rec".} = ref object
|
||||||
|
`label`*: Preserve[E]
|
||||||
|
`fields`*: seq[Template[E]]
|
||||||
|
|
||||||
`PAtom`* {.preservesOr.} = enum
|
TCompoundArr*[E] {.preservesRecord: "arr".} = ref object
|
||||||
|
`items`*: seq[Template[E]]
|
||||||
|
|
||||||
|
TCompoundDict*[E] {.preservesRecord: "dict".} = ref object
|
||||||
|
`entries`*: Table[Preserve[E], Template[E]]
|
||||||
|
|
||||||
|
`TCompound`*[E] {.preservesOr.} = ref object
|
||||||
|
case orKind*: TCompoundKind
|
||||||
|
of TCompoundKind.`rec`:
|
||||||
|
`rec`*: TCompoundRec[E]
|
||||||
|
|
||||||
|
of TCompoundKind.`arr`:
|
||||||
|
`arr`*: TCompoundArr[E]
|
||||||
|
|
||||||
|
of TCompoundKind.`dict`:
|
||||||
|
`dict`*: TCompoundDict[E]
|
||||||
|
|
||||||
|
|
||||||
|
`PAtom`* {.preservesOr, pure.} = enum
|
||||||
`Boolean`, `Float`, `Double`, `SignedInteger`, `String`, `ByteString`,
|
`Boolean`, `Float`, `Double`, `SignedInteger`, `String`, `ByteString`,
|
||||||
`Symbol`
|
`Symbol`
|
||||||
Attenuation*[E] = seq[Caveat[E]]
|
Attenuation*[E] = seq[Caveat[E]]
|
||||||
|
@ -80,10 +101,6 @@ type
|
||||||
`alts`*: Alts[E]
|
`alts`*: Alts[E]
|
||||||
|
|
||||||
|
|
||||||
CArr* {.preservesRecord: "arr".} = object
|
|
||||||
`arity`*: int
|
|
||||||
|
|
||||||
PCompoundMembers*[E] = Table[Preserve[E], Pattern[E]]
|
|
||||||
PNot*[E] {.preservesRecord: "not".} = ref object
|
PNot*[E] {.preservesRecord: "not".} = ref object
|
||||||
`pattern`*: Pattern[E]
|
`pattern`*: Pattern[E]
|
||||||
|
|
||||||
|
@ -120,8 +137,6 @@ type
|
||||||
Alts*[E] {.preservesRecord: "or".} = ref object
|
Alts*[E] {.preservesRecord: "or".} = ref object
|
||||||
`alternatives`*: seq[Rewrite[E]]
|
`alternatives`*: seq[Rewrite[E]]
|
||||||
|
|
||||||
CDict* {.preservesRecord: "dict".} = object
|
|
||||||
|
|
||||||
PatternKind* {.pure.} = enum
|
PatternKind* {.pure.} = enum
|
||||||
`PDiscard`, `PAtom`, `PEmbedded`, `PBind`, `PAnd`, `PNot`, `Lit`,
|
`PDiscard`, `PAtom`, `PEmbedded`, `PBind`, `PAnd`, `PNot`, `Lit`,
|
||||||
`PCompound`
|
`PCompound`
|
||||||
|
@ -152,16 +167,11 @@ type
|
||||||
`pcompound`*: PCompound[E]
|
`pcompound`*: PCompound[E]
|
||||||
|
|
||||||
|
|
||||||
proc `$`*[E](x: CRec[E] | PCompound[E] | ConstructorSpec[E] | PAnd[E] |
|
proc `$`*[E](x: PCompound[E] | PAnd[E] | Rewrite[E] | PBind[E] | Lit[E] |
|
||||||
Rewrite[E] |
|
|
||||||
TCompoundMembers[E] |
|
|
||||||
PBind[E] |
|
|
||||||
Lit[E] |
|
|
||||||
TCompound[E] |
|
TCompound[E] |
|
||||||
Attenuation[E] |
|
Attenuation[E] |
|
||||||
Template[E] |
|
Template[E] |
|
||||||
Caveat[E] |
|
Caveat[E] |
|
||||||
PCompoundMembers[E] |
|
|
||||||
PNot[E] |
|
PNot[E] |
|
||||||
SturdyRef[E] |
|
SturdyRef[E] |
|
||||||
WireRef[E] |
|
WireRef[E] |
|
||||||
|
@ -170,16 +180,11 @@ proc `$`*[E](x: CRec[E] | PCompound[E] | ConstructorSpec[E] | PAnd[E] |
|
||||||
Pattern[E]): string =
|
Pattern[E]): string =
|
||||||
`$`(toPreserve(x, E))
|
`$`(toPreserve(x, E))
|
||||||
|
|
||||||
proc encode*[E](x: CRec[E] | PCompound[E] | ConstructorSpec[E] | PAnd[E] |
|
proc encode*[E](x: PCompound[E] | PAnd[E] | Rewrite[E] | PBind[E] | Lit[E] |
|
||||||
Rewrite[E] |
|
|
||||||
TCompoundMembers[E] |
|
|
||||||
PBind[E] |
|
|
||||||
Lit[E] |
|
|
||||||
TCompound[E] |
|
TCompound[E] |
|
||||||
Attenuation[E] |
|
Attenuation[E] |
|
||||||
Template[E] |
|
Template[E] |
|
||||||
Caveat[E] |
|
Caveat[E] |
|
||||||
PCompoundMembers[E] |
|
|
||||||
PNot[E] |
|
PNot[E] |
|
||||||
SturdyRef[E] |
|
SturdyRef[E] |
|
||||||
WireRef[E] |
|
WireRef[E] |
|
||||||
|
@ -188,8 +193,8 @@ proc encode*[E](x: CRec[E] | PCompound[E] | ConstructorSpec[E] | PAnd[E] |
|
||||||
Pattern[E]): seq[byte] =
|
Pattern[E]): seq[byte] =
|
||||||
encode(toPreserve(x, E))
|
encode(toPreserve(x, E))
|
||||||
|
|
||||||
proc `$`*(x: TRef | PDiscard | CArr | Oid | CDict): string =
|
proc `$`*(x: TRef | PDiscard | Oid): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
proc encode*(x: TRef | PDiscard | CArr | Oid | CDict): seq[byte] =
|
proc encode*(x: TRef | PDiscard | Oid): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserve(x))
|
||||||
|
|
|
@ -12,7 +12,7 @@ type
|
||||||
`msecs`*: float64
|
`msecs`*: float64
|
||||||
`kind`*: TimerKind
|
`kind`*: TimerKind
|
||||||
|
|
||||||
`TimerKind`* {.preservesOr.} = enum
|
`TimerKind`* {.preservesOr, pure.} = enum
|
||||||
`relative`, `absolute`, `clear`
|
`relative`, `absolute`, `clear`
|
||||||
LaterThan* {.preservesRecord: "later-than".} = object
|
LaterThan* {.preservesRecord: "later-than".} = object
|
||||||
`msecs`*: float64
|
`msecs`*: float64
|
||||||
|
|
Loading…
Reference in New Issue