nucleation 0.10.4 → 0.10.7
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/CellExecutor.d.mts +51 -0
- package/CellExecutor.d.ts +51 -0
- package/CellExecutor.mjs +171 -0
- package/Curve3D.mjs +1 -1
- package/DefinitionRegion.mjs +4 -4
- package/Design.d.mts +348 -0
- package/Design.d.ts +348 -0
- package/Design.mjs +1334 -0
- package/Hdl.d.mts +56 -0
- package/Hdl.d.ts +56 -0
- package/Hdl.mjs +163 -0
- package/MchprsWorld.mjs +2 -2
- package/MeshConfig.mjs +4 -4
- package/MeshResult.d.mts +11 -0
- package/MeshResult.d.ts +11 -0
- package/MeshResult.mjs +38 -1
- package/NucleationError.d.mts +12 -0
- package/NucleationError.d.ts +12 -0
- package/NucleationError.mjs +25 -0
- package/Routing.d.mts +66 -0
- package/Routing.d.ts +66 -0
- package/Routing.mjs +220 -0
- package/Schematic.d.mts +73 -1
- package/Schematic.d.ts +73 -1
- package/Schematic.mjs +259 -1
- package/SchematicSplitResult.d.mts +26 -0
- package/SchematicSplitResult.d.ts +26 -0
- package/SchematicSplitResult.mjs +84 -0
- package/Store.d.mts +1 -1
- package/Store.d.ts +1 -1
- package/Store.mjs +1 -1
- package/TickSimulation.d.mts +231 -0
- package/TickSimulation.d.ts +231 -0
- package/TickSimulation.mjs +404 -2
- package/index.d.mts +10 -0
- package/index.d.ts +10 -0
- package/index.mjs +10 -0
- package/nucleation.wasm +0 -0
- package/package.json +6 -1
- package/veneer/design.d.ts +167 -0
- package/veneer/design.mjs +480 -0
package/Design.mjs
ADDED
|
@@ -0,0 +1,1334 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import { NucleationError } from "./NucleationError.mjs"
|
|
3
|
+
import { Schematic } from "./Schematic.mjs"
|
|
4
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
5
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
6
|
+
|
|
7
|
+
const Design_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
8
|
+
wasm.Design_destroy(ptr);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A composition document: loose blocks + cell instances + bus layers
|
|
13
|
+
* over a shared coordinate space.
|
|
14
|
+
*/
|
|
15
|
+
export class Design {
|
|
16
|
+
// Internal ptr reference:
|
|
17
|
+
#ptr = null;
|
|
18
|
+
|
|
19
|
+
// Lifetimes are only to keep dependencies alive.
|
|
20
|
+
// Since JS won't garbage collect until there are no incoming edges.
|
|
21
|
+
#selfEdge = [];
|
|
22
|
+
|
|
23
|
+
#internalConstructor(symbol, ptr, selfEdge) {
|
|
24
|
+
if (symbol !== diplomatRuntime.internalConstructor) {
|
|
25
|
+
console.error("Design is an Opaque type. You cannot call its constructor.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.#ptr = ptr;
|
|
29
|
+
this.#selfEdge = selfEdge;
|
|
30
|
+
|
|
31
|
+
// Are we being borrowed? If not, we can register.
|
|
32
|
+
if (this.#selfEdge.length === 0) {
|
|
33
|
+
Design_box_destroy_registry.register(this, this.#ptr);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** @internal */
|
|
39
|
+
get ffiValue() {
|
|
40
|
+
return this.#ptr;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An empty design.
|
|
46
|
+
*/
|
|
47
|
+
static create(name) {
|
|
48
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
49
|
+
|
|
50
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
51
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const result = wasm.Design_create(diplomatReceive.buffer, nameSlice.ptr);
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (!diplomatReceive.resultFlag) {
|
|
58
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
59
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
60
|
+
}
|
|
61
|
+
return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
finally {
|
|
65
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
66
|
+
functionCleanupArena.free();
|
|
67
|
+
|
|
68
|
+
diplomatReceive.free();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A design whose loose block layer is a copy of `base` (endpoint
|
|
74
|
+
* hardware placed with raw `set_block`).
|
|
75
|
+
*/
|
|
76
|
+
static forSchematic(name, base) {
|
|
77
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
78
|
+
|
|
79
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
80
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const result = wasm.Design_for_schematic(diplomatReceive.buffer, nameSlice.ptr, base.ffiValue);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
if (!diplomatReceive.resultFlag) {
|
|
87
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
88
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
89
|
+
}
|
|
90
|
+
return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
finally {
|
|
94
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
95
|
+
functionCleanupArena.free();
|
|
96
|
+
|
|
97
|
+
diplomatReceive.free();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Register a library cell; its contract is resolved from the
|
|
103
|
+
* schematic (embedded metadata first, Insign signs as fallback)
|
|
104
|
+
* and registration fails loudly when no source defines one.
|
|
105
|
+
* Writes resolution warnings as a JSON array of strings.
|
|
106
|
+
*/
|
|
107
|
+
addCell(name, cell) {
|
|
108
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
109
|
+
|
|
110
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
111
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
112
|
+
|
|
113
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const result = wasm.Design_add_cell(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, cell.ffiValue, write.buffer);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
if (!diplomatReceive.resultFlag) {
|
|
120
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
121
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
122
|
+
}
|
|
123
|
+
return write.readString8();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
finally {
|
|
127
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
128
|
+
functionCleanupArena.free();
|
|
129
|
+
|
|
130
|
+
diplomatReceive.free();
|
|
131
|
+
write.free();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Place an instance layer referencing a library cell. `rot_y` is
|
|
137
|
+
* in degrees, a multiple of 90.
|
|
138
|
+
*/
|
|
139
|
+
place(name, cell, x, y, z, rotY) {
|
|
140
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
141
|
+
|
|
142
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
143
|
+
const cellSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, cell)));
|
|
144
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
const result = wasm.Design_place(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, cellSlice.ptr, x, y, z, rotY);
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
if (!diplomatReceive.resultFlag) {
|
|
151
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
152
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
finally {
|
|
157
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
158
|
+
functionCleanupArena.free();
|
|
159
|
+
|
|
160
|
+
diplomatReceive.free();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Declare a drivable input port: anchor = bit-0 connection cell,
|
|
166
|
+
* step to the next bit, `width` bits of `ty` (`"uint"` or
|
|
167
|
+
* `"bool"`). The hardware is scanned (adjacent lever per bit) and
|
|
168
|
+
* validated loudly.
|
|
169
|
+
*/
|
|
170
|
+
declareInput(name, ax, ay, az, sx, sy, sz, width, ty) {
|
|
171
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
172
|
+
|
|
173
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
174
|
+
const tySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ty)));
|
|
175
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
const result = wasm.Design_declare_input(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, ax, ay, az, sx, sy, sz, width, tySlice.ptr);
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
if (!diplomatReceive.resultFlag) {
|
|
182
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
183
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
finally {
|
|
188
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
189
|
+
functionCleanupArena.free();
|
|
190
|
+
|
|
191
|
+
diplomatReceive.free();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Declare a readable output port (adjacent lamp per bit); same
|
|
197
|
+
* shape as `declare_input`.
|
|
198
|
+
*/
|
|
199
|
+
declareOutput(name, ax, ay, az, sx, sy, sz, width, ty) {
|
|
200
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
201
|
+
|
|
202
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
203
|
+
const tySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ty)));
|
|
204
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
const result = wasm.Design_declare_output(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, ax, ay, az, sx, sy, sz, width, tySlice.ptr);
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
if (!diplomatReceive.resultFlag) {
|
|
211
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
212
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
finally {
|
|
217
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
218
|
+
functionCleanupArena.free();
|
|
219
|
+
|
|
220
|
+
diplomatReceive.free();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Declare AND realize a bus. `sinks_json` is a JSON array of port
|
|
226
|
+
* names; `gates_json` an array of `{"name", "anchor": [x,y,z],
|
|
227
|
+
* "step": [x,y,z]}` (pass `[]` for none); `style_json` an object
|
|
228
|
+
* with optional `bus_block` / `transparent_block`. Declaration
|
|
229
|
+
* errors are error returns; geometric unroutability is the
|
|
230
|
+
* written STATE: `"routed"` or `"failed: reason"` — realization
|
|
231
|
+
* is atomic, never half-routed.
|
|
232
|
+
*/
|
|
233
|
+
routeBus(name, driver, sinksJson, gatesJson, styleJson) {
|
|
234
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
235
|
+
|
|
236
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
237
|
+
const driverSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driver)));
|
|
238
|
+
const sinksJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksJson)));
|
|
239
|
+
const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
|
|
240
|
+
const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
|
|
241
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
242
|
+
|
|
243
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
const result = wasm.Design_route_bus(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driverSlice.ptr, sinksJsonSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, write.buffer);
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
if (!diplomatReceive.resultFlag) {
|
|
250
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
251
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
252
|
+
}
|
|
253
|
+
return write.readString8();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
finally {
|
|
257
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
258
|
+
functionCleanupArena.free();
|
|
259
|
+
|
|
260
|
+
diplomatReceive.free();
|
|
261
|
+
write.free();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Declare AND realize a wired-OR bus: `drivers_json` is a JSON
|
|
267
|
+
* array of port names — multiple drivers are legal ONLY through
|
|
268
|
+
* this explicit merge (`merge="or"`). Extra drivers join the
|
|
269
|
+
* trunk as diode-isolated dust-merge branches; the LVS intent
|
|
270
|
+
* stays ONE net per bit. Same shapes as `route_bus` otherwise.
|
|
271
|
+
*/
|
|
272
|
+
routeBusOr(name, driversJson, sinksJson, gatesJson, styleJson) {
|
|
273
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
274
|
+
|
|
275
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
276
|
+
const driversJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driversJson)));
|
|
277
|
+
const sinksJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksJson)));
|
|
278
|
+
const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
|
|
279
|
+
const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
|
|
280
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
281
|
+
|
|
282
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
const result = wasm.Design_route_bus_or(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driversJsonSlice.ptr, sinksJsonSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, write.buffer);
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
if (!diplomatReceive.resultFlag) {
|
|
289
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
290
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
291
|
+
}
|
|
292
|
+
return write.readString8();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
finally {
|
|
296
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
297
|
+
functionCleanupArena.free();
|
|
298
|
+
|
|
299
|
+
diplomatReceive.free();
|
|
300
|
+
write.free();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Edit the loose block layer: plain `set_block` on the base
|
|
306
|
+
* schematic (participates in occupancy and flatten).
|
|
307
|
+
*/
|
|
308
|
+
setBlock(x, y, z, block) {
|
|
309
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
310
|
+
|
|
311
|
+
const blockSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, block)));
|
|
312
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
const result = wasm.Design_set_block(diplomatReceive.buffer, this.ffiValue, x, y, z, blockSlice.ptr);
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
if (!diplomatReceive.resultFlag) {
|
|
319
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
320
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
finally {
|
|
325
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
326
|
+
functionCleanupArena.free();
|
|
327
|
+
|
|
328
|
+
diplomatReceive.free();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Drag an instance layer to a new position/rotation. The move
|
|
334
|
+
* itself ALWAYS succeeds (the document's truth); the affected bus
|
|
335
|
+
* set — fragments intersecting the old or new footprint +
|
|
336
|
+
* influence halo, plus every already-failed bus — is ripped and
|
|
337
|
+
* co-rerouted deterministically with bounded retry rounds.
|
|
338
|
+
* Writes `{"rerouted": [...], "failed": {name: reason}}`.
|
|
339
|
+
*/
|
|
340
|
+
moveInstance(name, x, y, z, rotY) {
|
|
341
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
342
|
+
|
|
343
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
344
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
345
|
+
|
|
346
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
const result = wasm.Design_move_instance(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, x, y, z, rotY, write.buffer);
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
if (!diplomatReceive.resultFlag) {
|
|
353
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
354
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
355
|
+
}
|
|
356
|
+
return write.readString8();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
finally {
|
|
360
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
361
|
+
functionCleanupArena.free();
|
|
362
|
+
|
|
363
|
+
diplomatReceive.free();
|
|
364
|
+
write.free();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Remove an instance layer. Buses that terminate on one of its
|
|
370
|
+
* ports are DELETED (they lost an endpoint); buses that merely
|
|
371
|
+
* crossed its space are ripped and co-rerouted. Writes
|
|
372
|
+
* `{"removed_buses": [...], "rerouted": [...], "failed": {...}}`.
|
|
373
|
+
*/
|
|
374
|
+
removeInstance(name) {
|
|
375
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
376
|
+
|
|
377
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
378
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
379
|
+
|
|
380
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
const result = wasm.Design_remove_instance(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
384
|
+
|
|
385
|
+
try {
|
|
386
|
+
if (!diplomatReceive.resultFlag) {
|
|
387
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
388
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
389
|
+
}
|
|
390
|
+
return write.readString8();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
finally {
|
|
394
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
395
|
+
functionCleanupArena.free();
|
|
396
|
+
|
|
397
|
+
diplomatReceive.free();
|
|
398
|
+
write.free();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Re-realize a bus from its stored declaration (the counterpart to
|
|
404
|
+
* `rip`); writes the resulting bus state.
|
|
405
|
+
*/
|
|
406
|
+
reroute(name) {
|
|
407
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
408
|
+
|
|
409
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
410
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
411
|
+
|
|
412
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
const result = wasm.Design_reroute(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
416
|
+
|
|
417
|
+
try {
|
|
418
|
+
if (!diplomatReceive.resultFlag) {
|
|
419
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
420
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
421
|
+
}
|
|
422
|
+
return write.readString8();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
finally {
|
|
426
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
427
|
+
functionCleanupArena.free();
|
|
428
|
+
|
|
429
|
+
diplomatReceive.free();
|
|
430
|
+
write.free();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Delete a bus outright — fragment AND declaration, freeing the
|
|
436
|
+
* name. `rip` keeps the declaration so the bus can be rerouted.
|
|
437
|
+
*/
|
|
438
|
+
removeBus(name) {
|
|
439
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
440
|
+
|
|
441
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
442
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
const result = wasm.Design_remove_bus(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr);
|
|
446
|
+
|
|
447
|
+
try {
|
|
448
|
+
if (!diplomatReceive.resultFlag) {
|
|
449
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
450
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
finally {
|
|
455
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
456
|
+
functionCleanupArena.free();
|
|
457
|
+
|
|
458
|
+
diplomatReceive.free();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The flattened artifact as `.schem` bytes, base64. Unlike
|
|
464
|
+
* `flatten()` + the schematic writer, this composites the layer
|
|
465
|
+
* stack into ONE region first: `.schem` has no layers, and the
|
|
466
|
+
* region merge drops named-layer cells that the loose layer's
|
|
467
|
+
* bounding box shadows.
|
|
468
|
+
*/
|
|
469
|
+
toSchemB64() {
|
|
470
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
471
|
+
|
|
472
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
const result = wasm.Design_to_schem_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
|
|
476
|
+
|
|
477
|
+
try {
|
|
478
|
+
if (!diplomatReceive.resultFlag) {
|
|
479
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
480
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
481
|
+
}
|
|
482
|
+
return write.readString8();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
finally {
|
|
486
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
487
|
+
diplomatReceive.free();
|
|
488
|
+
write.free();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The flattened artifact composited into ONE region (see
|
|
494
|
+
* `to_schem_b64`) — the shape an interchange export wants.
|
|
495
|
+
*/
|
|
496
|
+
flattenComposite() {
|
|
497
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
const result = wasm.Design_flatten_composite(diplomatReceive.buffer, this.ffiValue);
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
if (!diplomatReceive.resultFlag) {
|
|
504
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
505
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
506
|
+
}
|
|
507
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
finally {
|
|
511
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
512
|
+
diplomatReceive.free();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Every routing endpoint the placed instances expose, as a JSON
|
|
518
|
+
* array of `{name, instance, port, role, ty, width, hardware,
|
|
519
|
+
* wires, step, routable, blocked}`. `name` is `{instance}.{port}`
|
|
520
|
+
* — exactly what `route_bus` accepts; `role` is the CELL-facing
|
|
521
|
+
* direction, so `"output"` drives a bus and `"input"` receives
|
|
522
|
+
* one. A port whose bits have no dust connection cell (a lever
|
|
523
|
+
* input, say) reports `routable: false` and why in `blocked`.
|
|
524
|
+
*/
|
|
525
|
+
instancePorts() {
|
|
526
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
527
|
+
|
|
528
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
const result = wasm.Design_instance_ports(diplomatReceive.buffer, this.ffiValue, write.buffer);
|
|
532
|
+
|
|
533
|
+
try {
|
|
534
|
+
if (!diplomatReceive.resultFlag) {
|
|
535
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
536
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
537
|
+
}
|
|
538
|
+
return write.readString8();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
finally {
|
|
542
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
543
|
+
diplomatReceive.free();
|
|
544
|
+
write.free();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Switch a port between executor hardware and a routable dust input.
|
|
550
|
+
*
|
|
551
|
+
* `mode` is `"bus"` or `"executor"`. Community cells name LEVERS for
|
|
552
|
+
* their inputs and nothing in redstone drives a lever, so a port must
|
|
553
|
+
* be in `"bus"` mode before a bus can land on it. The switch is a
|
|
554
|
+
* reversible per-instance patch — `"executor"` restores the shipped
|
|
555
|
+
* blocks byte-exactly.
|
|
556
|
+
*
|
|
557
|
+
* Returns the report as JSON: `{port, mode, note, changed:[{at,from,
|
|
558
|
+
* to}], removed_buses, moves, patch}` — `note` is a ready-made toast
|
|
559
|
+
* and `changed` is in WORLD coordinates.
|
|
560
|
+
*/
|
|
561
|
+
setPortMode(instance, port, mode) {
|
|
562
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
563
|
+
|
|
564
|
+
const instanceSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, instance)));
|
|
565
|
+
const portSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, port)));
|
|
566
|
+
const modeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, mode)));
|
|
567
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
568
|
+
|
|
569
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
const result = wasm.Design_set_port_mode(diplomatReceive.buffer, this.ffiValue, instanceSlice.ptr, portSlice.ptr, modeSlice.ptr, write.buffer);
|
|
573
|
+
|
|
574
|
+
try {
|
|
575
|
+
if (!diplomatReceive.resultFlag) {
|
|
576
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
577
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
578
|
+
}
|
|
579
|
+
return write.readString8();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
finally {
|
|
583
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
584
|
+
functionCleanupArena.free();
|
|
585
|
+
|
|
586
|
+
diplomatReceive.free();
|
|
587
|
+
write.free();
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Every port whose mode has been switched, as JSON:
|
|
593
|
+
* `[{"name":"u0.bin","mode":"bus","patch":{..}}]`. Ports absent from
|
|
594
|
+
* the array are in `"executor"` mode.
|
|
595
|
+
*/
|
|
596
|
+
portModes() {
|
|
597
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
598
|
+
|
|
599
|
+
wasm.Design_port_modes(this.ffiValue, write.buffer);
|
|
600
|
+
|
|
601
|
+
try {
|
|
602
|
+
return write.readString8();
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
finally {
|
|
606
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
607
|
+
write.free();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Describe (without applying) what switching a port to `"bus"` mode
|
|
613
|
+
* would do: `{"wires","hardware","step","removed","added","pivoted",
|
|
614
|
+
* "note"}`. Errors when the port cannot be promoted, with the reason.
|
|
615
|
+
*/
|
|
616
|
+
planPortPromotion(instance, port) {
|
|
617
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
618
|
+
|
|
619
|
+
const instanceSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, instance)));
|
|
620
|
+
const portSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, port)));
|
|
621
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
622
|
+
|
|
623
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
const result = wasm.Design_plan_port_promotion(diplomatReceive.buffer, this.ffiValue, instanceSlice.ptr, portSlice.ptr, write.buffer);
|
|
627
|
+
|
|
628
|
+
try {
|
|
629
|
+
if (!diplomatReceive.resultFlag) {
|
|
630
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
631
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
632
|
+
}
|
|
633
|
+
return write.readString8();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
finally {
|
|
637
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
638
|
+
functionCleanupArena.free();
|
|
639
|
+
|
|
640
|
+
diplomatReceive.free();
|
|
641
|
+
write.free();
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Resolve one routing endpoint name — a declared design port or an
|
|
647
|
+
* instance port `{instance}.{port}` — to the geometry a bus would
|
|
648
|
+
* use: `{"name","anchor","step","width","direction","connectable"}`.
|
|
649
|
+
* `direction` is DESIGN-facing (`"input"` drives buses).
|
|
650
|
+
*/
|
|
651
|
+
resolvePort(name) {
|
|
652
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
653
|
+
|
|
654
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
655
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
656
|
+
|
|
657
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
const result = wasm.Design_resolve_port(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
661
|
+
|
|
662
|
+
try {
|
|
663
|
+
if (!diplomatReceive.resultFlag) {
|
|
664
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
665
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
666
|
+
}
|
|
667
|
+
return write.readString8();
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
finally {
|
|
671
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
672
|
+
functionCleanupArena.free();
|
|
673
|
+
|
|
674
|
+
diplomatReceive.free();
|
|
675
|
+
write.free();
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Add a gate to an existing bus (splitting the segment it lands
|
|
681
|
+
* in) and re-realize it. Writes the resulting bus state.
|
|
682
|
+
*/
|
|
683
|
+
addGate(bus, gate, x, y, z, sx, sy, sz) {
|
|
684
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
685
|
+
|
|
686
|
+
const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
|
|
687
|
+
const gateSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gate)));
|
|
688
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
689
|
+
|
|
690
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
const result = wasm.Design_add_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, gateSlice.ptr, x, y, z, sx, sy, sz, write.buffer);
|
|
694
|
+
|
|
695
|
+
try {
|
|
696
|
+
if (!diplomatReceive.resultFlag) {
|
|
697
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
698
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
699
|
+
}
|
|
700
|
+
return write.readString8();
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
finally {
|
|
704
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
705
|
+
functionCleanupArena.free();
|
|
706
|
+
|
|
707
|
+
diplomatReceive.free();
|
|
708
|
+
write.free();
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Drag a gate: the anchor moves unconditionally, then EXACTLY the
|
|
714
|
+
* two adjacent segments are ripped and rerouted atomically. An
|
|
715
|
+
* unroutable move leaves the bus `failed: reason` — visible,
|
|
716
|
+
* never half-routed. Writes `{"state": "...",
|
|
717
|
+
* "rerouted_segments": n, "changed": [layer, ...]}`, where `changed`
|
|
718
|
+
* is the COMPLETE redraw set (see `changed_layers_since`).
|
|
719
|
+
*/
|
|
720
|
+
moveGate(bus, gate, x, y, z) {
|
|
721
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
722
|
+
|
|
723
|
+
const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
|
|
724
|
+
const gateSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gate)));
|
|
725
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
726
|
+
|
|
727
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
const result = wasm.Design_move_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, gateSlice.ptr, x, y, z, write.buffer);
|
|
731
|
+
|
|
732
|
+
try {
|
|
733
|
+
if (!diplomatReceive.resultFlag) {
|
|
734
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
735
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
736
|
+
}
|
|
737
|
+
return write.readString8();
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
finally {
|
|
741
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
742
|
+
functionCleanupArena.free();
|
|
743
|
+
|
|
744
|
+
diplomatReceive.free();
|
|
745
|
+
write.free();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Remove a gate by index and re-realize the bus, so the two spans it
|
|
751
|
+
* separated MERGE and route as one — removing a checkpoint relaxes a
|
|
752
|
+
* constraint, so the result is shorter and straighter, not the two old
|
|
753
|
+
* legs stitched together. Writes the same JSON as `move_gate`:
|
|
754
|
+
* `{"state", "rerouted_segments", "changed"}`.
|
|
755
|
+
*/
|
|
756
|
+
removeGate(bus, index) {
|
|
757
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
758
|
+
|
|
759
|
+
const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
|
|
760
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
761
|
+
|
|
762
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
const result = wasm.Design_remove_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, index, write.buffer);
|
|
766
|
+
|
|
767
|
+
try {
|
|
768
|
+
if (!diplomatReceive.resultFlag) {
|
|
769
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
770
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
771
|
+
}
|
|
772
|
+
return write.readString8();
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
finally {
|
|
776
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
777
|
+
functionCleanupArena.free();
|
|
778
|
+
|
|
779
|
+
diplomatReceive.free();
|
|
780
|
+
write.free();
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Undo a design port declaration. Removing an ENDPOINT changes the
|
|
786
|
+
* netlist, so every bus that named it is deleted — pass `force=false`
|
|
787
|
+
* first to be refused with the list and confirm. An instance port is
|
|
788
|
+
* derived from its cell's contract; use `set_port_mode` there.
|
|
789
|
+
*
|
|
790
|
+
* Writes `{"removed_buses":[...],"rerouted":[...],"failed":{...},
|
|
791
|
+
* "changed":[...]}`.
|
|
792
|
+
*/
|
|
793
|
+
removePort(name, force) {
|
|
794
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
795
|
+
|
|
796
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
797
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
798
|
+
|
|
799
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
const result = wasm.Design_remove_port(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, force, write.buffer);
|
|
803
|
+
|
|
804
|
+
try {
|
|
805
|
+
if (!diplomatReceive.resultFlag) {
|
|
806
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
807
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
808
|
+
}
|
|
809
|
+
return write.readString8();
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
finally {
|
|
813
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
814
|
+
functionCleanupArena.free();
|
|
815
|
+
|
|
816
|
+
diplomatReceive.free();
|
|
817
|
+
write.free();
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Declare and route a bus with an explicit WIDTH-ADAPTATION policy, so
|
|
823
|
+
* a narrower word can drive a wider port.
|
|
824
|
+
*
|
|
825
|
+
* `align`: 0 = lsb (bit 0 to bit 0, magnitude preserved), 1 = msb (top
|
|
826
|
+
* bit to top bit — a shift up by the width difference), 2 = use
|
|
827
|
+
* `shift` verbatim (positive moves toward the MSB). `truncate` permits
|
|
828
|
+
* DROPPING source bits that fall outside the destination; without it a
|
|
829
|
+
* lossy connection is refused, because losing a word's high bits is not
|
|
830
|
+
* the router's call. Destination bits nothing drives read 0 with no
|
|
831
|
+
* hardware at all.
|
|
832
|
+
*
|
|
833
|
+
* Writes the resulting bus state; `bus_width_map` reports the mapping.
|
|
834
|
+
*/
|
|
835
|
+
routeBusAdapted(name, driver, sinksCsv, gatesJson, styleJson, align, shift, truncate) {
|
|
836
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
837
|
+
|
|
838
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
839
|
+
const driverSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driver)));
|
|
840
|
+
const sinksCsvSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksCsv)));
|
|
841
|
+
const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
|
|
842
|
+
const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
|
|
843
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
844
|
+
|
|
845
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
const result = wasm.Design_route_bus_adapted(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driverSlice.ptr, sinksCsvSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, align, shift, truncate, write.buffer);
|
|
849
|
+
|
|
850
|
+
try {
|
|
851
|
+
if (!diplomatReceive.resultFlag) {
|
|
852
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
853
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
854
|
+
}
|
|
855
|
+
return write.readString8();
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
finally {
|
|
859
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
860
|
+
functionCleanupArena.free();
|
|
861
|
+
|
|
862
|
+
diplomatReceive.free();
|
|
863
|
+
write.free();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* The resolved bit mapping of a width-adapted bus (`null` when the
|
|
869
|
+
* widths matched): `{"map":{...,"pairs":[[dbit,sbit],..]},"note":".."}`.
|
|
870
|
+
*/
|
|
871
|
+
busWidthMap(name) {
|
|
872
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
873
|
+
|
|
874
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
875
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
876
|
+
|
|
877
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
const result = wasm.Design_bus_width_map(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
881
|
+
|
|
882
|
+
try {
|
|
883
|
+
if (!diplomatReceive.resultFlag) {
|
|
884
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
885
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
886
|
+
}
|
|
887
|
+
return write.readString8();
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
finally {
|
|
891
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
892
|
+
functionCleanupArena.free();
|
|
893
|
+
|
|
894
|
+
diplomatReceive.free();
|
|
895
|
+
write.free();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* The current bus-layer GEOMETRY REVISION. Read it before a mutating
|
|
901
|
+
* call, pass it to `changed_layers_since` after, and redraw exactly
|
|
902
|
+
* the layers named.
|
|
903
|
+
*/
|
|
904
|
+
layerRevision() {
|
|
905
|
+
|
|
906
|
+
const result = wasm.Design_layer_revision(this.ffiValue);
|
|
907
|
+
|
|
908
|
+
try {
|
|
909
|
+
return result;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
finally {
|
|
913
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* The COMPLETE set of bus layers whose geometry was rewritten since
|
|
919
|
+
* `rev`, as a JSON array of names.
|
|
920
|
+
*
|
|
921
|
+
* This is the contract a viewer must trust: it is stamped at every
|
|
922
|
+
* write to a layer's fragment, so it also names layers changed
|
|
923
|
+
* INDIRECTLY — a crossing stamps a through-bus station into a bus
|
|
924
|
+
* that was never ripped and appears in no other report. It also names
|
|
925
|
+
* DELETED layers (a name here that `bus_state` no longer knows means
|
|
926
|
+
* drop the mesh). `route_bus`, which returns only a state, is covered
|
|
927
|
+
* by this too: bracket it with `layer_revision`.
|
|
928
|
+
*/
|
|
929
|
+
changedLayersSince(rev) {
|
|
930
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
931
|
+
|
|
932
|
+
wasm.Design_changed_layers_since(this.ffiValue, rev, write.buffer);
|
|
933
|
+
|
|
934
|
+
try {
|
|
935
|
+
return write.readString8();
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
finally {
|
|
939
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
940
|
+
write.free();
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Attach a net-class discipline to a bus (JSON `NetClassRule`:
|
|
946
|
+
* optional `max_len_rt` delay budget, `y_band` layer band, …);
|
|
947
|
+
* `check()` enforces it.
|
|
948
|
+
*/
|
|
949
|
+
setBusRule(bus, ruleJson) {
|
|
950
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
951
|
+
|
|
952
|
+
const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
|
|
953
|
+
const ruleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ruleJson)));
|
|
954
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
const result = wasm.Design_set_bus_rule(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, ruleJsonSlice.ptr);
|
|
958
|
+
|
|
959
|
+
try {
|
|
960
|
+
if (!diplomatReceive.resultFlag) {
|
|
961
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
962
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
finally {
|
|
967
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
968
|
+
functionCleanupArena.free();
|
|
969
|
+
|
|
970
|
+
diplomatReceive.free();
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Per-bus skew from the routed fragment: writes
|
|
976
|
+
* `{"per_bit_rt": [...], "skew_rt": n, "max_rt": n}`.
|
|
977
|
+
*/
|
|
978
|
+
busSkew(name) {
|
|
979
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
980
|
+
|
|
981
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
982
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
983
|
+
|
|
984
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
const result = wasm.Design_bus_skew(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
988
|
+
|
|
989
|
+
try {
|
|
990
|
+
if (!diplomatReceive.resultFlag) {
|
|
991
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
992
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
993
|
+
}
|
|
994
|
+
return write.readString8();
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
finally {
|
|
998
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
999
|
+
functionCleanupArena.free();
|
|
1000
|
+
|
|
1001
|
+
diplomatReceive.free();
|
|
1002
|
+
write.free();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* The lifecycle state of a bus: `"intended"`, `"routed"` or
|
|
1008
|
+
* `"failed: reason"`.
|
|
1009
|
+
*/
|
|
1010
|
+
busState(name) {
|
|
1011
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1012
|
+
|
|
1013
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
1014
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1015
|
+
|
|
1016
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
const result = wasm.Design_bus_state(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
1020
|
+
|
|
1021
|
+
try {
|
|
1022
|
+
if (!diplomatReceive.resultFlag) {
|
|
1023
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1024
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1025
|
+
}
|
|
1026
|
+
return write.readString8();
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
finally {
|
|
1030
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1031
|
+
functionCleanupArena.free();
|
|
1032
|
+
|
|
1033
|
+
diplomatReceive.free();
|
|
1034
|
+
write.free();
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* ONE bus layer's cells as `[[x,y,z,"block"],..]`.
|
|
1040
|
+
*
|
|
1041
|
+
* The live-re-route fast path: `flatten()` rebuilds every layer in the
|
|
1042
|
+
* document to answer "what changed about this one bus". An unrouted bus
|
|
1043
|
+
* yields `[]`.
|
|
1044
|
+
*/
|
|
1045
|
+
busBlocksJson(name) {
|
|
1046
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1047
|
+
|
|
1048
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
1049
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1050
|
+
|
|
1051
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
const result = wasm.Design_bus_blocks_json(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
1055
|
+
|
|
1056
|
+
try {
|
|
1057
|
+
if (!diplomatReceive.resultFlag) {
|
|
1058
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1059
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1060
|
+
}
|
|
1061
|
+
return write.readString8();
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
finally {
|
|
1065
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1066
|
+
functionCleanupArena.free();
|
|
1067
|
+
|
|
1068
|
+
diplomatReceive.free();
|
|
1069
|
+
write.free();
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* ONE instance's placed cells as `[[x,y,z,"block"],..]`, transform
|
|
1075
|
+
* applied. Same fast path as `bus_blocks_json`.
|
|
1076
|
+
*/
|
|
1077
|
+
instanceBlocksJson(name) {
|
|
1078
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1079
|
+
|
|
1080
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
1081
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1082
|
+
|
|
1083
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
const result = wasm.Design_instance_blocks_json(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
|
|
1087
|
+
|
|
1088
|
+
try {
|
|
1089
|
+
if (!diplomatReceive.resultFlag) {
|
|
1090
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1091
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1092
|
+
}
|
|
1093
|
+
return write.readString8();
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
finally {
|
|
1097
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1098
|
+
functionCleanupArena.free();
|
|
1099
|
+
|
|
1100
|
+
diplomatReceive.free();
|
|
1101
|
+
write.free();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Rip a bus: clear its fragment, back to `intended`.
|
|
1107
|
+
*/
|
|
1108
|
+
rip(name) {
|
|
1109
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1110
|
+
|
|
1111
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
1112
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
const result = wasm.Design_rip(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr);
|
|
1116
|
+
|
|
1117
|
+
try {
|
|
1118
|
+
if (!diplomatReceive.resultFlag) {
|
|
1119
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1120
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
finally {
|
|
1125
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1126
|
+
functionCleanupArena.free();
|
|
1127
|
+
|
|
1128
|
+
diplomatReceive.free();
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Collapse the layer stack into ONE self-describing schematic:
|
|
1134
|
+
* named regions per layer (`inst:x`, `bus:y`) and the merged
|
|
1135
|
+
* contract embedded in the metadata — itself placeable as a cell.
|
|
1136
|
+
*/
|
|
1137
|
+
flatten() {
|
|
1138
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
const result = wasm.Design_flatten(diplomatReceive.buffer, this.ffiValue);
|
|
1142
|
+
|
|
1143
|
+
try {
|
|
1144
|
+
if (!diplomatReceive.resultFlag) {
|
|
1145
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1146
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1147
|
+
}
|
|
1148
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
finally {
|
|
1152
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1153
|
+
diplomatReceive.free();
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* DRC + LVS over the flattened artifact. Writes `{"clean",
|
|
1159
|
+
* "drc": [...], "lvs": {...}, "buses": {...}}`.
|
|
1160
|
+
*/
|
|
1161
|
+
check() {
|
|
1162
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1163
|
+
|
|
1164
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
const result = wasm.Design_check(diplomatReceive.buffer, this.ffiValue, write.buffer);
|
|
1168
|
+
|
|
1169
|
+
try {
|
|
1170
|
+
if (!diplomatReceive.resultFlag) {
|
|
1171
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1172
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1173
|
+
}
|
|
1174
|
+
return write.readString8();
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
finally {
|
|
1178
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1179
|
+
diplomatReceive.free();
|
|
1180
|
+
write.free();
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Settle the flattened artifact in the vanilla-accurate tick
|
|
1186
|
+
* engine and return it with every settled state written back and
|
|
1187
|
+
* `InitialState::Baked` stamped into the embedded contract (needs
|
|
1188
|
+
* the `mc-tick` feature, else errors).
|
|
1189
|
+
*/
|
|
1190
|
+
bake(budget) {
|
|
1191
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
const result = wasm.Design_bake(diplomatReceive.buffer, this.ffiValue, budget);
|
|
1195
|
+
|
|
1196
|
+
try {
|
|
1197
|
+
if (!diplomatReceive.resultFlag) {
|
|
1198
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1199
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1200
|
+
}
|
|
1201
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
finally {
|
|
1205
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1206
|
+
diplomatReceive.free();
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* Serialize the FULL design document to `.nucm` project-tier
|
|
1212
|
+
* bytes (magic `NUCM`): cells deduped by content hash, instance
|
|
1213
|
+
* transforms, ports with scanned hardware, every bus layer with
|
|
1214
|
+
* its fragment, runs and `intended`/`routed`/`failed: reason`
|
|
1215
|
+
* state, and the loose base layer. Base64 across the bridge.
|
|
1216
|
+
*/
|
|
1217
|
+
toNucmB64() {
|
|
1218
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1219
|
+
|
|
1220
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
const result = wasm.Design_to_nucm_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
|
|
1224
|
+
|
|
1225
|
+
try {
|
|
1226
|
+
if (!diplomatReceive.resultFlag) {
|
|
1227
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1228
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1229
|
+
}
|
|
1230
|
+
return write.readString8();
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
finally {
|
|
1234
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1235
|
+
diplomatReceive.free();
|
|
1236
|
+
write.free();
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* Reopen a `.nucm` design document from raw bytes. The reloaded
|
|
1242
|
+
* design is the same model mid-edit: rerouting works.
|
|
1243
|
+
*/
|
|
1244
|
+
static fromNucm(data) {
|
|
1245
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1246
|
+
|
|
1247
|
+
const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
|
|
1248
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
const result = wasm.Design_from_nucm(diplomatReceive.buffer, dataSlice.ptr);
|
|
1252
|
+
|
|
1253
|
+
try {
|
|
1254
|
+
if (!diplomatReceive.resultFlag) {
|
|
1255
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1256
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1257
|
+
}
|
|
1258
|
+
return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
finally {
|
|
1262
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1263
|
+
functionCleanupArena.free();
|
|
1264
|
+
|
|
1265
|
+
diplomatReceive.free();
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Export the design as a LAYERED `.litematic` (interchange tier):
|
|
1271
|
+
* one named region per layer (`inst:{name}`, `bus:{name}`, loose
|
|
1272
|
+
* base) plus the design manifest as a root-level
|
|
1273
|
+
* `NucleationDesign` tag. Opens in Litematica as a plain
|
|
1274
|
+
* multi-region litematic; reimports as a design whose cell
|
|
1275
|
+
* references have degraded to embedded copies. Base64 across the
|
|
1276
|
+
* bridge.
|
|
1277
|
+
*/
|
|
1278
|
+
toLitematicB64() {
|
|
1279
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1280
|
+
|
|
1281
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
const result = wasm.Design_to_litematic_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
|
|
1285
|
+
|
|
1286
|
+
try {
|
|
1287
|
+
if (!diplomatReceive.resultFlag) {
|
|
1288
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1289
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1290
|
+
}
|
|
1291
|
+
return write.readString8();
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
finally {
|
|
1295
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1296
|
+
diplomatReceive.free();
|
|
1297
|
+
write.free();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Import a layered `.litematic` (with a `NucleationDesign`
|
|
1303
|
+
* manifest) from raw bytes; a plain litematic errors loudly —
|
|
1304
|
+
* open those with `Schematic.from_litematic`.
|
|
1305
|
+
*/
|
|
1306
|
+
static fromLitematic(data) {
|
|
1307
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
1308
|
+
|
|
1309
|
+
const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
|
|
1310
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
const result = wasm.Design_from_litematic(diplomatReceive.buffer, dataSlice.ptr);
|
|
1314
|
+
|
|
1315
|
+
try {
|
|
1316
|
+
if (!diplomatReceive.resultFlag) {
|
|
1317
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
1318
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
1319
|
+
}
|
|
1320
|
+
return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
finally {
|
|
1324
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
1325
|
+
functionCleanupArena.free();
|
|
1326
|
+
|
|
1327
|
+
diplomatReceive.free();
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
constructor(symbol, ptr, selfEdge) {
|
|
1332
|
+
return this.#internalConstructor(...arguments)
|
|
1333
|
+
}
|
|
1334
|
+
}
|