@json-schema-engine/compiler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/emit.d.ts +52 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/emit.js +166 -0
- package/dist/emit.js.map +1 -0
- package/dist/explain.d.ts +28 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +42 -0
- package/dist/explain.js.map +1 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/plan.d.ts +83 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +385 -0
- package/dist/plan.js.map +1 -0
- package/dist/runtime-compile.d.ts +30 -0
- package/dist/runtime-compile.d.ts.map +1 -0
- package/dist/runtime-compile.js +29 -0
- package/dist/runtime-compile.js.map +1 -0
- package/dist/runtime.d.ts +157 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +336 -0
- package/dist/runtime.js.map +1 -0
- package/dist/serialize/apply.d.ts +28 -0
- package/dist/serialize/apply.d.ts.map +1 -0
- package/dist/serialize/apply.js +211 -0
- package/dist/serialize/apply.js.map +1 -0
- package/dist/serialize/context.d.ts +143 -0
- package/dist/serialize/context.d.ts.map +1 -0
- package/dist/serialize/context.js +93 -0
- package/dist/serialize/context.js.map +1 -0
- package/dist/serialize/expressions.d.ts +7 -0
- package/dist/serialize/expressions.d.ts.map +1 -0
- package/dist/serialize/expressions.js +177 -0
- package/dist/serialize/expressions.js.map +1 -0
- package/dist/serialize/guards.d.ts +7 -0
- package/dist/serialize/guards.d.ts.map +1 -0
- package/dist/serialize/guards.js +19 -0
- package/dist/serialize/guards.js.map +1 -0
- package/dist/serialize/index.d.ts +7 -0
- package/dist/serialize/index.d.ts.map +1 -0
- package/dist/serialize/index.js +266 -0
- package/dist/serialize/index.js.map +1 -0
- package/dist/serialize/keywords.d.ts +32 -0
- package/dist/serialize/keywords.d.ts.map +1 -0
- package/dist/serialize/keywords.js +131 -0
- package/dist/serialize/keywords.js.map +1 -0
- package/dist/serialize/messages.d.ts +36 -0
- package/dist/serialize/messages.d.ts.map +1 -0
- package/dist/serialize/messages.js +100 -0
- package/dist/serialize/messages.js.map +1 -0
- package/dist/serialize/names.d.ts +47 -0
- package/dist/serialize/names.d.ts.map +1 -0
- package/dist/serialize/names.js +115 -0
- package/dist/serialize/names.js.map +1 -0
- package/dist/serialize/spans.d.ts +34 -0
- package/dist/serialize/spans.d.ts.map +1 -0
- package/dist/serialize/spans.js +61 -0
- package/dist/serialize/spans.js.map +1 -0
- package/dist/serialize/statements.d.ts +16 -0
- package/dist/serialize/statements.d.ts.map +1 -0
- package/dist/serialize/statements.js +396 -0
- package/dist/serialize/statements.js.map +1 -0
- package/dist/serialize/unit.d.ts +8 -0
- package/dist/serialize/unit.d.ts.map +1 -0
- package/dist/serialize/unit.js +107 -0
- package/dist/serialize/unit.js.map +1 -0
- package/dist/standalone.d.ts +24 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +166 -0
- package/dist/standalone.js.map +1 -0
- package/package.json +38 -0
- package/src/emit.ts +196 -0
- package/src/explain.ts +67 -0
- package/src/index.ts +366 -0
- package/src/plan.ts +496 -0
- package/src/runtime-compile.ts +90 -0
- package/src/runtime.ts +599 -0
- package/src/serialize/apply.ts +251 -0
- package/src/serialize/context.ts +161 -0
- package/src/serialize/expressions.ts +202 -0
- package/src/serialize/guards.ts +20 -0
- package/src/serialize/index.ts +432 -0
- package/src/serialize/keywords.ts +144 -0
- package/src/serialize/messages.ts +120 -0
- package/src/serialize/names.ts +136 -0
- package/src/serialize/spans.ts +88 -0
- package/src/serialize/statements.ts +531 -0
- package/src/serialize/unit.ts +118 -0
- package/src/standalone.ts +187 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Per-keyword state in annotation and region modes: the produce accumulator
|
|
2
|
+
// both channels read, the annotation-unit literal, and the channel push.
|
|
3
|
+
import { escapeSegment, } from "@json-schema-engine/core";
|
|
4
|
+
import { id, js, num, str } from "../emit.js";
|
|
5
|
+
import { EV, findProduce, hasAnnotate } from "./names.js";
|
|
6
|
+
import { expr } from "./expressions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Prepare the keyword currently being emitted: decide whether its annotate
|
|
9
|
+
* survives the static retention lists, whether its produce feeds the
|
|
10
|
+
* coverage channel, and allocate the produce's accumulator (declared by the
|
|
11
|
+
* returned chunks). No-op outside annotation and region modes.
|
|
12
|
+
*/
|
|
13
|
+
export function beginKeyword(ctx, stmts) {
|
|
14
|
+
ctx.annKw = null;
|
|
15
|
+
ctx.annKwKept = false;
|
|
16
|
+
ctx.covKwKept = false;
|
|
17
|
+
// Trace emission pre-declared every keyword's verdict slot (unit.ts).
|
|
18
|
+
ctx.kwOk = ctx.trace
|
|
19
|
+
? (ctx.kwVerdicts.get(ctx.currentKeyword) ?? null)
|
|
20
|
+
: null;
|
|
21
|
+
if (!ctx.annMode && !ctx.regionMode)
|
|
22
|
+
return [];
|
|
23
|
+
ctx.annKwKept =
|
|
24
|
+
ctx.annMode &&
|
|
25
|
+
hasAnnotate(stmts) &&
|
|
26
|
+
(!ctx.annKeep || ctx.annKeep("", ctx.currentKeyword, ctx.currentVocab));
|
|
27
|
+
const value = findProduce(stmts);
|
|
28
|
+
if (!value)
|
|
29
|
+
return [];
|
|
30
|
+
// Region channel-push gate (rule 5): only a coverage producer some
|
|
31
|
+
// consumer reads feeds the channel. Retention never affects it —
|
|
32
|
+
// dependency data is not output.
|
|
33
|
+
ctx.covKwKept = ctx.regionMode && ctx.coverageIds.has(ctx.currentBehaviorId);
|
|
34
|
+
if (!ctx.covKwKept)
|
|
35
|
+
return [];
|
|
36
|
+
const decls = [];
|
|
37
|
+
if (ctx.output === "list" && !ctx.trace) {
|
|
38
|
+
const k = id("k" + String(ctx.counters.temp++));
|
|
39
|
+
ctx.kwOk = k;
|
|
40
|
+
decls.push(js `let ${k} = true;`);
|
|
41
|
+
}
|
|
42
|
+
if (value.kind === "collectedNames") {
|
|
43
|
+
const n = id("n" + String(ctx.counters.temp++));
|
|
44
|
+
ctx.annKw = { produceKind: "collectedNames", names: n };
|
|
45
|
+
decls.push(js `const ${n} = new Set();`);
|
|
46
|
+
}
|
|
47
|
+
else if (value.render === "largestOrTrue") {
|
|
48
|
+
const m = id("n" + String(ctx.counters.temp++));
|
|
49
|
+
ctx.annKw = { produceKind: "largestOrTrue", max: m };
|
|
50
|
+
decls.push(js `let ${m} = -1;`);
|
|
51
|
+
}
|
|
52
|
+
else if (value.render === "appliedTrue") {
|
|
53
|
+
const a = id("n" + String(ctx.counters.temp++));
|
|
54
|
+
ctx.annKw = { produceKind: "appliedTrue", applied: a };
|
|
55
|
+
decls.push(js `let ${a} = false;`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const t = id("n" + String(ctx.counters.temp++));
|
|
59
|
+
ctx.annKw = { produceKind: "matchedOrAllTrue", matched: t };
|
|
60
|
+
decls.push(js `const ${t} = [];`);
|
|
61
|
+
}
|
|
62
|
+
return decls;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The annotation-unit object literal for the current keyword: constant
|
|
66
|
+
* keyword/vocabulary/schemaLocation, runtime evaluationPath (`ep` suffix)
|
|
67
|
+
* and inputLocation (`ip`), key order matching core's renderAnnotation.
|
|
68
|
+
* `vocabulary` is omitted when null (unknown keywords only).
|
|
69
|
+
*/
|
|
70
|
+
export function annUnit(ctx, valueExpr) {
|
|
71
|
+
const suffix = "/" + escapeSegment(ctx.currentKeyword);
|
|
72
|
+
const sloc = ctx.unit.ref.baseUri + "#" + ctx.unit.ref.pointer + suffix;
|
|
73
|
+
const vocab = ctx.currentVocab !== null
|
|
74
|
+
? js `vocabulary: ${str(ctx.currentVocab)}, `
|
|
75
|
+
: js ``;
|
|
76
|
+
return js `{ keyword: ${str(ctx.currentKeyword)}, ${vocab}evaluationPath: ${id("ep")} + ${str(suffix)}, schemaLocation: ${str(sloc)}, inputLocation: ${id("ip")}, annotation: ${valueExpr} }`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record an attempted child-of-here application's segment into the current
|
|
80
|
+
* keyword's produce accumulator (before the verdict — the segment is
|
|
81
|
+
* "attempted", not "succeeded"). Non-child-of-here cursors, and keywords
|
|
82
|
+
* without an active accumulator, record nothing.
|
|
83
|
+
*/
|
|
84
|
+
export function annRecordSegment(ctx, cursor) {
|
|
85
|
+
if (!ctx.annKw)
|
|
86
|
+
return null;
|
|
87
|
+
if (cursor.kind !== "child" || cursor.of.kind !== "here")
|
|
88
|
+
return null;
|
|
89
|
+
const seg = cursor.segment;
|
|
90
|
+
const segExpr = typeof seg === "string"
|
|
91
|
+
? str(seg)
|
|
92
|
+
: typeof seg === "number"
|
|
93
|
+
? num(seg)
|
|
94
|
+
: expr(ctx, seg);
|
|
95
|
+
switch (ctx.annKw.produceKind) {
|
|
96
|
+
case "collectedNames":
|
|
97
|
+
return js `${ctx.annKw.names}.add(${segExpr});`;
|
|
98
|
+
case "largestOrTrue":
|
|
99
|
+
return js `if (${segExpr} > ${ctx.annKw.max}) ${ctx.annKw.max} = ${segExpr};`;
|
|
100
|
+
case "appliedTrue":
|
|
101
|
+
return js `${ctx.annKw.applied} = true;`;
|
|
102
|
+
default:
|
|
103
|
+
// matchedOrAllTrue records inside its countRange, not at apply sites.
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Push a consumed producer's dependency data onto the runtime coverage
|
|
109
|
+
* channel (rule 5), writing the value the interpreter would produce. The
|
|
110
|
+
* "has data" guards match the interpreter's produce conditions so the
|
|
111
|
+
* channel carries exactly what a consumer's visible-records fold sees.
|
|
112
|
+
*/
|
|
113
|
+
export function produceChannel(ctx, value) {
|
|
114
|
+
const v = ctx.valueVar;
|
|
115
|
+
if (value.kind === "collectedNames") {
|
|
116
|
+
// The enclosing lower() gates this produce behind an object-type test;
|
|
117
|
+
// the (attempted, deduped) name array spreads from the Set.
|
|
118
|
+
return js `${EV}.push([...${ctx.annKw.names}]);`;
|
|
119
|
+
}
|
|
120
|
+
if (value.render === "largestOrTrue") {
|
|
121
|
+
const mx = ctx.annKw.max;
|
|
122
|
+
return js `if (${mx} >= 0) ${EV}.push(${mx} + 1 === ${v}.length ? true : ${mx});`;
|
|
123
|
+
}
|
|
124
|
+
if (value.render === "appliedTrue") {
|
|
125
|
+
const ap = ctx.annKw.applied;
|
|
126
|
+
return js `if (${ap}) ${EV}.push(true);`;
|
|
127
|
+
}
|
|
128
|
+
const mt = ctx.annKw.matched;
|
|
129
|
+
return js `if (${mt}.length > 0) ${EV}.push(${mt}.length === ${v}.length ? true : ${mt});`;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=keywords.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.js","sourceRoot":"","sources":["../../src/serialize/keywords.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AAEzE,OAAO,EACL,aAAa,GAId,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAgB,EAChB,KAA2B;IAE3B,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;IACjB,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;IACtB,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;IACtB,sEAAsE;IACtE,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK;QAClB,CAAC,CAAC,CAAC,GAAG,C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,CAAC,KAAM,CAAC,OAAQ,CAAC;IAC/B,OAAO,EAAE,CAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,CAAC,oBAAoB,EAAE,IAAI,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type LowerMessage, type LowerParams } from "@json-schema-engine/core";
|
|
2
|
+
import { type CodeChunk } from "../emit.js";
|
|
3
|
+
import { UnitContext } from "./context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a LowerMessage to a string expression. `tallyVar` binds the
|
|
6
|
+
* message's tally placeholder (combine/count checks).
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderMessage(ctx: UnitContext, msg: LowerMessage, tallyVar?: CodeChunk): CodeChunk;
|
|
9
|
+
/**
|
|
10
|
+
* Renders a LowerParams map to an object-literal expression, mirroring
|
|
11
|
+
* renderError's includeParams shape. `tallyVar` binds tally placeholders
|
|
12
|
+
* exactly as in {@link renderMessage}.
|
|
13
|
+
*/
|
|
14
|
+
export declare function paramsChunk(ctx: UnitContext, params: LowerParams | undefined, tallyVar?: CodeChunk, tallyListVar?: CodeChunk): CodeChunk;
|
|
15
|
+
/**
|
|
16
|
+
* List-mode failure: mark the unit invalid and push an interpreter-exact
|
|
17
|
+
* error unit (renderError's shape — keyword suffix escaped on both
|
|
18
|
+
* paths). Unit objects materialize only here, on the failure path (D9e).
|
|
19
|
+
*/
|
|
20
|
+
export declare function pushError(ctx: UnitContext, msg: CodeChunk, withKeyword?: boolean, params?: CodeChunk): CodeChunk;
|
|
21
|
+
/** The error channel's current length: the value a relevance mark takes. */
|
|
22
|
+
export declare function errsLength(ctx: UnitContext): CodeChunk;
|
|
23
|
+
/**
|
|
24
|
+
* Drop the errors pushed since mark `m` (an accepting keyword made them
|
|
25
|
+
* irrelevant). Trace emission routes the cut through the runtime, which
|
|
26
|
+
* discards or retains them by the artifact's level.
|
|
27
|
+
*/
|
|
28
|
+
export declare function errsCut(ctx: UnitContext, m: CodeChunk): CodeChunk;
|
|
29
|
+
/**
|
|
30
|
+
* Error relevance (draft-03 §12.2) in list mode: a keyword that accepts
|
|
31
|
+
* makes the errors its sub-evaluations pushed irrelevant. Callers take the
|
|
32
|
+
* mark before the keyword's applies and truncate on the accept path;
|
|
33
|
+
* every branch's errors land in the shared `errs` between the two.
|
|
34
|
+
*/
|
|
35
|
+
export declare function errMark(ctx: UnitContext): CodeChunk | null;
|
|
36
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/serialize/messages.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAkB,MAAM,cAAc,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,YAAY,EACjB,QAAQ,CAAC,EAAE,SAAS,GACnB,SAAS,CAWX;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,QAAQ,CAAC,EAAE,SAAS,EACpB,YAAY,CAAC,EAAE,SAAS,GACvB,SAAS,CAiBX;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,SAAS,EACd,WAAW,UAAO,EAClB,MAAM,CAAC,EAAE,SAAS,GACjB,SAAS,CAoBX;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,SAAS,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS,CAIjE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Error-unit rendering for list mode: messages, structured params, and the
|
|
2
|
+
// relevance mark that truncates a keyword's rejected sub-evaluation errors.
|
|
3
|
+
import { escapeSegment, } from "@json-schema-engine/core";
|
|
4
|
+
import { id, join, js, str } from "../emit.js";
|
|
5
|
+
import { ERRS, ST, TN } from "./names.js";
|
|
6
|
+
import { SerializeError } from "./context.js";
|
|
7
|
+
import { expr } from "./expressions.js";
|
|
8
|
+
/**
|
|
9
|
+
* Renders a LowerMessage to a string expression. `tallyVar` binds the
|
|
10
|
+
* message's tally placeholder (combine/count checks).
|
|
11
|
+
*/
|
|
12
|
+
export function renderMessage(ctx, msg, tallyVar) {
|
|
13
|
+
const parts = msg.map((part) => {
|
|
14
|
+
if (typeof part === "string")
|
|
15
|
+
return str(part);
|
|
16
|
+
if (part.kind === "tally") {
|
|
17
|
+
if (!tallyVar)
|
|
18
|
+
throw new SerializeError("tally outside a counted check");
|
|
19
|
+
return js `String(${tallyVar})`;
|
|
20
|
+
}
|
|
21
|
+
return js `String(${expr(ctx, part)})`;
|
|
22
|
+
});
|
|
23
|
+
if (parts.length === 0)
|
|
24
|
+
return str("");
|
|
25
|
+
return parts.length === 1 ? parts[0] : js `(${join(" + ", parts)})`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders a LowerParams map to an object-literal expression, mirroring
|
|
29
|
+
* renderError's includeParams shape. `tallyVar` binds tally placeholders
|
|
30
|
+
* exactly as in {@link renderMessage}.
|
|
31
|
+
*/
|
|
32
|
+
export function paramsChunk(ctx, params, tallyVar, tallyListVar) {
|
|
33
|
+
// pushError drops the chunk entirely when params are off — don't render
|
|
34
|
+
// (a tallyList reference has no accumulator to bind to in that mode).
|
|
35
|
+
if (!ctx.listParams || params === undefined)
|
|
36
|
+
return js `{}`;
|
|
37
|
+
const entries = Object.entries(params).map(([key, part]) => {
|
|
38
|
+
let value;
|
|
39
|
+
if (part.kind === "tally" || part.kind === "tallyList") {
|
|
40
|
+
const bound = part.kind === "tally" ? tallyVar : tallyListVar;
|
|
41
|
+
if (!bound)
|
|
42
|
+
throw new SerializeError(part.kind + " outside a counted check");
|
|
43
|
+
value = bound;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
value = expr(ctx, part);
|
|
47
|
+
}
|
|
48
|
+
return js `${str(key)}: ${value}`;
|
|
49
|
+
});
|
|
50
|
+
return js `{ ${join(", ", entries)} }`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* List-mode failure: mark the unit invalid and push an interpreter-exact
|
|
54
|
+
* error unit (renderError's shape — keyword suffix escaped on both
|
|
55
|
+
* paths). Unit objects materialize only here, on the failure path (D9e).
|
|
56
|
+
*/
|
|
57
|
+
export function pushError(ctx, msg, withKeyword = true, params) {
|
|
58
|
+
const suffix = withKeyword ? "/" + escapeSegment(ctx.currentKeyword) : "";
|
|
59
|
+
const sloc = ctx.unit.ref.baseUri + "#" + ctx.unit.ref.pointer + suffix;
|
|
60
|
+
const vocab = ctx.currentVocab !== null
|
|
61
|
+
? js `vocabulary: ${str(ctx.currentVocab)}, `
|
|
62
|
+
: js ``;
|
|
63
|
+
const extra = ctx.listParams
|
|
64
|
+
? withKeyword
|
|
65
|
+
? js `, keyword: ${str(ctx.currentKeyword)}, ${vocab}params: ${params ?? js `{}`}`
|
|
66
|
+
: js `, params: ${params ?? js `{}`}`
|
|
67
|
+
: js ``;
|
|
68
|
+
const fail = ctx.kwOk
|
|
69
|
+
? js `ok = false; ${ctx.kwOk} = false;`
|
|
70
|
+
: js `ok = false;`;
|
|
71
|
+
const unit = js `{ evaluationPath: ${id("ep")} + ${str(suffix)}, schemaLocation: ${str(sloc)}, inputLocation: ${id("ip")}, error: ${msg}${extra} }`;
|
|
72
|
+
// Trace emission records the raising application with the unit.
|
|
73
|
+
return ctx.trace
|
|
74
|
+
? js `${fail} ${id("h_err")}(${ST}, ${TN}, ${unit});`
|
|
75
|
+
: js `${fail} ${ERRS}.push(${unit});`;
|
|
76
|
+
}
|
|
77
|
+
/** The error channel's current length: the value a relevance mark takes. */
|
|
78
|
+
export function errsLength(ctx) {
|
|
79
|
+
return ctx.trace ? js `${ST}.errs.length` : js `${ERRS}.length`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Drop the errors pushed since mark `m` (an accepting keyword made them
|
|
83
|
+
* irrelevant). Trace emission routes the cut through the runtime, which
|
|
84
|
+
* discards or retains them by the artifact's level.
|
|
85
|
+
*/
|
|
86
|
+
export function errsCut(ctx, m) {
|
|
87
|
+
return ctx.trace
|
|
88
|
+
? js `${id("h_cutE")}(${ST}, ${m});`
|
|
89
|
+
: js `${ERRS}.length = ${m};`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Error relevance (draft-03 §12.2) in list mode: a keyword that accepts
|
|
93
|
+
* makes the errors its sub-evaluations pushed irrelevant. Callers take the
|
|
94
|
+
* mark before the keyword's applies and truncate on the accept path;
|
|
95
|
+
* every branch's errors land in the shared `errs` between the two.
|
|
96
|
+
*/
|
|
97
|
+
export function errMark(ctx) {
|
|
98
|
+
return ctx.output === "list" ? id("m" + String(ctx.counters.temp++)) : null;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/serialize/messages.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAE5E,OAAO,EACL,aAAa,GAGd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO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AC,CAAC,EAAE,CAAA,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,GAAgB;IACtC,OAAO,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type LowerProduceValue, type LowerStmt } from "@json-schema-engine/core";
|
|
2
|
+
import { type CodeChunk } from "../emit.js";
|
|
3
|
+
import type { EmitOutput, UnitContext } from "./context.js";
|
|
4
|
+
export declare const V: CodeChunk;
|
|
5
|
+
export declare const D: CodeChunk;
|
|
6
|
+
export declare const S: CodeChunk;
|
|
7
|
+
export declare const R: CodeChunk;
|
|
8
|
+
export declare const T: CodeChunk;
|
|
9
|
+
export declare const EV: CodeChunk;
|
|
10
|
+
export declare const EP: CodeChunk;
|
|
11
|
+
export declare const IP: CodeChunk;
|
|
12
|
+
export declare const ERRS: CodeChunk;
|
|
13
|
+
export declare const ANNS: CodeChunk;
|
|
14
|
+
export declare const ST: CodeChunk;
|
|
15
|
+
export declare const TP: CodeChunk;
|
|
16
|
+
export declare const TN: CodeChunk;
|
|
17
|
+
/** Which channels an emission threads through every application. */
|
|
18
|
+
export interface ChannelShape {
|
|
19
|
+
output: EmitOutput;
|
|
20
|
+
annMode: boolean;
|
|
21
|
+
trace: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const shapeOf: (ctx: UnitContext) => ChannelShape;
|
|
24
|
+
/**
|
|
25
|
+
* The arguments every application carries after the instance, depth, and
|
|
26
|
+
* scope: in list emission the two location prefixes and the record
|
|
27
|
+
* channels (the trace state and parent node under trace emission), and the
|
|
28
|
+
* coverage channel for an in-place region call. Unit signatures, unit
|
|
29
|
+
* calls, trampolines, and the root call all build from here, so the
|
|
30
|
+
* variants cannot drift apart. `locate` is called only in list emission —
|
|
31
|
+
* a flag-mode apply never computes its prefixes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function channelArgs(shape: ChannelShape, locate: () => [CodeChunk, CodeChunk], parent: CodeChunk, ev: boolean): CodeChunk[];
|
|
34
|
+
/** The interpreter trampoline an emission calls for an interpreted target. */
|
|
35
|
+
export declare function fragHelper(shape: ChannelShape, inPlaceRegion: boolean): CodeChunk;
|
|
36
|
+
export declare const unitFn: (index: number) => CodeChunk;
|
|
37
|
+
export declare const unitFnRegion: (index: number) => CodeChunk;
|
|
38
|
+
export declare const bindingVar: (n: number) => CodeChunk;
|
|
39
|
+
export declare const regexConst: (i: number) => CodeChunk;
|
|
40
|
+
export declare const formatConst: (i: number) => CodeChunk;
|
|
41
|
+
export declare const counterVar: (n: number) => CodeChunk;
|
|
42
|
+
export declare const foldVar: (n: number) => CodeChunk;
|
|
43
|
+
/** First `produce` node in a keyword's lowered statement list (searched into blocks). */
|
|
44
|
+
export declare function findProduce(stmts: readonly LowerStmt[]): LowerProduceValue | null;
|
|
45
|
+
/** True when a keyword's lowered statement list contains an `annotate` node (searched into blocks). */
|
|
46
|
+
export declare function hasAnnotate(stmts: readonly LowerStmt[]): boolean;
|
|
47
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/serialize/names.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAAM,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE5D,eAAO,MAAM,CAAC,WAAU,CAAC;AACzB,eAAO,MAAM,CAAC,WAAU,CAAC;AACzB,eAAO,MAAM,CAAC,WAAU,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xE,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,KAAG,SAAgC,CAAC;AAErE,yFAAyF;AACzF,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,SAAS,EAAE,GAC1B,iBAAiB,GAAG,IAAI,CAyB1B;AAED,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAkBhE"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Emitted identifier names and IR scans shared by the serializer's modules.
|
|
2
|
+
import { id } from "../emit.js";
|
|
3
|
+
export const V = id("v"); // instance parameter
|
|
4
|
+
export const D = id("d"); // depth parameter
|
|
5
|
+
export const S = id("s"); // dynamic-scope parameter
|
|
6
|
+
export const R = id("R"); // runtime closure
|
|
7
|
+
export const T = id("T"); // interpreted-target table
|
|
8
|
+
export const EV = id("ev"); // runtime coverage channel (region emission, phase B)
|
|
9
|
+
export const EP = id("ep"); // evaluation-path prefix parameter (list emission)
|
|
10
|
+
export const IP = id("ip"); // instance-pointer prefix parameter (list emission)
|
|
11
|
+
export const ERRS = id("errs"); // error channel (list emission)
|
|
12
|
+
export const ANNS = id("anns"); // annotation channel (annotation mode)
|
|
13
|
+
export const ST = id("st"); // per-evaluation trace state (trace emission)
|
|
14
|
+
export const TP = id("tp"); // parent application node parameter (trace emission)
|
|
15
|
+
export const TN = id("tn"); // this application's node (trace emission)
|
|
16
|
+
export const shapeOf = (ctx) => ({
|
|
17
|
+
output: ctx.output,
|
|
18
|
+
annMode: ctx.annMode,
|
|
19
|
+
trace: ctx.trace,
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* The arguments every application carries after the instance, depth, and
|
|
23
|
+
* scope: in list emission the two location prefixes and the record
|
|
24
|
+
* channels (the trace state and parent node under trace emission), and the
|
|
25
|
+
* coverage channel for an in-place region call. Unit signatures, unit
|
|
26
|
+
* calls, trampolines, and the root call all build from here, so the
|
|
27
|
+
* variants cannot drift apart. `locate` is called only in list emission —
|
|
28
|
+
* a flag-mode apply never computes its prefixes.
|
|
29
|
+
*/
|
|
30
|
+
export function channelArgs(shape, locate, parent, ev) {
|
|
31
|
+
const args = [];
|
|
32
|
+
if (shape.output === "list") {
|
|
33
|
+
args.push(...locate());
|
|
34
|
+
if (shape.trace)
|
|
35
|
+
args.push(ST, parent);
|
|
36
|
+
else {
|
|
37
|
+
args.push(ERRS);
|
|
38
|
+
if (shape.annMode)
|
|
39
|
+
args.push(ANNS);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (ev)
|
|
43
|
+
args.push(EV);
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
46
|
+
/** The interpreter trampoline an emission calls for an interpreted target. */
|
|
47
|
+
export function fragHelper(shape, inPlaceRegion) {
|
|
48
|
+
if (shape.output !== "list")
|
|
49
|
+
return id(inPlaceRegion ? "h_fragc" : "h_frag");
|
|
50
|
+
if (shape.trace)
|
|
51
|
+
return id("h_fragt");
|
|
52
|
+
return id(shape.annMode ? "h_fragla" : "h_fragl");
|
|
53
|
+
}
|
|
54
|
+
export const unitFn = (index) => id("u" + String(index));
|
|
55
|
+
// Region-variant of a unit function: same body with the trailing coverage
|
|
56
|
+
// channel threaded (COMPILED-CONSUMERS.md phase B). A distinct name so a unit
|
|
57
|
+
// can carry both a plain and a channel-threaded emission.
|
|
58
|
+
export const unitFnRegion = (index) => id("u" + String(index) + "c");
|
|
59
|
+
export const bindingVar = (n) => id("b" + String(n));
|
|
60
|
+
export const regexConst = (i) => id("r" + String(i));
|
|
61
|
+
export const formatConst = (i) => id("fmt" + String(i));
|
|
62
|
+
export const counterVar = (n) => id("c" + String(n));
|
|
63
|
+
export const foldVar = (n) => id("f" + String(n));
|
|
64
|
+
/** First `produce` node in a keyword's lowered statement list (searched into blocks). */
|
|
65
|
+
export function findProduce(stmts) {
|
|
66
|
+
for (const stmt of stmts) {
|
|
67
|
+
switch (stmt.kind) {
|
|
68
|
+
case "produce":
|
|
69
|
+
return stmt.value;
|
|
70
|
+
case "if": {
|
|
71
|
+
const t = findProduce(stmt.then);
|
|
72
|
+
if (t)
|
|
73
|
+
return t;
|
|
74
|
+
if (stmt.else) {
|
|
75
|
+
const e = findProduce(stmt.else);
|
|
76
|
+
if (e)
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case "forEachKey":
|
|
82
|
+
case "forEachIndex": {
|
|
83
|
+
const b = findProduce(stmt.body);
|
|
84
|
+
if (b)
|
|
85
|
+
return b;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/** True when a keyword's lowered statement list contains an `annotate` node (searched into blocks). */
|
|
95
|
+
export function hasAnnotate(stmts) {
|
|
96
|
+
for (const stmt of stmts) {
|
|
97
|
+
switch (stmt.kind) {
|
|
98
|
+
case "annotate":
|
|
99
|
+
return true;
|
|
100
|
+
case "if":
|
|
101
|
+
if (hasAnnotate(stmt.then) || (stmt.else && hasAnnotate(stmt.else)))
|
|
102
|
+
return true;
|
|
103
|
+
break;
|
|
104
|
+
case "forEachKey":
|
|
105
|
+
case "forEachIndex":
|
|
106
|
+
if (hasAnnotate(stmt.body))
|
|
107
|
+
return true;
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../src/serialize/names.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAM5E,OAAO,EAAkB,EAAE,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,qBAAqB;AAC/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AC;gBACpB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjC,IAAI,CAAC;oBAAE,OAAO,CAAC,CAAC;gBAChB,MAAM;YACR,CAAC;YACD;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,WAAW,CAAC,KAA2B;IACrD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC;YACd,KAAK,IAAI;gBACP,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACjE,OAAO,IAAI,CAAC;gBACd,MAAM;YACR,KAAK,YAAY,CAAC;YAClB,KAAK,cAAc;gBACjB,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBACxC,MAAM;YACR;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CodeChunk } from "../emit.js";
|
|
2
|
+
import { UnitContext } from "./context.js";
|
|
3
|
+
/** One marked channel: the annotation channel or the coverage channel. */
|
|
4
|
+
export interface Span {
|
|
5
|
+
kind: "anns" | "ev";
|
|
6
|
+
m: CodeChunk;
|
|
7
|
+
}
|
|
8
|
+
/** The annotation channel's current length: the value a span mark takes. */
|
|
9
|
+
export declare function annsLength(ctx: UnitContext): CodeChunk;
|
|
10
|
+
/**
|
|
11
|
+
* Drop the annotations pushed since mark `m` (a failed application's).
|
|
12
|
+
* Trace emission routes the cut through the runtime, which discards or
|
|
13
|
+
* retains them by the artifact's level.
|
|
14
|
+
*/
|
|
15
|
+
export declare function annsCut(ctx: UnitContext, m: CodeChunk): CodeChunk;
|
|
16
|
+
/** Push one annotation unit; trace emission records the application with it. */
|
|
17
|
+
export declare function annsPush(ctx: UnitContext, unit: CodeChunk): CodeChunk;
|
|
18
|
+
/**
|
|
19
|
+
* The channel spans active at an application boundary: `anns` in annotation
|
|
20
|
+
* mode, `ev` in region emission, both when composed, none otherwise. errs
|
|
21
|
+
* is not one of them: a failed application keeps its errors (they become
|
|
22
|
+
* irrelevant only when an enclosing KEYWORD accepts, draft-03 §12.2), so
|
|
23
|
+
* error truncation is keyword-scoped — see errMark() — not per branch.
|
|
24
|
+
*/
|
|
25
|
+
export declare function channelSpans(ctx: UnitContext, includeEv?: boolean): Span[];
|
|
26
|
+
export declare function spanDecls(ctx: UnitContext, spans: Span[]): CodeChunk;
|
|
27
|
+
export declare function spanResets(ctx: UnitContext, spans: Span[]): CodeChunk;
|
|
28
|
+
/**
|
|
29
|
+
* One grouped-fold branch: run `call`, apply `hit` on success, truncate the
|
|
30
|
+
* active channel spans on failure (a failed branch's records and
|
|
31
|
+
* coverage discard; a passing branch's merge — channel rule 3 per branch).
|
|
32
|
+
*/
|
|
33
|
+
export declare function branchSpan(ctx: UnitContext, call: CodeChunk, hit: CodeChunk): CodeChunk;
|
|
34
|
+
//# sourceMappingURL=spans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spans.d.ts","sourceRoot":"","sources":["../../src/serialize/spans.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAgB,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,0EAA0E;AAC1E,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,CAAC,EAAE,SAAS,CAAC;CACd;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,SAAS,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS,CAIjE;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,CAIrE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,UAAO,GAAG,IAAI,EAAE,CASvE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,CASpE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,CAOrE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,SAAS,EACf,GAAG,EAAE,SAAS,GACb,SAAS,CAIX"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Channel spans at application boundaries: the annotation and coverage
|
|
2
|
+
// channels mark before an application and truncate when it fails (rule 3).
|
|
3
|
+
import { id, join, js } from "../emit.js";
|
|
4
|
+
import { ANNS, EV, ST, TN } from "./names.js";
|
|
5
|
+
/** The annotation channel's current length: the value a span mark takes. */
|
|
6
|
+
export function annsLength(ctx) {
|
|
7
|
+
return ctx.trace ? js `${ST}.anns.length` : js `${ANNS}.length`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Drop the annotations pushed since mark `m` (a failed application's).
|
|
11
|
+
* Trace emission routes the cut through the runtime, which discards or
|
|
12
|
+
* retains them by the artifact's level.
|
|
13
|
+
*/
|
|
14
|
+
export function annsCut(ctx, m) {
|
|
15
|
+
return ctx.trace
|
|
16
|
+
? js `${id("h_cutA")}(${ST}, ${m});`
|
|
17
|
+
: js `${ANNS}.length = ${m};`;
|
|
18
|
+
}
|
|
19
|
+
/** Push one annotation unit; trace emission records the application with it. */
|
|
20
|
+
export function annsPush(ctx, unit) {
|
|
21
|
+
return ctx.trace
|
|
22
|
+
? js `${id("h_ann")}(${ST}, ${TN}, ${unit});`
|
|
23
|
+
: js `${ANNS}.push(${unit});`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The channel spans active at an application boundary: `anns` in annotation
|
|
27
|
+
* mode, `ev` in region emission, both when composed, none otherwise. errs
|
|
28
|
+
* is not one of them: a failed application keeps its errors (they become
|
|
29
|
+
* irrelevant only when an enclosing KEYWORD accepts, draft-03 §12.2), so
|
|
30
|
+
* error truncation is keyword-scoped — see errMark() — not per branch.
|
|
31
|
+
*/
|
|
32
|
+
export function channelSpans(ctx, includeEv = true) {
|
|
33
|
+
const spans = [];
|
|
34
|
+
if (ctx.annMode) {
|
|
35
|
+
spans.push({ kind: "anns", m: id("m" + String(ctx.counters.temp++)) });
|
|
36
|
+
}
|
|
37
|
+
if (ctx.regionMode && includeEv) {
|
|
38
|
+
spans.push({ kind: "ev", m: id("m" + String(ctx.counters.temp++)) });
|
|
39
|
+
}
|
|
40
|
+
return spans;
|
|
41
|
+
}
|
|
42
|
+
export function spanDecls(ctx, spans) {
|
|
43
|
+
return join(" ", spans.map(({ kind, m }) => kind === "anns"
|
|
44
|
+
? js `const ${m} = ${annsLength(ctx)};`
|
|
45
|
+
: js `const ${m} = ${EV}.length;`));
|
|
46
|
+
}
|
|
47
|
+
export function spanResets(ctx, spans) {
|
|
48
|
+
return join(" ", spans.map(({ kind, m }) => kind === "anns" ? annsCut(ctx, m) : js `${EV}.length = ${m};`));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One grouped-fold branch: run `call`, apply `hit` on success, truncate the
|
|
52
|
+
* active channel spans on failure (a failed branch's records and
|
|
53
|
+
* coverage discard; a passing branch's merge — channel rule 3 per branch).
|
|
54
|
+
*/
|
|
55
|
+
export function branchSpan(ctx, call, hit) {
|
|
56
|
+
const spans = channelSpans(ctx);
|
|
57
|
+
if (spans.length === 0)
|
|
58
|
+
return js `if (${call}) { ${hit} }`;
|
|
59
|
+
return js `{ ${spanDecls(ctx, spans)} if (${call}) { ${hit} } else { ${spanResets(ctx, spans)} } }`;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=spans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spans.js","sourceRoot":"","sources":["../../src/serialize/spans.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,2EAA2E;AAE3E,OAAO,EAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAS9C,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,GAAgB;IACzC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA,GAAG,IAAI,SAAS,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,GAAgB,EAAE,CAAY;IACpD,OAAO,GAAG,CAAC,KAAK;QACd,CAAC,CAAC,EAAE,CAAA,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI;QACnC,CAAC,CAAC,EAAE,CAAA,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC;AACjC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,QAAQ,CAAC,GAAgB,EAAE,IAAe;IACxD,OAAO,GAAG,CAAC,KAAK;QACd,CAAC,CAAC,EAAE,CAAA,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,IAAI,IAAI;QAC5C,CAAC,CAAC,EAAE,CAAA,GAAG,IAAI,SAAS,IAAI,IAAI,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM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7D,CACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,GAAgB,EAChB,IAAe,EACf,GAAc;IAEd,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA,OAAO,IAAI,OAAO,GAAG,IAAI,CAAC;IAC3D,OAAO,EAAE,CAAA,KAAK,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,IAAI,OAAO,GAAG,aAAa,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LowerApply, type LowerStmt } from "@json-schema-engine/core";
|
|
2
|
+
import { type CodeChunk } from "../emit.js";
|
|
3
|
+
import { UnitContext } from "./context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Serialize one keyword's statement list. Runs of anyMayPass applies
|
|
6
|
+
* (the anyOf shape) group into a single OR check; short-circuit emission
|
|
7
|
+
* is licensed here because the planner interpreted every node whose
|
|
8
|
+
* channel a consumer could observe (slice licensing, DESIGN §7). Runs of
|
|
9
|
+
* exactlyOne applies (the oneOf shape) group into a counter block that
|
|
10
|
+
* runs EVERY branch — never stop-at-first-success, since the count past 1
|
|
11
|
+
* must still be exact.
|
|
12
|
+
*/
|
|
13
|
+
export declare function keywordStatements(ctx: UnitContext, stmts: readonly LowerStmt[]): CodeChunk[];
|
|
14
|
+
export declare function statement(ctx: UnitContext, stmt: LowerStmt): CodeChunk;
|
|
15
|
+
export declare function applyStatement(ctx: UnitContext, apply: LowerApply): CodeChunk;
|
|
16
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/serialize/statements.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,UAAU,EAGf,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,WAAW,EAAkB,MAAM,cAAc,CAAC;AAsB3D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,SAAS,EAAE,GAC1B,SAAS,EAAE,CAmHb;AAmND,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,CAyBtE;AAyFD,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,CA4C7E"}
|