Skip to content

Conversation

old-thug
Copy link

This pull request adds support for short-circuit logical operators to the B compiler for the gas_x86_64 target:
Implemented Binop::LogAnd (&&) and Binop::LogOr (||) in the parser and lexer.
Updated code generation to support short-circuit evaluation:
LogOr evaluates the right-hand side only if the left-hand side is false.
LogAnd evaluates the right-hand side only if the left-hand side is true.
Includes appropriate unique branch labels to avoid collisions.
Fully tested with basic expressions (0 || 0, 1 || 0, 0 || 1, 1 && 0, etc.).

@yui-915
Copy link
Contributor

yui-915 commented Oct 12, 2025

I think making it compile to jumps at the IR level would be better, especially so that it wouldn't require special assembly for each target.

@old-thug
Copy link
Author

I think making it compile to jumps at the IR level would be better, especially so that it wouldn't require special assembly for each target.

i didn't know that. i guess i'll check it out then

@yui-915
Copy link
Contributor

yui-915 commented Oct 12, 2025

check the implementation of the ternary operator, it's also short-circuiting and it uses jumps instead of a special Op. 😄

intermediate representation, so they now work for all targets
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.

3 participants