Schema: make all Preserves embeddable

This commit is contained in:
Emery Hemingway 2021-10-17 14:50:27 +02:00
parent 171502f1d2
commit 5250707f0e
3 changed files with 183 additions and 185 deletions

View File

@ -13,6 +13,20 @@ import compiler/[ast, idents, renderer, lineinfos]
import ../preserves, ./schema, ./parse
type
Bundle = schema.Bundle[void]
Modules = schema.Modules[void]
Schema = schema.Schema[void]
Definitions = schema.Definitions[void]
Definition = schema.Definition[void]
Pattern = schema.Pattern[void]
SimplePattern = schema.SimplePattern[void]
CompoundPattern = schema.CompoundPattern[void]
DictionaryEntries = schema.DictionaryEntries[void]
NamedAlternative = schema.NamedAlternative[void]
NamedSimplePattern = schema.NamedSimplePattern[void]
NamedPattern = schema.NamedPattern[void]
Binding = schema.Binding[void]
TypeSpec = tuple[node: PNode, embeddable: bool]
TypeTable = OrderedTable[string, PNode]
@ -53,7 +67,7 @@ proc pattern(np: NamedSimplePattern): SimplePattern =
np.anonymous
proc ident(sp: SimplePattern): PNode =
raiseAssert "need ident from " & $sp
raiseAssert "need ident from " #& $sp
proc ident(cp: CompoundPattern; fallback: string): PNode =
case cp.orKind
@ -113,11 +127,8 @@ proc deref(scm: Schema; r: Ref): Definition =
assert r.module == @[]
scm.data.definitions[r.name]
proc isEmbeddable(scm: Schema): bool =
scm.data.embeddedType.orKind == EmbeddedtypenameKind.`Ref`
proc preserveIdent(scm: Schema): Pnode =
nn(nkBracketExpr, ident"Preserve", ident(if scm.isEmbeddable: "E" else: "void"))
nn(nkBracketExpr, ident"Preserve", ident("E"))
proc embeddedIdent(scm: Schema): PNode =
case scm.data.embeddedType.orKind
@ -131,27 +142,25 @@ proc isEmbeddable(scm: Schema; pat: Pattern; seen: RefSet): bool {.gcsafe.}
proc isEmbeddable(scm: Schema; def: Definition; seen: RefSet): bool {.gcsafe.}
proc isEmbeddable(scm: Schema; sp: SimplePattern; seen: RefSet): bool =
if not scm.isEmbeddable: false
else:
case sp.orKind
of SimplepatternKind.`atom`, SimplepatternKind.`lit`: false
of SimplepatternKind.`any`: true
of SimplepatternKind.`embedded`: true
of SimplepatternKind.`seqof`:
isEmbeddable(scm, sp.seqof.pattern, seen)
of SimplepatternKind.`setof`:
isEmbeddable(scm, sp.setof.pattern, seen)
of SimplepatternKind.`dictof`:
isEmbeddable(scm, sp.dictof.key, seen) or
isEmbeddable(scm, sp.dictof.value, seen)
of SimplepatternKind.`Ref`:
if sp.ref.module != @[]: true
case sp.orKind
of SimplepatternKind.`atom`, SimplepatternKind.`lit`: false
of SimplepatternKind.`any`: true
of SimplepatternKind.`embedded`: true
of SimplepatternKind.`seqof`:
isEmbeddable(scm, sp.seqof.pattern, seen)
of SimplepatternKind.`setof`:
isEmbeddable(scm, sp.setof.pattern, seen)
of SimplepatternKind.`dictof`:
isEmbeddable(scm, sp.dictof.key, seen) or
isEmbeddable(scm, sp.dictof.value, seen)
of SimplepatternKind.`Ref`:
if sp.ref.module != @[]: true
else:
if sp.ref in seen: false
else:
if sp.ref in seen: false
else:
var seen = seen
seen.incl sp.ref
isEmbeddable(scm, deref(scm, sp.ref), seen)
var seen = seen
seen.incl sp.ref
isEmbeddable(scm, deref(scm, sp.ref), seen)
proc isEmbeddable(scm: Schema; np: NamedSimplePattern; seen: RefSet): bool =
case np.orKind
@ -161,22 +170,20 @@ proc isEmbeddable(scm: Schema; np: NamedSimplePattern; seen: RefSet): bool =
isEmbeddable(scm, np.anonymous, seen)
proc isEmbeddable(scm: Schema; cp: CompoundPattern; seen: RefSet): bool =
if not scm.isEmbeddable: false
else:
case cp.orKind
of CompoundPatternKind.`rec`:
isEmbeddable(scm, cp.rec.label.pattern, seen) or
isEmbeddable(scm, cp.rec.fields.pattern, seen)
of CompoundPatternKind.`tuple`:
any(cp.tuple.patterns) do (np: NamedPattern) -> bool:
isEmbeddable(scm, np.pattern, seen)
of CompoundPatternKind.`tupleprefix`:
proc pred(np: NamedPattern): bool =
isEmbeddable(scm, np.pattern, seen)
isEmbeddable(scm, cp.tupleprefix.variable, seen) or
any(cp.tupleprefix.fixed, pred)
of CompoundPatternKind.`dict`:
true # the key type is `Preserve`
case cp.orKind
of CompoundPatternKind.`rec`:
isEmbeddable(scm, cp.rec.label.pattern, seen) or
isEmbeddable(scm, cp.rec.fields.pattern, seen)
of CompoundPatternKind.`tuple`:
any(cp.tuple.patterns) do (np: NamedPattern) -> bool:
isEmbeddable(scm, np.pattern, seen)
of CompoundPatternKind.`tupleprefix`:
proc pred(np: NamedPattern): bool =
isEmbeddable(scm, np.pattern, seen)
isEmbeddable(scm, cp.tupleprefix.variable, seen) or
any(cp.tupleprefix.fixed, pred)
of CompoundPatternKind.`dict`:
true # the key type is `Preserve`
proc isEmbeddable(scm: Schema; pat: Pattern; seen: RefSet): bool =
case pat.orKind
@ -185,26 +192,26 @@ proc isEmbeddable(scm: Schema; pat: Pattern; seen: RefSet): bool =
of PatternKind.`CompoundPattern`:
isEmbeddable(scm, pat.compoundPattern, seen)
proc isEmbeddable(scm: Schema; def: Definition; seen: RefSet): bool =
if not scm.isEmbeddable: false
else:
case def.orKind
of DefinitionKind.`or`:
proc isEmbeddable(na: NamedAlternative): bool =
isEmbeddable(scm, na.pattern, seen)
isEmbeddable(def.or.data.pattern0) or
isEmbeddable(def.or.data.pattern1) or
any(def.or.data.patternN, isEmbeddable)
of DefinitionKind.`and`:
proc isEmbeddable(np: NamedPattern): bool =
isEmbeddable(scm, np.pattern, seen)
isEmbeddable(def.and.data.pattern0) or
isEmbeddable(def.and.data.pattern1) or
any(def.and.data.patternN, isEmbeddable)
of DefinitionKind.`Pattern`:
isEmbeddable(scm, def.pattern, seen)
proc isEmbeddable(scm: Schema; orDef: DefinitionOr; seen: RefSet): bool =
proc isEmbeddable(na: NamedAlternative): bool =
isEmbeddable(scm, na.pattern, seen)
isEmbeddable(orDef.data.pattern0) or
isEmbeddable(orDef.data.pattern1) or
any(orDef.data.patternN, isEmbeddable)
proc isEmbeddable(scm: Schema; p: Definition|Pattern|SimplePattern): bool =
proc isEmbeddable(scm: Schema; def: Definition; seen: RefSet): bool =
case def.orKind
of DefinitionKind.`or`: isEmbeddable(scm, def.or, seen)
of DefinitionKind.`and`:
proc isEmbeddable(np: NamedPattern): bool =
isEmbeddable(scm, np.pattern, seen)
isEmbeddable(def.and.data.pattern0) or
isEmbeddable(def.and.data.pattern1) or
any(def.and.data.patternN, isEmbeddable)
of DefinitionKind.`Pattern`:
isEmbeddable(scm, def.pattern, seen)
proc isEmbeddable(scm: Schema; p: Definition|DefinitionOr|Pattern|CompoundPattern|SimplePattern): bool =
var seen: RefSet
isEmbeddable(scm, p, seen)
@ -273,8 +280,6 @@ proc typeIdent(scm: Schema; sp: SimplePattern): TypeSpec =
case sp.orKind
of SimplepatternKind.`atom`:
result = (typeIdent(sp.atom.atomKind), false)
of SimplepatternKind.`embedded`:
result = (scm.embeddedIdent, scm.isEmbeddable)
of SimplepatternKind.`seqof`:
result = typeIdent(scm, sp.seqof.pattern)
result.node = nn(nkBracketExpr, ident"seq", result.node)
@ -291,7 +296,7 @@ proc typeIdent(scm: Schema; sp: SimplePattern): TypeSpec =
result = (ident(sp.ref), isEmbeddable(scm, sp))
result.node = parameterize(result)
else:
result = (preserveIdent(scm), isEmbeddable(scm))
result = (preserveIdent(scm), true)
proc typeIdent(scm: Schema; pat: Pattern): TypeSpec =
case pat.orKind
@ -325,22 +330,9 @@ proc toFieldIdent(scm: Schema, label: string; pat: Pattern): PNode =
proc newEmpty(): PNode = newNode(nkEmpty)
#[
proc literal(scm: Schema; sn: SchemaNode): Value =
case sn.orKind
of snkLiteral: result = sn.value
of snkRef:
if sn.refPath.len == 1:
result = literal(scm, scm.definitions[sn.refPath[0]])
else:
raiseAssert("not convertable to a literal: " & $sn)
else:
raiseAssert("not convertable to a literal: " & $sn)
]#
proc embeddingParams(embeddable: bool): PNode =
if embeddable:
nn(nkGenericParams, nn(nkIdentDefs, ident"E", newEmpty(), ident"void"))
nn(nkGenericParams, nn(nkIdentDefs, ident"E", newEmpty(), newEmpty()))
else:
newEmpty()
@ -456,7 +448,7 @@ proc addFields(recList: PNode; scm: Schema; known: var TypeTable; cp: CompoundPa
case cp.orKind
of CompoundPatternKind.rec:
# recList.add identDef(ident(label), nimTypeOf(scm, known, cp, ""))
raiseassert "unexpected record of fields " & $cp.rec
raiseassert "unexpected record of fields " #& $cp.rec
of CompoundPatternKind.tuple:
for np in cp.tuple.patterns:
let
@ -470,14 +462,14 @@ proc addFields(recList: PNode; scm: Schema; known: var TypeTable; cp: CompoundPa
typeName = parentName & capitalizeAscii(label)
fieldSpec = nimTypeOf(scm, known, pat, label)
known[typeName] = typeDef(scm, typeName, pat, fieldSpec.node)
recList.add identDef(id, ident(typeName), fieldSpec.embeddable)
else: raiseAssert "not adding fields for " & $cp
recList.add identDef(id, ident(typeName), isEmbeddable(scm, pat))
else: raiseAssert "not adding fields for " #& $cp
reclist
proc addFields(recList: PNode; scm: Schema; known: var TypeTable; pat: Pattern; parentName: string): PNode {.discardable.} =
case pat.orKind
of PatternKind.SimplePattern:
raiseAssert "addFields called with SimplePattern " & $pat.simplePattern
raiseAssert "addFields called with SimplePattern " #& $pat.simplePattern
# addField(recList, scm, known, pat.simplePattern, "data")
of PatternKind.CompoundPattern:
discard addFields(recList, scm, known, pat.compoundPattern, parentName)
@ -531,6 +523,8 @@ proc nimTypeOf(scm: Schema; known: var TypeTable; cp: CompoundPattern; name: str
of CompoundPatternKind.`dict`:
result.node = nn(nkObjectTy, newEmpty(), newEmpty(),
nn(nkRecList).addFields(scm, known, cp.dict.entries, name))
if result.node.kind == nkObjectTy and isEmbeddable(scm, cp):
result.node = nn(nkRefTy, result.node)
proc nimTypeOf(scm: Schema; known: var TypeTable; pat: Pattern; name: string): TypeSpec =
case pat.orKind
@ -583,6 +577,8 @@ proc nimTypeOf(scm: Schema; known: var TypeTable; orDef: DefinitionOr; name: str
known[memberTypeName] =
typeDef(scm, memberTypeName, na.pattern, ty.node)
orEmbed result, memberType
memberType.node = parameterize(
memberType.node, isEmbeddable(scm, na.pattern))
branchRecList.add nn(nkIdentDefs,
toFieldIdent(scm, na.variantLabel.normalize, na.pattern),
memberType.node, newEmpty())
@ -593,10 +589,12 @@ proc nimTypeOf(scm: Schema; known: var TypeTable; orDef: DefinitionOr; name: str
addCase(orDef.data.pattern0)
addCase(orDef.data.pattern1)
for na in orDef.data.patternN: addCase(na)
result.node = nn(nkRefTy, nn(nkObjectTy,
result.node = nn(nkObjectTy,
newEmpty(),
newEmpty(),
nn(nkRecList, recCase)))
nn(nkRecList, recCase))
if result.node.kind == nkObjectTy and isEmbeddable(scm, orDef):
result.node = nn(nkRefTy, result.node)
proc nimTypeOf(scm: Schema; known: var TypeTable; def: Definition; name: string): TypeSpec =
case def.orKind
@ -721,15 +719,13 @@ proc renderNimModule*(scm: Schema): string =
ident"std/typetraits",
ident"preserves")
collectRefImports(imports, scm)
let dollarGenericParams =
if isEmbeddable(scm):
nn(nkGenericParams, nn(nkIdentDefs, ident"E", newEmpty(), newEmpty()))
else: newEmpty()
let genericParams =
nn(nkGenericParams, nn(nkIdentDefs, ident"E", newEmpty(), newEmpty()))
if not embeddableType.isNil:
procs.add nn(nkProcDef,
"$".toFieldIdent,
newEmpty(),
dollarGenericParams,
genericParams,
nn(nkFormalParams,
ident"string",
nn(nkIdentDefs,
@ -744,7 +740,7 @@ proc renderNimModule*(scm: Schema): string =
procs.add nn(nkProcDef,
"encode".ident.toExport,
newEmpty(),
nn(nkGenericParams, nn(nkIdentDefs, ident"E", newEmpty(), newEmpty())),
genericParams,
nn(nkFormalParams,
nn(nkBracketExpr, ident"seq", ident"byte"),
nn(nkIdentDefs,

View File

@ -7,44 +7,44 @@ type
`name`* {.preservesSymbol.}: string
ModulePath* = seq[string]
Bundle* {.preservesRecord: "bundle".} = object
`modules`*: Modules
Bundle*[E] {.preservesRecord: "bundle".} = ref object
`modules`*: Modules[E]
CompoundPatternKind* {.pure.} = enum
`rec`, `tuple`, `tuplePrefix`, `dict`
CompoundPatternRec* {.preservesRecord: "rec".} = object
`label`*: NamedPattern
`fields`*: NamedPattern
CompoundPatternRec*[E] {.preservesRecord: "rec".} = ref object
`label`*: NamedPattern[E]
`fields`*: NamedPattern[E]
CompoundPatternTuple* {.preservesRecord: "tuple".} = object
`patterns`*: seq[NamedPattern]
CompoundPatternTuple*[E] {.preservesRecord: "tuple".} = ref object
`patterns`*: seq[NamedPattern[E]]
CompoundPatternTuplePrefix* {.preservesRecord: "tuplePrefix".} = object
`fixed`*: seq[NamedPattern]
`variable`*: NamedSimplePattern
CompoundPatternTuplePrefix*[E] {.preservesRecord: "tuplePrefix".} = ref object
`fixed`*: seq[NamedPattern[E]]
`variable`*: NamedSimplePattern[E]
CompoundPatternDict* {.preservesRecord: "dict".} = object
`entries`*: DictionaryEntries
CompoundPatternDict*[E] {.preservesRecord: "dict".} = ref object
`entries`*: DictionaryEntries[E]
`CompoundPattern`* {.preservesOr.} = ref object
`CompoundPattern`*[E] {.preservesOr.} = ref object
case orKind*: CompoundPatternKind
of CompoundPatternKind.`rec`:
`rec`*: CompoundPatternRec
`rec`*: CompoundPatternRec[E]
of CompoundPatternKind.`tuple`:
`tuple`*: CompoundPatternTuple
`tuple`*: CompoundPatternTuple[E]
of CompoundPatternKind.`tuplePrefix`:
`tupleprefix`*: CompoundPatternTuplePrefix
`tupleprefix`*: CompoundPatternTuplePrefix[E]
of CompoundPatternKind.`dict`:
`dict`*: CompoundPatternDict
`dict`*: CompoundPatternDict[E]
Modules* = Table[ModulePath, Schema]
Modules*[E] = Table[ModulePath, Schema[E]]
EmbeddedTypeNameKind* {.pure.} = enum
`Ref`, `false`
`EmbeddedTypeName`* {.preservesOr.} = ref object
`EmbeddedTypeName`* {.preservesOr.} = object
case orKind*: EmbeddedTypeNameKind
of EmbeddedTypeNameKind.`Ref`:
`ref`*: Ref
@ -56,17 +56,17 @@ type
`AtomKind`* {.preservesOr.} = enum
`Boolean`, `Float`, `Double`, `SignedInteger`, `String`, `ByteString`,
`Symbol`
Definitions* = Table[string, Definition]
DictionaryEntries* = Table[Preserve[void], NamedSimplePattern]
Definitions*[E] = Table[string, Definition[E]]
DictionaryEntries*[E] = Table[Preserve[E], NamedSimplePattern[E]]
NamedPatternKind* {.pure.} = enum
`named`, `anonymous`
`NamedPattern`* {.preservesOr.} = ref object
`NamedPattern`*[E] {.preservesOr.} = ref object
case orKind*: NamedPatternKind
of NamedPatternKind.`named`:
`named`*: Binding
`named`*: Binding[E]
of NamedPatternKind.`anonymous`:
`anonymous`*: Pattern
`anonymous`*: Pattern[E]
SimplePatternKind* {.pure.} = enum
@ -74,23 +74,23 @@ type
SimplePatternAtom* {.preservesRecord: "atom".} = object
`atomKind`*: AtomKind
SimplePatternEmbedded* {.preservesRecord: "embedded".} = object
`interface`*: SimplePattern
SimplePatternEmbedded*[E] {.preservesRecord: "embedded".} = ref object
`interface`*: SimplePattern[E]
SimplePatternLit* {.preservesRecord: "lit".} = object
`value`*: Preserve[void]
SimplePatternLit*[E] {.preservesRecord: "lit".} = ref object
`value`*: Preserve[E]
SimplePatternSeqof* {.preservesRecord: "seqof".} = object
`pattern`*: SimplePattern
SimplePatternSeqof*[E] {.preservesRecord: "seqof".} = ref object
`pattern`*: SimplePattern[E]
SimplePatternSetof* {.preservesRecord: "setof".} = object
`pattern`*: SimplePattern
SimplePatternSetof*[E] {.preservesRecord: "setof".} = ref object
`pattern`*: SimplePattern[E]
SimplePatternDictof* {.preservesRecord: "dictof".} = object
`key`*: SimplePattern
`value`*: SimplePattern
SimplePatternDictof*[E] {.preservesRecord: "dictof".} = ref object
`key`*: SimplePattern[E]
`value`*: SimplePattern[E]
`SimplePattern`* {.preservesOr.} = ref object
`SimplePattern`*[E] {.preservesOr.} = ref object
case orKind*: SimplePatternKind
of SimplePatternKind.`any`:
`any`* {.preservesLiteral: "any".}: bool
@ -99,19 +99,19 @@ type
`atom`*: SimplePatternAtom
of SimplePatternKind.`embedded`:
`embedded`*: SimplePatternEmbedded
`embedded`*: SimplePatternEmbedded[E]
of SimplePatternKind.`lit`:
`lit`*: SimplePatternLit
`lit`*: SimplePatternLit[E]
of SimplePatternKind.`seqof`:
`seqof`*: SimplePatternSeqof
`seqof`*: SimplePatternSeqof[E]
of SimplePatternKind.`setof`:
`setof`*: SimplePatternSetof
`setof`*: SimplePatternSetof[E]
of SimplePatternKind.`dictof`:
`dictof`*: SimplePatternDictof
`dictof`*: SimplePatternDictof[E]
of SimplePatternKind.`Ref`:
`ref`*: Ref
@ -119,96 +119,98 @@ type
NamedSimplePatternKind* {.pure.} = enum
`named`, `anonymous`
`NamedSimplePattern`* {.preservesOr.} = ref object
`NamedSimplePattern`*[E] {.preservesOr.} = ref object
case orKind*: NamedSimplePatternKind
of NamedSimplePatternKind.`named`:
`named`*: Binding
`named`*: Binding[E]
of NamedSimplePatternKind.`anonymous`:
`anonymous`*: SimplePattern
`anonymous`*: SimplePattern[E]
DefinitionKind* {.pure.} = enum
`or`, `and`, `Pattern`
DefinitionOrData* {.preservesTuple.} = object
`pattern0`*: NamedAlternative
`pattern1`*: NamedAlternative
`patternN`* {.preservesTupleTail.}: seq[NamedAlternative]
DefinitionOrData*[E] {.preservesTuple.} = ref object
`pattern0`*: NamedAlternative[E]
`pattern1`*: NamedAlternative[E]
`patternN`* {.preservesTupleTail.}: seq[NamedAlternative[E]]
DefinitionOr* {.preservesRecord: "or".} = object
`data`*: DefinitionOrData
DefinitionOr*[E] {.preservesRecord: "or".} = ref object
`data`*: DefinitionOrData[E]
DefinitionAndData* {.preservesTuple.} = object
`pattern0`*: NamedPattern
`pattern1`*: NamedPattern
`patternN`* {.preservesTupleTail.}: seq[NamedPattern]
DefinitionAndData*[E] {.preservesTuple.} = ref object
`pattern0`*: NamedPattern[E]
`pattern1`*: NamedPattern[E]
`patternN`* {.preservesTupleTail.}: seq[NamedPattern[E]]
DefinitionAnd* {.preservesRecord: "and".} = object
`data`*: DefinitionAndData
DefinitionAnd*[E] {.preservesRecord: "and".} = ref object
`data`*: DefinitionAndData[E]
`Definition`* {.preservesOr.} = ref object
`Definition`*[E] {.preservesOr.} = ref object
case orKind*: DefinitionKind
of DefinitionKind.`or`:
`or`*: DefinitionOr
`or`*: DefinitionOr[E]
of DefinitionKind.`and`:
`and`*: DefinitionAnd
`and`*: DefinitionAnd[E]
of DefinitionKind.`Pattern`:
`pattern`*: Pattern
`pattern`*: Pattern[E]
NamedAlternative* {.preservesTuple.} = object
NamedAlternative*[E] {.preservesTuple.} = ref object
`variantLabel`*: string
`pattern`*: Pattern
`pattern`*: Pattern[E]
SchemaData* {.preservesDictionary.} = object
SchemaData*[E] {.preservesDictionary.} = ref object
`embeddedType`*: EmbeddedTypeName
`version`* {.preservesLiteral: "1".}: bool
`definitions`*: Definitions
`definitions`*: Definitions[E]
Schema* {.preservesRecord: "schema".} = object
`data`*: SchemaData
Schema*[E] {.preservesRecord: "schema".} = ref object
`data`*: SchemaData[E]
PatternKind* {.pure.} = enum
`SimplePattern`, `CompoundPattern`
`Pattern`* {.preservesOr.} = ref object
`Pattern`*[E] {.preservesOr.} = ref object
case orKind*: PatternKind
of PatternKind.`SimplePattern`:
`simplepattern`*: SimplePattern
`simplepattern`*: SimplePattern[E]
of PatternKind.`CompoundPattern`:
`compoundpattern`*: CompoundPattern
`compoundpattern`*: CompoundPattern[E]
Binding* {.preservesRecord: "named".} = object
Binding*[E] {.preservesRecord: "named".} = ref object
`name`* {.preservesSymbol.}: string
`pattern`*: SimplePattern
`pattern`*: SimplePattern[E]
proc `$`*(x: Ref | ModulePath | Bundle | CompoundPattern | Modules |
EmbeddedTypeName |
Definitions |
DictionaryEntries |
NamedPattern |
SimplePattern |
NamedSimplePattern |
Definition |
NamedAlternative |
Schema |
Pattern |
Binding): string =
proc `$`*[E](x: Bundle[E] | CompoundPattern[E] | Modules[E] | Definitions[E] |
DictionaryEntries[E] |
NamedPattern[E] |
SimplePattern[E] |
NamedSimplePattern[E] |
Definition[E] |
NamedAlternative[E] |
Schema[E] |
Pattern[E] |
Binding[E]): string =
`$`(toPreserve(x))
proc encode*(x: Ref | ModulePath | Bundle | CompoundPattern | Modules |
EmbeddedTypeName |
Definitions |
DictionaryEntries |
NamedPattern |
SimplePattern |
NamedSimplePattern |
Definition |
NamedAlternative |
Schema |
Pattern |
Binding): seq[byte] =
proc encode*[E](x: Bundle[E] | CompoundPattern[E] | Modules[E] | Definitions[E] |
DictionaryEntries[E] |
NamedPattern[E] |
SimplePattern[E] |
NamedSimplePattern[E] |
Definition[E] |
NamedAlternative[E] |
Schema[E] |
Pattern[E] |
Binding[E]): seq[byte] =
encode(toPreserve(x, E))
proc `$`*(x: Ref | ModulePath | EmbeddedTypeName): string =
`$`(toPreserve(x))
proc encode*(x: Ref | ModulePath | EmbeddedTypeName): seq[byte] =
encode(toPreserve(x))

View File

@ -14,7 +14,7 @@ suite "schema":
else:
var
b = decodePreserves readFile(binPath)
scm = preserveTo(b, Schema)
scm = preserveTo(b, Schema[void])
check scm.isSome
if scm.isSome:
var a = toPreserve(get scm)