feat: port labels on component gates + persistent internal state
Show input/output labels next to ports on custom component chips, and persist internal gate state between evaluations so latches and flip-flops retain their values correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,8 @@ export function saveComponentFromCircuit(name) {
|
||||
/**
|
||||
* Evaluate a component instance.
|
||||
* Simulates the internal circuit and returns an array of output values.
|
||||
* IMPORTANT: Uses persistent internal state so latches/flip-flops retain
|
||||
* their values between evaluations (just like the main circuit).
|
||||
*/
|
||||
export function evaluateComponent(gate, inputs) {
|
||||
if (!gate.component) {
|
||||
@@ -62,8 +64,11 @@ export function evaluateComponent(gate, inputs) {
|
||||
|
||||
const comp = gate.component;
|
||||
|
||||
// Deep clone internal circuit for simulation
|
||||
const internalGates = JSON.parse(JSON.stringify(comp.gates));
|
||||
// Persist internal gate state on the gate instance so latches hold their value
|
||||
if (!gate._internalGates) {
|
||||
gate._internalGates = JSON.parse(JSON.stringify(comp.gates));
|
||||
}
|
||||
const internalGates = gate._internalGates;
|
||||
const internalConns = comp.connections; // read-only, no need to clone
|
||||
|
||||
// Map external inputs to internal INPUT gates using stored inputIds
|
||||
@@ -133,7 +138,8 @@ export function evaluateComponent(gate, inputs) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[component] eval "${comp.name}" inputs=[${inputs}] → outputs=[${outputs}]`);
|
||||
console.log(`[component] eval "${comp.name}" inputs=[${inputs}] → outputs=[${outputs}]`,
|
||||
`(internal state preserved: ${gate._internalGates ? 'yes' : 'no'})`);
|
||||
return outputs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user