MCPcopy
hub / github.com/bbycroft/llm-viz / createCompIoComps

Function createCompIoComps

src/cpu/comps/CompPort.tsx:63–159  ·  view source on GitHub ↗
(args: ICompBuilderArgs)

Source from the content-addressed store, hash-verified

61export const compPortDefId = 'core/comp/port';
62
63export function createCompIoComps(args: ICompBuilderArgs) {
64
65 let w = 6;
66 let h = 6;
67 let compPort: ICompDef<ICompPortData, ICompPortConfig> = {
68 defId: 'comp/port',
69 name: "Port",
70 size: new Vec3(w, h),
71 ports: (args, compDef) => {
72
73 let internalPortDir = switchPortDir(args.type);
74 let pos = portPlacementToPos(args.portPos, args.w, args.h);
75
76 return [
77 { id: 'a', name: '', pos, type: internalPortDir, width: args.bitWidth },
78 ];
79 },
80 initConfig: () => ({
81 portId: '',
82 name: '',
83 w: 6,
84 h: 6,
85 type: PortType.Out,
86 portPos: PortPlacement.Right,
87 bitWidth: 1,
88 signed: false,
89 valueMode: HexValueInputType.Dec,
90 inputOverride: false,
91 inputValueOverride: 0,
92 }),
93 applyConfig(comp, args) {
94 comp.size = new Vec3(args.w, args.h);
95 },
96 build: (builder) => {
97 let args = builder.comp.args;
98 let isInput = hasFlag(args.type, PortType.In);
99
100 let data = builder.addData({
101 port: builder.getPort('a'),
102 externalPort: builder.createExternalPort('_b', args.type, args.bitWidth),
103 externalPortBound: false,
104 value: isInput && args.inputOverride ? args.inputValueOverride : 0,
105 });
106
107 if (isInput) {
108 builder.addPhase(({ data }) => {
109 if (data.externalPortBound) {
110 data.value = data.externalPort.value;
111 }
112 data.port.value = data.value;
113 data.port.ioEnabled = true;
114 }, [data.externalPort], [data.port]);
115
116 } else {
117 builder.addPhase(({ data }) => {
118 data.value = data.port.value;
119 if (data.externalPortBound) {
120 data.externalPort.value = data.value;

Callers 1

buildCompLibraryFunction · 0.90

Calls 9

hasFlagFunction · 0.90
makeCanvasFontFunction · 0.90
switchPortDirFunction · 0.85
portPlacementToPosFunction · 0.85
addDataMethod · 0.80
getPortMethod · 0.80
createExternalPortMethod · 0.80
addPhaseMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected