@oseo/compiler 0.0.0-stage → 0.1.0-canary.368

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.
Files changed (105) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +59 -2
  3. package/dist/agent-programs.d.ts +28 -0
  4. package/dist/agent-programs.d.ts.map +1 -0
  5. package/dist/agent-programs.js +134 -0
  6. package/dist/agent-programs.js.map +1 -0
  7. package/dist/agent-templates.d.ts +33 -0
  8. package/dist/agent-templates.d.ts.map +1 -0
  9. package/dist/agent-templates.js +45 -0
  10. package/dist/agent-templates.js.map +1 -0
  11. package/dist/compile.d.ts +20 -0
  12. package/dist/compile.d.ts.map +1 -0
  13. package/dist/compile.js +75 -0
  14. package/dist/compile.js.map +1 -0
  15. package/dist/fragments.d.ts +72 -0
  16. package/dist/fragments.d.ts.map +1 -0
  17. package/dist/fragments.js +158 -0
  18. package/dist/fragments.js.map +1 -0
  19. package/dist/hir-build.d.ts +80 -0
  20. package/dist/hir-build.d.ts.map +1 -0
  21. package/dist/hir-build.js +3077 -0
  22. package/dist/hir-build.js.map +1 -0
  23. package/dist/hir-print.d.ts +10 -0
  24. package/dist/hir-print.d.ts.map +1 -0
  25. package/dist/hir-print.js +271 -0
  26. package/dist/hir-print.js.map +1 -0
  27. package/dist/hir.d.ts +1246 -0
  28. package/dist/hir.d.ts.map +1 -0
  29. package/dist/hir.js +147 -0
  30. package/dist/hir.js.map +1 -0
  31. package/dist/host-scripts.d.ts +14 -0
  32. package/dist/host-scripts.d.ts.map +1 -0
  33. package/dist/host-scripts.js +204 -0
  34. package/dist/host-scripts.js.map +1 -0
  35. package/dist/index.d.ts +26 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +27 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/mir-build.d.ts +8 -0
  40. package/dist/mir-build.d.ts.map +1 -0
  41. package/dist/mir-build.js +5113 -0
  42. package/dist/mir-build.js.map +1 -0
  43. package/dist/mir-print.d.ts +7 -0
  44. package/dist/mir-print.d.ts.map +1 -0
  45. package/dist/mir-print.js +65 -0
  46. package/dist/mir-print.js.map +1 -0
  47. package/dist/mir-specialize.d.ts +7 -0
  48. package/dist/mir-specialize.d.ts.map +1 -0
  49. package/dist/mir-specialize.js +182 -0
  50. package/dist/mir-specialize.js.map +1 -0
  51. package/dist/mir.d.ts +571 -0
  52. package/dist/mir.d.ts.map +1 -0
  53. package/dist/mir.js +1 -0
  54. package/dist/module-builtin.d.ts +20 -0
  55. package/dist/module-builtin.d.ts.map +1 -0
  56. package/dist/module-builtin.js +57 -0
  57. package/dist/module-builtin.js.map +1 -0
  58. package/dist/module-compile.d.ts +64 -0
  59. package/dist/module-compile.d.ts.map +1 -0
  60. package/dist/module-compile.js +690 -0
  61. package/dist/module-compile.js.map +1 -0
  62. package/dist/module-json.d.ts +7 -0
  63. package/dist/module-json.d.ts.map +1 -0
  64. package/dist/module-json.js +88 -0
  65. package/dist/module-json.js.map +1 -0
  66. package/dist/modules.d.ts +87 -0
  67. package/dist/modules.d.ts.map +1 -0
  68. package/dist/modules.js +734 -0
  69. package/dist/modules.js.map +1 -0
  70. package/dist/native-fragments.d.ts +36 -0
  71. package/dist/native-fragments.d.ts.map +1 -0
  72. package/dist/native-fragments.js +110 -0
  73. package/dist/native-fragments.js.map +1 -0
  74. package/dist/native.d.ts +282 -0
  75. package/dist/native.d.ts.map +1 -0
  76. package/dist/native.js +47 -0
  77. package/dist/native.js.map +1 -0
  78. package/dist/regexp-execute.d.ts +74 -0
  79. package/dist/regexp-execute.d.ts.map +1 -0
  80. package/dist/regexp-execute.js +480 -0
  81. package/dist/regexp-execute.js.map +1 -0
  82. package/dist/regexp-matcher.d.ts +279 -0
  83. package/dist/regexp-matcher.d.ts.map +1 -0
  84. package/dist/regexp-matcher.js +1098 -0
  85. package/dist/regexp-matcher.js.map +1 -0
  86. package/dist/regexp-parse.d.ts +22 -0
  87. package/dist/regexp-parse.d.ts.map +1 -0
  88. package/dist/regexp-parse.js +1440 -0
  89. package/dist/regexp-parse.js.map +1 -0
  90. package/dist/regexp-print.d.ts +24 -0
  91. package/dist/regexp-print.d.ts.map +1 -0
  92. package/dist/regexp-print.js +147 -0
  93. package/dist/regexp-print.js.map +1 -0
  94. package/dist/regexp.d.ts +324 -0
  95. package/dist/regexp.d.ts.map +1 -0
  96. package/dist/regexp.js +22 -0
  97. package/dist/regexp.js.map +1 -0
  98. package/dist/source.d.ts +38 -0
  99. package/dist/source.d.ts.map +1 -0
  100. package/dist/source.js +10 -0
  101. package/dist/source.js.map +1 -0
  102. package/dist/syntax.d.ts +1232 -0
  103. package/dist/syntax.d.ts.map +1 -0
  104. package/dist/syntax.js +1 -0
  105. package/package.json +32 -3
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ `@oseo/compiler`
2
+ ================
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ `@oseo/compiler` is the host-independent core of Oseo, an ahead-of-time
5
+ compiler for JavaScript and TypeScript. It resolves bindings and module
6
+ graphs, lowers programs to Oseo's intermediate representations, and applies
7
+ guarded optimizations. It defines the interfaces for frontends, backends,
8
+ runtimes, and toolchains but does not ship those adapters. To compile and run
9
+ a file from the shell, use the [Oseo CLI].
10
+
11
+ [Oseo CLI]: https://github.com/dahlia/oseo/blob/main/docs/using/cli.md
12
+
13
+
14
+ Compile a script to MIR
15
+ -----------------------
16
+
17
+ With Node.js 24 or later, add the compiler and the Babel frontend to your
18
+ project:
19
+
20
+ ~~~~ sh
21
+ npm install @oseo/compiler @oseo/parser-babel
22
+ ~~~~
23
+
24
+ Or, with Deno 2.9 or later:
25
+
26
+ ~~~~ sh
27
+ deno add jsr:@oseo/compiler jsr:@oseo/parser-babel
28
+ ~~~~
29
+
30
+ Save this example as *compile.mjs*:
31
+
32
+ ~~~~ js
33
+ import { compileSource, printMir, renderDiagnostic } from "@oseo/compiler";
34
+ import { createBabelFrontend } from "@oseo/parser-babel";
35
+
36
+ const result = compileSource(createBabelFrontend(), {
37
+ sourceId: "answer.js",
38
+ source: "console.log(6 * 7);",
39
+ });
40
+
41
+ if (result.mir == null) {
42
+ throw new Error(result.diagnostics.map(renderDiagnostic).join("\n"));
43
+ }
44
+ console.log(printMir(result.mir));
45
+ ~~~~
46
+
47
+ Run `node compile.mjs` or `deno run compile.mjs`. This prints Oseo's mid-level
48
+ intermediate representation (MIR) without running the script or invoking a
49
+ native toolchain. For a module entry, use
50
+ `buildModuleGraph()` with a module frontend, loader, and resolver, then
51
+ `compileModuleGraph()` to lower the graph. Use [the C backend] to emit C11
52
+ from the resulting MIR.
53
+
54
+ Import from `@oseo/compiler` rather than from internal files. See the
55
+ [design document] for the compiler stages and the
56
+ [compiler implementation notes] for binding and module discovery details.
57
+
58
+ [the C backend]: https://github.com/dahlia/oseo/tree/main/packages/backend-c
59
+ [design document]: https://github.com/dahlia/oseo/blob/main/DESIGN.md
60
+ [compiler implementation notes]: https://github.com/dahlia/oseo/blob/main/docs/development/package-compiler.md
@@ -0,0 +1,28 @@
1
+ import { Diagnostic } from "./source.js";
2
+ import { SourceFrontend } from "./syntax.js";
3
+ import { AgentSourceTemplate } from "./agent-templates.js";
4
+ import { CompilerOptions, MirProgram } from "./mir.js";
5
+ //#region src/agent-programs.d.ts
6
+ /** An agent program compiled from one template, or why it was not. */
7
+ type AgentProgramResult = {
8
+ readonly diagnostics: readonly Diagnostic[];
9
+ } | {
10
+ readonly mir: MirProgram;
11
+ };
12
+ /**
13
+ * Compiles one agent program from its template (ADR 0026). The program
14
+ * is the template text with each hole replaced by a fresh identifier that
15
+ * resolves to the hole's Number, so it evaluates exactly what a start
16
+ * source reads when each hole holds a decimal integer literal, which is
17
+ * all the runtime lets a hole match: both replacements are one
18
+ * PrimaryExpression token in the same position. The template is rejected
19
+ * unless every hole is delimited as one token, the text with `0` in each
20
+ * hole parses, and each placeholder is resolved as exactly one identifier
21
+ * read and nothing else.
22
+ */
23
+ declare function compileAgentTemplate(frontend: SourceFrontend, template: AgentSourceTemplate, index: number, mainSourceId: string, options: CompilerOptions): AgentProgramResult;
24
+ /** The source identity an agent program's diagnostics report. */
25
+ declare function agentSourceId(mainSourceId: string, index: number): string;
26
+ //#endregion
27
+ export { AgentProgramResult, agentSourceId, compileAgentTemplate };
28
+ //# sourceMappingURL=agent-programs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-programs.d.ts","names":[],"sources":["../src/agent-programs.ts"],"mappings":";;;;;;KA+BY;WACG,sBAAsB;;WACtB,KAAK;;;;;;;;;;;;;iBAwDJ,qBACd,UAAU,gBACV,UAAU,qBACV,eACA,sBACA,SAAS,kBACR;;iBAgHa,cAAc,sBAAsB"}
@@ -0,0 +1,134 @@
1
+ import { buildHir } from "./hir-build.js";
2
+ import { buildMir } from "./mir-build.js";
3
+
4
+ //#region src/agent-programs.ts
5
+ function decodeUnicodeEscapes(text) {
6
+ return text.replaceAll(/\\u(?:\{([0-9A-Fa-f]+)\}|([0-9A-Fa-f]{4}))/gu, (escape, braced, fixed) => {
7
+ const codePoint = Number.parseInt(braced ?? fixed ?? "", 16);
8
+ return codePoint <= 1114111 ? String.fromCodePoint(codePoint) : escape;
9
+ });
10
+ }
11
+ function separatesHole(character) {
12
+ if (character == null) return true;
13
+ if (character.charCodeAt(0) >= 128) return false;
14
+ return !/[A-Za-z0-9$_.\\]/u.test(character);
15
+ }
16
+ function templateDiagnostic(template, sourceId, message) {
17
+ return {
18
+ byteRange: {
19
+ end: 0,
20
+ start: 0
21
+ },
22
+ code: "OSEO1001",
23
+ message,
24
+ range: template.range,
25
+ sourceId
26
+ };
27
+ }
28
+ /**
29
+ * Compiles one agent program from its template (ADR 0026). The program
30
+ * is the template text with each hole replaced by a fresh identifier that
31
+ * resolves to the hole's Number, so it evaluates exactly what a start
32
+ * source reads when each hole holds a decimal integer literal, which is
33
+ * all the runtime lets a hole match: both replacements are one
34
+ * PrimaryExpression token in the same position. The template is rejected
35
+ * unless every hole is delimited as one token, the text with `0` in each
36
+ * hole parses, and each placeholder is resolved as exactly one identifier
37
+ * read and nothing else.
38
+ */
39
+ function compileAgentTemplate(frontend, template, index, mainSourceId, options) {
40
+ const sourceId = agentSourceId(mainSourceId, index);
41
+ const { segments } = template;
42
+ const text = segments.join("");
43
+ const decoded = decodeUnicodeEscapes(text);
44
+ const names = segments.slice(1).map((_, hole) => {
45
+ let name = `$262AgentHole${hole}`;
46
+ while (text.includes(name) || decoded.includes(name)) name = `_${name}`;
47
+ return name;
48
+ });
49
+ for (let hole = 0; hole < names.length; hole += 1) if (!separatesHole(segments[hole]?.at(-1)) || !separatesHole(segments[hole + 1]?.at(0))) return { diagnostics: [templateDiagnostic(template, mainSourceId, `Agent source template hole ${hole} is not delimited as one numeric literal token.`)] };
50
+ const literal = frontend.parse({
51
+ source: segments.join("0"),
52
+ sourceId
53
+ });
54
+ if (literal.program == null) return { diagnostics: literal.diagnostics };
55
+ const encoder = new TextEncoder();
56
+ const holes = [];
57
+ let source = segments[0] ?? "";
58
+ for (const [position, name] of names.entries()) {
59
+ const start = encoder.encode(source).length;
60
+ holes.push({
61
+ name,
62
+ span: {
63
+ end: start + name.length,
64
+ start
65
+ }
66
+ });
67
+ source += name + (segments[position + 1] ?? "");
68
+ }
69
+ const parsed = frontend.parse({
70
+ source,
71
+ sourceId
72
+ });
73
+ if (parsed.program == null) return { diagnostics: parsed.diagnostics };
74
+ const hir = buildHir(parsed.program, { agentHoles: holes });
75
+ if (hir.program == null) return { diagnostics: hir.diagnostics };
76
+ const mir = buildMir(hir.program, {
77
+ ...options,
78
+ test262Host: false
79
+ });
80
+ const split = (operation) => {
81
+ const functionSource = operation.functionSource;
82
+ if (functionSource == null) return operation;
83
+ const functionSourceHoles = splitAtPlaceholders(functionSource, names);
84
+ return functionSourceHoles == null ? operation : {
85
+ ...operation,
86
+ functionSourceHoles
87
+ };
88
+ };
89
+ const splitFunction = (functionValue) => ({
90
+ ...functionValue,
91
+ blocks: functionValue.blocks.map((block) => ({
92
+ ...block,
93
+ operations: block.operations.map(split)
94
+ }))
95
+ });
96
+ return { mir: {
97
+ ...mir,
98
+ agentProgram: index,
99
+ functions: mir.functions.map(splitFunction),
100
+ script: splitFunction(mir.script)
101
+ } };
102
+ }
103
+ function splitAtPlaceholders(text, names) {
104
+ const holeIndexes = [];
105
+ const runs = [];
106
+ let position = 0;
107
+ let run = "";
108
+ while (position < text.length) {
109
+ let hole = -1;
110
+ for (const [index, name] of names.entries()) if (text.startsWith(name, position) && (hole < 0 || name.length > names[hole].length)) hole = index;
111
+ if (hole < 0) {
112
+ run += text[position];
113
+ position += 1;
114
+ continue;
115
+ }
116
+ runs.push(run);
117
+ run = "";
118
+ holeIndexes.push(hole);
119
+ position += names[hole].length;
120
+ }
121
+ runs.push(run);
122
+ return holeIndexes.length === 0 ? void 0 : {
123
+ holes: holeIndexes,
124
+ runs
125
+ };
126
+ }
127
+ /** The source identity an agent program's diagnostics report. */
128
+ function agentSourceId(mainSourceId, index) {
129
+ return `${mainSourceId}#agent-${index}`;
130
+ }
131
+
132
+ //#endregion
133
+ export { agentSourceId, compileAgentTemplate };
134
+ //# sourceMappingURL=agent-programs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-programs.js","names":[],"sources":["../src/agent-programs.ts"],"sourcesContent":["/*\n * Oseo, an ahead-of-time compiler for JavaScript and TypeScript.\n * Copyright (C) 2026 Hong Minhee <https://hongminhee.org/>\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\n */\n\nimport type { AgentSourceTemplate } from \"./agent-templates.ts\";\nimport { type AgentHolePlaceholder, buildHir } from \"./hir-build.ts\";\nimport type {\n CompilerOptions,\n MirFunction,\n MirOperation,\n MirProgram,\n} from \"./mir.ts\";\nimport { buildMir } from \"./mir-build.ts\";\nimport type { Diagnostic } from \"./source.ts\";\nimport type { SourceFrontend } from \"./syntax.ts\";\n\n/** An agent program compiled from one template, or why it was not. */\nexport type AgentProgramResult =\n | { readonly diagnostics: readonly Diagnostic[] }\n | { readonly mir: MirProgram };\n\n/*\n * The text with every `\\uXXXX` and `\\u{X...}` escape replaced by the code\n * point it spells. It over-approximates the identifiers an escape can\n * name, because it also decodes escapes inside strings and comments,\n * which only makes a placeholder name more conservative.\n */\nfunction decodeUnicodeEscapes(text: string): string {\n return text.replaceAll(\n /\\\\u(?:\\{([0-9A-Fa-f]+)\\}|([0-9A-Fa-f]{4}))/gu,\n (escape, braced: string | undefined, fixed: string | undefined) => {\n const codePoint = Number.parseInt(braced ?? fixed ?? \"\", 16);\n return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : escape;\n },\n );\n}\n\n/*\n * Whether the character beside a hole ends every token there. A decimal\n * literal cannot touch an identifier character, a digit, or a dot without\n * forming a different token, and a non-ASCII neighbor may be an\n * identifier character, so each of those rejects the template.\n */\nfunction separatesHole(character: string | undefined): boolean {\n if (character == null) return true;\n const code = character.charCodeAt(0);\n if (code >= 0x80) return false;\n return !/[A-Za-z0-9$_.\\\\]/u.test(character);\n}\n\nfunction templateDiagnostic(\n template: AgentSourceTemplate,\n sourceId: string,\n message: string,\n): Diagnostic {\n return {\n byteRange: { end: 0, start: 0 },\n code: \"OSEO1001\",\n message,\n range: template.range,\n sourceId,\n };\n}\n\n/**\n * Compiles one agent program from its template (ADR 0026). The program\n * is the template text with each hole replaced by a fresh identifier that\n * resolves to the hole's Number, so it evaluates exactly what a start\n * source reads when each hole holds a decimal integer literal, which is\n * all the runtime lets a hole match: both replacements are one\n * PrimaryExpression token in the same position. The template is rejected\n * unless every hole is delimited as one token, the text with `0` in each\n * hole parses, and each placeholder is resolved as exactly one identifier\n * read and nothing else.\n */\nexport function compileAgentTemplate(\n frontend: SourceFrontend,\n template: AgentSourceTemplate,\n index: number,\n mainSourceId: string,\n options: CompilerOptions,\n): AgentProgramResult {\n const sourceId = agentSourceId(mainSourceId, index);\n const { segments } = template;\n // A placeholder must be fresh against every identifier the template can\n // spell, including one written with Unicode escapes, so the check runs\n // over the raw text and over the text with every escape decoded.\n const text = segments.join(\"\");\n const decoded = decodeUnicodeEscapes(text);\n const names = segments.slice(1).map((_, hole) => {\n let name = `$262AgentHole${hole}`;\n while (text.includes(name) || decoded.includes(name)) name = `_${name}`;\n return name;\n });\n for (let hole = 0; hole < names.length; hole += 1) {\n if (\n !separatesHole(segments[hole]?.at(-1)) ||\n !separatesHole(segments[hole + 1]?.at(0))\n ) {\n return {\n diagnostics: [\n templateDiagnostic(\n template,\n mainSourceId,\n `Agent source template hole ${hole} is not delimited as one ` +\n \"numeric literal token.\",\n ),\n ],\n };\n }\n }\n const literal = frontend.parse({ source: segments.join(\"0\"), sourceId });\n if (literal.program == null) return { diagnostics: literal.diagnostics };\n // Each placeholder's UTF-8 byte span, which the one read that may\n // resolve to the hole must occupy exactly.\n const encoder = new TextEncoder();\n const holes: AgentHolePlaceholder[] = [];\n let source = segments[0] ?? \"\";\n for (const [position, name] of names.entries()) {\n const start = encoder.encode(source).length;\n holes.push({ name, span: { end: start + name.length, start } });\n source += name + (segments[position + 1] ?? \"\");\n }\n const parsed = frontend.parse({ source, sourceId });\n if (parsed.program == null) return { diagnostics: parsed.diagnostics };\n const hir = buildHir(parsed.program, { agentHoles: holes });\n if (hir.program == null) return { diagnostics: hir.diagnostics };\n const mir = buildMir(hir.program, { ...options, test262Host: false });\n const split = (operation: MirOperation): MirOperation => {\n const functionSource = operation.functionSource;\n if (functionSource == null) return operation;\n const functionSourceHoles = splitAtPlaceholders(functionSource, names);\n return functionSourceHoles == null\n ? operation\n : { ...operation, functionSourceHoles };\n };\n const splitFunction = (functionValue: MirFunction): MirFunction => ({\n ...functionValue,\n blocks: functionValue.blocks.map((block) => ({\n ...block,\n operations: block.operations.map(split),\n })),\n });\n return {\n mir: {\n ...mir,\n agentProgram: index,\n functions: mir.functions.map(splitFunction),\n script: splitFunction(mir.script),\n },\n };\n}\n\n/*\n * A function's source text split at every placeholder it contains, or\n * undefined when it contains none. Each placeholder is absent from the\n * template's own text, and a hole never touches an identifier character,\n * so every occurrence is the hole it names.\n */\nfunction splitAtPlaceholders(\n text: string,\n names: readonly string[],\n): { readonly holes: readonly number[]; readonly runs: string[] } | undefined {\n const holeIndexes: number[] = [];\n const runs: string[] = [];\n let position = 0;\n let run = \"\";\n while (position < text.length) {\n // The longest placeholder wins, so hole 1 never claims hole 10.\n let hole = -1;\n for (const [index, name] of names.entries()) {\n if (\n text.startsWith(name, position) &&\n (hole < 0 || name.length > names[hole]!.length)\n ) {\n hole = index;\n }\n }\n if (hole < 0) {\n run += text[position];\n position += 1;\n continue;\n }\n runs.push(run);\n run = \"\";\n holeIndexes.push(hole);\n position += names[hole]!.length;\n }\n runs.push(run);\n return holeIndexes.length === 0 ? undefined : { holes: holeIndexes, runs };\n}\n\n/** The source identity an agent program's diagnostics report. */\nexport function agentSourceId(mainSourceId: string, index: number): string {\n return `${mainSourceId}#agent-${index}`;\n}\n"],"mappings":"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"}
@@ -0,0 +1,33 @@
1
+ import { SourceRange } from "./source.js";
2
+ import { SyntaxCallArgument, SyntaxCallTarget } from "./syntax.js";
3
+ //#region src/agent-templates.d.ts
4
+ /**
5
+ * The global name of the test262 host object a Script compiled for the
6
+ * test262 host reads.
7
+ */
8
+ declare const test262HostGlobalName = "$262";
9
+ /**
10
+ * One `$262.agent.start` source template found in a Script: the cooked
11
+ * literal text around each substitution of a template literal, or the
12
+ * whole text of a string literal, which has no substitution.
13
+ */
14
+ interface AgentSourceTemplate {
15
+ readonly range: SourceRange;
16
+ readonly segments: readonly string[];
17
+ }
18
+ /** Whether a call target is exactly `$262.agent.start`. */
19
+ declare function isAgentStartTarget(target: SyntaxCallTarget): boolean;
20
+ /**
21
+ * The literal runs of a start argument. The frontend lowers an untagged
22
+ * template literal to a left-nested `+` chain that starts with its first
23
+ * cooked string and continues with a `to-string` conversion for each
24
+ * substitution and a string for each nonempty later run, so the chain is
25
+ * read back into runs with one hole per conversion. A plain string literal
26
+ * is one run, and a chain of string literals is their concatenation. Any
27
+ * other argument has no template, and a start with it reaches the
28
+ * runtime's owned boundary instead.
29
+ */
30
+ declare function agentTemplateSegments(argument: SyntaxCallArgument | undefined): readonly string[] | undefined;
31
+ //#endregion
32
+ export { AgentSourceTemplate, agentTemplateSegments, isAgentStartTarget, test262HostGlobalName };
33
+ //# sourceMappingURL=agent-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-templates.d.ts","names":[],"sources":["../src/agent-templates.ts"],"mappings":";;;;;;;cA6Ba;;;;;;UAOI;WACN,OAAO;WACP;;;iBAQK,mBAAmB,QAAQ;;;;;;;;;;;iBAwB3B,sBACd,UAAU"}
@@ -0,0 +1,45 @@
1
+ //#region src/agent-templates.ts
2
+ /**
3
+ * The global name of the test262 host object a Script compiled for the
4
+ * test262 host reads.
5
+ */
6
+ const test262HostGlobalName = "$262";
7
+ function stringKey(expression, name) {
8
+ return expression.kind === "string" && expression.value === name;
9
+ }
10
+ /** Whether a call target is exactly `$262.agent.start`. */
11
+ function isAgentStartTarget(target) {
12
+ if (target.kind !== "property" || !stringKey(target.key, "start")) return false;
13
+ const agent = target.object;
14
+ if (agent.kind !== "property-get" || !stringKey(agent.key, "agent")) return false;
15
+ return agent.object.kind === "identifier" && agent.object.name === "$262";
16
+ }
17
+ /**
18
+ * The literal runs of a start argument. The frontend lowers an untagged
19
+ * template literal to a left-nested `+` chain that starts with its first
20
+ * cooked string and continues with a `to-string` conversion for each
21
+ * substitution and a string for each nonempty later run, so the chain is
22
+ * read back into runs with one hole per conversion. A plain string literal
23
+ * is one run, and a chain of string literals is their concatenation. Any
24
+ * other argument has no template, and a start with it reaches the
25
+ * runtime's owned boundary instead.
26
+ */
27
+ function agentTemplateSegments(argument) {
28
+ if (argument == null || argument.kind === "spread") return void 0;
29
+ const pieces = [];
30
+ let current = argument;
31
+ while (current.kind === "binary" && current.operator === "+") {
32
+ pieces.push(current.right);
33
+ current = current.left;
34
+ }
35
+ if (current.kind !== "string") return void 0;
36
+ const segments = [current.value];
37
+ for (const piece of pieces.toReversed()) if (piece.kind === "unary" && piece.operator === "to-string") segments.push("");
38
+ else if (piece.kind === "string") segments[segments.length - 1] += piece.value;
39
+ else return;
40
+ return segments;
41
+ }
42
+
43
+ //#endregion
44
+ export { agentTemplateSegments, isAgentStartTarget, test262HostGlobalName };
45
+ //# sourceMappingURL=agent-templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-templates.js","names":[],"sources":["../src/agent-templates.ts"],"sourcesContent":["/*\n * Oseo, an ahead-of-time compiler for JavaScript and TypeScript.\n * Copyright (C) 2026 Hong Minhee <https://hongminhee.org/>\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\n */\n\nimport type { SourceRange } from \"./source.ts\";\nimport type {\n SyntaxCallArgument,\n SyntaxCallTarget,\n SyntaxExpression,\n} from \"./syntax.ts\";\n\n/**\n * The global name of the test262 host object a Script compiled for the\n * test262 host reads.\n */\nexport const test262HostGlobalName = \"$262\";\n\n/**\n * One `$262.agent.start` source template found in a Script: the cooked\n * literal text around each substitution of a template literal, or the\n * whole text of a string literal, which has no substitution.\n */\nexport interface AgentSourceTemplate {\n readonly range: SourceRange;\n readonly segments: readonly string[];\n}\n\nfunction stringKey(expression: SyntaxExpression, name: string): boolean {\n return expression.kind === \"string\" && expression.value === name;\n}\n\n/** Whether a call target is exactly `$262.agent.start`. */\nexport function isAgentStartTarget(target: SyntaxCallTarget): boolean {\n if (target.kind !== \"property\" || !stringKey(target.key, \"start\")) {\n return false;\n }\n const agent = target.object;\n if (agent.kind !== \"property-get\" || !stringKey(agent.key, \"agent\")) {\n return false;\n }\n return (\n agent.object.kind === \"identifier\" &&\n agent.object.name === test262HostGlobalName\n );\n}\n\n/**\n * The literal runs of a start argument. The frontend lowers an untagged\n * template literal to a left-nested `+` chain that starts with its first\n * cooked string and continues with a `to-string` conversion for each\n * substitution and a string for each nonempty later run, so the chain is\n * read back into runs with one hole per conversion. A plain string literal\n * is one run, and a chain of string literals is their concatenation. Any\n * other argument has no template, and a start with it reaches the\n * runtime's owned boundary instead.\n */\nexport function agentTemplateSegments(\n argument: SyntaxCallArgument | undefined,\n): readonly string[] | undefined {\n if (argument == null || argument.kind === \"spread\") return undefined;\n const pieces: SyntaxExpression[] = [];\n let current: SyntaxExpression = argument;\n while (current.kind === \"binary\" && current.operator === \"+\") {\n pieces.push(current.right);\n current = current.left;\n }\n if (current.kind !== \"string\") return undefined;\n const segments = [current.value];\n for (const piece of pieces.toReversed()) {\n if (piece.kind === \"unary\" && piece.operator === \"to-string\") {\n segments.push(\"\");\n } else if (piece.kind === \"string\") {\n segments[segments.length - 1] += piece.value;\n } else {\n return undefined;\n }\n }\n return segments;\n}\n"],"mappings":";;;;;AA6BA,MAAa,wBAAwB;AAYrC,SAAS,UAAU,YAA8B,MAAuB;CACtE,OAAO,WAAW,SAAS,YAAY,WAAW,UAAU;AAC9D;;AAGA,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,OAAO,SAAS,cAAc,CAAC,UAAU,OAAO,KAAK,OAAO,GAC9D,OAAO;CAET,MAAM,QAAQ,OAAO;CACrB,IAAI,MAAM,SAAS,kBAAkB,CAAC,UAAU,MAAM,KAAK,OAAO,GAChE,OAAO;CAET,OACE,MAAM,OAAO,SAAS,gBACtB,MAAM,OAAO;AAEjB;;;;;;;;;;;AAYA,SAAgB,sBACd,UAC+B;CAC/B,IAAI,YAAY,QAAQ,SAAS,SAAS,UAAU,OAAO;CAC3D,MAAM,SAA6B,CAAC;CACpC,IAAI,UAA4B;CAChC,OAAO,QAAQ,SAAS,YAAY,QAAQ,aAAa,KAAK;EAC5D,OAAO,KAAK,QAAQ,KAAK;EACzB,UAAU,QAAQ;CACpB;CACA,IAAI,QAAQ,SAAS,UAAU,OAAO;CACtC,MAAM,WAAW,CAAC,QAAQ,KAAK;CAC/B,KAAK,MAAM,SAAS,OAAO,WAAW,GACpC,IAAI,MAAM,SAAS,WAAW,MAAM,aAAa,aAC/C,SAAS,KAAK,EAAE;MACX,IAAI,MAAM,SAAS,UACxB,SAAS,SAAS,SAAS,MAAM,MAAM;MAEvC;CAGJ,OAAO;AACT"}
@@ -0,0 +1,20 @@
1
+ import { SourceInput } from "./source.js";
2
+ import { SourceFrontend } from "./syntax.js";
3
+ import { CompilerOptions } from "./mir.js";
4
+ import { CompilationResult, ScriptModuleRequests } from "./module-compile.js";
5
+ //#region src/compile.d.ts
6
+ /**
7
+ * Compile source through owned syntax, HIR, and policy-selected MIR. With
8
+ * the test262 host option, the result also carries one agent program for
9
+ * each `$262.agent.start` template, and the main program's table names
10
+ * them in the same order.
11
+ *
12
+ * `requests` names the modules a Script's `import()` calls reach, as
13
+ * `buildScriptRequests` discovered them for the same Script under
14
+ * its canonical identity. Without it, every `import()` keeps its profile
15
+ * diagnostic.
16
+ */
17
+ declare function compileSource(frontend: SourceFrontend, input: SourceInput, options?: CompilerOptions, requests?: ScriptModuleRequests): CompilationResult;
18
+ //#endregion
19
+ export { compileSource };
20
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","names":[],"sources":["../src/compile.ts"],"mappings":";;;;;;;;;;;;;;;;iBAyCgB,cACd,UAAU,gBACV,OAAO,aACP,UAAS,iBACT,WAAW,uBACV"}
@@ -0,0 +1,75 @@
1
+ import { buildSeededHir } from "./hir-build.js";
2
+ import { buildMir } from "./mir-build.js";
3
+ import { agentSourceId, compileAgentTemplate } from "./agent-programs.js";
4
+ import { compileHostScripts } from "./host-scripts.js";
5
+ import { buildScriptGraphHir } from "./module-compile.js";
6
+
7
+ //#region src/compile.ts
8
+ /**
9
+ * Compile source through owned syntax, HIR, and policy-selected MIR. With
10
+ * the test262 host option, the result also carries one agent program for
11
+ * each `$262.agent.start` template, and the main program's table names
12
+ * them in the same order.
13
+ *
14
+ * `requests` names the modules a Script's `import()` calls reach, as
15
+ * `buildScriptRequests` discovered them for the same Script under
16
+ * its canonical identity. Without it, every `import()` keeps its profile
17
+ * diagnostic.
18
+ */
19
+ function compileSource(frontend, input, options = {}, requests) {
20
+ const frontendResult = frontend.parse(input);
21
+ if (frontendResult.program == null) return { diagnostics: frontendResult.diagnostics };
22
+ const host = options.test262Host === true;
23
+ const seed = host ? {
24
+ collectAgentTemplates: true,
25
+ hostScriptBindings: true
26
+ } : {};
27
+ const hirResult = requests == null ? buildSeededHir(frontendResult.program, seed) : buildScriptGraphHir(frontendResult.program, requests, seed);
28
+ if (hirResult.program == null) return {
29
+ diagnostics: hirResult.diagnostics,
30
+ syntax: frontendResult.program
31
+ };
32
+ const mir = buildMir(hirResult.program, options);
33
+ if (!host) return {
34
+ diagnostics: [],
35
+ hir: hirResult.program,
36
+ mir,
37
+ syntax: frontendResult.program
38
+ };
39
+ const agents = [];
40
+ const templates = [];
41
+ for (const [index, template] of (hirResult.program.agentTemplates ?? []).entries()) {
42
+ const compiled = compileAgentTemplate(frontend, template, index, input.sourceId, options);
43
+ if ("diagnostics" in compiled) return {
44
+ diagnostics: compiled.diagnostics,
45
+ syntax: frontendResult.program
46
+ };
47
+ agents.push(compiled.mir);
48
+ templates.push({
49
+ segments: template.segments,
50
+ sourceId: agentSourceId(input.sourceId, index)
51
+ });
52
+ }
53
+ const scripts = compileHostScripts(frontend, frontendResult.program, options, hirResult.nextBindingId, hirResult.nextFunctionId, hirResult.program.hostScriptSources ?? []);
54
+ return {
55
+ agents,
56
+ diagnostics: [],
57
+ hir: hirResult.program,
58
+ mir: {
59
+ ...mir,
60
+ functions: [...mir.functions, ...scripts.functions],
61
+ globalBindings: [...mir.globalBindings, ...scripts.globals],
62
+ hostObjectBindings: scripts.objects,
63
+ test262Host: {
64
+ agents: templates,
65
+ mainAgentCanBlock: options.mainAgentCanBlock ?? true,
66
+ scripts: scripts.scripts
67
+ }
68
+ },
69
+ syntax: frontendResult.program
70
+ };
71
+ }
72
+
73
+ //#endregion
74
+ export { compileSource };
75
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","names":[],"sources":["../src/compile.ts"],"sourcesContent":["/*\n * Oseo, an ahead-of-time compiler for JavaScript and TypeScript.\n * Copyright (C) 2026 Hong Minhee <https://hongminhee.org/>\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\n */\n\nimport { agentSourceId, compileAgentTemplate } from \"./agent-programs.ts\";\nimport { compileHostScripts } from \"./host-scripts.ts\";\nimport { buildSeededHir } from \"./hir-build.ts\";\nimport type { CompilerOptions, MirAgentTemplate, MirProgram } from \"./mir.ts\";\nimport { buildMir } from \"./mir-build.ts\";\nimport {\n buildScriptGraphHir,\n type CompilationResult,\n type ScriptModuleRequests,\n} from \"./module-compile.ts\";\nimport type { SourceInput } from \"./source.ts\";\nimport type { SourceFrontend } from \"./syntax.ts\";\n/**\n * Compile source through owned syntax, HIR, and policy-selected MIR. With\n * the test262 host option, the result also carries one agent program for\n * each `$262.agent.start` template, and the main program's table names\n * them in the same order.\n *\n * `requests` names the modules a Script's `import()` calls reach, as\n * `buildScriptRequests` discovered them for the same Script under\n * its canonical identity. Without it, every `import()` keeps its profile\n * diagnostic.\n */\nexport function compileSource(\n frontend: SourceFrontend,\n input: SourceInput,\n options: CompilerOptions = {},\n requests?: ScriptModuleRequests,\n): CompilationResult {\n const frontendResult = frontend.parse(input);\n if (frontendResult.program == null) {\n return { diagnostics: frontendResult.diagnostics };\n }\n const host = options.test262Host === true;\n const seed = host\n ? { collectAgentTemplates: true, hostScriptBindings: true }\n : {};\n // A Script with `import()` calls carries the modules they reach.\n const hirResult =\n requests == null\n ? buildSeededHir(frontendResult.program, seed)\n : buildScriptGraphHir(frontendResult.program, requests, seed);\n if (hirResult.program == null) {\n return {\n diagnostics: hirResult.diagnostics,\n syntax: frontendResult.program,\n };\n }\n const mir = buildMir(hirResult.program, options);\n if (!host) {\n return {\n diagnostics: [],\n hir: hirResult.program,\n mir,\n syntax: frontendResult.program,\n };\n }\n const agents: MirProgram[] = [];\n const templates: MirAgentTemplate[] = [];\n for (const [index, template] of (\n hirResult.program.agentTemplates ?? []\n ).entries()) {\n const compiled = compileAgentTemplate(\n frontend,\n template,\n index,\n input.sourceId,\n options,\n );\n if (\"diagnostics\" in compiled) {\n return {\n diagnostics: compiled.diagnostics,\n syntax: frontendResult.program,\n };\n }\n agents.push(compiled.mir);\n templates.push({\n segments: template.segments,\n sourceId: agentSourceId(input.sourceId, index),\n });\n }\n const scripts = compileHostScripts(\n frontend,\n frontendResult.program,\n options,\n hirResult.nextBindingId,\n hirResult.nextFunctionId,\n hirResult.program.hostScriptSources ?? [],\n );\n return {\n agents,\n diagnostics: [],\n hir: hirResult.program,\n mir: {\n ...mir,\n functions: [...mir.functions, ...scripts.functions],\n globalBindings: [...mir.globalBindings, ...scripts.globals],\n hostObjectBindings: scripts.objects,\n test262Host: {\n agents: templates,\n mainAgentCanBlock: options.mainAgentCanBlock ?? true,\n scripts: scripts.scripts,\n },\n },\n syntax: frontendResult.program,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyCA,SAAgB,cACd,UACA,OACA,UAA2B,CAAC,GAC5B,UACmB;CACnB,MAAM,iBAAiB,SAAS,MAAM,KAAK;CAC3C,IAAI,eAAe,WAAW,MAC5B,OAAO,EAAE,aAAa,eAAe,YAAY;CAEnD,MAAM,OAAO,QAAQ,gBAAgB;CACrC,MAAM,OAAO,OACT;EAAE,uBAAuB;EAAM,oBAAoB;CAAK,IACxD,CAAC;CAEL,MAAM,YACJ,YAAY,OACR,eAAe,eAAe,SAAS,IAAI,IAC3C,oBAAoB,eAAe,SAAS,UAAU,IAAI;CAChE,IAAI,UAAU,WAAW,MACvB,OAAO;EACL,aAAa,UAAU;EACvB,QAAQ,eAAe;CACzB;CAEF,MAAM,MAAM,SAAS,UAAU,SAAS,OAAO;CAC/C,IAAI,CAAC,MACH,OAAO;EACL,aAAa,CAAC;EACd,KAAK,UAAU;EACf;EACA,QAAQ,eAAe;CACzB;CAEF,MAAM,SAAuB,CAAC;CAC9B,MAAM,YAAgC,CAAC;CACvC,KAAK,MAAM,CAAC,OAAO,cACjB,UAAU,QAAQ,kBAAkB,CAAC,EAAC,CACtC,QAAQ,GAAG;EACX,MAAM,WAAW,qBACf,UACA,UACA,OACA,MAAM,UACN,OACF;EACA,IAAI,iBAAiB,UACnB,OAAO;GACL,aAAa,SAAS;GACtB,QAAQ,eAAe;EACzB;EAEF,OAAO,KAAK,SAAS,GAAG;EACxB,UAAU,KAAK;GACb,UAAU,SAAS;GACnB,UAAU,cAAc,MAAM,UAAU,KAAK;EAC/C,CAAC;CACH;CACA,MAAM,UAAU,mBACd,UACA,eAAe,SACf,SACA,UAAU,eACV,UAAU,gBACV,UAAU,QAAQ,qBAAqB,CAAC,CAC1C;CACA,OAAO;EACL;EACA,aAAa,CAAC;EACd,KAAK,UAAU;EACf,KAAK;GACH,GAAG;GACH,WAAW,CAAC,GAAG,IAAI,WAAW,GAAG,QAAQ,SAAS;GAClD,gBAAgB,CAAC,GAAG,IAAI,gBAAgB,GAAG,QAAQ,OAAO;GAC1D,oBAAoB,QAAQ;GAC5B,aAAa;IACX,QAAQ;IACR,mBAAmB,QAAQ,qBAAqB;IAChD,SAAS,QAAQ;GACnB;EACF;EACA,QAAQ,eAAe;CACzB;AACF"}
@@ -0,0 +1,72 @@
1
+ import { Diagnostic, SourceInput } from "./source.js";
2
+ import { SourceFrontend } from "./syntax.js";
3
+ import { HirProgram } from "./hir.js";
4
+ import { CompilerOptions, MirProgram } from "./mir.js";
5
+ //#region src/fragments.d.ts
6
+ /** Private fragment contract; changes invalidate generated object reuse. */
7
+ declare const scriptFragmentAbi = "oseo-script-fragments-v1";
8
+ /** A Script binding exported to a later fragment in the same environment. */
9
+ interface FragmentBinding {
10
+ readonly id: number;
11
+ readonly name: string;
12
+ readonly mutable: boolean;
13
+ readonly globalObject: boolean;
14
+ }
15
+ /**
16
+ * Independently lowered unit, not a standalone executable MirProgram.
17
+ * The launcher owns instantiation and supplies the shared environment.
18
+ */
19
+ interface ScriptFragment {
20
+ readonly hir: HirProgram;
21
+ readonly mir: MirProgram;
22
+ /** Exclusive limits include hidden bindings and all nested functions. */
23
+ readonly nextBindingId: number;
24
+ readonly nextFunctionId: number;
25
+ /** HIR body indices owned by launcher instantiation, not evaluation. */
26
+ readonly launcherInitializers: readonly number[];
27
+ }
28
+ /** Prepared ordered bundle. No body input contributes to these bytes. */
29
+ interface HarnessFragment extends ScriptFragment {
30
+ readonly abi: typeof scriptFragmentAbi;
31
+ readonly sources: readonly SourceInput[];
32
+ readonly bindings: readonly FragmentBinding[];
33
+ readonly globalReferences: readonly string[];
34
+ readonly strict: boolean;
35
+ readonly options: CompilerOptions;
36
+ }
37
+ /** A failed preparation must use the existing whole-Script path. */
38
+ type HarnessFragmentResult = {
39
+ readonly kind: "compiled";
40
+ readonly harness: HarnessFragment;
41
+ } | {
42
+ readonly kind: "fallback";
43
+ readonly diagnostics: readonly Diagnostic[];
44
+ };
45
+ /** A body is either compatible with a prepared bundle or requires fallback. */
46
+ type BodyFragmentResult = {
47
+ readonly kind: "compiled";
48
+ readonly body: ScriptFragment;
49
+ readonly bindingCount: number;
50
+ } | {
51
+ readonly kind: "fallback";
52
+ readonly reason: "diagnostic" | "shadowing" | "strictness" | "metadata" | "global-effects" | "requests";
53
+ readonly names: readonly string[];
54
+ readonly diagnostics: readonly Diagnostic[];
55
+ };
56
+ /**
57
+ * Compile an ordered bundle once, reserving every ID before any case resolves.
58
+ * Source order and duplicates are significant. Locations use the fixed virtual
59
+ * bundle source; native emission must supply the launcher's logical source map.
60
+ */
61
+ declare function compileHarnessFragment(frontend: SourceFrontend, sources: readonly SourceInput[], strict?: boolean, options?: CompilerOptions): HarnessFragmentResult;
62
+ /**
63
+ * Resolve a case against a prepared harness without mutating the harness.
64
+ * Fallback is an instruction to compile the original assembled Script, not a
65
+ * replacement diagnostic. Module/raw admission belongs to the future runner.
66
+ */
67
+ declare function compileBodyFragment(frontend: SourceFrontend, harness: HarnessFragment, input: SourceInput): BodyFragmentResult;
68
+ /** Separate launcher-owned initialization from ordered evaluation in MIR. */
69
+ declare function lowerFragmentPhases(unit: ScriptFragment): readonly [MirProgram, MirProgram];
70
+ //#endregion
71
+ export { BodyFragmentResult, FragmentBinding, HarnessFragment, HarnessFragmentResult, ScriptFragment, compileBodyFragment, compileHarnessFragment, lowerFragmentPhases, scriptFragmentAbi };
72
+ //# sourceMappingURL=fragments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragments.d.ts","names":[],"sources":["../src/fragments.ts"],"mappings":";;;;;;cA0Ba;;UAGI;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN,KAAK;WACL,KAAK;;WAEL;WACA;;WAEA;;;UAIM,wBAAwB;WAC9B,YAAY;WACZ,kBAAkB;WAClB,mBAAmB;WACnB;WACA;WACA,SAAS;;;KAIR;WACG;WAA2B,SAAS;;WACpC;WAA2B,sBAAsB;;;KAGpD;WAEG;WACA,MAAM;WACN;;WAGA;WACA;WAOA;WACA,sBAAsB;;;;;;;iBAqCrB,uBACd,UAAU,gBACV,kBAAkB,eAClB,kBACA,UAAS,kBACR;;;;;;iBA6Ea,oBACd,UAAU,gBACV,SAAS,iBACT,OAAO,cACN;;iBA0Fa,oBACd,MAAM,2BACK,YAAY"}