Skip to content

Add mirror | and invert - operators with stacking (i#)#7

Open
jawhitti wants to merge 1 commit into
masterfrom
mirror-mirror-on-wall
Open

Add mirror | and invert - operators with stacking (i#)#7
jawhitti wants to merge 1 commit into
masterfrom
mirror-mirror-on-wall

Conversation

@jawhitti
Copy link
Copy Markdown
Owner

Summary

  • Add two new unary operators: | (staple/horizontal mirror — bit reversal) and - (worm/vertical mirror — ones' complement)
  • Enable stacking of all six unary operators in any order, evaluated right-to-left (e.g., '&-|?.1')
  • Refactor parser from single unary op to list-based stacking across all three expression contexts
  • 30 new tests covering runtime math, tokenization, parsing, commutativity, and identity cases

Why

  • - (invert) gives INTERCAL a primitive it never had — ones' complement — simplifying the syslib subtract routine from ~40 lines to 3
  • | (mirror) enables MSB-first bit iteration, which unblocks integer division in the syslib
  • Together they complete the path to division and modulo, giving INTERCAL all four basic arithmetic operations
  • |-|- is identity, which means # has always been two staples and two worms. The mesh symbol knew all along.

Test plan

  • All 156 existing tests still pass
  • 30 new tests for Mirror16/32/64, Invert16/32/64, commutativity, identity, tokenization, and parsing
  • Manual test: compile a program using #|1 and #-1
  • Manual test: compile stacked operators like #-|5

🤖 Generated with Claude Code

Introduce two new unary operators:
- | (horizontal mirror / staple): bit-reversal within variable width
- - (vertical mirror / worm): ones' complement (bit inversion)

These are perpendicular mirrors — | reflects left-right, - reflects top-bottom.
They commute, and |-|- is identity, which means # has always been |-|-.

All six unary operators (& V v ? | -) can now be stacked in any order,
evaluated right-to-left (e.g., '&-|?.1'). Parser refactored from single
unary op to list-based stacking across all three expression contexts.

Enables future syslib division (| for MSB-first iteration, - for
complement in subtraction) — completing INTERCAL's four basic arithmetic ops.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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