Skip to content

Feat(#250): Implement bitwise operators (&,|,^,~,<<,>>)#257

Draft
AryanBhirud wants to merge 2 commits intoarxlang:mainfrom
AryanBhirud:main
Draft

Feat(#250): Implement bitwise operators (&,|,^,~,<<,>>)#257
AryanBhirud wants to merge 2 commits intoarxlang:mainfrom
AryanBhirud:main

Conversation

@AryanBhirud
Copy link
Copy Markdown

Notes

  • This repository uses an AI bot for reviews. Keep your PR in Draft while
    you work. When you’re ready for a review, change the status to Ready for
    review
    to trigger a new review round. If you make additional changes and
    don’t want to trigger the bot, switch the PR back to Draft.
  • AI-bot comments may not always be accurate. Please review them critically and
    share your feedback; it helps us improve the tool.
  • Avoid changing code that is unrelated to your proposal. Keep your PR as short
    as possible to increase the chances of a timely review. Large PRs may not be
    reviewed and may be closed.
  • Don’t add unnecessary comments. Your code should be readable and
    self-documenting
    (guidance).
  • Don’t change core features without prior discussion with the community. Use
    our Discord to discuss ideas, blockers, or issues
    (https://discord.gg/Nu4MdGj9jB).
  • Do not include secrets (API keys, tokens, passwords), credentials, or
    sensitive data/PII in code, configs, logs, screenshots, or commit history. If
    something leaks, rotate the credentials immediately, invalidate the old key,
    and note it in the PR so maintainers can assist.
  • Do not commit large binaries or generated artifacts. If large datasets are
    needed for tests, prefer small fixtures or programmatic downloads declared in
    makim.yaml (e.g., a task that fetches data at test time). If a large binary is
    unavoidable, discuss first and consider Git LFS.

Pull Request description

Solves #250

How to test these changes

  • ...

Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more
    complexity.
  • New and old tests passed locally.

Additional information

Reviewer's checklist

Copy and paste this template for your review's note:

Reviewer's Checklist

  • I managed to reproduce the problem locally from the main branch
  • I managed to test the new changes locally
  • I confirm that the issues mentioned were fixed/resolved .

(astx.Int32, astx.LiteralInt32),
(astx.Int16, astx.LiteralInt16),
(astx.Int8, astx.LiteralInt8),
(astx.Int64, astx.LiteralInt64),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add float here too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm afraid I don't think python supports bitwise operators for floats

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@AryanBhirud you are right that bitwise operators don't apply to floats but i guess @yuvimittal meant adding unsigned integer types here? e.g. (astx.UInt8, astx.LiteralUInt8),(astx.UInt16, astx.LiteralUInt16), etc. That would also help catch the >> signed vs unsigned behavior, since ashr and lshr produce different results

@Jaskirat-s7
Copy link
Copy Markdown
Contributor

Hey @AryanBhirud, nice work on implementing all six bitwise operators! A few things I noticed:

1.first is that >> should use lshr for unsigned types — Right now it always uses ashr (arithmetic shift right), which preserves the sign bit. For unsigned integers it should use lshr (logical shift right). You can check _is_unsigned_node(node) the same way the / operator does (line ~1236 on main).

2.the second thing i noticed is missing float guard that is If someone accidentally passes float operands to &, |, etc., LLVM will crash. The other arithmetic ops (+, -, *) check is_fp_type() before dispatching,it might be good to add an early error like raise Exception("Bitwise operators are not supported for float types.").
Looks great overall, just these small things

@xmnlab
Copy link
Copy Markdown
Contributor

xmnlab commented Apr 1, 2026

@AryanBhirud it seems I cannot push changes to your branch .. maybe because you are working on a branch called "main", which usually we don't do.
please rebase your branch on top of the upstream/main.

I like the ideas @Jaskirat-s7 mentioned. please implement that. in a very near future we should move this kind of validation to the semantic layer. which we don't have yet.

@xmnlab xmnlab marked this pull request as draft April 1, 2026 04:48
@AryanBhirud
Copy link
Copy Markdown
Author

i was stuck up with some other work this past week so I couldn't get the changes done, I'll get started on them this week 👍🏻

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.

4 participants