From 5afb1469f37dcc6ff098e895cb1227f27f4d7b6d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 14 Mar 2021 21:10:47 +0100 Subject: [PATCH] Faster generated decoders --- .../javascript/packages/core/src/decoder.ts | 97 +-- .../packages/schema/src/compiler.ts | 357 +++++--- .../packages/schema/src/gen/schema.ts | 820 +++++++++--------- 3 files changed, 680 insertions(+), 594 deletions(-) diff --git a/implementations/javascript/packages/core/src/decoder.ts b/implementations/javascript/packages/core/src/decoder.ts index 8d62eff..7680e34 100644 --- a/implementations/javascript/packages/core/src/decoder.ts +++ b/implementations/javascript/packages/core/src/decoder.ts @@ -44,7 +44,10 @@ export interface TypedDecoder { closeCompound(): boolean; } -export function checkIs>(actual: Value, expected: E): E | undefined { +export function asLiteral, Annotated>>( + actual: Value, + expected: E): E | undefined +{ return is(actual, expected) ? expected : void 0; } @@ -78,16 +81,7 @@ export class Decoder implements TypedDecoder { nextbyte(): number { if (this.atEnd()) throw new ShortPacket("Short packet"); - return this.packet[this.advance()]; - } - - peekbyte(): number { - if (this.atEnd()) throw new ShortPacket("Short packet"); - return this.packet[this.index]; - } - - advance(): number { - return this.index++; + return this.packet[this.index++]; } nextbytes(n: number): DataView { @@ -106,7 +100,7 @@ export class Decoder implements TypedDecoder { } peekend(): boolean { - return (this.peekbyte() === Tag.End) && (this.advance(), true); + return (this.nextbyte() === Tag.End) || (this.index--, false); } nextvalues(): Value[] { @@ -259,55 +253,42 @@ export class Decoder implements TypedDecoder { } skipAnnotations(): void { - while (this.peekbyte() === Tag.Annotation) { - this.advance(); + if (!this.atEnd() && this.packet[this.index] === Tag.Annotation) { + this.index++; this.skip(); } } nextBoolean(): boolean | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.False: this.advance(); return false; - case Tag.True: this.advance(); return true; + switch (this.nextbyte()) { + case Tag.False: return false; + case Tag.True: return true; default: return void 0; } } nextFloat(): SingleFloat | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.Float: - this.advance(); - return new SingleFloat(this.nextbytes(4).getFloat32(0, false)); - default: - return void 0; + switch (this.nextbyte()) { + case Tag.Float: return new SingleFloat(this.nextbytes(4).getFloat32(0, false)); + default: return void 0; } } nextDouble(): DoubleFloat | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.Double: - this.advance(); - return new DoubleFloat(this.nextbytes(8).getFloat64(0, false)); - default: - return void 0; + switch (this.nextbyte()) { + case Tag.Double: return new DoubleFloat(this.nextbytes(8).getFloat64(0, false)); + default: return void 0; } } nextPointer(): T | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.Pointer: { - this.advance(); - const M = this.mark(); - const v = this.decodePointer(this); - if (v === void 0) this.restoreMark(M); - return v; - } - default: - return void 0; + switch (this.nextbyte()) { + case Tag.Pointer: return this.decodePointer(this); + default: return void 0; } } @@ -315,43 +296,31 @@ export class Decoder implements TypedDecoder { this.skipAnnotations(); const b = this.nextbyte(); switch (b) { - case Tag.SignedInteger: - return this.nextint(this.varint()); - default: { - const v = this.nextSmallOrMediumInteger(b); - if (v === void 0) this.index--; // ugh - return v; - } + case Tag.SignedInteger: return this.nextint(this.varint()); + default: return this.nextSmallOrMediumInteger(b); } } nextString(): string | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.String: - this.advance(); - return Bytes.from(this.nextbytes(this.varint())).fromUtf8(); - default: - return void 0; + switch (this.nextbyte()) { + case Tag.String: return Bytes.from(this.nextbytes(this.varint())).fromUtf8(); + default: return void 0; } } nextByteString(): Bytes | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { - case Tag.ByteString: - this.advance(); - return Bytes.from(this.nextbytes(this.varint())); - default: - return void 0; + switch (this.nextbyte()) { + case Tag.ByteString: return Bytes.from(this.nextbytes(this.varint())); + default: return void 0; } } nextSymbol(): symbol | undefined { this.skipAnnotations(); - switch (this.peekbyte()) { + switch (this.nextbyte()) { case Tag.Symbol: - this.advance(); return Symbol.for(Bytes.from(this.nextbytes(this.varint())).fromUtf8()); default: return void 0; @@ -360,22 +329,22 @@ export class Decoder implements TypedDecoder { openRecord(): boolean { this.skipAnnotations(); - return (this.peekbyte() === Tag.Record) && (this.advance(), true); + return (this.nextbyte() === Tag.Record) || (this.index--, false); } openSequence(): boolean { this.skipAnnotations(); - return (this.peekbyte() === Tag.Sequence) && (this.advance(), true); + return (this.nextbyte() === Tag.Sequence) || (this.index--, false); } openSet(): boolean { this.skipAnnotations(); - return (this.peekbyte() === Tag.Set) && (this.advance(), true); + return (this.nextbyte() === Tag.Set) || (this.index--, false); } openDictionary(): boolean { this.skipAnnotations(); - return (this.peekbyte() === Tag.Dictionary) && (this.advance(), true); + return (this.nextbyte() === Tag.Dictionary) || (this.index--, false); } closeCompound(): boolean { diff --git a/implementations/javascript/packages/schema/src/compiler.ts b/implementations/javascript/packages/schema/src/compiler.ts index f6407f3..c1e5813 100644 --- a/implementations/javascript/packages/schema/src/compiler.ts +++ b/implementations/javascript/packages/schema/src/compiler.ts @@ -20,10 +20,12 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio const functions: Array = []; const imports = new KeyedSet<[string, string]>(); let temps: Array = []; + let body: Array = []; + let tempCounter = 0; const pointerName = Schema._.details(schema).get(M.$pointer); function gentemp(): string { - const varname = '_tmp' + temps.length; + const varname = '_tmp' + tempCounter++; temps.push(varname); return varname; } @@ -40,113 +42,245 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio return varname; } - function decoderFor(p: Pattern, recordFields = false): Item { + function emit(item: Item): void { + body.push(item); + } + + function collectBody(f: () => void): Item { + const oldTemps = temps; + const oldBody = body; + temps = [] + body = []; + f(); + const ts = temps; + const result = body; + temps = oldTemps; + body = oldBody; + return block( + ... ts.length > 0 ? [seq('let ', commas(... ts), ': any')] : [], + ... result); + } + + function accumulateCompound(p: Pattern, + kFail: () => Item[], + kAcc: (temp: string) => Item[]): Item + { + const t = gentemp(); + return seq(`while (!d.closeCompound()) `, collectBody(() => { + emit(seq(`${t} = void 0`)); + decoderFor(p, t); + emit(seq(`if (${t} === void 0) `, block( + ... kFail(), + seq(`break`)))); + kAcc(t).forEach(emit); + })); + } + + function derefPattern(p: Pattern): Pattern { + if (p.label === M.$ref) { + return lookup(refPosition(p), p, env, + (p) => p, + (p) => p, + (_mod, _modPath, pp) => pp ?? p); + } else { + return p; + } + } + + function decoderForTuple(ps: Pattern[], + dest: string, + recordFields: boolean, + variablePattern: Pattern | undefined): void { + const temps = ps.map(gentemp); + function loop(i: number) { + if (i < ps.length) { + decoderFor(ps[i], temps[i]); + emit(seq(`if (${temps[i]} !== void 0) `, + collectBody(() => loop(i + 1)))); + } else { + if (variablePattern === void 0) { + emit(seq(`if (d.closeCompound()) ${dest} = `, brackets(... temps))); + } else { + emit(block( + seq(`let vN: Array<`, typeFor(variablePattern), + `> | undefined = `, brackets(... temps)), + accumulateCompound(variablePattern, + () => [`vN = void 0`], + (t) => [`vN.push(${t})`]), + seq(`${dest} = vN`))); + } + } + } + if (recordFields) { + loop(0); + } else { + emit(seq(`if (d.openSequence()) `, collectBody(() => loop(0)))); + } + } + + function decoderFor(p: Pattern, dest: string, recordFields = false): void { switch (p.label) { case M.$atom: switch (p[0]) { - case M.$Boolean: return `d.nextBoolean()`; - case M.$Float: return `d.nextFloat()`; - case M.$Double: return `d.nextDouble()`; - case M.$SignedInteger: return `d.nextSignedInteger()`; - case M.$String: return `d.nextString()`; - case M.$ByteString: return `d.nextByteString()`; - case M.$Symbol: return `d.nextSymbol()`; + case M.$Boolean: emit(`${dest} = d.nextBoolean()`); break; + case M.$Float: emit(`${dest} = d.nextFloat()`); break; + case M.$Double: emit(`${dest} = d.nextDouble()`); break; + case M.$SignedInteger: emit(`${dest} = d.nextSignedInteger()`); break; + case M.$String: emit(`${dest} = d.nextString()`); break; + case M.$ByteString: emit(`${dest} = d.nextByteString()`); break; + case M.$Symbol: emit(`${dest} = d.nextSymbol()`); break; } - case M.$lit: + break; + case M.$lit: { + let n: string; switch (typeof p[0]) { - case 'boolean': return `_.checkIs(d.nextBoolean(), ${literal(p[0])})`; - case 'string': return `_.checkIs(d.nextString(), ${literal(p[0])})`; - case 'number': return `_.checkIs(d.nextSignedInteger(), ${literal(p[0])})`; - case 'symbol': return `_.checkIs(d.nextSymbol(), ${literal(p[0])})`; - default: return `_.checkIs(d.next(), ${literal(p[0])})`; + case 'boolean': n = `d.nextBoolean()`; break; + case 'string': n = `d.nextString()`; break; + case 'number': n = `d.nextSignedInteger()`; break; + case 'symbol': n = `d.nextSymbol()`; break; + default: n = `d.next()`; break; } + emit(`${dest} = _.asLiteral(${n}, ${literal(p[0])})`); + break; + } case M.$ref: - return lookup(refPosition(p), p, env, - (_p) => `decode${p[1].description!}(d)`, - (p) => decoderFor(p), - (mod, modPath,_p) => { - imports.add([mod, modPath]); - return `${mod}.decode${p[1].description!}(d)`; - }); - case M.$or: - return opseq('void 0', ' ?? ', ... p[0].map(pp => decoderFor(pp))); - case M.$and: - switch (p[0].length) { - case 0: return `d.next()`; - case 1: return decoderFor(p[0][0]); - default: { - const tmp = gentemp(); - const [pp0, ... ppN] = p[0]; - const otherChecks = - opseq('false', ' && ', ... ppN.map(pp => predicateFor(tmp, pp))); - return seq(`((${tmp} = `, decoderFor(pp0), `) != void 0) && `, - otherChecks, ` ? ${tmp} : void 0`); + lookup(refPosition(p), p, env, + (_p) => emit(`${dest} = decode${p[1].description!}(d)`), + (p) => decoderFor(p, dest), + (mod, modPath,_p) => { + imports.add([mod, modPath]); + emit(`${dest} = ${mod}.decode${p[1].description!}(d)`); + }); + break; + case M.$or: { + const alts = p[0]; + const recs = alts.map(derefPattern); + if (recs.length > 1 && recs.every(pp => pp.label === M.$rec)) { + // Hoist the record check up. + // This is pretty hacky. If we lift the level of + // discourse a little, we can do this + // automatically and generically... + emit(seq(`if (d.openRecord()) `, collectBody(() => { + const label = gentemp(); + emit(seq(`${label} = d.next()`)); + const mark = gentemp(); + emit(seq(`${mark} = d.mark()`)); + function loop(i: number) { + const alt = recs[i]; + if (alt.label !== M.$rec) return; // avoid a cast + emit(seq(`if (`, predicateFor(label, alt[0]), `) `, collectBody(() => { + const fs = gentemp(); + decoderFor(alt[1], fs, true); + emit(seq(`if (${fs} !== void 0) ${dest} = _.Record`, + anglebrackets(typeFor(alt[0]), typeFor(alt[1])), + parens(seq(label, ` as any`), + seq(fs, ` as any`)))); + }))); + if (i < recs.length - 1) { + emit(seq(`if (${dest} === void 0) `, collectBody(() => { + emit(`d.restoreMark(${mark})`); + loop(i + 1); + }))); + } + } + loop(0); + }))); + } else { + switch (alts.length) { + case 0: break; // assume dest is already void 0 + case 1: decoderFor(alts[0], dest); break; + default: { + const mark = gentemp(); + emit(`${mark} = d.mark()`); + function loop(i: number) { + decoderFor(alts[i], dest); + if (i < alts.length - 1) { + emit(seq(`if (${dest} === void 0) `, collectBody(() => { + emit(`d.restoreMark(${mark})`); + loop(i + 1); + }))); + } + } + loop(0); + break; + } } } + break; + } + case M.$and: + switch (p[0].length) { + case 0: emit(`${dest} = d.next()`); break; + case 1: decoderFor(p[0][0], dest); break; + default: { + const [pp0, ... ppN] = p[0]; + decoderFor(pp0, dest); + const otherChecks = + opseq('true', ' && ', ... ppN.map(pp => predicateFor(dest, pp))); + emit(seq(`if (!`, otherChecks, `) ${dest} = void 0`)); + break; + } + } + break; case M.$pointer: - return `_decodePtr(d)`; + emit(`${dest} = _decodePtr(d)`); + break; case M.$rec: - return fnblock( - seq(`const M = d.mark()`), - seq(`if (!d.openRecord()) return void 0`), - seq(`const L = `, decoderFor(p[0])), - seq(`if (L === void 0) { d.restoreMark(M); return void 0; }`), - seq(`const Fs = (`, decoderFor(p[1], true), `) as any`), - seq(`if (Fs === void 0) { d.restoreMark(M); return void 0; }`), - seq(`return _.Record`, - anglebrackets(typeFor(p[0]), typeFor(p[1])), - parens(`L`, `Fs`))); + // assume dest is already void 0 + emit(seq(`if (d.openRecord()) `, collectBody(() => { + const label = gentemp(); + decoderFor(p[0], label); + emit(seq(`if (${label} !== void 0) `, + collectBody(() => { + const fs = gentemp(); + decoderFor(p[1], fs, true); + emit(seq( + `if (${fs} !== void 0) ${dest} = _.Record`, + anglebrackets(typeFor(p[0]), typeFor(p[1])), + parens(seq(label, ` as any`), + seq(fs, ` as any`)))); + }))); + }))); + break; case M.$tuple: - return fnblock( - seq(`const M = d.mark()`), - ... recordFields ? [] : [seq(`if (!d.openSequence()) return void 0`)], - ... p[0].map((pp, i) => - seq(`const v${i} = `, decoderFor(unname(pp)), `; `, - `if (v${i} === void 0) { d.restoreMark(M); return void 0; }`)), - seq(`if (!d.closeCompound()) { d.restoreMark(M); return void 0; }`), - seq(`return [${p[0].map((_pp, i) => `v${i}`).join(', ')}] as `, typeFor(p))); + // assume dest is already void 0 + decoderForTuple(p[0].map(unname), dest, recordFields, void 0); + break; case M.$tuple_STAR_: - return fnblock( - seq(`const M = d.mark()`), - ... recordFields ? [] : [seq(`if (!d.openSequence()) return void 0`)], - ... p[0].map((pp, i) => - seq(`const v${i} = `, decoderFor(unname(pp)), `; `, - `if (v${i} === void 0) { d.restoreMark(M); return void 0; }`)), - seq(`const vN: Array<`, typeFor(unname(p[1])), `> = []`), - seq(`let tmp: undefined | `, typeFor(unname(p[1]))), - seq(`while ((tmp = `, decoderFor(unname(p[1])), `) !== void 0) vN.push(tmp)`), - seq(`if (!d.closeCompound()) { d.restoreMark(M); return void 0; }`), - (p[0].length === 0 - ? seq(`return vN`) - : seq(`return [${p[0].map((_pp, i) => `v${i}`).join(', ')}, ... vN] as `, - typeFor(p)))); + // assume dest is already void 0 + decoderForTuple(p[0].map(unname), dest, recordFields, unname(p[1])); + break; case M.$setof: - return fnblock( - seq(`const M = d.mark()`), - seq(`if (!d.openSet()) return void 0`), - seq(`const r: `, typeFor(p), ` = new _.KeyedSet()`), - seq(`let tmp: undefined | `, typeFor(p[0])), - seq(`while ((tmp = `, decoderFor(p[0]), `) !== void 0) r.add(tmp)`), - seq(`if (!d.closeCompound()) { d.restoreMark(M); return void 0; }`), - seq(`return r`)); + // assume dest is already void 0 + emit(seq(`if (d.openSet()) `, collectBody(() => { + emit(seq(`let r: `, typeFor(p), ` | undefined = new _.KeyedSet()`)); + emit(accumulateCompound(p[0], + () => [`r = void 0`], + (t) => [`r.add(${t})`])); + emit(`${dest} = r`); + }))); + break; case M.$dictof: - return fnblock( - seq(`const M = d.mark()`), - seq(`if (!d.openDictionary()) return void 0`), - seq(`const r: `, typeFor(p), ` = new _.KeyedDictionary()`), - seq(`let K: undefined | `, typeFor(p[0])), - seq(`while ((K = `, decoderFor(p[0]), `) !== void 0) `, block( - seq(`const V = `, decoderFor(p[1])), - seq(`if (V === void 0) { d.restoreMark(M); return void 0; }`), - seq(`r.set(K, V)`))), - seq(`if (!d.closeCompound()) { d.restoreMark(M); return void 0; }`), - seq(`return r`)); + // assume dest is already void 0 + emit(seq(`if (d.openDictionary()) `, collectBody(() => { + emit(seq(`let r: `, typeFor(p), ` | undefined = new _.KeyedDictionary()`)); + emit(seq(`while (!d.closeCompound()) `, collectBody(() => { + emit(seq(`let K: undefined | `, typeFor(p[0]), ` = void 0`)); + decoderFor(p[0], 'K'); + emit(seq(`if (K === void 0) { r = void 0; break; }`)); + emit(seq(`let V: undefined | `, typeFor(p[1]), ` = void 0`)); + decoderFor(p[1], 'V'); + emit(seq(`if (V === void 0) { r = void 0; break; }`)); + emit(seq(`r.set(K, V)`)); + }))); + emit(seq(`${dest} = r`)); + }))); + break; case M.$dict: - return fnblock( - seq(`const M = d.mark()`), - seq(`const r = d.next()`), - seq(`if (!(`, predicateFor('r', p), `)) { d.restoreMark(M); return void 0; }`), - seq(`return r`)); + emit(seq(`${dest} = d.next()`)); + emit(seq( + `if (${dest} !== void 0 && !(`, predicateFor(dest, p), `)) ${dest} = void 0`)); + break; default: ((_p: never) => {})(p); throw new Error("Unreachable"); @@ -223,7 +357,7 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio case M.$Symbol: return `typeof ${v} === 'symbol'`; } case M.$lit: - return `_.is(${v}, ${literal(p[0])})`; + return `_.asLiteral(${v}, ${literal(p[0])}) !== void 0`; case M.$ref: return lookup(refPosition(p), p, env, (_p) => `is${Ref._.name(p).description!}(${v})`, @@ -232,8 +366,22 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio imports.add([mod, modPath]); return `${mod}.is${Ref._.name(p).description!}(${v})`; }); - case M.$or: - return opseq('false', ' || ', ... p[0].map(pp => predicateFor(v, pp))); + case M.$or: { + const alts = p[0]; + const recs = alts.map(derefPattern); + if (recs.length > 1 && recs.every(pp => pp.label === M.$rec)) { + return seq( + `_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(${v}) && `, + parens(opseq('false', ' || ', + ... recs.map(r => + (r.label !== M.$rec) ? '' : parens(seq( + predicateFor(`${v}.label`, r[0]), + ' && ', + predicateFor(v, r[1], true))))))); + } else { + return opseq('false', ' || ', ... p[0].map(pp => predicateFor(v, pp))); + } + } case M.$and: return opseq('true', ' && ', ... p[0].map(pp => predicateFor(v, pp))); case M.$pointer: @@ -254,7 +402,7 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio ... (recordOkAsTuple ? [] : [`_.Array.isArray(${v})`, `!_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(${v})`]), `(${v}.length >= ${p[0].length})`, - seq(`${v}.slice(${p[0].length})`, + seq(p[0].length > 0 ? `${v}.slice(${p[0].length})` : v, `.every(v => `, parens(predicateFor('v', unname(p[1]))), `)`), @@ -332,14 +480,14 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio ' else ', block(`return v`))))); - temps = []; - const decoder = decoderFor(pattern); functions.push( seq(`export function decode${name.description!}`, `(d: _.TypedDecoder<_ptr>): ${name.description!} | undefined `, - block( - ... temps.length > 0 ? [seq('let ', commas(... temps), ': any')] : [], - seq(`return `, decoder)))); + collectBody(() => { + emit(seq(`let result`)); + decoderFor(pattern, 'result'); + emit(seq(`return result`)); + }))); } types.push(seq('export type _ptr = ', pointerName === false ? 'never' : typeFor(pointerName), `;`)); @@ -347,7 +495,12 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio functions.push(seq(`export const _decodePtr = `, (pointerName === false ? '() => { throw new _.DecodeError("Pointers forbidden"); }' - : seq(`(d: _.TypedDecoder<_ptr>) => `, decoderFor(pointerName))), + : seq(`(d: _.TypedDecoder<_ptr>) => `, + collectBody(() => { + emit(seq(`let result`)); + decoderFor(pointerName, 'result'); + emit(seq(`return result`)); + }))), `;`)); const f = new Formatter(); diff --git a/implementations/javascript/packages/schema/src/gen/schema.ts b/implementations/javascript/packages/schema/src/gen/schema.ts index 846c1de..248b168 100644 --- a/implementations/javascript/packages/schema/src/gen/schema.ts +++ b/implementations/javascript/packages/schema/src/gen/schema.ts @@ -109,7 +109,7 @@ export function isSchema(v: any): v is Schema { let _tmp0, _tmp1, _tmp2: any; return ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $schema) && + _.asLiteral(v.label, $schema) !== void 0 && ( (v.length === 1) && ( @@ -138,193 +138,160 @@ export function asSchema(v: any): Schema { } export function decodeSchema(d: _.TypedDecoder<_ptr>): Schema | undefined { - let _tmp0, _tmp1, _tmp2: any; - return ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $schema); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - const r = d.next(); - if (!(( - _.Dictionary.isDictionary<_val, _ptr>(r) && - ((_tmp0 = r.get($version)) !== void 0 && isVersion(_tmp0)) && - ((_tmp1 = r.get($pointer)) !== void 0 && isPointerName(_tmp1)) && - ( - (_tmp2 = r.get($definitions)) !== void 0 && ( - _.Dictionary.isDictionary<_val, _ptr>(_tmp2) && - ((() => { - for (const e of _tmp2) { - if (!(typeof e[0] === 'symbol')) return false; - if (!(isPattern(e[1]))) return false; - }; - return true; - })()) - ) + let result; + if (d.openRecord()) { + let _tmp3: any; + _tmp3 = _.asLiteral(d.nextSymbol(), $schema); + if (_tmp3 !== void 0) { + let _tmp4, _tmp5, _tmp6, _tmp7, _tmp8: any; + _tmp5 = d.next(); + if (_tmp5 !== void 0 && !(( + _.Dictionary.isDictionary<_val, _ptr>(_tmp5) && + ((_tmp6 = _tmp5.get($version)) !== void 0 && isVersion(_tmp6)) && + ((_tmp7 = _tmp5.get($pointer)) !== void 0 && isPointerName(_tmp7)) && + ( + (_tmp8 = _tmp5.get($definitions)) !== void 0 && ( + _.Dictionary.isDictionary<_val, _ptr>(_tmp8) && + ((() => { + for (const e of _tmp8) { + if (!(typeof e[0] === 'symbol')) return false; + if (!(isPattern(e[1]))) return false; + }; + return true; + })()) ) - ))) { d.restoreMark(M); return void 0; }; - return r; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [ - ( - { - get(k: typeof $version): Version; - get(k: typeof $pointer): PointerName; - get(k: typeof $definitions): _.KeyedDictionary; - has(k: typeof $version): true; - has(k: typeof $pointer): true; - has(k: typeof $definitions): true; - } & _.Dictionary<_val, _ptr> ) - ]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record< - (typeof $schema), - [ - ( - { - get(k: typeof $version): Version; - get(k: typeof $pointer): PointerName; - get(k: typeof $definitions): _.KeyedDictionary; - has(k: typeof $version): true; - has(k: typeof $pointer): true; - has(k: typeof $definitions): true; - } & _.Dictionary<_val, _ptr> - ) - ] - >(L, Fs); - })()); + ))) _tmp5 = void 0; + if (_tmp5 !== void 0) {if (d.closeCompound()) _tmp4 = [_tmp5];}; + if (_tmp4 !== void 0) result = _.Record< + (typeof $schema), + [ + ( + { + get(k: typeof $version): Version; + get(k: typeof $pointer): PointerName; + get(k: typeof $definitions): _.KeyedDictionary; + has(k: typeof $version): true; + has(k: typeof $pointer): true; + has(k: typeof $definitions): true; + } & _.Dictionary<_val, _ptr> + ) + ] + >(_tmp3 as any, _tmp4 as any); + }; + }; + return result; } -export function isVersion(v: any): v is Version {return _.is(v, $1);} +export function isVersion(v: any): v is Version {return _.asLiteral(v, $1) !== void 0;} export function asVersion(v: any): Version { if (!isVersion(v)) {throw new TypeError(`Invalid Version: ${_.stringify(v)}`);} else {return v;}; } -export function decodeVersion(d: _.TypedDecoder<_ptr>): Version | undefined {return _.checkIs(d.nextSignedInteger(), $1);} +export function decodeVersion(d: _.TypedDecoder<_ptr>): Version | undefined {let result; result = _.asLiteral(d.nextSignedInteger(), $1); return result;} -export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.is(v, __lit5));} +export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.asLiteral(v, __lit5) !== void 0);} export function asPointerName(v: any): PointerName { if (!isPointerName(v)) {throw new TypeError(`Invalid PointerName: ${_.stringify(v)}`);} else {return v;}; } -export function decodePointerName(d: _.TypedDecoder<_ptr>): PointerName | undefined {return (decodeRef(d) ?? _.checkIs(d.nextBoolean(), __lit5));} +export function decodePointerName(d: _.TypedDecoder<_ptr>): PointerName | undefined { + let _tmp9: any; + let result; + _tmp9 = d.mark(); + result = decodeRef(d); + if (result === void 0) {d.restoreMark(_tmp9); result = _.asLiteral(d.nextBoolean(), __lit5);}; + return result; +} export function isPattern(v: any): v is Pattern { - return ( + return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && ( ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $atom) && ( - (v.length === 1) && - ( - _.is(v[0], $Boolean) || - _.is(v[0], $Float) || - _.is(v[0], $Double) || - _.is(v[0], $SignedInteger) || - _.is(v[0], $String) || - _.is(v[0], $ByteString) || - _.is(v[0], $Symbol) + _.asLiteral(v.label, $atom) !== void 0 && ( + (v.length === 1) && + ( + _.asLiteral(v[0], $Boolean) !== void 0 || + _.asLiteral(v[0], $Float) !== void 0 || + _.asLiteral(v[0], $Double) !== void 0 || + _.asLiteral(v[0], $SignedInteger) !== void 0 || + _.asLiteral(v[0], $String) !== void 0 || + _.asLiteral(v[0], $ByteString) !== void 0 || + _.asLiteral(v[0], $Symbol) !== void 0 + ) ) - ) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $pointer) && - ((v.length === 0)) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $lit) && - ((v.length === 1) && true) - ) || - isRef(v) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $or) && + ) || + (_.asLiteral(v.label, $pointer) !== void 0 && ((v.length === 0))) || + (_.asLiteral(v.label, $lit) !== void 0 && ((v.length === 1) && true)) || ( - (v.length === 1) && - ( - _.Array.isArray(v[0]) && - !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && - (v[0].length >= 0) && - v[0].slice(0).every(v => (isPattern(v))) + _.asLiteral(v.label, $ref) !== void 0 && ((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol') + ) || + ( + _.asLiteral(v.label, $or) !== void 0 && ( + (v.length === 1) && + ( + _.Array.isArray(v[0]) && + !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && + (v[0].length >= 0) && + v[0].every(v => (isPattern(v))) + ) ) - ) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $and) && + ) || ( - (v.length === 1) && - ( - _.Array.isArray(v[0]) && - !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && - (v[0].length >= 0) && - v[0].slice(0).every(v => (isPattern(v))) + _.asLiteral(v.label, $and) !== void 0 && ( + (v.length === 1) && + ( + _.Array.isArray(v[0]) && + !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && + (v[0].length >= 0) && + v[0].every(v => (isPattern(v))) + ) ) - ) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $rec) && - ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $tuple) && + ) || ( - (v.length === 1) && - ( - _.Array.isArray(v[0]) && - !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && - (v[0].length >= 0) && - v[0].slice(0).every(v => (isNamedPattern(v))) + _.asLiteral(v.label, $rec) !== void 0 && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) + ) || + ( + _.asLiteral(v.label, $tuple) !== void 0 && ( + (v.length === 1) && + ( + _.Array.isArray(v[0]) && + !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && + (v[0].length >= 0) && + v[0].every(v => (isNamedPattern(v))) + ) ) - ) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $tuple_STAR_) && + ) || ( - (v.length === 2) && - ( - _.Array.isArray(v[0]) && - !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && - (v[0].length >= 0) && - v[0].slice(0).every(v => (isNamedPattern(v))) - ) && - isNamedPattern(v[1]) - ) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $setof) && - ((v.length === 1) && isPattern(v[0])) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $dictof) && - ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) - ) || - ( - _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $dict) && + _.asLiteral(v.label, $tuple_STAR_) !== void 0 && ( + (v.length === 2) && + ( + _.Array.isArray(v[0]) && + !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v[0]) && + (v[0].length >= 0) && + v[0].every(v => (isNamedPattern(v))) + ) && + isNamedPattern(v[1]) + ) + ) || ( - (v.length === 1) && - ( - _.Dictionary.isDictionary<_val, _ptr>(v[0]) && - ((() => { - for (const e of v[0]) {if (!(true)) return false; if (!(isPattern(e[1]))) return false;}; - return true; - })()) + _.asLiteral(v.label, $setof) !== void 0 && ((v.length === 1) && isPattern(v[0])) + ) || + ( + _.asLiteral(v.label, $dictof) !== void 0 && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1])) + ) || + ( + _.asLiteral(v.label, $dict) !== void 0 && ( + (v.length === 1) && + ( + _.Dictionary.isDictionary<_val, _ptr>(v[0]) && + ((() => { + for (const e of v[0]) {if (!(true)) return false; if (!(isPattern(e[1]))) return false;}; + return true; + })()) + ) ) ) ) @@ -336,38 +303,38 @@ export function asPattern(v: any): Pattern { } export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined { - return ( - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $atom); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ( - _.checkIs(d.nextSymbol(), $Boolean) ?? - _.checkIs(d.nextSymbol(), $Float) ?? - _.checkIs(d.nextSymbol(), $Double) ?? - _.checkIs(d.nextSymbol(), $SignedInteger) ?? - _.checkIs(d.nextSymbol(), $String) ?? - _.checkIs(d.nextSymbol(), $ByteString) ?? - _.checkIs(d.nextSymbol(), $Symbol) - ); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [ - ( - (typeof $Boolean) | - (typeof $Float) | - (typeof $Double) | - (typeof $SignedInteger) | - (typeof $String) | - (typeof $ByteString) | - (typeof $Symbol) - ) - ]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record< + let result; + if (d.openRecord()) { + let _tmp10, _tmp11: any; + _tmp10 = d.next(); + _tmp11 = d.mark(); + if (_.asLiteral(_tmp10, $atom) !== void 0) { + let _tmp12, _tmp13, _tmp14: any; + _tmp14 = d.mark(); + _tmp13 = _.asLiteral(d.nextSymbol(), $Boolean); + if (_tmp13 === void 0) { + d.restoreMark(_tmp14); + _tmp13 = _.asLiteral(d.nextSymbol(), $Float); + if (_tmp13 === void 0) { + d.restoreMark(_tmp14); + _tmp13 = _.asLiteral(d.nextSymbol(), $Double); + if (_tmp13 === void 0) { + d.restoreMark(_tmp14); + _tmp13 = _.asLiteral(d.nextSymbol(), $SignedInteger); + if (_tmp13 === void 0) { + d.restoreMark(_tmp14); + _tmp13 = _.asLiteral(d.nextSymbol(), $String); + if (_tmp13 === void 0) { + d.restoreMark(_tmp14); + _tmp13 = _.asLiteral(d.nextSymbol(), $ByteString); + if (_tmp13 === void 0) {d.restoreMark(_tmp14); _tmp13 = _.asLiteral(d.nextSymbol(), $Symbol);}; + }; + }; + }; + }; + }; + if (_tmp13 !== void 0) {if (d.closeCompound()) _tmp12 = [_tmp13];}; + if (_tmp12 !== void 0) result = _.Record< (typeof $atom), [ ( @@ -380,203 +347,187 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined { (typeof $Symbol) ) ] - >(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $pointer); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [] as []; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $pointer), []>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $lit); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = d.next(); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [_val]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $lit), [_val]>(L, Fs); - })()) ?? - decodeRef(d) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $or); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - if (!d.openSequence()) return void 0; - const vN: Array = []; - let tmp: undefined | Pattern; - while ((tmp = decodePattern(d)) !== void 0) vN.push(tmp); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return vN; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [Array]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $or), [Array]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $and); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - if (!d.openSequence()) return void 0; - const vN: Array = []; - let tmp: undefined | Pattern; - while ((tmp = decodePattern(d)) !== void 0) vN.push(tmp); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return vN; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [Array]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $and), [Array]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $rec); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - const v1 = decodePattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0, v1] as [Pattern, Pattern]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $rec), [Pattern, Pattern]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $tuple); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - if (!d.openSequence()) return void 0; - const vN: Array = []; - let tmp: undefined | NamedPattern; - while ((tmp = decodeNamedPattern(d)) !== void 0) vN.push(tmp); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return vN; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [Array]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $tuple), [Array]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $tuple_STAR_); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - if (!d.openSequence()) return void 0; - const vN: Array = []; - let tmp: undefined | NamedPattern; - while ((tmp = decodeNamedPattern(d)) !== void 0) vN.push(tmp); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return vN; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - const v1 = decodeNamedPattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0, v1] as [Array, NamedPattern]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $tuple_STAR_), [Array, NamedPattern]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $setof); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [Pattern]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $setof), [Pattern]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $dictof); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = decodePattern(d); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - const v1 = decodePattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0, v1] as [Pattern, Pattern]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $dictof), [Pattern, Pattern]>(L, Fs); - })()) ?? - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $dict); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = ((() => { - const M = d.mark(); - if (!d.openDictionary()) return void 0; - const r: _.KeyedDictionary<_val, Pattern, _ptr> = new _.KeyedDictionary(); - let K: undefined | _val; - while ((K = d.next()) !== void 0) { - const V = decodePattern(d); - if (V === void 0) { d.restoreMark(M); return void 0; }; - r.set(K, V); + >(_tmp10 as any, _tmp12 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $pointer) !== void 0) { + let _tmp15: any; + if (d.closeCompound()) _tmp15 = []; + if (_tmp15 !== void 0) result = _.Record<(typeof $pointer), []>(_tmp10 as any, _tmp15 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $lit) !== void 0) { + let _tmp16, _tmp17: any; + _tmp17 = d.next(); + if (_tmp17 !== void 0) {if (d.closeCompound()) _tmp16 = [_tmp17];}; + if (_tmp16 !== void 0) result = _.Record<(typeof $lit), [_val]>(_tmp10 as any, _tmp16 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $ref) !== void 0) { + let _tmp18, _tmp19, _tmp20: any; + _tmp19 = decodeModuleRef(d); + if (_tmp19 !== void 0) { + _tmp20 = d.nextSymbol(); + if (_tmp20 !== void 0) {if (d.closeCompound()) _tmp18 = [_tmp19, _tmp20];}; + }; + if (_tmp18 !== void 0) result = _.Record<(typeof $ref), [ModuleRef, symbol]>(_tmp10 as any, _tmp18 as any); }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return r; - })()); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0] as [_.KeyedDictionary<_val, Pattern, _ptr>]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>]>(L, Fs); - })()) - ); + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $or) !== void 0) { + let _tmp21, _tmp22: any; + if (d.openSequence()) { + let _tmp23: any; + { + let vN: Array | undefined = []; + while (!d.closeCompound()) { + _tmp23 = void 0; + _tmp23 = decodePattern(d); + if (_tmp23 === void 0) {vN = void 0; break;}; + vN.push(_tmp23); + }; + _tmp22 = vN; + }; + }; + if (_tmp22 !== void 0) {if (d.closeCompound()) _tmp21 = [_tmp22];}; + if (_tmp21 !== void 0) result = _.Record<(typeof $or), [Array]>(_tmp10 as any, _tmp21 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $and) !== void 0) { + let _tmp24, _tmp25: any; + if (d.openSequence()) { + let _tmp26: any; + { + let vN: Array | undefined = []; + while (!d.closeCompound()) { + _tmp26 = void 0; + _tmp26 = decodePattern(d); + if (_tmp26 === void 0) {vN = void 0; break;}; + vN.push(_tmp26); + }; + _tmp25 = vN; + }; + }; + if (_tmp25 !== void 0) {if (d.closeCompound()) _tmp24 = [_tmp25];}; + if (_tmp24 !== void 0) result = _.Record<(typeof $and), [Array]>(_tmp10 as any, _tmp24 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $rec) !== void 0) { + let _tmp27, _tmp28, _tmp29: any; + _tmp28 = decodePattern(d); + if (_tmp28 !== void 0) { + _tmp29 = decodePattern(d); + if (_tmp29 !== void 0) {if (d.closeCompound()) _tmp27 = [_tmp28, _tmp29];}; + }; + if (_tmp27 !== void 0) result = _.Record<(typeof $rec), [Pattern, Pattern]>(_tmp10 as any, _tmp27 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $tuple) !== void 0) { + let _tmp30, _tmp31: any; + if (d.openSequence()) { + let _tmp32: any; + { + let vN: Array | undefined = []; + while (!d.closeCompound()) { + _tmp32 = void 0; + _tmp32 = decodeNamedPattern(d); + if (_tmp32 === void 0) {vN = void 0; break;}; + vN.push(_tmp32); + }; + _tmp31 = vN; + }; + }; + if (_tmp31 !== void 0) {if (d.closeCompound()) _tmp30 = [_tmp31];}; + if (_tmp30 !== void 0) result = _.Record<(typeof $tuple), [Array]>(_tmp10 as any, _tmp30 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $tuple_STAR_) !== void 0) { + let _tmp33, _tmp34, _tmp35: any; + if (d.openSequence()) { + let _tmp36: any; + { + let vN: Array | undefined = []; + while (!d.closeCompound()) { + _tmp36 = void 0; + _tmp36 = decodeNamedPattern(d); + if (_tmp36 === void 0) {vN = void 0; break;}; + vN.push(_tmp36); + }; + _tmp34 = vN; + }; + }; + if (_tmp34 !== void 0) { + _tmp35 = decodeNamedPattern(d); + if (_tmp35 !== void 0) {if (d.closeCompound()) _tmp33 = [_tmp34, _tmp35];}; + }; + if (_tmp33 !== void 0) result = _.Record<(typeof $tuple_STAR_), [Array, NamedPattern]>(_tmp10 as any, _tmp33 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $setof) !== void 0) { + let _tmp37, _tmp38: any; + _tmp38 = decodePattern(d); + if (_tmp38 !== void 0) {if (d.closeCompound()) _tmp37 = [_tmp38];}; + if (_tmp37 !== void 0) result = _.Record<(typeof $setof), [Pattern]>(_tmp10 as any, _tmp37 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $dictof) !== void 0) { + let _tmp39, _tmp40, _tmp41: any; + _tmp40 = decodePattern(d); + if (_tmp40 !== void 0) { + _tmp41 = decodePattern(d); + if (_tmp41 !== void 0) {if (d.closeCompound()) _tmp39 = [_tmp40, _tmp41];}; + }; + if (_tmp39 !== void 0) result = _.Record<(typeof $dictof), [Pattern, Pattern]>(_tmp10 as any, _tmp39 as any); + }; + if (result === void 0) { + d.restoreMark(_tmp11); + if (_.asLiteral(_tmp10, $dict) !== void 0) { + let _tmp42, _tmp43: any; + if (d.openDictionary()) { + let r: _.KeyedDictionary<_val, Pattern, _ptr> | undefined = new _.KeyedDictionary(); + while (!d.closeCompound()) { + let K: undefined | _val = void 0; + K = d.next(); + if (K === void 0) { r = void 0; break; }; + let V: undefined | Pattern = void 0; + V = decodePattern(d); + if (V === void 0) { r = void 0; break; }; + r.set(K, V); + }; + _tmp43 = r; + }; + if (_tmp43 !== void 0) {if (d.closeCompound()) _tmp42 = [_tmp43];}; + if (_tmp42 !== void 0) result = _.Record<(typeof $dict), [_.KeyedDictionary<_val, Pattern, _ptr>]>(_tmp10 as any, _tmp42 as any); + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + return result; } export function isNamedPattern(v: any): v is NamedPattern { return ( ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $named) && + _.asLiteral(v.label, $named) !== void 0 && ((v.length === 2) && typeof v[0] === 'symbol' && isPattern(v[1])) ) || isPattern(v) @@ -588,30 +539,30 @@ export function asNamedPattern(v: any): NamedPattern { } export function decodeNamedPattern(d: _.TypedDecoder<_ptr>): NamedPattern | undefined { - return ( - ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $named); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = d.nextSymbol(); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - const v1 = decodePattern(d); if (v1 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0, v1] as [symbol, Pattern]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $named), [symbol, Pattern]>(L, Fs); - })()) ?? - decodePattern(d) - ); + let _tmp44: any; + let result; + _tmp44 = d.mark(); + if (d.openRecord()) { + let _tmp45: any; + _tmp45 = _.asLiteral(d.nextSymbol(), $named); + if (_tmp45 !== void 0) { + let _tmp46, _tmp47, _tmp48: any; + _tmp47 = d.nextSymbol(); + if (_tmp47 !== void 0) { + _tmp48 = decodePattern(d); + if (_tmp48 !== void 0) {if (d.closeCompound()) _tmp46 = [_tmp47, _tmp48];}; + }; + if (_tmp46 !== void 0) result = _.Record<(typeof $named), [symbol, Pattern]>(_tmp45 as any, _tmp46 as any); + }; + }; + if (result === void 0) {d.restoreMark(_tmp44); result = decodePattern(d);}; + return result; } export function isRef(v: any): v is Ref { return ( _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && - _.is(v.label, $ref) && + _.asLiteral(v.label, $ref) !== void 0 && ((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol') ); } @@ -621,37 +572,44 @@ export function asRef(v: any): Ref { } export function decodeRef(d: _.TypedDecoder<_ptr>): Ref | undefined { - return ((() => { - const M = d.mark(); - if (!d.openRecord()) return void 0; - const L = _.checkIs(d.nextSymbol(), $ref); - if (L === void 0) { d.restoreMark(M); return void 0; }; - const Fs = (((() => { - const M = d.mark(); - const v0 = decodeModuleRef(d); if (v0 === void 0) { d.restoreMark(M); return void 0; }; - const v1 = d.nextSymbol(); if (v1 === void 0) { d.restoreMark(M); return void 0; }; - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return [v0, v1] as [ModuleRef, symbol]; - })())) as any; - if (Fs === void 0) { d.restoreMark(M); return void 0; }; - return _.Record<(typeof $ref), [ModuleRef, symbol]>(L, Fs); - })()); + let result; + if (d.openRecord()) { + let _tmp49: any; + _tmp49 = _.asLiteral(d.nextSymbol(), $ref); + if (_tmp49 !== void 0) { + let _tmp50, _tmp51, _tmp52: any; + _tmp51 = decodeModuleRef(d); + if (_tmp51 !== void 0) { + _tmp52 = d.nextSymbol(); + if (_tmp52 !== void 0) {if (d.closeCompound()) _tmp50 = [_tmp51, _tmp52];}; + }; + if (_tmp50 !== void 0) result = _.Record<(typeof $ref), [ModuleRef, symbol]>(_tmp49 as any, _tmp50 as any); + }; + }; + return result; } -export function isModuleRef(v: any): v is ModuleRef {return (_.is(v, $thisModule) || isModulePath(v));} +export function isModuleRef(v: any): v is ModuleRef {return (_.asLiteral(v, $thisModule) !== void 0 || isModulePath(v));} export function asModuleRef(v: any): ModuleRef { if (!isModuleRef(v)) {throw new TypeError(`Invalid ModuleRef: ${_.stringify(v)}`);} else {return v;}; } -export function decodeModuleRef(d: _.TypedDecoder<_ptr>): ModuleRef | undefined {return (_.checkIs(d.nextSymbol(), $thisModule) ?? decodeModulePath(d));} +export function decodeModuleRef(d: _.TypedDecoder<_ptr>): ModuleRef | undefined { + let _tmp53: any; + let result; + _tmp53 = d.mark(); + result = _.asLiteral(d.nextSymbol(), $thisModule); + if (result === void 0) {d.restoreMark(_tmp53); result = decodeModulePath(d);}; + return result; +} export function isModulePath(v: any): v is ModulePath { return ( _.Array.isArray(v) && !_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (v.length >= 0) && - v.slice(0).every(v => (typeof v === 'symbol')) + v.every(v => (typeof v === 'symbol')) ); } @@ -660,15 +618,21 @@ export function asModulePath(v: any): ModulePath { } export function decodeModulePath(d: _.TypedDecoder<_ptr>): ModulePath | undefined { - return ((() => { - const M = d.mark(); - if (!d.openSequence()) return void 0; - const vN: Array = []; - let tmp: undefined | symbol; - while ((tmp = d.nextSymbol()) !== void 0) vN.push(tmp); - if (!d.closeCompound()) { d.restoreMark(M); return void 0; }; - return vN; - })()); + let result; + if (d.openSequence()) { + let _tmp54: any; + { + let vN: Array | undefined = []; + while (!d.closeCompound()) { + _tmp54 = void 0; + _tmp54 = d.nextSymbol(); + if (_tmp54 === void 0) {vN = void 0; break;}; + vN.push(_tmp54); + }; + result = vN; + }; + }; + return result; } export const _decodePtr = () => { throw new _.DecodeError("Pointers forbidden"); };