Skip to content

feat: support comparison and logical operators with short-circuiting#3

Open
hand-burger wants to merge 3 commits into
AdamHameed:mainfrom
hand-burger:feature/operators
Open

feat: support comparison and logical operators with short-circuiting#3
hand-burger wants to merge 3 commits into
AdamHameed:mainfrom
hand-burger:feature/operators

Conversation

@hand-burger

Copy link
Copy Markdown

Summary of Changes

This PR adds support for all C relational, equality, and logical operators, complete with short-circuiting logic in code generation.

  1. New Operators Added:
    • Comparison: == (Equal), != (NotEqual), < (LessThan), <= (LessEqual), > (GreaterThan), >= (GreaterEqual).
    • Unary Logical: ! (LogicalNot).
    • Binary Logical: && (LogicalAnd), || (LogicalOr).
  2. Lexer Upgrades: Added matching for compound tokens (==, !=, <=, >=, &&, ||) and single character operators (<, >, !).
  3. Parser Upgrades: Updated the recursive descent precedence levels to match C standard priority:
    parse_expressionLogicalOrLogicalAndEqualityRelationalAdditiveMultiplicativeUnaryPrimary.
  4. LLVM Codegen & Short-Circuiting:
    • Lowered comparisons using LLVM icmp instruction and zero-extended (zext) the resulting i1 type back to standard i32 to match C's boolean integer mapping.
    • Implemented control flow branching (using Basic Blocks and phi nodes) to support standard short-circuit evaluation for && and ||.
  5. Testing: Implemented unit tests for lexer, parser, and codegen, as well as comprehensive integration tests verification.

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.

1 participant