behavior-contracts 0.8.6 → 0.8.8
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/cli-contract.yaml +189 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +76 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/codegen.d.ts +6 -0
- package/dist/commands/codegen.d.ts.map +1 -0
- package/dist/commands/codegen.js +39 -0
- package/dist/commands/codegen.js.map +1 -0
- package/dist/generated/commands.d.ts +8 -0
- package/dist/generated/commands.d.ts.map +1 -0
- package/dist/generated/commands.js +55 -0
- package/dist/generated/commands.js.map +1 -0
- package/dist/generated/contract.d.ts +3 -0
- package/dist/generated/contract.d.ts.map +1 -0
- package/dist/generated/contract.js +5 -0
- package/dist/generated/contract.js.map +1 -0
- package/dist/generated/index.d.ts +7 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +7 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/program.d.ts +17 -0
- package/dist/generated/program.d.ts.map +1 -0
- package/dist/generated/program.js +117 -0
- package/dist/generated/program.js.map +1 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +3 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +35 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +3 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/generator/core.d.ts +28 -0
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +7 -0
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-shared-debox.d.ts +108 -0
- package/dist/generator/emit-shared-debox.d.ts.map +1 -0
- package/dist/generator/emit-shared-debox.js +117 -0
- package/dist/generator/emit-shared-debox.js.map +1 -0
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +436 -1078
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +9 -7
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +313 -844
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/typed.d.ts +4 -2
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +4 -2
- package/dist/generator/typed.js.map +1 -1
- package/package.json +12 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../src/generated/program.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOjE,MAAM,UAAU,aAAa,CAC3B,QAAyB,EACzB,OAAe;IAEf,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACJ,IAAI,CAAC,IAAI,CAAC;SACV,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC;SACjC,WAAW,CAAC,6DAA6D,CAAC,CAAC;IAG9E,OAAO;SACJ,OAAO,CAAC,UAAU,CAAC;SACnB,WAAW,CAAC,gDAAgD,CAAC;SAC7D,MAAM,CAAC,kBAAkB,EAAE,4GAA4G,CAAC;SACxI,MAAM,CAAC,oBAAoB,EAAE,uDAAuD,CAAC;SACrF,MAAM,CAAC,cAAc,EAAE,oDAAoD,CAAC;SAC5E,MAAM,CAAC,yBAAyB,EAAE,8DAA8D,CAAC;SACjG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QAC1B,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEL,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAA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C,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;wBACrF,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;oBAC1B,CAAC;gBACH,CAAC;gBACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACpC,MAAM,OAAO,GAAG,EAAE,GAAI,EAA8B,EAAE,CAAC;oBACvD,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC;oBAC3B,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;gBACvB,CAAC;YACH,CAAC;YACD,IAAI,GAAG,CAAC,UAAU;gBAAE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;YACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IACL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/generated/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/generated/schemas.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface GenerateOptions {
|
|
2
|
+
lang: string;
|
|
3
|
+
in: string;
|
|
4
|
+
out?: string;
|
|
5
|
+
runtimeImport?: string;
|
|
6
|
+
}
|
|
7
|
+
export type GenerateExitCode = 0 | 1 | 2;
|
|
8
|
+
export type GenerateExitResult = {
|
|
9
|
+
exitCode: 0;
|
|
10
|
+
stdout: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
exitCode: 1;
|
|
13
|
+
stderr: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
exitCode: 2;
|
|
16
|
+
stderr: unknown;
|
|
17
|
+
};
|
|
18
|
+
export interface CheckOptions {
|
|
19
|
+
lang: string;
|
|
20
|
+
in: string;
|
|
21
|
+
out: string;
|
|
22
|
+
runtimeImport?: string;
|
|
23
|
+
}
|
|
24
|
+
export type CheckExitCode = 0 | 1 | 2;
|
|
25
|
+
export type CheckExitResult = {
|
|
26
|
+
exitCode: 0;
|
|
27
|
+
stdout: unknown;
|
|
28
|
+
} | {
|
|
29
|
+
exitCode: 1;
|
|
30
|
+
stderr: unknown;
|
|
31
|
+
} | {
|
|
32
|
+
exitCode: 2;
|
|
33
|
+
stderr: unknown;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generated/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEzC,MAAM,MAAM,kBAAkB,GAC5B;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC9B;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAChC;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtC,MAAM,MAAM,eAAe,GACzB;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC9B;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAChC;IAAE,QAAQ,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generated/types.ts"],"names":[],"mappings":"AAAA,gDAAgD"}
|
package/dist/generator/core.d.ts
CHANGED
|
@@ -13,6 +13,24 @@ import type { ComponentGraphIR } from "../behavior.js";
|
|
|
13
13
|
export type IoModel = "sync" | "async" | {
|
|
14
14
|
readonly asyncComponents: readonly string[];
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* GoWireOptions (go-typed-native) — the CONCRETE consumer wire seam names the covered read de-box
|
|
18
|
+
* classifies a node result against. bc does NOT define the wire types (that would own the wire format)
|
|
19
|
+
* and does NOT make them interfaces (a Go interface is vtable dynamic dispatch); it REFERENCES these
|
|
20
|
+
* concrete consumer type names and calls their methods directly (zero dynamic dispatch, zero dictionary):
|
|
21
|
+
* - `value` — the node-result WIRE type (methods `AsString/AsNumber/AsBool/AsRow/AsList`);
|
|
22
|
+
* - `row` — a wire map/record (methods `Keys/ProbeString/ProbeNumber/ProbeBool/ProbeRow/ProbeList`);
|
|
23
|
+
* - `list` — a wire array (methods `Len/ElemString/ElemNumber/ElemBool/ElemRow/ElemList`).
|
|
24
|
+
* Omitted → the IN-PACKAGE convention names `WireValue`/`WireRow`/`WireList` (the goldens + test companion
|
|
25
|
+
* provide concrete scripted implementations). `import` is the package the consumer's wire types live in
|
|
26
|
+
* (added to the covered module imports + used to qualify the names); omit for in-package types.
|
|
27
|
+
*/
|
|
28
|
+
export interface GoWireOptions {
|
|
29
|
+
value: string;
|
|
30
|
+
row: string;
|
|
31
|
+
list: string;
|
|
32
|
+
import?: string;
|
|
33
|
+
}
|
|
16
34
|
export type GeneratorFailureCode = "INPUT_NOT_PORTABLE_IR" | "UNSUPPORTED_IR_VERSION" | "UNSUPPORTED_EXPR_VERSION" | "EMPTY_IR" | "DUPLICATE_COMPONENT" | "UNKNOWN_LANGUAGE" | "UNSUPPORTED_NODE_STRAIGHTLINE";
|
|
17
35
|
export declare class GeneratorFailure extends Error {
|
|
18
36
|
code: GeneratorFailureCode;
|
|
@@ -47,6 +65,11 @@ export interface EmitContext {
|
|
|
47
65
|
* go は await 概念が無く annotation を無視(no-op)。python は native codegen surface が無く対象外。
|
|
48
66
|
*/
|
|
49
67
|
ioModel: IoModel;
|
|
68
|
+
/**
|
|
69
|
+
* go-typed-native の CONCRETE 消費者ワイヤ型名({@link GoWireOptions})。未指定なら in-package の
|
|
70
|
+
* 既定名 `WireValue`/`WireRow`/`WireList`。他言語 emitter(ts/py/php/rust)は無視。
|
|
71
|
+
*/
|
|
72
|
+
goWire?: GoWireOptions;
|
|
50
73
|
}
|
|
51
74
|
/**
|
|
52
75
|
* emitter ターゲット分類(consumer-interface.md §0/§1・#128/A6)。BC の実行モデルは根本 2 つ:
|
|
@@ -103,6 +126,11 @@ export interface GenerateOptions {
|
|
|
103
126
|
* {@link IoModel} と `async-plan.ts` の SSoT 伝播 pass を参照。
|
|
104
127
|
*/
|
|
105
128
|
ioModel?: IoModel;
|
|
129
|
+
/**
|
|
130
|
+
* go-typed-native の CONCRETE 消費者ワイヤ型名({@link GoWireOptions})。未指定なら in-package の
|
|
131
|
+
* 既定名 `WireValue`/`WireRow`/`WireList`。他言語 emitter は無視(no-op)。
|
|
132
|
+
*/
|
|
133
|
+
goWire?: GoWireOptions;
|
|
106
134
|
}
|
|
107
135
|
export interface GeneratedModule {
|
|
108
136
|
/** 生成言語。 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/generator/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/generator/core.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEzF;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,MAAM,oBAAoB,GAC5B,uBAAuB,GACvB,wBAAwB,GACxB,0BAA0B,GAC1B,UAAU,GACV,qBAAqB,GACrB,kBAAkB,GAClB,+BAA+B,CAAC;AAEpC,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,IAAI,EAAE,oBAAoB,CAAC;gBACf,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM;CAKxD;AAOD,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,mCAAmC;IACnC,EAAE,EAAE,gBAAgB,CAAC;IACrB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,YAAY,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,8BAA8B;IAC9B,c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AC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,uCAAuC;IACvC,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,8CAA8C;IAC9C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,eAAe,CAsCrF"}
|
package/dist/generator/core.js
CHANGED
|
@@ -26,6 +26,7 @@ import { SPEC_VERSIONS } from "../index.js";
|
|
|
26
26
|
import { assertPortableComponentGraph } from "../guard.js";
|
|
27
27
|
import { fingerprintComponentGraph } from "./fingerprint.js";
|
|
28
28
|
import { assertCompiled } from "../provenance.js";
|
|
29
|
+
import { assertAllNodeTypesDetermined } from "../type-gate.js";
|
|
29
30
|
export class GeneratorFailure extends Error {
|
|
30
31
|
code;
|
|
31
32
|
constructor(code, message) {
|
|
@@ -100,6 +101,11 @@ export function generateModule(ir, options) {
|
|
|
100
101
|
gfail("UNKNOWN_LANGUAGE", `no emitter registered for language '${options.language}' (registered: ${registeredLanguages().join(", ")}) (fail-closed)`);
|
|
101
102
|
assertCompiled(ir); // SA3/SA7 出自ゲート: codegen 入力も無 token/改竄 IR は NON_COMPILED_IR で fail-closed
|
|
102
103
|
const validated = validateGeneratorInput(ir);
|
|
104
|
+
// SA5 / SCP-only end-state: 全ノードの出力型が確定していること(未確定は fail-closed UNTYPED_NODE)を
|
|
105
|
+
// codegen 入口で強制する。authoring path(authoring.ts)と同一の SSoT ゲートを消費する(型 walk を
|
|
106
|
+
// 重複させない)。untyped straight-line フォールバックは存在しない — 型未確定 IR は compile-time エラー。
|
|
107
|
+
for (const comp of validated.components)
|
|
108
|
+
assertAllNodeTypesDetermined(comp);
|
|
103
109
|
const fingerprint = fingerprintComponentGraph(validated);
|
|
104
110
|
const specVersions = {
|
|
105
111
|
behavior: SPEC_VERSIONS.behavior,
|
|
@@ -114,6 +120,7 @@ export function generateModule(ir, options) {
|
|
|
114
120
|
componentNames,
|
|
115
121
|
runtimeImport: options.runtimeImport ?? plugin.defaultRuntimeImport,
|
|
116
122
|
ioModel: options.ioModel ?? "sync",
|
|
123
|
+
goWire: options.goWire,
|
|
117
124
|
};
|
|
118
125
|
return {
|
|
119
126
|
language: plugin.language,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/generator/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/generator/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AA6C/D,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,IAAI,CAAuB;IAC3B,YAAY,IAA0B,EAAE,OAAe;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,SAAS,KAAK,CAAC,IAA0B,EAAE,OAAe;IACxD,MAAM,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAA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C,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,IAAI,EAAE,aAAa,CAAC,IAAI;KACzB,CAAC;IACF,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAgB;QACvB,EAAE,EAAE,SAAS;QACb,WAAW;QACX,YAAY;QACZ,cAAc;QACd,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,MAAM,CAAC,oBAAoB;QACnE,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QACtB,WAAW;QACX,YAAY;QACZ,cAAc;QACd,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,sBAAsB,MAAM,CAAC,aAAa,EAAE;KAClF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emit-shared-debox.ts — the SINGLE, language-neutral source of truth for compiling a strict de-box
|
|
3
|
+
* from an SCP-resolved type.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS FILE EXISTS
|
|
6
|
+
* --------------------
|
|
7
|
+
* A strict de-box turns a producer's wire payload into the STATICALLY DECLARED native type, checking
|
|
8
|
+
* every value against that type and producing a structured Error Value on a mismatch. SCP resolves the
|
|
9
|
+
* whole type at parse time — every annotation point is a finite, ACYCLIC `TypeRef` tree (a named type
|
|
10
|
+
* can never contain itself; see typed.ts `structuralKey`, "型記法は非再帰"). Because the type is fully
|
|
11
|
+
* known at generation time, the de-box is a TOTAL function of the resolved type: for every position
|
|
12
|
+
* (node-result top, list element, map value, record field, any nesting) a decode can always be
|
|
13
|
+
* generated — scalar → probe + type-check, opt → present/absent, named → recurse each field, arr →
|
|
14
|
+
* recurse each element, map → recurse each value. There is NO shape that "cannot be de-boxed": the only
|
|
15
|
+
* legitimate non-generation is a type SCP could not resolve, and that fails at type resolution, never
|
|
16
|
+
* here.
|
|
17
|
+
*
|
|
18
|
+
* Historically the decision "which shapes de-box, and how" was scattered across per-POSITION predicates
|
|
19
|
+
* (a `recordTop` for node results, a `…ElemEligible` for map/fanout elements, a nested-value recursion,
|
|
20
|
+
* and a fail-close gate) DUPLICATED per language. They disagreed by construction (a top handled
|
|
21
|
+
* `opt(named)` while an element did not), so every new shape had to be added to all of them and a miss
|
|
22
|
+
* silently fell through to a fail-close — the recurring "de-box was missing here". This module removes
|
|
23
|
+
* that surface: {@link buildDeBoxPlan} is the ONE total walk over the grammar, producing a
|
|
24
|
+
* language-neutral {@link DeBoxPlan} tree. Each language emitter renders that tree to FLAT, INLINE,
|
|
25
|
+
* CONCRETE native code (no per-type helper function, no output-side recursion, no dynamic dispatch, no
|
|
26
|
+
* dictionary) — the type is baked all the way through by the TS compiler, not deferred to the target
|
|
27
|
+
* compiler's monomorphizer/inliner or to a runtime interface. The walk here owns STRUCTURE and
|
|
28
|
+
* totality; the renderers own only SYNTAX.
|
|
29
|
+
*/
|
|
30
|
+
import { type TypePlan, type TypeRef } from "./typed.js";
|
|
31
|
+
/** The four concrete scalar kinds a de-box leaf checks (the grammar's `null` scalar is handled
|
|
32
|
+
* separately — it is not a decodable datum but a producer-null marker). */
|
|
33
|
+
export type DeBoxScalar = "string" | "int" | "float" | "bool";
|
|
34
|
+
/**
|
|
35
|
+
* Access — HOW a plan node's wire value is obtained from its enclosing wire. This is the only thing a
|
|
36
|
+
* renderer needs to pick the right probe; the value's TYPE is carried by the plan node's kind.
|
|
37
|
+
* - `top` the value IS the node's result wire (a {@link WireValue}); probe it with `as_*`.
|
|
38
|
+
* - `field` a static-keyed attribute of the enclosing WireRow; probe with `probe_*(key)`.
|
|
39
|
+
* - `elem` the current element of the enclosing WireList; probe with `elem_*(index)`.
|
|
40
|
+
* - `mapval` the value at the current key of the enclosing WireRow (a declared `map(V)`); probe with
|
|
41
|
+
* `probe_*(key)` where the key is the loop variable the renderer supplies.
|
|
42
|
+
*/
|
|
43
|
+
export type DeBoxAccess = {
|
|
44
|
+
from: "top";
|
|
45
|
+
} | {
|
|
46
|
+
from: "field";
|
|
47
|
+
key: string;
|
|
48
|
+
} | {
|
|
49
|
+
from: "elem";
|
|
50
|
+
} | {
|
|
51
|
+
from: "mapval";
|
|
52
|
+
};
|
|
53
|
+
/** Common fields every plan node carries: the error labels (scp-error.md `model` / `field`), the
|
|
54
|
+
* STATICALLY rendered expected type (Portable Type Notation — nothing walks a type at runtime), the
|
|
55
|
+
* access, and `optDepth` (0 = required; N = wrapped in N optional layers — absent/null → the all-none
|
|
56
|
+
* value, so a required-position miss is a structured error while an optional-position miss is None). */
|
|
57
|
+
interface DeBoxCommon {
|
|
58
|
+
optDepth: number;
|
|
59
|
+
access: DeBoxAccess;
|
|
60
|
+
/** scp-error.md `model` — the declaring type name at this position (the enclosing named type, or the
|
|
61
|
+
* node/field label for a top-level or collection position). */
|
|
62
|
+
model: string;
|
|
63
|
+
/** scp-error.md `field` — the raw field label carried into the structured error. */
|
|
64
|
+
field: string;
|
|
65
|
+
/** the rendered Portable Type Notation of the ORIGINAL ref at this position (opt() included) —
|
|
66
|
+
* the `expectedType` literal baked into a mismatch error. */
|
|
67
|
+
expectedType: string;
|
|
68
|
+
}
|
|
69
|
+
/** DeBoxPlan — a node in the language-neutral decode plan tree. Every SCP-resolved type maps to exactly
|
|
70
|
+
* one of these (the walk is total); a renderer folds the tree into inline native code. */
|
|
71
|
+
export type DeBoxPlan = ({
|
|
72
|
+
k: "scalar";
|
|
73
|
+
scalar: DeBoxScalar;
|
|
74
|
+
} & DeBoxCommon) | ({
|
|
75
|
+
k: "record";
|
|
76
|
+
typeName: string;
|
|
77
|
+
fields: {
|
|
78
|
+
name: string;
|
|
79
|
+
plan: DeBoxPlan;
|
|
80
|
+
}[];
|
|
81
|
+
} & DeBoxCommon) | ({
|
|
82
|
+
k: "list";
|
|
83
|
+
elem: DeBoxPlan;
|
|
84
|
+
} & DeBoxCommon) | ({
|
|
85
|
+
k: "map";
|
|
86
|
+
value: DeBoxPlan;
|
|
87
|
+
} & DeBoxCommon);
|
|
88
|
+
/**
|
|
89
|
+
* notationOfRef — the Portable Type Notation of a TypeRef (scp-error.md), resolving a named ref to its
|
|
90
|
+
* `obj{…}` notation via the plan. Baked as the `expectedType` literal: a rendering of the STATICALLY
|
|
91
|
+
* declared type, so nothing walks a type at runtime. Language-neutral (shared by every emitter).
|
|
92
|
+
*/
|
|
93
|
+
export declare function notationOfRef(ref: TypeRef, plan: TypePlan): string;
|
|
94
|
+
/**
|
|
95
|
+
* buildDeBoxPlan — the ONE total walk. Given an SCP-resolved `ref` at a position reached via `access`,
|
|
96
|
+
* return the decode plan for a value of that type. Recurses over the FULL grammar at every nesting so
|
|
97
|
+
* arbitrary shapes (opt(named), arr(arr(named)), map(opt(named)), …) are covered by construction — there
|
|
98
|
+
* is no per-shape allow-list and no fail-close. `ctx.model` / `ctx.field` are the error labels inherited
|
|
99
|
+
* at this position (a named type re-roots them to its own name / field names for its fields; a
|
|
100
|
+
* collection keeps the enclosing labels, matching the whole-field granularity of the Error Value).
|
|
101
|
+
*/
|
|
102
|
+
export declare function buildDeBoxPlan(ref: TypeRef, access: DeBoxAccess, ctx: {
|
|
103
|
+
model: string;
|
|
104
|
+
field: string;
|
|
105
|
+
plan: TypePlan;
|
|
106
|
+
}): DeBoxPlan;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=emit-shared-debox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-shared-debox.d.ts","sourceRoot":"","sources":["../../src/generator/emit-shared-debox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAY,KAAK,QAAQ,EAAE,KAA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,GAAG,MAAM,CAgBlE;AAYD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,SAAS,CA2ClI"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emit-shared-debox.ts — the SINGLE, language-neutral source of truth for compiling a strict de-box
|
|
3
|
+
* from an SCP-resolved type.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS FILE EXISTS
|
|
6
|
+
* --------------------
|
|
7
|
+
* A strict de-box turns a producer's wire payload into the STATICALLY DECLARED native type, checking
|
|
8
|
+
* every value against that type and producing a structured Error Value on a mismatch. SCP resolves the
|
|
9
|
+
* whole type at parse time — every annotation point is a finite, ACYCLIC `TypeRef` tree (a named type
|
|
10
|
+
* can never contain itself; see typed.ts `structuralKey`, "型記法は非再帰"). Because the type is fully
|
|
11
|
+
* known at generation time, the de-box is a TOTAL function of the resolved type: for every position
|
|
12
|
+
* (node-result top, list element, map value, record field, any nesting) a decode can always be
|
|
13
|
+
* generated — scalar → probe + type-check, opt → present/absent, named → recurse each field, arr →
|
|
14
|
+
* recurse each element, map → recurse each value. There is NO shape that "cannot be de-boxed": the only
|
|
15
|
+
* legitimate non-generation is a type SCP could not resolve, and that fails at type resolution, never
|
|
16
|
+
* here.
|
|
17
|
+
*
|
|
18
|
+
* Historically the decision "which shapes de-box, and how" was scattered across per-POSITION predicates
|
|
19
|
+
* (a `recordTop` for node results, a `…ElemEligible` for map/fanout elements, a nested-value recursion,
|
|
20
|
+
* and a fail-close gate) DUPLICATED per language. They disagreed by construction (a top handled
|
|
21
|
+
* `opt(named)` while an element did not), so every new shape had to be added to all of them and a miss
|
|
22
|
+
* silently fell through to a fail-close — the recurring "de-box was missing here". This module removes
|
|
23
|
+
* that surface: {@link buildDeBoxPlan} is the ONE total walk over the grammar, producing a
|
|
24
|
+
* language-neutral {@link DeBoxPlan} tree. Each language emitter renders that tree to FLAT, INLINE,
|
|
25
|
+
* CONCRETE native code (no per-type helper function, no output-side recursion, no dynamic dispatch, no
|
|
26
|
+
* dictionary) — the type is baked all the way through by the TS compiler, not deferred to the target
|
|
27
|
+
* compiler's monomorphizer/inliner or to a runtime interface. The walk here owns STRUCTURE and
|
|
28
|
+
* totality; the renderers own only SYNTAX.
|
|
29
|
+
*/
|
|
30
|
+
import { GeneratorFailure } from "./core.js";
|
|
31
|
+
import { findDecl } from "./typed.js";
|
|
32
|
+
/**
|
|
33
|
+
* notationOfRef — the Portable Type Notation of a TypeRef (scp-error.md), resolving a named ref to its
|
|
34
|
+
* `obj{…}` notation via the plan. Baked as the `expectedType` literal: a rendering of the STATICALLY
|
|
35
|
+
* declared type, so nothing walks a type at runtime. Language-neutral (shared by every emitter).
|
|
36
|
+
*/
|
|
37
|
+
export function notationOfRef(ref, plan) {
|
|
38
|
+
switch (ref.kind) {
|
|
39
|
+
case "scalar":
|
|
40
|
+
return ref.scalar;
|
|
41
|
+
case "opt":
|
|
42
|
+
return `opt(${notationOfRef(ref.inner, plan)})`;
|
|
43
|
+
case "arr":
|
|
44
|
+
return `arr(${notationOfRef(ref.elem, plan)})`;
|
|
45
|
+
case "map":
|
|
46
|
+
return `map(${notationOfRef(ref.value, plan)})`;
|
|
47
|
+
case "named": {
|
|
48
|
+
const decl = findDecl(plan, ref.name);
|
|
49
|
+
if (decl === undefined)
|
|
50
|
+
return ref.name;
|
|
51
|
+
return `obj{${decl.fields.map((f) => `${f.name}:${notationOfRef(f.type, plan)}`).join(",")}}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** deBoxUnsupported — raise a generation-time (compile-time) failure for a type the de-box cannot bake.
|
|
56
|
+
* This is NEVER a runtime fail-close branch in the generated code: an unsupported/unresolvable type is a
|
|
57
|
+
* codegen error, surfaced here, exactly as the owner requires. In practice this is unreachable for a
|
|
58
|
+
* well-formed type plan (buildTypePlan covers every annotation point and the grammar is finite/acyclic);
|
|
59
|
+
* the one degenerate leaf it guards is a bare `null` scalar as a decode target, which no producer datum
|
|
60
|
+
* satisfies. */
|
|
61
|
+
function deBoxUnsupported(message) {
|
|
62
|
+
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", message);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* buildDeBoxPlan — the ONE total walk. Given an SCP-resolved `ref` at a position reached via `access`,
|
|
66
|
+
* return the decode plan for a value of that type. Recurses over the FULL grammar at every nesting so
|
|
67
|
+
* arbitrary shapes (opt(named), arr(arr(named)), map(opt(named)), …) are covered by construction — there
|
|
68
|
+
* is no per-shape allow-list and no fail-close. `ctx.model` / `ctx.field` are the error labels inherited
|
|
69
|
+
* at this position (a named type re-roots them to its own name / field names for its fields; a
|
|
70
|
+
* collection keeps the enclosing labels, matching the whole-field granularity of the Error Value).
|
|
71
|
+
*/
|
|
72
|
+
export function buildDeBoxPlan(ref, access, ctx) {
|
|
73
|
+
const { plan } = ctx;
|
|
74
|
+
const expectedType = notationOfRef(ref, plan);
|
|
75
|
+
// Strip optional layers, counting depth; the presence logic is single-bit at the wire (a nested
|
|
76
|
+
// Option is still decoded present → Some(Some(v)) / absent → None), but the native type keeps N wraps.
|
|
77
|
+
let optDepth = 0;
|
|
78
|
+
let base = ref;
|
|
79
|
+
while (base.kind === "opt") {
|
|
80
|
+
optDepth++;
|
|
81
|
+
base = base.inner;
|
|
82
|
+
}
|
|
83
|
+
const common = { optDepth, access, model: ctx.model, field: ctx.field, expectedType };
|
|
84
|
+
switch (base.kind) {
|
|
85
|
+
case "scalar": {
|
|
86
|
+
if (base.scalar === "null")
|
|
87
|
+
// a bare `null` type is not a decodable datum (no producer value is "the null type"); it only
|
|
88
|
+
// ever appears as an optional marker, which the optDepth path above already absorbed. Reaching
|
|
89
|
+
// here means a required bare-null field — degenerate; surface it rather than emit dead code.
|
|
90
|
+
deBoxUnsupported(`de-box: '${ctx.field}' of '${ctx.model}' is a bare 'null' type, which no producer datum satisfies`);
|
|
91
|
+
return { k: "scalar", scalar: base.scalar, ...common };
|
|
92
|
+
}
|
|
93
|
+
case "named": {
|
|
94
|
+
const decl = findDecl(plan, base.name);
|
|
95
|
+
if (decl === undefined)
|
|
96
|
+
deBoxUnsupported(`de-box: named type '${base.name}' is not in the type plan`);
|
|
97
|
+
const fields = decl.fields.map((f) => ({
|
|
98
|
+
name: f.name,
|
|
99
|
+
plan: buildDeBoxPlan(f.type, { from: "field", key: f.name }, { model: base.name, field: f.name, plan }),
|
|
100
|
+
}));
|
|
101
|
+
return { k: "record", typeName: base.name, fields, ...common };
|
|
102
|
+
}
|
|
103
|
+
case "arr": {
|
|
104
|
+
const elem = buildDeBoxPlan(base.elem, { from: "elem" }, { model: ctx.model, field: ctx.field, plan });
|
|
105
|
+
return { k: "list", elem, ...common };
|
|
106
|
+
}
|
|
107
|
+
case "map": {
|
|
108
|
+
const value = buildDeBoxPlan(base.value, { from: "mapval" }, { model: ctx.model, field: ctx.field, plan });
|
|
109
|
+
return { k: "map", value, ...common };
|
|
110
|
+
}
|
|
111
|
+
default:
|
|
112
|
+
// unreachable: the while-loop above strips every `opt`, so `base.kind` is scalar/named/arr/map.
|
|
113
|
+
// The throw keeps the return checker happy without a non-total cast.
|
|
114
|
+
deBoxUnsupported(`de-box: unexpected residual kind '${base.kind}'`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=emit-shared-debox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-shared-debox.js","sourceRoot":"","sources":["../../src/generator/emit-shared-debox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,QAA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E,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"emit-typed-native-go.d.ts","sourceRoot":"","sources":["../../src/generator/emit-typed-native-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,WAAW,CAAC;AAukF5D;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CA8ehF;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAOlC,CAAC"}
|