novy-syndicate/src/gen/sturdy.ts

991 lines
36 KiB
TypeScript

import * as _ from "@preserves/core";
export const $0 = 0;
export const $1 = 1;
export const $Boolean = Symbol.for("Boolean");
export const $ByteString = Symbol.for("ByteString");
export const $Double = Symbol.for("Double");
export const $Embedded = Symbol.for("Embedded");
export const $Float = Symbol.for("Float");
export const $SignedInteger = Symbol.for("SignedInteger");
export const $String = Symbol.for("String");
export const $Symbol = Symbol.for("Symbol");
export const $_ = Symbol.for("_");
export const $and = Symbol.for("and");
export const $arr = Symbol.for("arr");
export const $attenuate = Symbol.for("attenuate");
export const $bind = Symbol.for("bind");
export const $compound = Symbol.for("compound");
export const $dict = Symbol.for("dict");
export const $lit = Symbol.for("lit");
export const $not = Symbol.for("not");
export const $or = Symbol.for("or");
export const $rec = Symbol.for("rec");
export const $ref = Symbol.for("ref");
export const $rewrite = Symbol.for("rewrite");
export type _embedded = any;
export type _val = _.Value<_embedded>;
export type SturdyRef = {"oid": _val, "caveatChain": Array<Attenuation>, "sig": _.Bytes};
export type Attenuation = Array<Caveat>;
export type Caveat = (
{"_variant": "Rewrite", "value": Rewrite} |
{"_variant": "Alts", "value": Alts}
);
export type Rewrite = {"pattern": Pattern, "template": Template};
export type Alts = {"alternatives": Array<Rewrite>};
export type Oid = number;
export type WireRef = (
{"_variant": "mine", "oid": Oid} |
{"_variant": "yours", "oid": Oid, "attenuation": Array<Caveat>}
);
export type ConstructorSpec = (
{"_variant": "CRec", "value": CRec} |
{"_variant": "CArr", "value": CArr} |
{"_variant": "CDict", "value": CDict}
);
export type CRec = {"label": _val, "arity": number};
export type CArr = {"arity": number};
export type CDict = null;
export type Lit = {"value": _val};
export type Pattern = (
{"_variant": "PDiscard", "value": PDiscard} |
{"_variant": "PAtom", "value": PAtom} |
{"_variant": "PEmbedded", "value": PEmbedded} |
{"_variant": "PBind", "value": PBind} |
{"_variant": "PAnd", "value": PAnd} |
{"_variant": "PNot", "value": PNot} |
{"_variant": "Lit", "value": Lit} |
{"_variant": "PCompound", "value": PCompound}
);
export type PDiscard = null;
export type PAtom = (
{"_variant": "Boolean"} |
{"_variant": "Float"} |
{"_variant": "Double"} |
{"_variant": "SignedInteger"} |
{"_variant": "String"} |
{"_variant": "ByteString"} |
{"_variant": "Symbol"}
);
export type PEmbedded = null;
export type PBind = {"name": symbol, "pattern": Pattern};
export type PAnd = {"patterns": Array<Pattern>};
export type PNot = {"pattern": Pattern};
export type PCompound = {"ctor": ConstructorSpec, "members": PCompoundMembers};
export type PCompoundMembers = _.KeyedDictionary<_val, Pattern, _embedded>;
export type Template = (
{"_variant": "TAttenuate", "value": TAttenuate} |
{"_variant": "TRef", "value": TRef} |
{"_variant": "Lit", "value": Lit} |
{"_variant": "TCompound", "value": TCompound}
);
export type TAttenuate = {"template": Template, "attenuation": Attenuation};
export type TRef = {"name": symbol};
export type TCompound = {"ctor": ConstructorSpec, "members": TCompoundMembers};
export type TCompoundMembers = _.KeyedDictionary<_val, Template, _embedded>;
export function SturdyRef(
{oid, caveatChain, sig}: {oid: _val, caveatChain: Array<Attenuation>, sig: _.Bytes}
): SturdyRef {return {"oid": oid, "caveatChain": caveatChain, "sig": sig};}
export function Attenuation(value: Array<Caveat>): Attenuation {return value;}
export namespace Caveat {
export function Rewrite(value: Rewrite): Caveat {return {"_variant": "Rewrite", "value": value};};
export function Alts(value: Alts): Caveat {return {"_variant": "Alts", "value": value};};
}
export function Rewrite({pattern, template}: {pattern: Pattern, template: Template}): Rewrite {return {"pattern": pattern, "template": template};}
export function Alts(alternatives: Array<Rewrite>): Alts {return {"alternatives": alternatives};}
export function Oid(value: number): Oid {return value;}
export namespace WireRef {
export function mine(oid: Oid): WireRef {return {"_variant": "mine", "oid": oid};};
export function yours({oid, attenuation}: {oid: Oid, attenuation: Array<Caveat>}): WireRef {return {"_variant": "yours", "oid": oid, "attenuation": attenuation};};
}
export namespace ConstructorSpec {
export function CRec(value: CRec): ConstructorSpec {return {"_variant": "CRec", "value": value};};
export function CArr(value: CArr): ConstructorSpec {return {"_variant": "CArr", "value": value};};
export function CDict(value: CDict): ConstructorSpec {return {"_variant": "CDict", "value": value};};
}
export function CRec({label, arity}: {label: _val, arity: number}): CRec {return {"label": label, "arity": arity};}
export function CArr(arity: number): CArr {return {"arity": arity};}
export function CDict(): CDict {return null;}
export function Lit(value: _val): Lit {return {"value": value};}
export namespace Pattern {
export function PDiscard(value: PDiscard): Pattern {return {"_variant": "PDiscard", "value": value};};
export function PAtom(value: PAtom): Pattern {return {"_variant": "PAtom", "value": value};};
export function PEmbedded(value: PEmbedded): Pattern {return {"_variant": "PEmbedded", "value": value};};
export function PBind(value: PBind): Pattern {return {"_variant": "PBind", "value": value};};
export function PAnd(value: PAnd): Pattern {return {"_variant": "PAnd", "value": value};};
export function PNot(value: PNot): Pattern {return {"_variant": "PNot", "value": value};};
export function Lit(value: Lit): Pattern {return {"_variant": "Lit", "value": value};};
export function PCompound(value: PCompound): Pattern {return {"_variant": "PCompound", "value": value};};
}
export function PDiscard(): PDiscard {return null;}
export namespace PAtom {
export function Boolean(): PAtom {return {"_variant": "Boolean"};};
export function Float(): PAtom {return {"_variant": "Float"};};
export function Double(): PAtom {return {"_variant": "Double"};};
export function SignedInteger(): PAtom {return {"_variant": "SignedInteger"};};
export function String(): PAtom {return {"_variant": "String"};};
export function ByteString(): PAtom {return {"_variant": "ByteString"};};
export function Symbol(): PAtom {return {"_variant": "Symbol"};};
}
export function PEmbedded(): PEmbedded {return null;}
export function PBind({name, pattern}: {name: symbol, pattern: Pattern}): PBind {return {"name": name, "pattern": pattern};}
export function PAnd(patterns: Array<Pattern>): PAnd {return {"patterns": patterns};}
export function PNot(pattern: Pattern): PNot {return {"pattern": pattern};}
export function PCompound({ctor, members}: {ctor: ConstructorSpec, members: PCompoundMembers}): PCompound {return {"ctor": ctor, "members": members};}
export function PCompoundMembers(value: _.KeyedDictionary<_val, Pattern, _embedded>): PCompoundMembers {return value;}
export namespace Template {
export function TAttenuate(value: TAttenuate): Template {return {"_variant": "TAttenuate", "value": value};};
export function TRef(value: TRef): Template {return {"_variant": "TRef", "value": value};};
export function Lit(value: Lit): Template {return {"_variant": "Lit", "value": value};};
export function TCompound(value: TCompound): Template {return {"_variant": "TCompound", "value": value};};
}
export function TAttenuate({template, attenuation}: {template: Template, attenuation: Attenuation}): TAttenuate {return {"template": template, "attenuation": attenuation};}
export function TRef(name: symbol): TRef {return {"name": name};}
export function TCompound({ctor, members}: {ctor: ConstructorSpec, members: TCompoundMembers}): TCompound {return {"ctor": ctor, "members": members};}
export function TCompoundMembers(value: _.KeyedDictionary<_val, Template, _embedded>): TCompoundMembers {return value;}
export function asSturdyRef(v: _val): SturdyRef {
let result = toSturdyRef(v);
if (result === void 0) throw new TypeError(`Invalid SturdyRef: ${_.stringify(v)}`);
return result;
}
export function toSturdyRef(v: _val): undefined | SturdyRef {
let result: undefined | SturdyRef;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $ref) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_val) | undefined;
_tmp1 = v[0];
if (_tmp1 !== void 0) {
let _tmp2: (Array<Attenuation>) | undefined;
_tmp2 = void 0;
if (_.Array.isArray(v[1])) {
_tmp2 = [];
for (const _tmp3 of v[1]) {
let _tmp4: (Attenuation) | undefined;
_tmp4 = toAttenuation(_tmp3);
if (_tmp4 !== void 0) {_tmp2.push(_tmp4); continue;};
_tmp2 = void 0;
break;
};
};
if (_tmp2 !== void 0) {
let _tmp5: (_.Bytes) | undefined;
_tmp5 = _.Bytes.isBytes(v[2]) ? v[2] : void 0;
if (_tmp5 !== void 0) {result = {"oid": _tmp1, "caveatChain": _tmp2, "sig": _tmp5};};
};
};
};
};
return result;
}
export function fromSturdyRef(_v: SturdyRef): _val {
return _.Record($ref, [_v["oid"], _v["caveatChain"].map(v => fromAttenuation(v)), _v["sig"]]);
}
export function asAttenuation(v: _val): Attenuation {
let result = toAttenuation(v);
if (result === void 0) throw new TypeError(`Invalid Attenuation: ${_.stringify(v)}`);
return result;
}
export function toAttenuation(v: _val): undefined | Attenuation {
let _tmp0: (Array<Caveat>) | undefined;
let result: undefined | Attenuation;
_tmp0 = void 0;
if (_.Array.isArray(v)) {
_tmp0 = [];
for (const _tmp1 of v) {
let _tmp2: (Caveat) | undefined;
_tmp2 = toCaveat(_tmp1);
if (_tmp2 !== void 0) {_tmp0.push(_tmp2); continue;};
_tmp0 = void 0;
break;
};
};
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromAttenuation(_v: Attenuation): _val {return _v.map(v => fromCaveat(v));}
export function asCaveat(v: _val): Caveat {
let result = toCaveat(v);
if (result === void 0) throw new TypeError(`Invalid Caveat: ${_.stringify(v)}`);
return result;
}
export function toCaveat(v: _val): undefined | Caveat {
let _tmp0: (Rewrite) | undefined;
let result: undefined | Caveat;
_tmp0 = toRewrite(v);
if (_tmp0 !== void 0) {result = {"_variant": "Rewrite", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (Alts) | undefined;
_tmp1 = toAlts(v);
if (_tmp1 !== void 0) {result = {"_variant": "Alts", "value": _tmp1};};
};
return result;
}
export function fromCaveat(_v: Caveat): _val {
switch (_v._variant) {
case "Rewrite": {return fromRewrite(_v.value);};
case "Alts": {return fromAlts(_v.value);};
};
}
export function asRewrite(v: _val): Rewrite {
let result = toRewrite(v);
if (result === void 0) throw new TypeError(`Invalid Rewrite: ${_.stringify(v)}`);
return result;
}
export function toRewrite(v: _val): undefined | Rewrite {
let result: undefined | Rewrite;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $rewrite) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Pattern) | undefined;
_tmp1 = toPattern(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (Template) | undefined;
_tmp2 = toTemplate(v[1]);
if (_tmp2 !== void 0) {result = {"pattern": _tmp1, "template": _tmp2};};
};
};
};
return result;
}
export function fromRewrite(_v: Rewrite): _val {
return _.Record($rewrite, [fromPattern(_v["pattern"]), fromTemplate(_v["template"])]);
}
export function asAlts(v: _val): Alts {
let result = toAlts(v);
if (result === void 0) throw new TypeError(`Invalid Alts: ${_.stringify(v)}`);
return result;
}
export function toAlts(v: _val): undefined | Alts {
let result: undefined | Alts;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $or) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Array<Rewrite>) | undefined;
_tmp1 = void 0;
if (_.Array.isArray(v[0])) {
_tmp1 = [];
for (const _tmp2 of v[0]) {
let _tmp3: (Rewrite) | undefined;
_tmp3 = toRewrite(_tmp2);
if (_tmp3 !== void 0) {_tmp1.push(_tmp3); continue;};
_tmp1 = void 0;
break;
};
};
if (_tmp1 !== void 0) {result = {"alternatives": _tmp1};};
};
};
return result;
}
export function fromAlts(_v: Alts): _val {return _.Record($or, [_v["alternatives"].map(v => fromRewrite(v))]);}
export function asOid(v: _val): Oid {
let result = toOid(v);
if (result === void 0) throw new TypeError(`Invalid Oid: ${_.stringify(v)}`);
return result;
}
export function toOid(v: _val): undefined | Oid {
let _tmp0: (number) | undefined;
let result: undefined | Oid;
_tmp0 = typeof v === 'number' ? v : void 0;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromOid(_v: Oid): _val {return _v;}
export function asWireRef(v: _val): WireRef {
let result = toWireRef(v);
if (result === void 0) throw new TypeError(`Invalid WireRef: ${_.stringify(v)}`);
return result;
}
export function toWireRef(v: _val): undefined | WireRef {
let result: undefined | WireRef;
if (_.Array.isArray(v) && v.length === 2) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v[0], $0) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Oid) | undefined;
_tmp1 = toOid(v[1]);
if (_tmp1 !== void 0) {result = {"_variant": "mine", "oid": _tmp1};};
};
};
if (result === void 0) {
if (_.Array.isArray(v) && v.length >= 2) {
let _tmp2: (null) | undefined;
_tmp2 = _.is(v[0], $1) ? null : void 0;
if (_tmp2 !== void 0) {
let _tmp3: (Oid) | undefined;
_tmp3 = toOid(v[1]);
if (_tmp3 !== void 0) {
let _tmp4: (Array<_val>) | undefined;
let _tmp5: (Array<Caveat>) | undefined;
_tmp4 = v.slice(2);
_tmp5 = [];
for (const _tmp6 of _tmp4) {
let _tmp7: (Caveat) | undefined;
_tmp7 = toCaveat(_tmp6);
if (_tmp7 !== void 0) {_tmp5.push(_tmp7); continue;};
_tmp5 = void 0;
break;
};
if (_tmp5 !== void 0) {result = {"_variant": "yours", "oid": _tmp3, "attenuation": _tmp5};};
};
};
};
};
return result;
}
export function fromWireRef(_v: WireRef): _val {
switch (_v._variant) {
case "mine": {return [$0, fromOid(_v["oid"])];};
case "yours": {
return [$1, fromOid(_v["oid"]), ... _v["attenuation"].map(v => fromCaveat(v))];
};
};
}
export function asConstructorSpec(v: _val): ConstructorSpec {
let result = toConstructorSpec(v);
if (result === void 0) throw new TypeError(`Invalid ConstructorSpec: ${_.stringify(v)}`);
return result;
}
export function toConstructorSpec(v: _val): undefined | ConstructorSpec {
let _tmp0: (CRec) | undefined;
let result: undefined | ConstructorSpec;
_tmp0 = toCRec(v);
if (_tmp0 !== void 0) {result = {"_variant": "CRec", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (CArr) | undefined;
_tmp1 = toCArr(v);
if (_tmp1 !== void 0) {result = {"_variant": "CArr", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (CDict) | undefined;
_tmp2 = toCDict(v);
if (_tmp2 !== void 0) {result = {"_variant": "CDict", "value": _tmp2};};
};
};
return result;
}
export function fromConstructorSpec(_v: ConstructorSpec): _val {
switch (_v._variant) {
case "CRec": {return fromCRec(_v.value);};
case "CArr": {return fromCArr(_v.value);};
case "CDict": {return fromCDict(_v.value);};
};
}
export function asCRec(v: _val): CRec {
let result = toCRec(v);
if (result === void 0) throw new TypeError(`Invalid CRec: ${_.stringify(v)}`);
return result;
}
export function toCRec(v: _val): undefined | CRec {
let result: undefined | CRec;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $rec) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_val) | undefined;
_tmp1 = v[0];
if (_tmp1 !== void 0) {
let _tmp2: (number) | undefined;
_tmp2 = typeof v[1] === 'number' ? v[1] : void 0;
if (_tmp2 !== void 0) {result = {"label": _tmp1, "arity": _tmp2};};
};
};
};
return result;
}
export function fromCRec(_v: CRec): _val {return _.Record($rec, [_v["label"], _v["arity"]]);}
export function asCArr(v: _val): CArr {
let result = toCArr(v);
if (result === void 0) throw new TypeError(`Invalid CArr: ${_.stringify(v)}`);
return result;
}
export function toCArr(v: _val): undefined | CArr {
let result: undefined | CArr;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $arr) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (number) | undefined;
_tmp1 = typeof v[0] === 'number' ? v[0] : void 0;
if (_tmp1 !== void 0) {result = {"arity": _tmp1};};
};
};
return result;
}
export function fromCArr(_v: CArr): _val {return _.Record($arr, [_v["arity"]]);}
export function asCDict(v: _val): CDict {
let result = toCDict(v);
if (result === void 0) throw new TypeError(`Invalid CDict: ${_.stringify(v)}`);
return result;
}
export function toCDict(v: _val): undefined | CDict {
let result: undefined | CDict;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $dict) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
};
return result;
}
export function fromCDict(_v: CDict): _val {return _.Record($dict, []);}
export function asLit(v: _val): Lit {
let result = toLit(v);
if (result === void 0) throw new TypeError(`Invalid Lit: ${_.stringify(v)}`);
return result;
}
export function toLit(v: _val): undefined | Lit {
let result: undefined | Lit;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $lit) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (_val) | undefined;
_tmp1 = v[0];
if (_tmp1 !== void 0) {result = {"value": _tmp1};};
};
};
return result;
}
export function fromLit(_v: Lit): _val {return _.Record($lit, [_v["value"]]);}
export function asPattern(v: _val): Pattern {
let result = toPattern(v);
if (result === void 0) throw new TypeError(`Invalid Pattern: ${_.stringify(v)}`);
return result;
}
export function toPattern(v: _val): undefined | Pattern {
let _tmp0: (PDiscard) | undefined;
let result: undefined | Pattern;
_tmp0 = toPDiscard(v);
if (_tmp0 !== void 0) {result = {"_variant": "PDiscard", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (PAtom) | undefined;
_tmp1 = toPAtom(v);
if (_tmp1 !== void 0) {result = {"_variant": "PAtom", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (PEmbedded) | undefined;
_tmp2 = toPEmbedded(v);
if (_tmp2 !== void 0) {result = {"_variant": "PEmbedded", "value": _tmp2};};
if (result === void 0) {
let _tmp3: (PBind) | undefined;
_tmp3 = toPBind(v);
if (_tmp3 !== void 0) {result = {"_variant": "PBind", "value": _tmp3};};
if (result === void 0) {
let _tmp4: (PAnd) | undefined;
_tmp4 = toPAnd(v);
if (_tmp4 !== void 0) {result = {"_variant": "PAnd", "value": _tmp4};};
if (result === void 0) {
let _tmp5: (PNot) | undefined;
_tmp5 = toPNot(v);
if (_tmp5 !== void 0) {result = {"_variant": "PNot", "value": _tmp5};};
if (result === void 0) {
let _tmp6: (Lit) | undefined;
_tmp6 = toLit(v);
if (_tmp6 !== void 0) {result = {"_variant": "Lit", "value": _tmp6};};
if (result === void 0) {
let _tmp7: (PCompound) | undefined;
_tmp7 = toPCompound(v);
if (_tmp7 !== void 0) {result = {"_variant": "PCompound", "value": _tmp7};};
};
};
};
};
};
};
};
return result;
}
export function fromPattern(_v: Pattern): _val {
switch (_v._variant) {
case "PDiscard": {return fromPDiscard(_v.value);};
case "PAtom": {return fromPAtom(_v.value);};
case "PEmbedded": {return fromPEmbedded(_v.value);};
case "PBind": {return fromPBind(_v.value);};
case "PAnd": {return fromPAnd(_v.value);};
case "PNot": {return fromPNot(_v.value);};
case "Lit": {return fromLit(_v.value);};
case "PCompound": {return fromPCompound(_v.value);};
};
}
export function asPDiscard(v: _val): PDiscard {
let result = toPDiscard(v);
if (result === void 0) throw new TypeError(`Invalid PDiscard: ${_.stringify(v)}`);
return result;
}
export function toPDiscard(v: _val): undefined | PDiscard {
let result: undefined | PDiscard;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $_) ? null : void 0;
if (_tmp0 !== void 0) {result = null;};
};
return result;
}
export function fromPDiscard(_v: PDiscard): _val {return _.Record($_, []);}
export function asPAtom(v: _val): PAtom {
let result = toPAtom(v);
if (result === void 0) throw new TypeError(`Invalid PAtom: ${_.stringify(v)}`);
return result;
}
export function toPAtom(v: _val): undefined | PAtom {
let _tmp0: (null) | undefined;
let result: undefined | PAtom;
_tmp0 = _.is(v, $Boolean) ? null : void 0;
if (_tmp0 !== void 0) {result = {"_variant": "Boolean"};};
if (result === void 0) {
let _tmp1: (null) | undefined;
_tmp1 = _.is(v, $Float) ? null : void 0;
if (_tmp1 !== void 0) {result = {"_variant": "Float"};};
if (result === void 0) {
let _tmp2: (null) | undefined;
_tmp2 = _.is(v, $Double) ? null : void 0;
if (_tmp2 !== void 0) {result = {"_variant": "Double"};};
if (result === void 0) {
let _tmp3: (null) | undefined;
_tmp3 = _.is(v, $SignedInteger) ? null : void 0;
if (_tmp3 !== void 0) {result = {"_variant": "SignedInteger"};};
if (result === void 0) {
let _tmp4: (null) | undefined;
_tmp4 = _.is(v, $String) ? null : void 0;
if (_tmp4 !== void 0) {result = {"_variant": "String"};};
if (result === void 0) {
let _tmp5: (null) | undefined;
_tmp5 = _.is(v, $ByteString) ? null : void 0;
if (_tmp5 !== void 0) {result = {"_variant": "ByteString"};};
if (result === void 0) {
let _tmp6: (null) | undefined;
_tmp6 = _.is(v, $Symbol) ? null : void 0;
if (_tmp6 !== void 0) {result = {"_variant": "Symbol"};};
};
};
};
};
};
};
return result;
}
export function fromPAtom(_v: PAtom): _val {
switch (_v._variant) {
case "Boolean": {return $Boolean;};
case "Float": {return $Float;};
case "Double": {return $Double;};
case "SignedInteger": {return $SignedInteger;};
case "String": {return $String;};
case "ByteString": {return $ByteString;};
case "Symbol": {return $Symbol;};
};
}
export function asPEmbedded(v: _val): PEmbedded {
let result = toPEmbedded(v);
if (result === void 0) throw new TypeError(`Invalid PEmbedded: ${_.stringify(v)}`);
return result;
}
export function toPEmbedded(v: _val): undefined | PEmbedded {
let _tmp0: (null) | undefined;
let result: undefined | PEmbedded;
_tmp0 = _.is(v, $Embedded) ? null : void 0;
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromPEmbedded(_v: PEmbedded): _val {return $Embedded;}
export function asPBind(v: _val): PBind {
let result = toPBind(v);
if (result === void 0) throw new TypeError(`Invalid PBind: ${_.stringify(v)}`);
return result;
}
export function toPBind(v: _val): undefined | PBind {
let result: undefined | PBind;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $bind) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (symbol) | undefined;
_tmp1 = typeof v[0] === 'symbol' ? v[0] : void 0;
if (_tmp1 !== void 0) {
let _tmp2: (Pattern) | undefined;
_tmp2 = toPattern(v[1]);
if (_tmp2 !== void 0) {result = {"name": _tmp1, "pattern": _tmp2};};
};
};
};
return result;
}
export function fromPBind(_v: PBind): _val {return _.Record($bind, [_v["name"], fromPattern(_v["pattern"])]);}
export function asPAnd(v: _val): PAnd {
let result = toPAnd(v);
if (result === void 0) throw new TypeError(`Invalid PAnd: ${_.stringify(v)}`);
return result;
}
export function toPAnd(v: _val): undefined | PAnd {
let result: undefined | PAnd;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $and) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Array<Pattern>) | undefined;
_tmp1 = void 0;
if (_.Array.isArray(v[0])) {
_tmp1 = [];
for (const _tmp2 of v[0]) {
let _tmp3: (Pattern) | undefined;
_tmp3 = toPattern(_tmp2);
if (_tmp3 !== void 0) {_tmp1.push(_tmp3); continue;};
_tmp1 = void 0;
break;
};
};
if (_tmp1 !== void 0) {result = {"patterns": _tmp1};};
};
};
return result;
}
export function fromPAnd(_v: PAnd): _val {return _.Record($and, [_v["patterns"].map(v => fromPattern(v))]);}
export function asPNot(v: _val): PNot {
let result = toPNot(v);
if (result === void 0) throw new TypeError(`Invalid PNot: ${_.stringify(v)}`);
return result;
}
export function toPNot(v: _val): undefined | PNot {
let result: undefined | PNot;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $not) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Pattern) | undefined;
_tmp1 = toPattern(v[0]);
if (_tmp1 !== void 0) {result = {"pattern": _tmp1};};
};
};
return result;
}
export function fromPNot(_v: PNot): _val {return _.Record($not, [fromPattern(_v["pattern"])]);}
export function asPCompound(v: _val): PCompound {
let result = toPCompound(v);
if (result === void 0) throw new TypeError(`Invalid PCompound: ${_.stringify(v)}`);
return result;
}
export function toPCompound(v: _val): undefined | PCompound {
let result: undefined | PCompound;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $compound) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (ConstructorSpec) | undefined;
_tmp1 = toConstructorSpec(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (PCompoundMembers) | undefined;
_tmp2 = toPCompoundMembers(v[1]);
if (_tmp2 !== void 0) {result = {"ctor": _tmp1, "members": _tmp2};};
};
};
};
return result;
}
export function fromPCompound(_v: PCompound): _val {
return _.Record(
$compound,
[fromConstructorSpec(_v["ctor"]), fromPCompoundMembers(_v["members"])]
);
}
export function asPCompoundMembers(v: _val): PCompoundMembers {
let result = toPCompoundMembers(v);
if (result === void 0) throw new TypeError(`Invalid PCompoundMembers: ${_.stringify(v)}`);
return result;
}
export function toPCompoundMembers(v: _val): undefined | PCompoundMembers {
let _tmp0: (_.KeyedDictionary<_val, Pattern, _embedded>) | undefined;
let result: undefined | PCompoundMembers;
_tmp0 = void 0;
if (_.Dictionary.isDictionary<_embedded>(v)) {
_tmp0 = new _.KeyedDictionary();
for (const [_tmp2, _tmp1] of v) {
let _tmp3: (_val) | undefined;
_tmp3 = _tmp2;
if (_tmp3 !== void 0) {
let _tmp4: (Pattern) | undefined;
_tmp4 = toPattern(_tmp1);
if (_tmp4 !== void 0) {_tmp0.set(_tmp3, _tmp4); continue;};
};
_tmp0 = void 0;
break;
};
};
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromPCompoundMembers(_v: PCompoundMembers): _val {
return new _.Dictionary<_embedded>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromPattern(v)]));
}
export function asTemplate(v: _val): Template {
let result = toTemplate(v);
if (result === void 0) throw new TypeError(`Invalid Template: ${_.stringify(v)}`);
return result;
}
export function toTemplate(v: _val): undefined | Template {
let _tmp0: (TAttenuate) | undefined;
let result: undefined | Template;
_tmp0 = toTAttenuate(v);
if (_tmp0 !== void 0) {result = {"_variant": "TAttenuate", "value": _tmp0};};
if (result === void 0) {
let _tmp1: (TRef) | undefined;
_tmp1 = toTRef(v);
if (_tmp1 !== void 0) {result = {"_variant": "TRef", "value": _tmp1};};
if (result === void 0) {
let _tmp2: (Lit) | undefined;
_tmp2 = toLit(v);
if (_tmp2 !== void 0) {result = {"_variant": "Lit", "value": _tmp2};};
if (result === void 0) {
let _tmp3: (TCompound) | undefined;
_tmp3 = toTCompound(v);
if (_tmp3 !== void 0) {result = {"_variant": "TCompound", "value": _tmp3};};
};
};
};
return result;
}
export function fromTemplate(_v: Template): _val {
switch (_v._variant) {
case "TAttenuate": {return fromTAttenuate(_v.value);};
case "TRef": {return fromTRef(_v.value);};
case "Lit": {return fromLit(_v.value);};
case "TCompound": {return fromTCompound(_v.value);};
};
}
export function asTAttenuate(v: _val): TAttenuate {
let result = toTAttenuate(v);
if (result === void 0) throw new TypeError(`Invalid TAttenuate: ${_.stringify(v)}`);
return result;
}
export function toTAttenuate(v: _val): undefined | TAttenuate {
let result: undefined | TAttenuate;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $attenuate) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (Template) | undefined;
_tmp1 = toTemplate(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (Attenuation) | undefined;
_tmp2 = toAttenuation(v[1]);
if (_tmp2 !== void 0) {result = {"template": _tmp1, "attenuation": _tmp2};};
};
};
};
return result;
}
export function fromTAttenuate(_v: TAttenuate): _val {
return _.Record($attenuate, [fromTemplate(_v["template"]), fromAttenuation(_v["attenuation"])]);
}
export function asTRef(v: _val): TRef {
let result = toTRef(v);
if (result === void 0) throw new TypeError(`Invalid TRef: ${_.stringify(v)}`);
return result;
}
export function toTRef(v: _val): undefined | TRef {
let result: undefined | TRef;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $ref) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (symbol) | undefined;
_tmp1 = typeof v[0] === 'symbol' ? v[0] : void 0;
if (_tmp1 !== void 0) {result = {"name": _tmp1};};
};
};
return result;
}
export function fromTRef(_v: TRef): _val {return _.Record($ref, [_v["name"]]);}
export function asTCompound(v: _val): TCompound {
let result = toTCompound(v);
if (result === void 0) throw new TypeError(`Invalid TCompound: ${_.stringify(v)}`);
return result;
}
export function toTCompound(v: _val): undefined | TCompound {
let result: undefined | TCompound;
if (_.Record.isRecord<_val, _.Tuple<_val>, _embedded>(v)) {
let _tmp0: (null) | undefined;
_tmp0 = _.is(v.label, $compound) ? null : void 0;
if (_tmp0 !== void 0) {
let _tmp1: (ConstructorSpec) | undefined;
_tmp1 = toConstructorSpec(v[0]);
if (_tmp1 !== void 0) {
let _tmp2: (TCompoundMembers) | undefined;
_tmp2 = toTCompoundMembers(v[1]);
if (_tmp2 !== void 0) {result = {"ctor": _tmp1, "members": _tmp2};};
};
};
};
return result;
}
export function fromTCompound(_v: TCompound): _val {
return _.Record(
$compound,
[fromConstructorSpec(_v["ctor"]), fromTCompoundMembers(_v["members"])]
);
}
export function asTCompoundMembers(v: _val): TCompoundMembers {
let result = toTCompoundMembers(v);
if (result === void 0) throw new TypeError(`Invalid TCompoundMembers: ${_.stringify(v)}`);
return result;
}
export function toTCompoundMembers(v: _val): undefined | TCompoundMembers {
let _tmp0: (_.KeyedDictionary<_val, Template, _embedded>) | undefined;
let result: undefined | TCompoundMembers;
_tmp0 = void 0;
if (_.Dictionary.isDictionary<_embedded>(v)) {
_tmp0 = new _.KeyedDictionary();
for (const [_tmp2, _tmp1] of v) {
let _tmp3: (_val) | undefined;
_tmp3 = _tmp2;
if (_tmp3 !== void 0) {
let _tmp4: (Template) | undefined;
_tmp4 = toTemplate(_tmp1);
if (_tmp4 !== void 0) {_tmp0.set(_tmp3, _tmp4); continue;};
};
_tmp0 = void 0;
break;
};
};
if (_tmp0 !== void 0) {result = _tmp0;};
return result;
}
export function fromTCompoundMembers(_v: TCompoundMembers): _val {
return new _.Dictionary<_embedded>(_.Array.from(_v.entries()).map(([k, v]) => [k, fromTemplate(v)]));
}