diff --git a/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx b/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx index c3e2a81..1f4ab89 100644 --- a/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx +++ b/src/pages/edit/Editor/components/NodePinPropertyEditor.tsx @@ -32,9 +32,7 @@ export function CCComponentEditorNodePinPropertyEditor() { "NodePinPropertyEditor can only be used for node pins with user specified bit width", ); const componentPinAttributes = nullthrows( - IntrinsicComponentDefinition.intrinsicComponentPinAttributesByComponentPinId.get( - target.componentPinId, - ), + IntrinsicComponentDefinition.getPinAttributesByPinId(target.componentPinId), "NodePinPropertyEditor can only be used for intrinsic component pins", ); diff --git a/src/store/componentPin.ts b/src/store/componentPin.ts index e5ad966..43d3667 100644 --- a/src/store/componentPin.ts +++ b/src/store/componentPin.ts @@ -36,16 +36,25 @@ export const ccPinTypes: CCComponentPinType[] = ["input", "output"]; /** null for intrinsic components */ export type CCPinImplementation = CCNodePinId | null; +/** + * The resolved bit width status of a node pin instance. + * - `isFixed: false` — the bit width has not yet been determined. + * - `isFixed: true` — the bit width is known and available as `bitWidth`. + */ export type CCNodePinBitWidthStatus = | { isFixed: false } | { isFixed: true; bitWidth: number }; +/** + * The bit width status of a component pin definition. + * - `isFixed: false, fixMode: "automatic"` — the bit width is not yet determined and will be inferred automatically from connections. + * - `isFixed: false, fixMode: "manual"` — the bit width is not yet determined and must be specified manually by the user. + * - `isFixed: true` — the bit width is known and available as `bitWidth`. + */ export type CCComponentPinBitWidthStatus = | { isFixed: false; fixMode: "automatic" | "manual" } | { isFixed: true; bitWidth: number }; -export type CCNodePinFixedBitWidth = number; - export type CCComponentPinStoreEvents = { didRegister(pin: CCComponentPin): void; willUnregister(pin: CCComponentPin): void; @@ -217,6 +226,7 @@ export class CCComponentPinStore extends EventEmitter ): CCComponentPinBitWidthStatus { const pin = this.#pins.get(pinId); invariant(pin); + // TODO: Remove hardcoded intrinsic component pin IDs and replace with a more flexible system, such as metadata on the component definitions. switch (pin.id) { case nullthrows(and.inputPin.A.id): case nullthrows(and.inputPin.B.id): diff --git a/src/store/intrinsics/base.ts b/src/store/intrinsics/base.ts index 470ba35..2c09ec2 100644 --- a/src/store/intrinsics/base.ts +++ b/src/store/intrinsics/base.ts @@ -30,6 +30,7 @@ export type Context = { type IntrinsicComponentPinAttributes = { name: string; + bitWidthFixMode?: "fixed" | "configurable" | "splittable"; isBitWidthConfigurable?: boolean; isSplittable?: boolean; }; @@ -48,11 +49,6 @@ type Props = { export class IntrinsicComponentDefinition< Spec extends CCIntrinsicComponentSpec = CCIntrinsicComponentSpec, > { - static intrinsicComponentPinAttributesByComponentPinId: Map< - CCComponentPinId, - IntrinsicComponentPinAttributes - > = new Map(); - readonly id: CCComponentId; readonly type: CCIntrinsicComponentType; readonly name: string; @@ -98,7 +94,7 @@ export class IntrinsicComponentDefinition< order: this._lastLocalIndex++, name: attributes.name, }; - IntrinsicComponentDefinition.intrinsicComponentPinAttributesByComponentPinId.set( + IntrinsicComponentDefinition._pinAttributesByPinId.set( pin.id, attributes, ); @@ -114,7 +110,7 @@ export class IntrinsicComponentDefinition< order: this._lastLocalIndex++, name: attributes.name, }; - IntrinsicComponentDefinition.intrinsicComponentPinAttributesByComponentPinId.set( + IntrinsicComponentDefinition._pinAttributesByPinId.set( pin.id, attributes, ); @@ -122,18 +118,15 @@ export class IntrinsicComponentDefinition< return pin; }); this.initialConfig = props.initialConfig; - // this.outputPin = { - // id: this._generateId() as CCComponentPinId, - // componentId: this.id, - // type: "output", - // implementation: null, - // order: this._lastLocalIndex++, - // name: props.out.name, - // }; - // IntrinsicComponentDefinition.intrinsicComponentPinAttributesByComponentPinId.set( - // this.outputPin.id, - // props.out - // ); - // this.allPins.push(this.outputPin); + } + + private static _pinAttributesByPinId: Map< + CCComponentPinId, + IntrinsicComponentPinAttributes + > = new Map(); + static getPinAttributesByPinId(pinId: CCComponentPinId) { + return ( + IntrinsicComponentDefinition._pinAttributesByPinId.get(pinId) ?? null + ); } } diff --git a/src/store/intrinsics/definitions.ts b/src/store/intrinsics/definitions.ts index 227ecda..d1a5287 100644 --- a/src/store/intrinsics/definitions.ts +++ b/src/store/intrinsics/definitions.ts @@ -73,7 +73,15 @@ function createBinaryOperator( } invariant( inputValueA.length === inputValueB.length, - "Input lengths must match", + "Input lengths must match (name: " + + name + + ", nodeId: " + + nodeId + + ", inputValueA: " + + inputValueA + + ", inputValueB: " + + inputValueB + + ")", ); const outputValue = Array.from({ length: inputValueA.length }, (_, i) => evaluate(nullthrows(inputValueA[i]), nullthrows(inputValueB[i])), @@ -149,7 +157,7 @@ export const input = type: ccIntrinsicComponentTypes.INPUT, name: "Input", in: {}, - out: { Out: { name: "Out" } }, + out: { Out: { name: "In" } }, initialConfig: null, evaluate: (_context, _nodeId, _shape) => { return true; @@ -160,7 +168,7 @@ export const output = new IntrinsicComponentDefinition({ type: ccIntrinsicComponentTypes.OUTPUT, name: "Output", - in: { In: { name: "In" } }, + in: { In: { name: "Out" } }, out: {}, initialConfig: null, evaluate: (_context, _nodeId, _shape) => { @@ -272,6 +280,7 @@ export const flipflop = const outputShape = shape.outputShape.Out; invariant(outputShape[0] && !outputShape[1]); const nodePinIdToValue = context.currentFrame.nodes.get(nodeId)?.pins; + console.log("FlipFlop evaluate", { nodeId, inputShape, outputShape }); const previousValue = context.previousFrame?.nodes .get(nodeId) diff --git a/src/store/nodePin.ts b/src/store/nodePin.ts index 9514753..7a1d91a 100644 --- a/src/store/nodePin.ts +++ b/src/store/nodePin.ts @@ -377,10 +377,9 @@ export class CCNodePinStore extends EventEmitter { partialPin: Omit & Partial>, ): CCNodePin { - const attributes = - IntrinsicComponentDefinition.intrinsicComponentPinAttributesByComponentPinId.get( - partialPin.componentPinId, - ); + const attributes = IntrinsicComponentDefinition.getPinAttributesByPinId( + partialPin.componentPinId, + ); return { ...partialPin, id: crypto.randomUUID() as CCNodePinId,