Skip to content

feat: add logical AND (&) and OR (|) operators#15

Merged
danieljohnmorris merged 3 commits into
mainfrom
feat/logical-and-or
Feb 27, 2026
Merged

feat: add logical AND (&) and OR (|) operators#15
danieljohnmorris merged 3 commits into
mainfrom
feat/logical-and-or

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

@danieljohnmorris danieljohnmorris commented Feb 27, 2026

Summary

  • Add &a b (logical AND) and |a b (logical OR) with prefix syntax
  • Both operators support short-circuit evaluation: AND skips right operand when left is falsy, OR skips when left is truthy
  • Implemented across all layers: lexer (Amp/Pipe tokens), parser, AST (BinOp::And/BinOp::Or), VM (jump-based short-circuit), interpreter, and Python codegen
  • Includes constant folding for boolean literal operands
  • 9 new tests: parser (2), interpreter (2), VM (4, including short-circuit verification), codegen (1)

Test plan

  • cargo test — all 121 tests pass
  • cargo clippy — clean
  • Parser correctly produces BinOp::And / BinOp::Or from & / | tokens
  • VM short-circuit: &false x returns false without evaluating x; |true x returns true without evaluating x
  • Interpreter short-circuit returns the determining value (not just bool), matching JS/Python semantics
  • Python codegen emits and / or keywords

…luation

Prefix syntax: &a b (AND), |a b (OR). Both short-circuit: AND skips
right operand when left is falsy, OR skips when left is truthy.
Implemented across lexer, parser, VM (jump-based), interpreter, and
Python codegen. Includes constant folding for boolean literals.
@danieljohnmorris danieljohnmorris changed the title Add logical AND & and OR | operators feat: add logical AND (&) and OR (|) operators Feb 27, 2026
@danieljohnmorris danieljohnmorris marked this pull request as ready for review February 27, 2026 11:44
@danieljohnmorris danieljohnmorris merged commit fa5cb82 into main Feb 27, 2026
@danieljohnmorris danieljohnmorris deleted the feat/logical-and-or branch February 27, 2026 12:31
danieljohnmorris added a commit that referenced this pull request May 21, 2026
feat(slc): accept end=-1 as 'to end' sugar (#15)
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