-
Notifications
You must be signed in to change notification settings - Fork 222
refactor : ts integration : src/simulator/src/moduleSetup.ts #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ThatDeparted2061
wants to merge
3
commits into
CircuitVerse:main
from
ThatDeparted2061:moduleSetup.js
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import modules from './modules'; | ||
| import Adder from './modules/Adder'; | ||
| import ALU from './modules/ALU'; | ||
| import AndGate from './modules/AndGate'; | ||
| import Arrow from './modules/Arrow'; | ||
| import ImageAnnotation from './modules/ImageAnnotation'; | ||
| import BitSelector from './modules/BitSelector'; | ||
| import Buffer from './modules/Buffer'; | ||
| import Button from './modules/Button'; | ||
| import ConstantVal from './modules/ConstantVal'; | ||
| import ControlledInverter from './modules/ControlledInverter'; | ||
| import Counter from './modules/Counter'; | ||
| import Decoder from './modules/Decoder'; | ||
| import Demultiplexer from './modules/Demultiplexer'; | ||
| import DigitalLed from './modules/DigitalLed'; | ||
| import Flag from './modules/Flag'; | ||
| import Ground from './modules/Ground'; | ||
| import HexDisplay from './modules/HexDisplay'; | ||
| import Input from './modules/Input'; | ||
| import LSB from './modules/LSB'; | ||
| import MSB from './modules/MSB'; | ||
| import Multiplexer from './modules/Multiplexer'; | ||
| import NandGate from './modules/NandGate'; | ||
| import NorGate from './modules/NorGate'; | ||
| import NotGate from './modules/NotGate'; | ||
| import OrGate from './modules/OrGate'; | ||
| import Output from './modules/Output'; | ||
| import Power from './modules/Power'; | ||
| import PriorityEncoder from './modules/PriorityEncoder'; | ||
| import Random from './modules/Random'; | ||
| import Rectangle from './modules/Rectangle'; | ||
| import RGBLed from './modules/RGBLed'; | ||
| import RGBLedMatrix from './modules/RGBLedMatrix'; | ||
| import SevenSegDisplay from './modules/SevenSegDisplay'; | ||
| import SixteenSegDisplay from './modules/SixteenSegDisplay'; | ||
| import Splitter from './modules/Splitter'; | ||
| import SquareRGBLed from './modules/SquareRGBLed'; | ||
| import Stepper from './modules/Stepper'; | ||
| import Text from './modules/Text'; | ||
| import TriState from './modules/TriState'; | ||
| import Tunnel from './modules/Tunnel'; | ||
| import TwoComplement from './modules/TwoComplement'; | ||
| import VariableLed from './modules/VariableLed'; | ||
| import XnorGate from './modules/XnorGate'; | ||
| import XorGate from './modules/XorGate'; | ||
| import Clock from './sequential/Clock'; | ||
| import DflipFlop from './sequential/DflipFlop'; | ||
| import Dlatch from './sequential/Dlatch'; | ||
| import EEPROM from './sequential/EEPROM'; | ||
| import JKflipFlop from './sequential/JKflipFlop'; | ||
| import Keyboard from './sequential/Keyboard'; | ||
| import RAM from './sequential/RAM'; | ||
| import Rom from './sequential/Rom'; | ||
| import SRflipFlop from './sequential/SRflipFlop'; | ||
| import TflipFlop from './sequential/TflipFlop'; | ||
| import TTY from './sequential/TTY'; | ||
| import ForceGate from './sequential/ForceGate'; | ||
| import TB_Input from './testbench/testbenchInput'; | ||
| import TB_Output from './testbench/testbenchOutput'; | ||
| import verilogMultiplier from './modules/verilogMultiplier'; | ||
| import verilogDivider from './modules/verilogDivider'; | ||
| import verilogPower from './modules/verilogPower'; | ||
| import verilogShiftLeft from './modules/verilogShiftLeft'; | ||
| import verilogShiftRight from './modules/verilogShiftRight'; | ||
| import verilogRAM from './sequential/verilogRAM'; | ||
|
|
||
| // Define an interface for the module set to provide type safety | ||
| interface ModuleSet { | ||
| [key: string]: any; | ||
| } | ||
|
|
||
| export default function setupModules(): void { | ||
| const moduleSet: ModuleSet = { | ||
| AndGate, | ||
| Random, | ||
| NandGate, | ||
| Counter, | ||
| Multiplexer, | ||
| XorGate, | ||
| XnorGate, | ||
| SevenSegDisplay, | ||
| SixteenSegDisplay, | ||
| HexDisplay, | ||
| OrGate, | ||
| Stepper, | ||
| NotGate, | ||
| Text, | ||
| TriState, | ||
| Buffer, | ||
| ControlledInverter, | ||
| Adder, | ||
| verilogMultiplier, | ||
| verilogDivider, | ||
| verilogPower, | ||
| verilogShiftLeft, | ||
| verilogShiftRight, | ||
| TwoComplement, | ||
| Splitter, | ||
| Ground, | ||
| Power, | ||
| Input, | ||
| Output, | ||
| BitSelector, | ||
| ConstantVal, | ||
| NorGate, | ||
| DigitalLed, | ||
| VariableLed, | ||
| Button, | ||
| RGBLed, | ||
| SquareRGBLed, | ||
| Demultiplexer, | ||
| Decoder, | ||
| Flag, | ||
| MSB, | ||
| LSB, | ||
| PriorityEncoder, | ||
| Tunnel, | ||
| ALU, | ||
| Rectangle, | ||
| Arrow, | ||
| ImageAnnotation, | ||
| RGBLedMatrix, | ||
| TflipFlop, | ||
| DflipFlop, | ||
| Dlatch, | ||
| SRflipFlop, | ||
| JKflipFlop, | ||
| TTY, | ||
| Keyboard, | ||
| Clock, | ||
| Rom, | ||
| EEPROM, | ||
| RAM, | ||
| verilogRAM, | ||
| TB_Input, | ||
| TB_Output, | ||
| ForceGate, | ||
| }; | ||
|
|
||
| Object.assign(modules, moduleSet); | ||
| } | ||
|
Comment on lines
+72
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and consider immutability. The current implementation has several potential improvements:
export default function setupModules(): void {
if (!modules) {
throw new Error('Modules registry is not initialized');
}
// ... rest of the function
}
export default function setupModules(): Record<string, SimulatorModule> {
return { ...modules, ...moduleSet };
}
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Strengthen type safety by avoiding 'any'.
The current interface uses
anywhich negates TypeScript's type checking benefits. Consider creating a base interface for modules and using it as the value type: