Cleanup preserves_schema_nim

This commit is contained in:
Emery Hemingway 2023-04-01 12:33:15 -05:00
parent 466a8d3af4
commit 1a0cb2be5c
2 changed files with 2 additions and 39 deletions

View File

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

View File

@ -13,7 +13,6 @@ import compiler/[ast, idents, renderer, lineinfos]
import ../preserves, ./schema
type
Value = Preserve[void]
Attribute = enum
embedded
## type contains an embedded value and
@ -98,16 +97,9 @@ proc ident(np: NamedSimplePattern; fallback: string): PNode =
of NamedSimplePatternKind.anonymous:
ident(fallback)
proc isPreserve(n: PNode): bool =
n.kind == nkBracketExpr and
n.renderTree == "preserves.Value"
proc isEmbedded(ts: TypeSpec): bool =
embedded in ts.attrs
proc isRecursive(ts: TypeSpec): bool =
recursive in ts.attrs
proc addAttrs(x: var TypeSpec; y: TypeSpec) =
x.attrs = x.attrs + y.attrs
@ -167,8 +159,6 @@ proc attrs(loc: Location; def: Definition; seen: RefSet): Attributes {.gcsafe.}
proc attrs(loc: Location; n: NamedAlternative|NamedPattern; seen: RefSet): Attributes =
attrs(loc, n.pattern, seen)
proc step(loc: Location; r: Ref): Location = (loc.bundle, r.module)
proc attrs(loc: Location; sp: SimplePattern; seen: RefSet): Attributes =
case sp.orKind
of SimplepatternKind.atom, SimplepatternKind.lit: {}
@ -691,33 +681,6 @@ proc nimTypeOf(loc: Location; known: var TypeTable; def: Definition; name: strin
proc generateConstProcs(result: var seq[PNode]; scm: Schema, name: string; def: Definition) =
discard
proc literalToPreserveCall(scm: Schema; pr: Value): PNode =
var prConstr = nn(nkObjConstr, preserveIdent(scm))
proc constr(kind, field: string; lit: PNode) =
prConstr.add nn(nkExprColonExpr, ident"kind", ident(kind))
prConstr.add nn(nkExprColonExpr, ident(field), lit)
case pr.kind
of pkBoolean:
constr($pr.kind, "bool", if pr.bool: ident"true" else: ident"false")
of pkFloat:
constr($pr.kind, "float", newFloatNode(nkFloat32Lit, pr.float))
of pkDouble:
constr($pr.kind, "double", newFloatNode(nkFloat64Lit, pr.double))
of pkSignedInteger:
constr($pr.kind, "BiggestInt", newIntNode(nkInt64Lit, pr.int))
of pkString:
constr($pr.kind, "string", newStrNode(nkTripleStrLit, pr.string))
of pkByteString:
return nn(nkCall, ident"parsePreserves", newStrNode(nkTripleStrLit, $pr))
of pkSymbol:
constr($pr.kind, "symbol", newStrNode(nkStrLit, string pr.symbol))
else:
raise newException(ValueError, "refusing to convert to a literal: " & $pr)
prConstr
proc generateProcs(result: var seq[PNode]; scm: Schema; name: string; pat: Pattern) =
discard
proc generateProcs(result: var seq[PNode]; scm: Schema; name: string; def: Definition) =
discard
@ -927,7 +890,7 @@ when isMainModule:
add(path, Symbol fileName)
bundle.modules[path] = scm
elif fileExists inputPath:
var (dirPath, fileName, fileExt) = splitFile inputPath
var (dirPath, fileName, _) = splitFile inputPath
let raw = readFile inputPath
if raw[0] == 0xb4.char:
var pr = decodePreserves raw