preserves_schema_nim: add acyclic pragmas

This commit is contained in:
Emery Hemingway 2023-08-06 10:37:07 +01:00
parent ec77872467
commit 57f9984007
2 changed files with 19 additions and 22 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "20230805"
version = "20230806"
author = "Emery Hemingway"
description = "data model and serialization format"
license = "Unlicense"

View File

@ -472,38 +472,35 @@ proc typeDef(loc: Location; name: string; pat: Pattern; ty: PNode): PNode =
id = name.ident.toExport
case pat.orKind
of PatternKind.CompoundPattern:
let pragma = newNode(nkPragma)
if isRecursive(loc, pat): pragma.add(ident"acyclic")
case pat.compoundPattern.orKind
of CompoundPatternKind.rec:
if isLiteral(loc, pat.compoundPattern.rec.label):
nkTypeDef.newTree(
nkPragmaExpr.newTree(
id,
nkPragma.newTree(
nkExprColonExpr.newTree(
ident"preservesRecord",
PNode(kind: nkStrLit, strVal: pat.compoundPattern.rec.label.idStr)))),
embedParams,
ty)
pragma.add(
nkExprColonExpr.newTree(
ident"preservesRecord",
PNode(kind: nkStrLit, strVal: pat.compoundPattern.rec.label.idStr)))
nkTypeDef.newTree(nkPragmaExpr.newTree(id, pragma), embedParams, ty)
elif pragma.len > 0:
nkTypeDef.newTree(nkPragmaExpr.newTree(id, pragma), embedParams, ty)
else:
nkTypeDef.newTree(name.ident.toExport, embedParams, ty)
nkTypeDef.newTree(id, embedParams, ty)
of CompoundPatternKind.tuple, CompoundPatternKind.tuplePrefix:
nkTypeDef.newTree(
nkPragmaExpr.newTree(id, nkPragma.newTree(ident"preservesTuple")),
embedParams,
ty)
pragma.add(ident"preservesTuple")
nkTypeDef.newTree(nkPragmaExpr.newTree(id, pragma), embedParams, ty)
of CompoundPatternKind.dict:
nkTypeDef.newTree(
nkPragmaExpr.newTree(
id, nkPragma.newTree(ident"preservesDictionary")),
embedParams,
ty)
pragma.add(ident"preservesDictionary")
nkTypeDef.newTree(nkPragmaExpr.newTree(id, pragma), embedParams, ty)
else:
nkTypeDef.newTree(name.ident.toExport, embedParams, ty)
nkTypeDef.newTree(id, embedParams, ty)
proc typeDef(loc: Location; name: string; def: Definition; ty: PNode): PNode =
case def.orKind
of DefinitionKind.or:
let pragma = nkPragma.newTree(ident"preservesOr")
let pragma = newNode(nkPragma)
if isRecursive(loc, def): pragma.add(ident"acyclic")
pragma.add(ident"preservesOr")
if isSymbolEnum(loc, def):
pragma.add ident"pure"
nkTypeDef.newTree(