behavior-contracts 0.5.0 → 0.6.0
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/dist/behavior.d.ts +7 -0
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +10 -3
- package/dist/builder.js.map +1 -1
- package/dist/generator/async-plan.d.ts +78 -0
- package/dist/generator/async-plan.d.ts.map +1 -0
- package/dist/generator/async-plan.js +116 -0
- package/dist/generator/async-plan.js.map +1 -0
- package/dist/generator/core.d.ts +30 -9
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/{emit-straightline-typed-go.d.ts → emit-shared-go-typed.d.ts} +11 -17
- package/dist/generator/emit-shared-go-typed.d.ts.map +1 -0
- package/dist/generator/emit-shared-go-typed.js +572 -0
- package/dist/generator/emit-shared-go-typed.js.map +1 -0
- package/dist/generator/emit-shared-go.d.ts +29 -0
- package/dist/generator/emit-shared-go.d.ts.map +1 -0
- package/dist/generator/{emit-straightline-go.js → emit-shared-go.js} +2 -34
- package/dist/generator/emit-shared-go.js.map +1 -0
- package/dist/generator/{emit-straightline-typed-rust.d.ts → emit-shared-rust-typed.d.ts} +11 -17
- package/dist/generator/emit-shared-rust-typed.d.ts.map +1 -0
- package/dist/generator/emit-shared-rust-typed.js +576 -0
- package/dist/generator/emit-shared-rust-typed.js.map +1 -0
- package/dist/generator/{emit-straightline-rust.d.ts → emit-shared-rust.d.ts} +1 -36
- package/dist/generator/emit-shared-rust.d.ts.map +1 -0
- package/dist/generator/{emit-straightline-rust.js → emit-shared-rust.js} +2 -16
- package/dist/generator/emit-shared-rust.js.map +1 -0
- package/dist/generator/emit-shared-typescript.d.ts +12 -0
- package/dist/generator/emit-shared-typescript.d.ts.map +1 -0
- package/dist/generator/{emit-straightline-typescript.js → emit-shared-typescript.js} +5 -20
- package/dist/generator/emit-shared-typescript.js.map +1 -0
- package/dist/generator/emit-straightline-typed-typescript.d.ts +1 -1
- package/dist/generator/emit-straightline-typed-typescript.d.ts.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +495 -75
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +2 -1
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +553 -103
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +2 -12
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +10 -62
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/native-expr.d.ts +120 -0
- package/dist/generator/native-expr.d.ts.map +1 -0
- package/dist/generator/native-expr.js +456 -0
- package/dist/generator/native-expr.js.map +1 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +8 -0
- package/dist/generator/typed.js.map +1 -1
- package/dist/guard.js +14 -0
- package/dist/guard.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plan.d.ts +6 -2
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +4 -0
- package/dist/plan.js.map +1 -1
- package/package.json +1 -1
- package/dist/generator/emit-go.d.ts +0 -19
- package/dist/generator/emit-go.d.ts.map +0 -1
- package/dist/generator/emit-go.js +0 -79
- package/dist/generator/emit-go.js.map +0 -1
- package/dist/generator/emit-raw-abi-go.d.ts +0 -45
- package/dist/generator/emit-raw-abi-go.d.ts.map +0 -1
- package/dist/generator/emit-raw-abi-go.js +0 -346
- package/dist/generator/emit-raw-abi-go.js.map +0 -1
- package/dist/generator/emit-raw-abi-rust.d.ts +0 -45
- package/dist/generator/emit-raw-abi-rust.d.ts.map +0 -1
- package/dist/generator/emit-raw-abi-rust.js +0 -380
- package/dist/generator/emit-raw-abi-rust.js.map +0 -1
- package/dist/generator/emit-rust.d.ts +0 -25
- package/dist/generator/emit-rust.d.ts.map +0 -1
- package/dist/generator/emit-rust.js +0 -125
- package/dist/generator/emit-rust.js.map +0 -1
- package/dist/generator/emit-straightline-go.d.ts +0 -60
- package/dist/generator/emit-straightline-go.d.ts.map +0 -1
- package/dist/generator/emit-straightline-go.js.map +0 -1
- package/dist/generator/emit-straightline-native-go.d.ts +0 -54
- package/dist/generator/emit-straightline-native-go.d.ts.map +0 -1
- package/dist/generator/emit-straightline-native-go.js +0 -835
- package/dist/generator/emit-straightline-native-go.js.map +0 -1
- package/dist/generator/emit-straightline-native-rust.d.ts +0 -27
- package/dist/generator/emit-straightline-native-rust.d.ts.map +0 -1
- package/dist/generator/emit-straightline-native-rust.js +0 -624
- package/dist/generator/emit-straightline-native-rust.js.map +0 -1
- package/dist/generator/emit-straightline-php.d.ts +0 -46
- package/dist/generator/emit-straightline-php.d.ts.map +0 -1
- package/dist/generator/emit-straightline-php.js +0 -941
- package/dist/generator/emit-straightline-php.js.map +0 -1
- package/dist/generator/emit-straightline-python.d.ts +0 -36
- package/dist/generator/emit-straightline-python.d.ts.map +0 -1
- package/dist/generator/emit-straightline-python.js +0 -855
- package/dist/generator/emit-straightline-python.js.map +0 -1
- package/dist/generator/emit-straightline-rust.d.ts.map +0 -1
- package/dist/generator/emit-straightline-rust.js.map +0 -1
- package/dist/generator/emit-straightline-typed-go.d.ts.map +0 -1
- package/dist/generator/emit-straightline-typed-go.js +0 -1114
- package/dist/generator/emit-straightline-typed-go.js.map +0 -1
- package/dist/generator/emit-straightline-typed-rust.d.ts.map +0 -1
- package/dist/generator/emit-straightline-typed-rust.js +0 -1155
- package/dist/generator/emit-straightline-typed-rust.js.map +0 -1
- package/dist/generator/emit-straightline-typescript.d.ts +0 -47
- package/dist/generator/emit-straightline-typescript.d.ts.map +0 -1
- package/dist/generator/emit-straightline-typescript.js.map +0 -1
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import { GeneratorFailure } from "./core.js";
|
|
2
|
-
import { buildTypePlan, deriveTypeRef } from "./typed.js";
|
|
3
|
-
import { buildComponentPlan } from "./straightline.js";
|
|
4
|
-
import { rustTypedInternals } from "./emit-straightline-typed-rust.js";
|
|
5
|
-
const PORT_SCOPE = "port_scope()";
|
|
6
|
-
const { sanitize, rustFieldName, rustStrLit, renderTypeRef, rustScalar, typedCell, isTypedComponent, hasAnyTypeAnnotation, collectTypedNodes, emitTypeDecls, emitDefaults, emitSerializers, emitMarshallers, emitMarshalHelpers, serializeTyped, emitTypedValue, indentBlock, emitOpsLiteral, emitPlanLiteral, rustStraightlineEmitter, setRustForceRunPlanImports, } = rustTypedInternals;
|
|
7
|
-
// ── RAW marshallers (the de-box): read a RawValue field-by-field into a concrete struct ──
|
|
8
|
-
function emitRawMarshallers(plan) {
|
|
9
|
-
if (plan.decls.length === 0)
|
|
10
|
-
return "";
|
|
11
|
-
return plan.decls.map((d) => emitOneRawMarshaller(d, plan)).join("\n\n");
|
|
12
|
-
}
|
|
13
|
-
function emitOneRawMarshaller(d, plan) {
|
|
14
|
-
const lines = [];
|
|
15
|
-
lines.push(`#[allow(dead_code)]`);
|
|
16
|
-
lines.push(`fn marshal_raw_${d.name}(raw: &RawValue) -> Result<${d.name}, BehaviorError> {`);
|
|
17
|
-
// The row seam: a RawRow (native accessor), NOT a Value::Obj. This IS the de-box.
|
|
18
|
-
lines.push(` let row = match raw {`);
|
|
19
|
-
lines.push(` RawValue::Row(r) => r,`);
|
|
20
|
-
lines.push(` other => return Err(raw_type_mismatch(${rustStrLit("obj")}, other.type_name())),`);
|
|
21
|
-
lines.push(` };`);
|
|
22
|
-
const fieldInits = [];
|
|
23
|
-
for (const f of d.fields) {
|
|
24
|
-
const fieldVar = `field_${rustFieldName(f.name).replace(/^r#/, "")}`;
|
|
25
|
-
const keyLit = rustStrLit(f.name);
|
|
26
|
-
lines.push(` let ${fieldVar} = {`);
|
|
27
|
-
lines.push(` let fv = match row.field(${keyLit}) {`);
|
|
28
|
-
lines.push(` Some(v) => v,`);
|
|
29
|
-
lines.push(` None => return Err(raw_missing_prop(${rustStrLit(d.name)}, ${keyLit})),`);
|
|
30
|
-
lines.push(` };`);
|
|
31
|
-
lines.push(indentBlock(emitRawFieldMaterialize("fv", f.type, plan), 2));
|
|
32
|
-
lines.push(` };`);
|
|
33
|
-
fieldInits.push(` ${rustFieldName(f.name)}: ${fieldVar},`);
|
|
34
|
-
}
|
|
35
|
-
lines.push(` Ok(${d.name} {`);
|
|
36
|
-
lines.push(...fieldInits);
|
|
37
|
-
lines.push(` })`);
|
|
38
|
-
lines.push(`}`);
|
|
39
|
-
return lines.join("\n");
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* emitRawFieldMaterialize — materialize `src` (a `&RawValue` expr) into a concrete typed value
|
|
43
|
-
* per `ref` (a value-returning block). scalar -> RawValue match, named -> marshal_raw_T*, arr
|
|
44
|
-
* -> RawValue::Arr loop, opt -> RawValue::Null branch. No Value::Obj/Value ever built.
|
|
45
|
-
*/
|
|
46
|
-
function emitRawFieldMaterialize(src, ref, plan) {
|
|
47
|
-
switch (ref.kind) {
|
|
48
|
-
case "scalar": {
|
|
49
|
-
if (ref.scalar === "null") {
|
|
50
|
-
// null-only field stays a Value::Null (the struct field type is Value for null-only).
|
|
51
|
-
return `Value::Null`;
|
|
52
|
-
}
|
|
53
|
-
const variant = ref.scalar === "int" ? "Int" : ref.scalar === "float" ? "Float" : ref.scalar === "bool" ? "Bool" : "Str";
|
|
54
|
-
const bind = ref.scalar === "string" ? "s.clone()" : "*s";
|
|
55
|
-
return [
|
|
56
|
-
`match ${src} {`,
|
|
57
|
-
` RawValue::${variant}(s) => ${bind},`,
|
|
58
|
-
` other => return Err(raw_type_mismatch(${rustStrLit(ref.scalar)}, other.type_name())),`,
|
|
59
|
-
`}`,
|
|
60
|
-
].join("\n");
|
|
61
|
-
}
|
|
62
|
-
case "named": {
|
|
63
|
-
return `marshal_raw_${ref.name}(${src})?`;
|
|
64
|
-
}
|
|
65
|
-
case "arr": {
|
|
66
|
-
const elemTy = renderTypeRef(ref.elem);
|
|
67
|
-
const inner = emitRawFieldMaterialize("elem_raw", ref.elem, plan);
|
|
68
|
-
return [
|
|
69
|
-
`match ${src} {`,
|
|
70
|
-
` RawValue::Arr(items) => {`,
|
|
71
|
-
` let mut out: Vec<${elemTy}> = Vec::with_capacity(items.len());`,
|
|
72
|
-
` for elem_raw in items.iter() {`,
|
|
73
|
-
` let elem_out = ${indentBlock(inner, 3).trimStart()};`,
|
|
74
|
-
` out.push(elem_out);`,
|
|
75
|
-
` }`,
|
|
76
|
-
` out`,
|
|
77
|
-
` }`,
|
|
78
|
-
` other => return Err(raw_type_mismatch(${rustStrLit("arr")}, other.type_name())),`,
|
|
79
|
-
`}`,
|
|
80
|
-
].join("\n");
|
|
81
|
-
}
|
|
82
|
-
case "opt": {
|
|
83
|
-
const inner = emitRawFieldMaterialize("inner_raw", ref.inner, plan);
|
|
84
|
-
return [
|
|
85
|
-
`match ${src} {`,
|
|
86
|
-
` RawValue::Null => None,`,
|
|
87
|
-
` inner_raw => {`,
|
|
88
|
-
` let inner_out = ${indentBlock(inner, 2).trimStart()};`,
|
|
89
|
-
` Some(inner_out)`,
|
|
90
|
-
` }`,
|
|
91
|
-
`}`,
|
|
92
|
-
].join("\n");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/** scalar/arr/opt node RAW materializer name. */
|
|
97
|
-
function rawNodeMaterializerName(nodeId) {
|
|
98
|
-
return `materialize_raw_node_${typedCell(nodeId)}`;
|
|
99
|
-
}
|
|
100
|
-
function emitRawNodeMaterializers(comp, typedNodes, plan) {
|
|
101
|
-
const parts = [];
|
|
102
|
-
for (const [id, ref] of typedNodes.entries()) {
|
|
103
|
-
if (ref.kind === "named")
|
|
104
|
-
continue;
|
|
105
|
-
const ty = renderTypeRef(ref);
|
|
106
|
-
const body = emitRawFieldMaterialize("raw", ref, plan);
|
|
107
|
-
parts.push(`#[allow(dead_code)]\nfn ${rawNodeMaterializerName(id)}(raw: &RawValue) -> Result<${ty}, BehaviorError> {\n Ok(${indentBlock(body, 1).trimStart()})\n}`);
|
|
108
|
-
}
|
|
109
|
-
return parts.join("\n\n");
|
|
110
|
-
}
|
|
111
|
-
// ── RAW runner ────────────────────────────────────────────────────────────────────────
|
|
112
|
-
function assertRawSupported(comp) {
|
|
113
|
-
for (const n of comp.body) {
|
|
114
|
-
if ("map" in n || "cond" in n) {
|
|
115
|
-
const ot = n.outType;
|
|
116
|
-
if (ot !== undefined) {
|
|
117
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust raw ABI (bc#76): component '${comp.name}' node '${n.id}' is a typed ${"map" in n ? "map" : "cond"} node. The raw handler ABI de-box currently covers the componentRef read-handler shape (graphddb's row hydrator). Regenerate this component on the boxed typed path (rust-typed) — do NOT emit a raw module that re-boxes map/cond results.`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function emitStoreRawNode(nodeId, srcExpr, ref, indent, producedCell) {
|
|
123
|
-
const pad = " ".repeat(indent);
|
|
124
|
-
if (ref === undefined)
|
|
125
|
-
return `${pad}let _ = ${srcExpr};`;
|
|
126
|
-
const call = ref.kind === "named" ? `marshal_raw_${ref.name}(${srcExpr})` : `${rawNodeMaterializerName(nodeId)}(${srcExpr})`;
|
|
127
|
-
const prod = ` ${producedCell(nodeId)}.set(true);`;
|
|
128
|
-
return `${pad}match ${call} {
|
|
129
|
-
${pad} Ok(tv) => { *${typedCell(nodeId)}.borrow_mut() = tv;${prod} }
|
|
130
|
-
${pad} Err(e) => {
|
|
131
|
-
${pad} *err_cell = Some(e);
|
|
132
|
-
${pad} return ExecOutcome::Error("aborted".to_string());
|
|
133
|
-
${pad} }
|
|
134
|
-
${pad}}`;
|
|
135
|
-
}
|
|
136
|
-
function producedCellName(id) {
|
|
137
|
-
return `produced_${typedCell(id)}`;
|
|
138
|
-
}
|
|
139
|
-
function emitRawExecArm(op, typedNodes, plan) {
|
|
140
|
-
if (op.kind !== "componentRef") {
|
|
141
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust raw ABI (bc#76): node '${op.id}' kind '${op.kind}' is not supported on the raw path (componentRef only). Regenerate on rust-typed.`);
|
|
142
|
-
}
|
|
143
|
-
const portRows = op.ports.length === 0
|
|
144
|
-
? " Ok(Vec::new())"
|
|
145
|
-
: ` Ok(vec![\n${op.ports
|
|
146
|
-
.map((pt) => ` (${rustStrLit(pt.name)}.to_string(), (${pt.expr})?),`)
|
|
147
|
-
.join("\n")}\n ])`;
|
|
148
|
-
const ref = typedNodes.get(op.id);
|
|
149
|
-
const materialize = emitStoreRawNode(op.id, "v", ref, 4, producedCellName);
|
|
150
|
-
return ` if i == ${op.index} {
|
|
151
|
-
let eval_ports = || -> Result<Vec<(String, Value)>, behavior_contracts::ExprFailure> {
|
|
152
|
-
${portRows}
|
|
153
|
-
};
|
|
154
|
-
let ports = match eval_ports() {
|
|
155
|
-
Ok(p) => p,
|
|
156
|
-
Err(e) => {
|
|
157
|
-
*err_cell = Some(e.into());
|
|
158
|
-
return ExecOutcome::Error("aborted".to_string());
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
let outcome = match handlers.exec_raw_ctx(${rustStrLit(op.id)}, ${rustStrLit(op.component ?? "")}, &ports, None) {
|
|
162
|
-
Some(o) => o,
|
|
163
|
-
None => {
|
|
164
|
-
*err_cell = Some(BehaviorError::new("UNKNOWN_COMPONENT", format!("component '{}' has no handler (fail-closed)", ${rustStrLit(op.component ?? "")})));
|
|
165
|
-
return ExecOutcome::Error("aborted".to_string());
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
let v = match &outcome {
|
|
169
|
-
RawOutcome::Ok(v) => v,
|
|
170
|
-
RawOutcome::Error(e) => {
|
|
171
|
-
*err_cell = Some(BehaviorError::new("OP_FAILED", e.clone()));
|
|
172
|
-
return ExecOutcome::Error("aborted".to_string());
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
${materialize}
|
|
176
|
-
return ExecOutcome::Ok(Value::Null);
|
|
177
|
-
}`;
|
|
178
|
-
}
|
|
179
|
-
function emitRawRunner(comp, plan) {
|
|
180
|
-
assertRawSupported(comp);
|
|
181
|
-
const fn = sanitize(comp.name);
|
|
182
|
-
const plans = buildComponentPlan(comp, rustTypedInternals.rustStraightlineInternals.dialect, PORT_SCOPE);
|
|
183
|
-
const typedNodes = collectTypedNodes(comp, plan);
|
|
184
|
-
const cellDecls = [...typedNodes.entries()]
|
|
185
|
-
.map(([id, ref]) => ` let ${typedCell(id)}: RefCell<${renderTypeRef(ref)}> = RefCell::new(Default::default());`)
|
|
186
|
-
.join("\n");
|
|
187
|
-
const producedDecls = [...typedNodes.keys()]
|
|
188
|
-
.map((id) => ` let ${producedCellName(id)} = std::cell::Cell::new(false);`)
|
|
189
|
-
.join("\n");
|
|
190
|
-
const portScopeNodeInjections = [...typedNodes.entries()]
|
|
191
|
-
.map(([id, ref]) => {
|
|
192
|
-
const isBareCopyScalar = ref.kind === "scalar" && (ref.scalar === "int" || ref.scalar === "float" || ref.scalar === "bool");
|
|
193
|
-
const owned = isBareCopyScalar ? `*${typedCell(id)}.borrow()` : `${typedCell(id)}.borrow().clone()`;
|
|
194
|
-
const ser = serializeTyped(owned, ref, plan);
|
|
195
|
-
return ` if ${producedCellName(id)}.get() {\n s.push((${rustStrLit(id)}.to_string(), ${ser}));\n }`;
|
|
196
|
-
})
|
|
197
|
-
.join("\n");
|
|
198
|
-
const arms = plans.ops.map((op) => emitRawExecArm(op, typedNodes, plan)).join("\n");
|
|
199
|
-
const planExpr = comp.plan ? emitPlanLiteral(comp.plan) : "None";
|
|
200
|
-
const outRef = comp.outputType !== undefined ? deriveTypeRef(comp.outputType, plan) : undefined;
|
|
201
|
-
const out = emitTypedValue(comp.output, outRef, typedNodes, plan);
|
|
202
|
-
const outRefFinal = out.ref ?? outRef;
|
|
203
|
-
const serialized = outRefFinal ? serializeTyped("__typed_out", outRefFinal, plan) : "__typed_out";
|
|
204
|
-
const opsLiteral = emitOpsLiteral(plans);
|
|
205
|
-
return `// run_typed_raw_${fn} — RAW-ABI STRUCT-NATIVE exec (bc#76 de-box): the run_plan primitive drives the
|
|
206
|
-
// plan (plan SSoT); per-node arms call the RAW handler (exec_raw_ctx -> RawValue, NOT a boxed Value) and
|
|
207
|
-
// materialize the node's outType struct DIRECTLY from the RawValue via marshal_raw_T*. The dynamic
|
|
208
|
-
// Value/Value::Obj tree is NEVER built on the row data plane — that is the de-box the boxed typed path
|
|
209
|
-
// only LAYERED. Output is assembled as a struct and serialized to a Value ONLY at the final return
|
|
210
|
-
// boundary (the equivalence pin), so the OBSERVED result equals run_behavior. Called by bind_raw.
|
|
211
|
-
fn run_typed_raw_${fn}<H: RawComponentExec>(
|
|
212
|
-
handlers: &mut H,
|
|
213
|
-
input: &[(String, Value)],
|
|
214
|
-
) -> Result<Value, BehaviorError> {
|
|
215
|
-
let ops: Vec<OpSpec> = ${opsLiteral};
|
|
216
|
-
${cellDecls ? cellDecls + "\n" : ""}${producedDecls ? producedDecls + "\n" : ""} let port_scope = || -> Vec<(String, Value)> {
|
|
217
|
-
let mut s = input.to_vec();
|
|
218
|
-
${portScopeNodeInjections ? portScopeNodeInjections + "\n" : ""} s
|
|
219
|
-
};
|
|
220
|
-
let _ = &port_scope;
|
|
221
|
-
let mut pending_err: Option<BehaviorError> = None;
|
|
222
|
-
|
|
223
|
-
let run = {
|
|
224
|
-
let err_cell = &mut pending_err;
|
|
225
|
-
let exec = |op: &OpSpec, _bound: Option<&Value>| -> ExecOutcome {
|
|
226
|
-
if err_cell.is_some() {
|
|
227
|
-
return ExecOutcome::Error("aborted".to_string());
|
|
228
|
-
}
|
|
229
|
-
let i = match ops.iter().position(|o| o.id == op.id) {
|
|
230
|
-
Some(i) => i,
|
|
231
|
-
None => {
|
|
232
|
-
*err_cell = Some(no_typed_exec_arm(&op.id));
|
|
233
|
-
return ExecOutcome::Error("aborted".to_string());
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
let _ = i;
|
|
237
|
-
${arms}
|
|
238
|
-
*err_cell = Some(BehaviorError::new("UNKNOWN_NODE_KIND", format!("op '{}' has no generated raw exec arm (fail-closed)", op.id)));
|
|
239
|
-
ExecOutcome::Error("aborted".to_string())
|
|
240
|
-
};
|
|
241
|
-
run_plan(${planExpr}, &ops, exec)
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
if let Some(e) = pending_err {
|
|
245
|
-
return Err(e);
|
|
246
|
-
}
|
|
247
|
-
let _run = run?;
|
|
248
|
-
|
|
249
|
-
let __typed_out = ${out.expr};
|
|
250
|
-
Ok(${serialized})
|
|
251
|
-
}`;
|
|
252
|
-
}
|
|
253
|
-
// ── bind_raw dispatch surface ───────────────────────────────────────────────────────
|
|
254
|
-
function emitBindRaw(ctx) {
|
|
255
|
-
const typedComps = ctx.ir.components.filter((c) => isTypedComponent(c));
|
|
256
|
-
const names = typedComps.map((c) => rustStrLit(c.name));
|
|
257
|
-
const arms = typedComps
|
|
258
|
-
.map((c) => ` ${rustStrLit(c.name)} => run_typed_raw_${sanitize(c.name)}(&mut self.handlers, input),`)
|
|
259
|
-
.join("\n");
|
|
260
|
-
return `// COMPONENT_NAMES_RAW — typed components exposed on the RAW-ABI de-boxed path.
|
|
261
|
-
pub const COMPONENT_NAMES_RAW: [&str; ${names.length}] = [${names.join(", ")}];
|
|
262
|
-
|
|
263
|
-
// bind_raw / BoundRaw — the RAW-ABI dispatch surface (bc#76): binds a RawComponentExec (native-backed
|
|
264
|
-
// handler results) to the de-boxed struct-native runners. Mirrors bind/Bound::call but drives the raw
|
|
265
|
-
// runner. Untyped components stay on the boxed bind.
|
|
266
|
-
pub fn bind_raw<H: RawComponentExec>(handlers: H) -> BoundRaw<H> {
|
|
267
|
-
BoundRaw { handlers }
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
pub struct BoundRaw<H: RawComponentExec> {
|
|
271
|
-
handlers: H,
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
impl<H: RawComponentExec> BoundRaw<H> {
|
|
275
|
-
pub fn call(&mut self, name: &str, input: &[(String, Value)]) -> Result<Value, BehaviorError> {
|
|
276
|
-
match name {
|
|
277
|
-
${arms}
|
|
278
|
-
other => Err(BehaviorError::new("UNKNOWN_ENTRY", format!("component '{other}' is not a raw-typed entry (fail-closed)"))),
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}`;
|
|
282
|
-
}
|
|
283
|
-
// ── module assembly ──────────────────────────────────────────────────────────────────
|
|
284
|
-
function emit(ctx) {
|
|
285
|
-
const typed = hasAnyTypeAnnotation(ctx);
|
|
286
|
-
if (!typed) {
|
|
287
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", "rust raw ABI (bc#76): the IR has no outType/outputType annotations — there is nothing to de-box. Use rust-straightline for untyped IR.");
|
|
288
|
-
}
|
|
289
|
-
const plan = buildTypePlan(ctx.ir);
|
|
290
|
-
const decls = emitTypeDecls(plan);
|
|
291
|
-
const defaults = emitDefaults(plan);
|
|
292
|
-
const rawMarshallers = emitRawMarshallers(plan);
|
|
293
|
-
const serializers = emitSerializers(plan);
|
|
294
|
-
// Boxed marshallers + helpers exist ONLY for the Value-space output-assembly fallback
|
|
295
|
-
// (materializeExpr on an output that directly refs an input param of a named type — a Value
|
|
296
|
-
// boundary read, NOT the row data plane). The ROW data plane is de-boxed via marshal_raw_* in
|
|
297
|
-
// the runner (asserted by the anti-sham gate).
|
|
298
|
-
const boxedMarshallers = emitMarshallers(plan);
|
|
299
|
-
const marshalHelpers = emitMarshalHelpers();
|
|
300
|
-
const nodeMaterializers = [];
|
|
301
|
-
for (const comp of ctx.ir.components) {
|
|
302
|
-
if (!isTypedComponent(comp))
|
|
303
|
-
continue;
|
|
304
|
-
const typedNodes = new Map();
|
|
305
|
-
for (const n of comp.body) {
|
|
306
|
-
if ("map" in n)
|
|
307
|
-
continue;
|
|
308
|
-
const ot = n.outType;
|
|
309
|
-
if (ot !== undefined)
|
|
310
|
-
typedNodes.set(n.id, deriveTypeRef(ot, plan));
|
|
311
|
-
}
|
|
312
|
-
const nm = emitRawNodeMaterializers(comp, typedNodes, plan);
|
|
313
|
-
if (nm)
|
|
314
|
-
nodeMaterializers.push(nm);
|
|
315
|
-
}
|
|
316
|
-
const runners = ctx.ir.components
|
|
317
|
-
.filter((c) => isTypedComponent(c))
|
|
318
|
-
.map((c) => emitRawRunner(c, plan))
|
|
319
|
-
.join("\n\n");
|
|
320
|
-
const bindRaw = emitBindRaw(ctx);
|
|
321
|
-
const banner = `// ── RAW handler ABI layer (bc#76 — Rust de-box: struct materialized DIRECTLY from the wire payload) ──
|
|
322
|
-
// This layer is ADDITIVE to the straight-line body above. A RawComponentExec handler returns a RawValue
|
|
323
|
-
// (native-backed, NOT a Value::Obj tree — see rust/src/rawabi.rs). marshal_raw_T* matches on it straight
|
|
324
|
-
// into the concrete struct: the dynamic Value tree the boxed typed path built and then re-walked NEVER
|
|
325
|
-
// exists here. bind_raw drives the de-boxed runners.
|
|
326
|
-
use std::cell::RefCell;
|
|
327
|
-
use behavior_contracts::{RawComponentExec, RawOutcome, RawValue, raw_missing_prop, raw_type_mismatch};`;
|
|
328
|
-
const sections = [
|
|
329
|
-
banner,
|
|
330
|
-
decls || undefined,
|
|
331
|
-
defaults || undefined,
|
|
332
|
-
rawMarshallers
|
|
333
|
-
? `// RAW marshallers (§4.4, de-box): materialize a concrete struct field-by-field from a native RawValue.\n// NO Value::Obj on this data plane — that is the whole point of #76.\n${rawMarshallers}`
|
|
334
|
-
: undefined,
|
|
335
|
-
marshalHelpers,
|
|
336
|
-
boxedMarshallers
|
|
337
|
-
? `// Value-space output-assembly fallback (marshal_*): reached ONLY when an output directly refs an\n// input param of a named type (a Value boundary read, not the row data plane). Off the de-box hot path.\n${boxedMarshallers}`
|
|
338
|
-
: undefined,
|
|
339
|
-
nodeMaterializers.length
|
|
340
|
-
? `// scalar/arr/opt node RAW materializers: FAIL-CLOSED de-box (TYPE_MISMATCH/MISSING_PROP) from RawValue.\n${nodeMaterializers.join("\n\n")}`
|
|
341
|
-
: undefined,
|
|
342
|
-
serializers
|
|
343
|
-
? `// typed -> Value serializers (final return boundary only): canonical observation for the equivalence pin.\n${serializers}`
|
|
344
|
-
: undefined,
|
|
345
|
-
`// RAW-ABI struct-native runners: the REAL de-box exec path (called by bind_raw).\n${runners}`,
|
|
346
|
-
bindRaw,
|
|
347
|
-
];
|
|
348
|
-
const typedBody = sections.filter((s) => !!s).join("\n\n");
|
|
349
|
-
// Force the RunPlan-path imports the raw runner needs (run_plan/OpSpec/ExecOutcome). Ports are
|
|
350
|
-
// Value-space, so the straight-line body's expression helpers are reused unchanged. relationKind
|
|
351
|
-
// is needed when a raw op literal carries a relationKind (parent-field child/relation nodes, #74).
|
|
352
|
-
setRustForceRunPlanImports({
|
|
353
|
-
runPlan: true,
|
|
354
|
-
relationKind: /\bRelationKind\b/.test(typedBody),
|
|
355
|
-
json: /\bjson!\(/.test(typedBody),
|
|
356
|
-
});
|
|
357
|
-
const straightlineCode = rustStraightlineEmitter.emit(ctx);
|
|
358
|
-
setRustForceRunPlanImports(null);
|
|
359
|
-
// The RAW module reuses the straight-line body as a SUBSTRATE (its expression helpers drive the
|
|
360
|
-
// Value-space ports), but drives dispatch through bind_raw — so the boxed bind/Bound/run_* and the
|
|
361
|
-
// boxed-only marshal helpers are unused in this artifact. A module-level allow keeps the generated
|
|
362
|
-
// RAW module clippy -D warnings clean without hand-editing the shared straight-line emitter. This
|
|
363
|
-
// is a GENERATED-TOOLKIT allowance on dead SUBSTRATE, not a blanket allow on the de-box path: the
|
|
364
|
-
// de-box (marshal_raw_*, run_typed_raw_*, bind_raw) is exercised and asserted by the anti-sham gate.
|
|
365
|
-
const moduleAllow = `#![allow(dead_code, unused_imports)]\n`;
|
|
366
|
-
return `${moduleAllow}${straightlineCode.replace(/\n+$/, "\n")}\n${typedBody}\n`;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* rustRawAbiEmitter — language id `rust-typed-raw` (bc#76). Emits the straight-line body (for
|
|
370
|
-
* untyped components / helpers) plus the RAW-ABI de-boxed layer (struct materialized directly from
|
|
371
|
-
* RawValue) and the bind_raw surface. Requires at least one outType/outputType annotation.
|
|
372
|
-
*/
|
|
373
|
-
export const rustRawAbiEmitter = {
|
|
374
|
-
language: "rust-typed-raw",
|
|
375
|
-
fileExtension: ".rs",
|
|
376
|
-
defaultRuntimeImport: "behavior_contracts",
|
|
377
|
-
filenameHint: "behaviors_typed_raw_generated.rs",
|
|
378
|
-
emit,
|
|
379
|
-
};
|
|
380
|
-
//# sourceMappingURL=emit-raw-abi-rust.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emit-raw-abi-rust.js","sourceRoot":"","sources":["../../src/generator/emit-raw-abi-rust.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAA8C,MAAM,YAAY,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAGvE,MAAM,UAAU,GAAG,cAAc,CAAC;AAElC,MAAM,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,0BAA0B,GAC3B,G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;QACb,WAAW;YACT,CAAC,CAAC,+GAA+G,WAAW,EAAE;YAC9H,CAAC,CAAC,SAAS;QACb,sFAAsF,OAAO,EAAE;QAC/F,OAAO;KACR,CAAC;IACF,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAExE,+FAA+F;IAC/F,iGAAiG;IACjG,mGAAmG;IACnG,0BAA0B,CAAC;QACzB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC;QAChD,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;KAClC,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3D,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAEjC,gGAAgG;IAChG,mGAAmG;IACnG,mGAAmG;IACnG,kGAAkG;IAClG,kGAAkG;IAClG,qGAAqG;IACrG,MAAM,WAAW,GAAG,wCAAwC,CAAC;IAC7D,OAAO,GAAG,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC;AACnF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAkB;IAC9C,QAAQ,EAAE,gBAAgB;IAC1B,aAAa,EAAE,KAAK;IACpB,oBAAoB,EAAE,oBAAoB;IAC1C,YAAY,EAAE,kCAAkC;IAChD,IAAI;CACL,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* emit-rust.ts — Rust emitter(共通 Generator, bc#13 SP2)。
|
|
3
|
-
*
|
|
4
|
-
* 生成物: 可搬 IR を **`serde_json::json!` マクロのネイティブ構築コード**として埋め込み
|
|
5
|
-
* (JSON テキストの実行時パースなし・構文はコンパイル時検査)、runtime-core の
|
|
6
|
-
* `run_behavior` に handler 注入で渡す accessor(`bind` → `Bound::call`)を公開する
|
|
7
|
-
* .rs モジュール。
|
|
8
|
-
*
|
|
9
|
-
* **「true const」からの正直な逸脱(SP1 audit の SP2 指針 (c))**:
|
|
10
|
-
* Rust runtime は IR を `serde_json::Value` で消費するが、`Value` は const 構築
|
|
11
|
-
* できない。そのため IR は `std::sync::LazyLock`(std, Rust >= 1.80)で**初回使用時に
|
|
12
|
-
* 一度だけ**ネイティブ構築される(以後は共有参照)。実行時 JSON パースは行わず、
|
|
13
|
-
* 構築コストは初回 1 回のみ。const-friendly な型付き IR 受け皿を runtime に足す案は
|
|
14
|
-
* runtime 再設計を伴うため将来 issue(本 SP のスコープ外)。
|
|
15
|
-
*
|
|
16
|
-
* ロード時検査は **first-use 時**: `IR` の LazyLock 初期化子の中で spec-version /
|
|
17
|
-
* fingerprint を検査し、skew は panic で LOUD reject(`bind()` が最初に force する)。
|
|
18
|
-
*
|
|
19
|
-
* 出力は rustfmt-clean(rustfmt は json! マクロ本体を触らないため、emitter の
|
|
20
|
-
* レイアウトが不動点になる)— fixture byte-drift ゲートと `cargo fmt --check` 系
|
|
21
|
-
* ゲートの両立のため。
|
|
22
|
-
*/
|
|
23
|
-
import type { EmitterPlugin } from "./core.js";
|
|
24
|
-
export declare const rustEmitter: EmitterPlugin;
|
|
25
|
-
//# sourceMappingURL=emit-rust.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emit-rust.d.ts","sourceRoot":"","sources":["../../src/generator/emit-rust.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,WAAW,CAAC;AAyH5D,eAAO,MAAM,WAAW,EAAE,aAMzB,CAAC"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { emitDocLiteral } from "./literal.js";
|
|
2
|
-
function rustStrLit(s) {
|
|
3
|
-
// 識別子・fingerprint 用(ASCII 前提だが JSON エスケープで安全側に倒す)。
|
|
4
|
-
return JSON.stringify(s);
|
|
5
|
-
}
|
|
6
|
-
/** rustfmt の fits-on-one-line 規則を模倣した COMPONENT_NAMES 配列 emit。 */
|
|
7
|
-
function componentNamesConst(names) {
|
|
8
|
-
const items = names.map(rustStrLit);
|
|
9
|
-
const oneLine = `pub const COMPONENT_NAMES: [&str; ${names.length}] = [${items.join(", ")}];`;
|
|
10
|
-
if (oneLine.length <= 100)
|
|
11
|
-
return oneLine;
|
|
12
|
-
return `pub const COMPONENT_NAMES: [&str; ${names.length}] = [\n${items.map((s) => ` ${s},`).join("\n")}\n];`;
|
|
13
|
-
}
|
|
14
|
-
function emit(ctx) {
|
|
15
|
-
const { fingerprint, specVersions, componentNames, runtimeImport } = ctx;
|
|
16
|
-
const irLiteral = emitDocLiteral(ctx.ir, "rust", 1);
|
|
17
|
-
return `// GENERATED by behavior-contracts common generator (bc#13) — DO NOT EDIT.
|
|
18
|
-
// Input: portable component-graph IR only (scp-ir-architecture.md §5/§7.4).
|
|
19
|
-
// This module is the codegen endpoint (§7.3 endpoint 3): the IR is embedded as
|
|
20
|
-
// NATIVE json! constructor code (compile-time checked; no JSON-text parsing at
|
|
21
|
-
// runtime) and handed to the EXISTING runtime core (run_behavior) — no execution
|
|
22
|
-
// logic is generated. Handlers are ALWAYS injected at the boundary
|
|
23
|
-
// (IR + {effects,config,hooks} — concept.md §4.4); they are never generated.
|
|
24
|
-
//
|
|
25
|
-
// Const deviation (documented): serde_json::Value is not const-constructible, so
|
|
26
|
-
// the IR is built ONCE on first use behind std::sync::LazyLock (requires Rust
|
|
27
|
-
// >= 1.80). The first-use fail-closed checks (#208 prepared-artifact discipline)
|
|
28
|
-
// run inside the initializer: a spec-version skew or fingerprint mismatch panics
|
|
29
|
-
// LOUDLY before any behavior can run.
|
|
30
|
-
// irFingerprint: ${fingerprint}
|
|
31
|
-
|
|
32
|
-
use ${runtimeImport}::{
|
|
33
|
-
fingerprint_component_graph, run_behavior, BehaviorError, ComponentExec, SpecVersions, Value,
|
|
34
|
-
};
|
|
35
|
-
use serde_json::{json, Value as J};
|
|
36
|
-
use std::sync::LazyLock;
|
|
37
|
-
|
|
38
|
-
/// Spec versions baked at generation time (fail-closed comparison on first use).
|
|
39
|
-
pub const EXPECTED_SPEC_VERSIONS: [(&str, i64); 3] =
|
|
40
|
-
[("behavior", ${specVersions.behavior}), ("expression", ${specVersions.expression}), ("plan", ${specVersions.plan})];
|
|
41
|
-
|
|
42
|
-
/// FNV-1a 64 fingerprint of the source portable IR (canonical_json discipline, #208).
|
|
43
|
-
pub const IR_FINGERPRINT: &str = ${rustStrLit(fingerprint)};
|
|
44
|
-
|
|
45
|
-
/// Component names exposed by bind(), in IR declaration order.
|
|
46
|
-
${componentNamesConst(componentNames)}
|
|
47
|
-
|
|
48
|
-
/// The portable component-graph IR, built once on first use from native json!
|
|
49
|
-
/// constructor code (no JSON-text parsing at runtime; see the const-deviation
|
|
50
|
-
/// note in the module header).
|
|
51
|
-
pub static IR: LazyLock<J> = LazyLock::new(|| {
|
|
52
|
-
let ir = json!(${irLiteral});
|
|
53
|
-
check_generated_module(&ir);
|
|
54
|
-
ir
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
fn runtime_spec_version(key: &str) -> i64 {
|
|
58
|
-
match key {
|
|
59
|
-
"behavior" => SpecVersions::BEHAVIOR,
|
|
60
|
-
"expression" => SpecVersions::EXPRESSION,
|
|
61
|
-
"plan" => SpecVersions::PLAN,
|
|
62
|
-
other => {
|
|
63
|
-
panic!("behavior-contracts generated module: unknown spec key '{other}' (fail-closed)")
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// First-use fail-closed checks (#208 prepared-artifact discipline).
|
|
69
|
-
fn check_generated_module(ir: &J) {
|
|
70
|
-
for (key, want) in EXPECTED_SPEC_VERSIONS {
|
|
71
|
-
let got = runtime_spec_version(key);
|
|
72
|
-
if got != want {
|
|
73
|
-
panic!("behavior-contracts generated module: spec-version skew for '{key}' (generated={want}, runtime={got}) — regenerate against this runtime (fail-closed)");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
for name in COMPONENT_NAMES {
|
|
77
|
-
let found = ir["components"]
|
|
78
|
-
.as_array()
|
|
79
|
-
.is_some_and(|cs| cs.iter().any(|c| c["name"] == name));
|
|
80
|
-
if !found {
|
|
81
|
-
panic!("behavior-contracts generated module: component '{name}' missing from the embedded IR — the generated code was modified or corrupted (fail-closed)");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
let got_fp = fingerprint_component_graph(ir).unwrap_or_else(|e| {
|
|
85
|
-
panic!(
|
|
86
|
-
"behavior-contracts generated module: fingerprint recompute failed: {e} (fail-closed)"
|
|
87
|
-
)
|
|
88
|
-
});
|
|
89
|
-
if got_fp != IR_FINGERPRINT {
|
|
90
|
-
panic!("behavior-contracts generated module: IR fingerprint mismatch (baked={IR_FINGERPRINT}, embedded literal={got_fp}) — the generated code was modified or corrupted (fail-closed)");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/// Injected-handler accessor over the embedded IR (see [\`bind\`]). Rust ownership
|
|
95
|
-
/// makes a map of per-component closures sharing one \`&mut handlers\` impractical,
|
|
96
|
-
/// so the per-component executor surface is \`call(name, input)\` with the
|
|
97
|
-
/// component name checked against [\`COMPONENT_NAMES\`] by the runtime core.
|
|
98
|
-
pub struct Bound<H: ComponentExec> {
|
|
99
|
-
handlers: H,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/// bind — inject handlers (boundary injection; catalog name → implementation)
|
|
103
|
-
/// and get an executor over the embedded IR. Each \`call\` delegates to the
|
|
104
|
-
/// runtime core's run_behavior (dynamic-path equivalent — §7.3). Forces the
|
|
105
|
-
/// first-use fail-closed checks.
|
|
106
|
-
pub fn bind<H: ComponentExec>(handlers: H) -> Bound<H> {
|
|
107
|
-
LazyLock::force(&IR);
|
|
108
|
-
Bound { handlers }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
impl<H: ComponentExec> Bound<H> {
|
|
112
|
-
pub fn call(&mut self, name: &str, input: &[(String, Value)]) -> Result<Value, BehaviorError> {
|
|
113
|
-
run_behavior(&IR, &mut self.handlers, input, Some(name))
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
`;
|
|
117
|
-
}
|
|
118
|
-
export const rustEmitter = {
|
|
119
|
-
language: "rust",
|
|
120
|
-
fileExtension: ".rs",
|
|
121
|
-
defaultRuntimeImport: "behavior_contracts",
|
|
122
|
-
filenameHint: "behaviors_generated.rs",
|
|
123
|
-
emit,
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=emit-rust.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emit-rust.js","sourceRoot":"","sources":["../../src/generator/emit-rust.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,SAAS,UAAU,CAAC,CAAS;IAC3B,mDAAmD;IACnD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,kEAAkE;AAClE,SAAS,mBAAmB,CAAC,KAAe;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,qCAAqC,KAAK,CAAC,MAAM,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC9F,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,OAAO,CAAC;IAC1C,OAAO,qCAAqC,KAAK,CAAC,MAAM,UAAU,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AACnH,CAAC;AAED,SAAS,IAAI,CAAC,GAAgB;IAC5B,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC;IACzE,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACpD,OAAO;;;;;;;;;;;;;oBAaW,WAAW;;MAEzB,aAAa;;;;;;;;oBAQC,YAAY,CAAC,QAAQ,qBAAqB,YAAY,CAAC,UAAU,eAAe,YAAY,CAAC,IAAI;;;mCAGlF,UAAU,CAAC,WAAW,CAAC;;;EAGxD,mBAAmB,CAAC,cAAc,CAAC;;;;;;qBAMhB,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgE7B,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAkB;IACxC,QAAQ,EAAE,MAAM;IAChB,aAAa,EAAE,KAAK;IACpB,oBAAoB,EAAE,oBAAoB;IAC1C,YAAY,EAAE,wBAAwB;IACtC,IAAI;CACL,CAAC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* emit-straightline-go.ts — Go 直線 emitter(bc#38 / Layer A2 → bc#75 static-code rework)。
|
|
3
|
-
*
|
|
4
|
-
* typed-codegen.md §4.1 の Go 具体化。bc#75 で「解釈機構の転写」を排し、**本当の静的コード**を
|
|
5
|
-
* emit する(TS oracle と同じ static-wiring 解析 {@link sequentialOrder}/{@link analyzeSequentialOps}/
|
|
6
|
-
* {@link classifyExpr}/{@link isScopeFree} を消費する):
|
|
7
|
-
*
|
|
8
|
-
* - **逐次 plan(plan 無し / 全 stage 高々 1 op)は素の文列**として直線展開する。`RunPlan` も
|
|
9
|
-
* `[]OpSpec` テーブルも `baseScope()` snapshot も `exec` closure も `for k := range ops { if ops[k].ID== }`
|
|
10
|
-
* 線形探索も emit しない。ノード結果は素のローカル(`r_<id>`)に住み、skip 伝播(parent 連鎖 /
|
|
11
|
-
* bindField null-binding / continue policy)は静的に確定した分岐として展開する(Failure code /
|
|
12
|
-
* message は plan.go interpretOutcome と byte 一致)。
|
|
13
|
-
* - **静的形状の式はネイティブ inline**: string/bool/null リテラルは Go リテラル、静的 path の
|
|
14
|
-
* ref/refOpt は「ローカル直読み(配線は生成時に確定)+ field walk helper `slField`」、concat は
|
|
15
|
-
* 可変長 `slCat(...)`(評価済み値を受ける — closure も per-part func 値も無い)。
|
|
16
|
-
* - **per-expression scope snapshot を廃止**: scope を本当に読む residual dynamic 式(ref を含む
|
|
17
|
-
* primitive 経路)がある component だけが「進行形 scope(`scope *Obj`)」を組み、ノード完了ごとに
|
|
18
|
-
* 1 key を Set する。scope-free な primitive 式には空 scope 定数(`slEmpty()`)を渡す。
|
|
19
|
-
* - **RunPlan primitive は実並行 plan(複数 op の stage)だけ**が使う(bounded 並行の意味論 SSoT)。
|
|
20
|
-
* その経路も per-op exec は index で確定した switch(`for k := range ops` 線形探索は無い)。
|
|
21
|
-
*
|
|
22
|
-
* fail-closed 演算子意味論(overflow 算術・短絡 and/or/cond/coalesce・obj/arr 構築・比較・len・
|
|
23
|
-
* checked リテラル)は従来どおり A0 primitive SSoT(`Prim*`)を直呼びする(再実装しない)。
|
|
24
|
-
*
|
|
25
|
-
* この emitter は A1 の TS golden oracle と観測等価(値・発行 op 列・Failure)であることを
|
|
26
|
-
* conformance(codegen-straightline.test.ts の Go 節)で実 Go toolchain 実行により pin する。
|
|
27
|
-
*/
|
|
28
|
-
import type { EmitterPlugin } from "./core.js";
|
|
29
|
-
import { type ComponentPlan, type StraightlineDialect } from "./straightline.js";
|
|
30
|
-
export declare function setGoForceRunPlanHelpers(on: boolean): void;
|
|
31
|
-
export declare function setGoForceStraightHelpers(on: boolean): void;
|
|
32
|
-
/**
|
|
33
|
-
* emitExpr — Expression IR ノードを「scope を受けて (Value, error) を返す」Go 式に落とす
|
|
34
|
-
* (**dynamic 式専用**の legacy 経路 — RunPlan 経路と typed emitter が流用する seam)。
|
|
35
|
-
*/
|
|
36
|
-
declare function emitExpr(node: unknown, scopeVar: string): string;
|
|
37
|
-
/** component 名を Go 関数名に使える形へ(決定的。名前一意は DUPLICATE_COMPONENT で保証)。 */
|
|
38
|
-
declare function sanitize(name: string): string;
|
|
39
|
-
/** ops リテラル(RunPlan に渡す []OpSpec の Go リテラル)を綴じる。 */
|
|
40
|
-
declare function emitOpsLiteral(plan: ComponentPlan): string;
|
|
41
|
-
/** port ローカル変数名(Go 識別子として安全)。 */
|
|
42
|
-
declare function goPortVar(name: string): string;
|
|
43
|
-
/** behavior plan({groups, concurrency})を *ExecutionPlanSpec Go リテラルへ。 */
|
|
44
|
-
declare function emitBehaviorPlanLiteral(plan: unknown): string;
|
|
45
|
-
/**
|
|
46
|
-
* go-typed(bc#47)が struct-native exec を綴じるために再利用する内部 emit ヘルパ。
|
|
47
|
-
*/
|
|
48
|
-
export declare const goStraightlineInternals: {
|
|
49
|
-
PKG: string;
|
|
50
|
-
emitExpr: typeof emitExpr;
|
|
51
|
-
emitOpsLiteral: typeof emitOpsLiteral;
|
|
52
|
-
emitBehaviorPlanLiteral: typeof emitBehaviorPlanLiteral;
|
|
53
|
-
goPortVar: typeof goPortVar;
|
|
54
|
-
sanitize: typeof sanitize;
|
|
55
|
-
dialect: StraightlineDialect;
|
|
56
|
-
setGoForceStraightHelpers: typeof setGoForceStraightHelpers;
|
|
57
|
-
};
|
|
58
|
-
export declare const goStraightlineEmitter: EmitterPlugin;
|
|
59
|
-
export {};
|
|
60
|
-
//# sourceMappingURL=emit-straightline-go.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emit-straightline-go.d.ts","sourceRoot":"","sources":["../../src/generator/emit-straightline-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAQL,KAAK,aAAa,EAIlB,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAmC3B,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAE1D;AAUD,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAE3D;AA8ED;;;GAGG;AACH,iBAAS,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA4BzD;AAgHD,oEAAoE;AACpE,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtC;AAkZD,oDAAoD;AACpD,iBAAS,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CASnD;AAmCD,iCAAiC;AACjC,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvC;AAgND,yEAAyE;AACzE,iBAAS,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAMtD;AA0PD;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;CASnC,CAAC;AAMF,eAAO,MAAM,qBAAqB,EAAE,aAUnC,CAAC"}
|