Skip to content

Add six equality operators.#3

Open
NeilFraser wants to merge 1 commit intomainfrom
Comparison
Open

Add six equality operators.#3
NeilFraser wants to merge 1 commit intomainfrom
Comparison

Conversation

@NeilFraser
Copy link
Owner

An interesting and flexible way to do ==, !=, <, >, <=, and >= comparison operators.
Fully tested.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a small set of stack-based comparison helpers to the Apps/Blockly.agc runtime so Blockly-generated programs can implement ==, !=, <, >, <=, >= via simple chained TCR calls.

Changes:

  • Added OP-EQ plus suffix helpers (OP-LTE, OP-GTE, OP-NEG) to implement all six comparison operators.
  • Introduced DROP as a companion to POP for stack manipulation.
  • Renamed the T4 interrupt wakeup label to T4WAKEUP and tightened a couple of inline comments in SLEEP.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +188 to +190
# The six equality operators start by pushing two values on the stack.
# Then several chained calls are made depending on which operator is needed.
# In all cases, if 0 is returned on the A register, then the operator is true.
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The operator usage docs are ambiguous about operand order and return shape. Since OP-EQ pops the second value first and reads the first from the stack, please explicitly document the required push order (e.g., push first operand, then push second operand). Also consider clarifying that OP-EQ returns a signed difference (not strictly 0/1), while the suffix operators normalize to 0 (true) / 1 (false).

Suggested change
# The six equality operators start by pushing two values on the stack.
# Then several chained calls are made depending on which operator is needed.
# In all cases, if 0 is returned on the A register, then the operator is true.
# The six equality operators start by pushing two values on the stack:
# push first operand, then push second operand.
# OP-EQ will pop the second value first, then the first value, and return
# the signed difference (first - second) in the A register. This value is
# not itself normalized to 0/1.
# The suffix operators (OP-NEG, OP-LTE, OP-GTE) then interpret that signed
# difference and normalize the result to 0 (true) or 1 (false). Callers of
# the composite operators should rely on this convention: if 0 is returned
# in the A register, then the operator is true; if 1 is returned, it is false.

Copilot uses AI. Check for mistakes.
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.

2 participants