@womp/spark-agent 1.0.1 → 2.1.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/README.md +42 -19
- package/dist/capabilities/health.d.ts +9 -0
- package/dist/capabilities/health.js +27 -0
- package/dist/capabilities/scene-draft.d.ts +2 -404
- package/dist/capabilities/scene.d.ts +1 -1
- package/dist/capabilities/scene.js +13 -4
- package/dist/capabilities.d.ts +3 -1
- package/dist/capabilities.js +1 -0
- package/dist/cli.js +20 -2
- package/dist/client.js +15 -15
- package/dist/coordinates.d.ts +23 -0
- package/dist/coordinates.js +132 -0
- package/dist/generated/health-declarations.d.ts +1 -0
- package/dist/generated/health-declarations.js +3 -0
- package/dist/generated/scene-declarations.d.ts +1 -1
- package/dist/generated/scene-declarations.js +1 -1
- package/dist/geometry/backendRegistry.d.ts +37 -0
- package/dist/geometry/backendRegistry.js +61 -0
- package/dist/geometry/common.d.ts +26 -0
- package/dist/geometry/common.js +78 -0
- package/dist/geometry/compiler.d.ts +35 -0
- package/dist/geometry/compiler.js +115 -0
- package/dist/geometry/graph.d.ts +39 -0
- package/dist/geometry/graph.js +32 -0
- package/dist/geometry/index.d.ts +9 -0
- package/dist/geometry/index.js +12 -0
- package/dist/geometry/lift.d.ts +7 -0
- package/dist/geometry/lift.js +376 -0
- package/dist/geometry/lower.d.ts +9 -0
- package/dist/geometry/lower.js +363 -0
- package/dist/geometry/parameters.d.ts +23 -0
- package/dist/geometry/parameters.js +46 -0
- package/dist/geometry/schemas/backend-schema.json +3394 -0
- package/dist/geometry/schemas/flowir-dialect.json +976 -0
- package/dist/geometry/writeParamData.d.ts +18 -0
- package/dist/geometry/writeParamData.js +47 -0
- package/dist/geometry.d.ts +10 -0
- package/dist/geometry.js +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kakapo.d.ts +9 -5
- package/dist/kakapo.js +7 -6
- package/dist/openscad.d.ts +85 -0
- package/dist/openscad.js +223 -0
- package/dist/pricing.js +9 -29
- package/dist/repair-state.d.ts +50 -0
- package/dist/repair-state.js +96 -0
- package/dist/runtime.d.ts +16 -36
- package/dist/runtime.js +132 -139
- package/dist/scene-environment.d.ts +25 -0
- package/dist/scene-environment.js +76 -0
- package/dist/scene-health.d.ts +49 -0
- package/dist/scene-health.js +176 -0
- package/dist/scene-metadata.d.ts +6 -0
- package/dist/scene-metadata.js +65 -0
- package/dist/scene-operations.d.ts +47 -0
- package/dist/scene-operations.js +126 -0
- package/dist/sdk-geometry-host.d.ts +12 -0
- package/dist/sdk-geometry-host.js +306 -0
- package/dist/sdk-openscad-host.d.ts +14 -0
- package/dist/sdk-openscad-host.js +296 -0
- package/dist/sdk-openscad-renderer.d.ts +11 -0
- package/dist/sdk-openscad-renderer.js +71 -0
- package/dist/sdk-scene-health-host.d.ts +4 -0
- package/dist/sdk-scene-health-host.js +13 -0
- package/dist/sdk-scene-host.d.ts +312 -0
- package/dist/sdk-scene-host.js +202 -0
- package/dist/sdk-scene-screenshot.d.ts +7 -0
- package/dist/sdk-scene-screenshot.js +17 -0
- package/dist/server/demo-scene-materials.d.ts +3 -0
- package/dist/server/demo-scene-materials.js +18 -0
- package/dist/server/express.js +2 -4
- package/dist/server/fixtures/materials/matte-blue.json +14 -0
- package/dist/server/fixtures/materials/polished-copper.json +14 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +2 -1
- package/dist/server/service.d.ts +4 -0
- package/dist/server/service.js +26 -2
- package/dist/server/sqlite-store.d.ts +31 -0
- package/dist/server/sqlite-store.js +224 -0
- package/dist/server/standalone.d.ts +14 -1
- package/dist/server/standalone.js +160 -27
- package/dist/server/store.js +3 -1
- package/dist/types.d.ts +1 -1
- package/dist/womp-scene-api.d.ts +283 -0
- package/dist/womp-scene-api.js +974 -0
- package/package.json +22 -10
- package/dist/kakapo-capability.d.ts +0 -45
- package/dist/kakapo-capability.js +0 -169
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { VALUE_BACKEND_NAMES, titleToAstName, isArrayPortType, buildIncomingMap, defaultScalar, } from "./common.js";
|
|
2
|
+
const POS = { line: 0, column: 0 };
|
|
3
|
+
function decimal(value) {
|
|
4
|
+
const text = value.toLocaleString("en-US", {
|
|
5
|
+
useGrouping: false,
|
|
6
|
+
maximumSignificantDigits: 21,
|
|
7
|
+
});
|
|
8
|
+
return text.includes(".") ? text : `${text}.0`;
|
|
9
|
+
}
|
|
10
|
+
function isVec3Object(v) {
|
|
11
|
+
if (!v || typeof v !== "object")
|
|
12
|
+
return false;
|
|
13
|
+
const obj = v;
|
|
14
|
+
return (typeof obj.x === "number" &&
|
|
15
|
+
typeof obj.y === "number" &&
|
|
16
|
+
typeof obj.z === "number");
|
|
17
|
+
}
|
|
18
|
+
function getData(graph, bid, portIndex) {
|
|
19
|
+
const nodeData = graph.data?.[bid];
|
|
20
|
+
if (!nodeData?.inputs)
|
|
21
|
+
return null;
|
|
22
|
+
const val = nodeData.inputs[portIndex];
|
|
23
|
+
return val !== undefined ? val : null;
|
|
24
|
+
}
|
|
25
|
+
function getDataAsNumber(graph, bid, portIndex) {
|
|
26
|
+
const val = getData(graph, bid, portIndex);
|
|
27
|
+
if (typeof val === "number")
|
|
28
|
+
return val;
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function classifyNodes(graph, reverseMap, gipTypeId, outputTypeId, valueTypeIds) {
|
|
32
|
+
const result = [];
|
|
33
|
+
const nodes = graph.nodes;
|
|
34
|
+
for (const [bid, node] of Object.entries(nodes)) {
|
|
35
|
+
const typeId = node.type_id;
|
|
36
|
+
if (typeId === gipTypeId) {
|
|
37
|
+
result.push({ bid, typeId, cls: "gip" });
|
|
38
|
+
}
|
|
39
|
+
else if (valueTypeIds.has(typeId)) {
|
|
40
|
+
result.push({
|
|
41
|
+
bid,
|
|
42
|
+
typeId,
|
|
43
|
+
cls: "value",
|
|
44
|
+
valueTypeName: valueTypeIds.get(typeId),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (typeId === outputTypeId) {
|
|
48
|
+
result.push({ bid, typeId, cls: "output" });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const dialectName = reverseMap.get(typeId);
|
|
52
|
+
if (dialectName) {
|
|
53
|
+
result.push({ bid, typeId, cls: "dialect", dialectName });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function toposort(bids, incoming) {
|
|
60
|
+
const bidSet = new Set(bids);
|
|
61
|
+
const inDegree = new Map();
|
|
62
|
+
const adjacency = new Map();
|
|
63
|
+
for (const bid of bids) {
|
|
64
|
+
inDegree.set(bid, 0);
|
|
65
|
+
adjacency.set(bid, []);
|
|
66
|
+
}
|
|
67
|
+
for (const bid of bids) {
|
|
68
|
+
const edges = incoming.get(bid);
|
|
69
|
+
if (!edges)
|
|
70
|
+
continue;
|
|
71
|
+
for (const edge of edges) {
|
|
72
|
+
if (bidSet.has(edge.fromBid)) {
|
|
73
|
+
inDegree.set(bid, (inDegree.get(bid) ?? 0) + 1);
|
|
74
|
+
adjacency.get(edge.fromBid).push(bid);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const queue = [];
|
|
79
|
+
for (const bid of bids) {
|
|
80
|
+
if (inDegree.get(bid) === 0)
|
|
81
|
+
queue.push(bid);
|
|
82
|
+
}
|
|
83
|
+
const sorted = [];
|
|
84
|
+
while (queue.length > 0) {
|
|
85
|
+
const bid = queue.shift();
|
|
86
|
+
sorted.push(bid);
|
|
87
|
+
for (const next of adjacency.get(bid) ?? []) {
|
|
88
|
+
const deg = (inDegree.get(next) ?? 1) - 1;
|
|
89
|
+
inDegree.set(next, deg);
|
|
90
|
+
if (deg === 0)
|
|
91
|
+
queue.push(next);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (sorted.length < bids.length) {
|
|
95
|
+
for (const bid of bids) {
|
|
96
|
+
if (!sorted.includes(bid))
|
|
97
|
+
sorted.push(bid);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return sorted;
|
|
101
|
+
}
|
|
102
|
+
function decodeScalarValue(raw, typeName) {
|
|
103
|
+
if (typeName === "Vec3") {
|
|
104
|
+
const vec = isVec3Object(raw) ? raw : { x: 0, y: 0, z: 0 };
|
|
105
|
+
return {
|
|
106
|
+
kind: "vec3",
|
|
107
|
+
value: [vec.x, vec.y, vec.z],
|
|
108
|
+
raw: `Vec3(${decimal(vec.x)}, ${decimal(vec.y)}, ${decimal(vec.z)})`,
|
|
109
|
+
pos: POS,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (typeName === "Bool" && typeof raw === "boolean") {
|
|
113
|
+
return { kind: "bool", value: raw, pos: POS };
|
|
114
|
+
}
|
|
115
|
+
if (typeName === "Int" && typeof raw === "number") {
|
|
116
|
+
const v = Math.trunc(raw);
|
|
117
|
+
return { kind: "int", value: v, raw: String(v), pos: POS };
|
|
118
|
+
}
|
|
119
|
+
const num = typeof raw === "number" ? raw : 0;
|
|
120
|
+
return { kind: "float", value: num, raw: decimal(num), pos: POS };
|
|
121
|
+
}
|
|
122
|
+
function decodeBackendValue(raw, backendPort, dialectPort, flowirRegistry) {
|
|
123
|
+
if (dialectPort.enum && typeof raw === "number") {
|
|
124
|
+
const values = flowirRegistry.getEnumValues(dialectPort.enum);
|
|
125
|
+
const name = values[raw];
|
|
126
|
+
if (name)
|
|
127
|
+
return { kind: "ident", name, pos: POS };
|
|
128
|
+
}
|
|
129
|
+
if (backendPort.enumValues?.length && typeof raw === "number") {
|
|
130
|
+
const name = backendPort.enumValues[raw];
|
|
131
|
+
if (name)
|
|
132
|
+
return { kind: "ident", name, pos: POS };
|
|
133
|
+
}
|
|
134
|
+
const unwrapped = isArrayPortType(backendPort.type) && Array.isArray(raw) && raw.length === 1
|
|
135
|
+
? raw[0]
|
|
136
|
+
: raw;
|
|
137
|
+
if (isVec3Object(unwrapped)) {
|
|
138
|
+
return {
|
|
139
|
+
kind: "vec3",
|
|
140
|
+
value: [unwrapped.x, unwrapped.y, unwrapped.z],
|
|
141
|
+
raw: `Vec3(${decimal(unwrapped.x)}, ${decimal(unwrapped.y)}, ${decimal(unwrapped.z)})`,
|
|
142
|
+
pos: POS,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (typeof unwrapped === "boolean") {
|
|
146
|
+
return { kind: "bool", value: unwrapped, pos: POS };
|
|
147
|
+
}
|
|
148
|
+
if (typeof unwrapped === "number") {
|
|
149
|
+
if (dialectPort.type === "Int" || dialectPort.type === "Int[]") {
|
|
150
|
+
const v = Math.trunc(unwrapped);
|
|
151
|
+
return { kind: "int", value: v, raw: String(v), pos: POS };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
kind: "float",
|
|
155
|
+
value: unwrapped,
|
|
156
|
+
raw: decimal(unwrapped),
|
|
157
|
+
pos: POS,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
function liftParam(vNode, gipBid, paramCounter, ctx) {
|
|
163
|
+
const typeName = vNode.valueTypeName ?? "Float";
|
|
164
|
+
const extName = ctx.graphExt.nodes?.[gipBid]?.name;
|
|
165
|
+
const name = extName ? titleToAstName(extName) : `p${paramCounter}`;
|
|
166
|
+
const rawDefault = getData(ctx.graph, vNode.bid, "0");
|
|
167
|
+
const paramTypeName = typeName === "Bool" ? "Float" : typeName;
|
|
168
|
+
return {
|
|
169
|
+
kind: "param",
|
|
170
|
+
name,
|
|
171
|
+
typeName: paramTypeName,
|
|
172
|
+
value: rawDefault != null
|
|
173
|
+
? decodeScalarValue(rawDefault, typeName)
|
|
174
|
+
: decodeScalarValue(typeName === "Vec3" ? { x: 0, y: 0, z: 0 } : 0, typeName),
|
|
175
|
+
range: {
|
|
176
|
+
min: getDataAsNumber(ctx.graph, gipBid, "0"),
|
|
177
|
+
max: getDataAsNumber(ctx.graph, gipBid, "1"),
|
|
178
|
+
step: getDataAsNumber(ctx.graph, gipBid, "2"),
|
|
179
|
+
},
|
|
180
|
+
pos: POS,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function liftConst(vNode, constCounter, ctx) {
|
|
184
|
+
const typeName = vNode.valueTypeName ?? "Float";
|
|
185
|
+
const rawDefault = getData(ctx.graph, vNode.bid, "0");
|
|
186
|
+
return {
|
|
187
|
+
kind: "const",
|
|
188
|
+
name: `c${constCounter}`,
|
|
189
|
+
typeName: typeName,
|
|
190
|
+
value: rawDefault != null
|
|
191
|
+
? decodeScalarValue(rawDefault, typeName)
|
|
192
|
+
: decodeScalarValue(typeName === "Vec3" ? { x: 0, y: 0, z: 0 } : 0, typeName),
|
|
193
|
+
pos: POS,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function resolveInputBinding(bid, idx, dialectPort, backendPort, ctx) {
|
|
197
|
+
const connEdge = ctx.incoming.get(bid)?.find((e) => e.toPort === idx);
|
|
198
|
+
if (connEdge) {
|
|
199
|
+
const sourceNode = ctx.classMap.get(connEdge.fromBid);
|
|
200
|
+
if (!sourceNode)
|
|
201
|
+
return null;
|
|
202
|
+
const paramName = ctx.paramBids.get(connEdge.fromBid);
|
|
203
|
+
if (paramName) {
|
|
204
|
+
return {
|
|
205
|
+
name: dialectPort.name,
|
|
206
|
+
value: { kind: "ident", name: paramName, pos: POS },
|
|
207
|
+
pos: POS,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
if (sourceNode.cls === "dialect" && sourceNode.dialectName) {
|
|
211
|
+
const sourceDialect = ctx.flowirRegistry.getNode(sourceNode.dialectName);
|
|
212
|
+
const sourceStmtId = ctx.dialectStmtIds.get(connEdge.fromBid);
|
|
213
|
+
if (sourceDialect && sourceStmtId) {
|
|
214
|
+
const outputPort = sourceDialect.outputs[connEdge.fromPort];
|
|
215
|
+
if (outputPort) {
|
|
216
|
+
return {
|
|
217
|
+
name: dialectPort.name,
|
|
218
|
+
value: {
|
|
219
|
+
kind: "ref",
|
|
220
|
+
nodeId: sourceStmtId,
|
|
221
|
+
port: outputPort.name,
|
|
222
|
+
pos: POS,
|
|
223
|
+
},
|
|
224
|
+
pos: POS,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const rawData = getData(ctx.graph, bid, String(idx)) ?? defaultScalar(backendPort);
|
|
232
|
+
if (rawData == null)
|
|
233
|
+
return null;
|
|
234
|
+
const decoded = decodeBackendValue(rawData, backendPort, dialectPort, ctx.flowirRegistry);
|
|
235
|
+
if (!decoded)
|
|
236
|
+
return null;
|
|
237
|
+
return { name: dialectPort.name, value: decoded, pos: POS };
|
|
238
|
+
}
|
|
239
|
+
function liftNodeStmt(bid, cNode, ctx) {
|
|
240
|
+
const dialectName = cNode.dialectName;
|
|
241
|
+
const stmtId = ctx.dialectStmtIds.get(bid);
|
|
242
|
+
const dialectNode = ctx.flowirRegistry.getNode(dialectName);
|
|
243
|
+
if (!dialectNode)
|
|
244
|
+
return null;
|
|
245
|
+
const backendSchema = ctx.backendRegistry.getSchema(cNode.typeId);
|
|
246
|
+
if (!backendSchema)
|
|
247
|
+
return null;
|
|
248
|
+
const inputs = [];
|
|
249
|
+
for (let idx = 0; idx < dialectNode.inputs.length; idx++) {
|
|
250
|
+
const backendPort = idx < backendSchema.inputs.length ? backendSchema.inputs[idx] : null;
|
|
251
|
+
if (!backendPort)
|
|
252
|
+
continue;
|
|
253
|
+
const binding = resolveInputBinding(bid, idx, dialectNode.inputs[idx], backendPort, ctx);
|
|
254
|
+
if (binding)
|
|
255
|
+
inputs.push(binding);
|
|
256
|
+
}
|
|
257
|
+
return { kind: "node", id: stmtId, nodeType: dialectName, inputs, pos: POS };
|
|
258
|
+
}
|
|
259
|
+
function liftOutStmt(oNode, ctx) {
|
|
260
|
+
const geoEdge = ctx.incoming.get(oNode.bid)?.find((e) => e.toPort === 1);
|
|
261
|
+
if (!geoEdge)
|
|
262
|
+
return null;
|
|
263
|
+
const sourceNode = ctx.classMap.get(geoEdge.fromBid);
|
|
264
|
+
if (!sourceNode || sourceNode.cls !== "dialect" || !sourceNode.dialectName)
|
|
265
|
+
return null;
|
|
266
|
+
const sourceDialect = ctx.flowirRegistry.getNode(sourceNode.dialectName);
|
|
267
|
+
const sourceStmtId = ctx.dialectStmtIds.get(geoEdge.fromBid);
|
|
268
|
+
if (!sourceDialect || !sourceStmtId)
|
|
269
|
+
return null;
|
|
270
|
+
const outputPort = sourceDialect.outputs[geoEdge.fromPort];
|
|
271
|
+
if (!outputPort)
|
|
272
|
+
return null;
|
|
273
|
+
return {
|
|
274
|
+
kind: "out",
|
|
275
|
+
outputName: "Geometry",
|
|
276
|
+
value: {
|
|
277
|
+
kind: "ref",
|
|
278
|
+
nodeId: sourceStmtId,
|
|
279
|
+
port: outputPort.name,
|
|
280
|
+
pos: POS,
|
|
281
|
+
},
|
|
282
|
+
pos: POS,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export function lift(graph, graphExt, flowirRegistry, backendRegistry) {
|
|
286
|
+
const reverseMap = new Map();
|
|
287
|
+
for (const name of flowirRegistry.listNodeNames()) {
|
|
288
|
+
const id = flowirRegistry.getNodeTypeId(name);
|
|
289
|
+
if (id == null)
|
|
290
|
+
continue;
|
|
291
|
+
const outputs = backendRegistry.getSchema(id)?.outputs;
|
|
292
|
+
// Dialect aliases can share a backend ID. Lift the native output type,
|
|
293
|
+
// so vector math is not accidentally narrowed to its scalar alias.
|
|
294
|
+
const matches = flowirRegistry
|
|
295
|
+
.getNode(name)
|
|
296
|
+
?.outputs.every((port, index) => port.type ===
|
|
297
|
+
outputs?.[index]?.type
|
|
298
|
+
.replace(/Array$/, "[]")
|
|
299
|
+
.replace(/^Vec(?=\[|$)/, "Vec3"));
|
|
300
|
+
if (!reverseMap.has(id) || matches)
|
|
301
|
+
reverseMap.set(id, name);
|
|
302
|
+
}
|
|
303
|
+
const gipTypeId = backendRegistry.getSchemaByName("GroupInputParam")?.typeId ?? null;
|
|
304
|
+
const outputTypeId = backendRegistry.getSchemaByName("OutputArea")?.typeId ?? null;
|
|
305
|
+
const valueTypeIds = new Map();
|
|
306
|
+
for (const [backendName, typeName] of Object.entries(VALUE_BACKEND_NAMES)) {
|
|
307
|
+
const schema = backendRegistry.getSchemaByName(backendName);
|
|
308
|
+
if (schema)
|
|
309
|
+
valueTypeIds.set(schema.typeId, typeName);
|
|
310
|
+
}
|
|
311
|
+
const incoming = buildIncomingMap(graph.connections);
|
|
312
|
+
const classified = classifyNodes(graph, reverseMap, gipTypeId, outputTypeId, valueTypeIds);
|
|
313
|
+
const classMap = new Map();
|
|
314
|
+
for (const node of classified)
|
|
315
|
+
classMap.set(node.bid, node);
|
|
316
|
+
const ctx = {
|
|
317
|
+
graph,
|
|
318
|
+
graphExt,
|
|
319
|
+
flowirRegistry,
|
|
320
|
+
backendRegistry,
|
|
321
|
+
incoming,
|
|
322
|
+
classMap,
|
|
323
|
+
paramBids: new Map(),
|
|
324
|
+
dialectStmtIds: new Map(),
|
|
325
|
+
};
|
|
326
|
+
const statements = [];
|
|
327
|
+
const nodeIds = {};
|
|
328
|
+
let paramCounter = 0;
|
|
329
|
+
let constCounter = 0;
|
|
330
|
+
const valueNodes = classified.filter((n) => n.cls === "value");
|
|
331
|
+
for (const vNode of valueNodes) {
|
|
332
|
+
const edges = incoming.get(vNode.bid);
|
|
333
|
+
const gipEdge = edges?.find((e) => classMap.get(e.fromBid)?.cls === "gip" && e.toPort === 0);
|
|
334
|
+
if (gipEdge) {
|
|
335
|
+
statements.push(liftParam(vNode, gipEdge.fromBid, paramCounter, ctx));
|
|
336
|
+
const stmt = statements[statements.length - 1];
|
|
337
|
+
ctx.paramBids.set(vNode.bid, stmt.name);
|
|
338
|
+
nodeIds[`param:${stmt.name}`] = vNode.bid;
|
|
339
|
+
nodeIds[`param-input:${stmt.name}`] = gipEdge.fromBid;
|
|
340
|
+
paramCounter++;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
statements.push(liftConst(vNode, constCounter, ctx));
|
|
344
|
+
const stmt = statements[statements.length - 1];
|
|
345
|
+
ctx.paramBids.set(vNode.bid, stmt.name);
|
|
346
|
+
nodeIds[`const:${stmt.name}`] = vNode.bid;
|
|
347
|
+
constCounter++;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const dialectBids = classified
|
|
351
|
+
.filter((n) => n.cls === "dialect")
|
|
352
|
+
.map((n) => n.bid);
|
|
353
|
+
const sortedBids = toposort(dialectBids, incoming);
|
|
354
|
+
let nodeCounter = 0;
|
|
355
|
+
for (const bid of sortedBids) {
|
|
356
|
+
ctx.dialectStmtIds.set(bid, `n${nodeCounter}`);
|
|
357
|
+
nodeCounter++;
|
|
358
|
+
}
|
|
359
|
+
for (const bid of sortedBids) {
|
|
360
|
+
const cNode = classMap.get(bid);
|
|
361
|
+
const stmt = liftNodeStmt(bid, cNode, ctx);
|
|
362
|
+
if (stmt) {
|
|
363
|
+
statements.push(stmt);
|
|
364
|
+
nodeIds[`node:${stmt.id}`] = bid;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const outputNodes = classified.filter((n) => n.cls === "output");
|
|
368
|
+
for (const oNode of outputNodes) {
|
|
369
|
+
const stmt = liftOutStmt(oNode, ctx);
|
|
370
|
+
if (stmt) {
|
|
371
|
+
statements.push(stmt);
|
|
372
|
+
nodeIds[`out:${stmt.outputName}`] = oNode.bid;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return { program: { statements }, nodeIds };
|
|
376
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
import type { GeometryGraph, StatementNodes } from "./graph.js";
|
|
3
|
+
import type { BackendRegistry, GraphExt } from "./backendRegistry.js";
|
|
4
|
+
export type LowerResult = {
|
|
5
|
+
graph: GeometryGraph;
|
|
6
|
+
graphExt: GraphExt;
|
|
7
|
+
nodeIds: StatementNodes;
|
|
8
|
+
};
|
|
9
|
+
export declare function lower(program: flowir.AstProgram, flowirRegistry: flowir.Registry, backendRegistry: BackendRegistry): LowerResult;
|