Skip to content
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

Added Subtractor Component to misc menu #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shivamsahu-tech
Copy link

@shivamsahu-tech shivamsahu-tech commented Mar 9, 2025

Fixes #516 - Add Subtractor Module in Misc Menu

Summary of Changes:

  • Implemented Subtractor.js in v0/src/simulator/src/modules.
  • Registered the Subtractor module in moduleSetup.js (v0/src/simulator/src/moduleSetup.js).
  • Updated metadata.json (v0/src/simulator/src/metadata.json) to include the Subtractor.
  • Added relevant images for Adder & Subtractor in:
    • v0/src/assets/img
    • v0/src/simulator/src/img

Screenshots & Testing:

Screenshot:

Screenshot

🎥 Testing Video: Watch here

Additional Notes:

✔ Code follows project structure and conventions.
✔ Fully tested to ensure correct functionality.
✔ Please check "Allow edits from maintainers" for any required refinements.

Looking forward to your feedback! 🚀

Summary by CodeRabbit

  • New Features
    • Introduced a new simulation element, "Subtractor", which performs subtraction operations with configurable bit width and borrow handling.
    • Integrated the new element into the simulation environment, expanding available circuit components for enhanced simulation capabilities.

Copy link
Contributor

coderabbitai bot commented Mar 9, 2025

Walkthrough

This update integrates a new circuit element named "Subtractor" into the simulator. The configuration file now includes the element in both the available element list and the hierarchy under the "Misc" category. In addition, the module setup file has been updated to import and register the new Subtractor, and a dedicated module file implements its class with methods to handle resolution, bit width adjustments, and Verilog code generation.

Changes

File(s) Change Summary
v0/src/simulator/src/{metadata.json, moduleSetup.js} Declarations updated to include "Subtractor": added to the circuitElementList, included in elementHierarchy, imported in module setup, and added to the moduleSet export.
v0/src/simulator/src/modules/Subtractor.js New Subtractor class created (extending CircuitElement), with methods for initialization, saving state, input resolution, subtraction computation, and Verilog generation.

Sequence Diagram(s)

sequenceDiagram
    participant S as Simulator
    participant M as ModuleSetup
    participant SB as Subtractor
    S->>M: Initialize module set
    M->>SB: Import & register Subtractor
    S->>SB: Create Subtractor instance
    SB->>SB: Validate inputs (isResolvable)
    SB->>SB: Compute subtraction (resolve)
    SB-->>S: Return computed outputs
Loading

Poem

Oh, I’m a rabbit with a digital cheer,
Hopping through circuits far and near.
A brand-new Subtractor is here to play,
Calculating bits in a whimsical way.
Carrots and code in a joyful display—
Hooray for this change on our circuit highway!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Mar 9, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit eb93a96
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/67cdc40ed2e04200080d03f4
😎 Deploy Preview https://deploy-preview-517--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 42
Accessibility: 72
Best Practices: 92
SEO: 80
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
v0/src/simulator/src/modules/Subtractor.js (2)

76-93: Improve the borrowOut calculation in the Verilog output

The resolve method correctly handles the subtraction logic, borrow-in, and borrow-out calculations. However, the borrow-out signal is not included in the Verilog code generation method below.


95-100: Include borrowOut in Verilog generation

The generateVerilog method only generates code for the difference output but not for the borrowOut signal. Consider adding Verilog code to handle the borrowOut signal as well.

 generateVerilog() {
     if (this.borrowIn.verilogLabel) {
-        return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel} - ${this.borrowIn.verilogLabel};`;
+        return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel} - ${this.borrowIn.verilogLabel};
+assign ${this.borrowOut.verilogLabel} = (${this.inpA.verilogLabel} < ${this.inpB.verilogLabel} + ${this.borrowIn.verilogLabel});`;
     }
-    return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel};`;
+    return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel};
+assign ${this.borrowOut.verilogLabel} = (${this.inpA.verilogLabel} < ${this.inpB.verilogLabel});`;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9f309 and eb93a96.

⛔ Files ignored due to path filters (4)
  • v0/src/assets/img/Adder.svg is excluded by !**/*.svg
  • v0/src/assets/img/Subtractor.svg is excluded by !**/*.svg
  • v0/src/simulator/src/img/Adder.svg is excluded by !**/*.svg
  • v0/src/simulator/src/img/Subtractor.svg is excluded by !**/*.svg
📒 Files selected for processing (3)
  • v0/src/simulator/src/metadata.json (2 hunks)
  • v0/src/simulator/src/moduleSetup.js (2 hunks)
  • v0/src/simulator/src/modules/Subtractor.js (1 hunks)
🔇 Additional comments (8)
v0/src/simulator/src/metadata.json (2)

24-24: LGTM: Subtractor element added to circuitElementList

The Subtractor element has been correctly added to the circuit element list, positioned logically after the Adder element.


165-165: LGTM: Subtractor added to Misc category hierarchy

The Subtractor element has been correctly added to the "Misc" category in the element hierarchy with appropriate name and label properties, positioned logically after the Adder element.

v0/src/simulator/src/moduleSetup.js (2)

3-3: LGTM: Subtractor module import added

The Subtractor module import has been correctly added, following a logical order after the Adder import.


88-88: LGTM: Subtractor added to moduleSet

The Subtractor has been correctly added to the moduleSet object, maintaining the same ordering as the imports.

v0/src/simulator/src/modules/Subtractor.js (4)

17-30: LGTM: Subtractor class structure and initialization

The Subtractor class extends CircuitElement appropriately and initializes with the correct parameters and node structure. The implementation follows the project's conventions for circuit elements.


37-49: LGTM: Proper customSave implementation

The customSave method correctly saves the constructor parameters and node references, following the pattern established by other circuit elements.


56-58: LGTM: Correct resolvability check

The isResolvable method correctly checks that both input values are defined before attempting to resolve the subtractor.


65-70: LGTM: Proper bitWidth handling

The newBitWidth method correctly updates the bitWidth for the element and its input/output nodes.

Comment on lines +109 to +111
Subtractor.prototype.tooltipText = 'Subtractor ToolTip : Performs subtraction of numbers.';
Subtractor.prototype.helplink = 'https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor';
Subtractor.prototype.objectType = 'Subtractor';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify documentation link

The helplink points to a specific URL that might not exist yet. Please ensure the documentation for the Subtractor component exists at this location or update the URL accordingly.


🌐 Web query:

Does the page https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor exist and contain documentation for the Subtractor component?

💡 Result:

The page https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor does not appear to exist in the provided documentation. While CircuitVerse's documentation ([2]) covers general usage of the simulator and digital circuit concepts, none of the search results reference this specific URL or confirm the existence of a dedicated "Subtractor" component documentation section at this address.

However, multiple CircuitVerse projects ([1][3][4][5][9][11]) demonstrate subtractor implementations (half/full subtractors, 2-bit to 8-bit variants) with detailed explanations of their logic equations, truth tables, and circuit designs. For example:

  • Full subtractors use SOP forms like Diff=xy' z'+x' y' z+xyz+x'yz' and Borrow=x' z+x' y+yz [1][4]
  • 4-bit adder-subtractor circuits implement two's complement subtraction through XOR gates and controlled inversion [3][5]

For official documentation, the main CircuitVerse docs ([2][6]) remain the primary resource, though subtractor-specific guidance would need to be inferred from general circuit design principles and community project examples.

Citations:


Action Required: Update the Subtractor Documentation URL

The current helplink property in v0/src/simulator/src/modules/Subtractor.js (lines 109-111) points to:

https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor

However, our verification indicates that this URL does not exist in the CircuitVerse documentation. Please update the URL to point to valid and relevant documentation for the Subtractor component, or remove it if no dedicated documentation is available.

  • File: v0/src/simulator/src/modules/Subtractor.js
  • Lines: 109-111
  • Issue: Invalid documentation link for the Subtractor component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Subtractor as a Core Logical Tool in Misc Menu
1 participant