Skip to content

Refactor tuples into typed opcode subclasses#473

Merged
bertysentry merged 3 commits into
mainfrom
470-refactor-tuple-typed-subclasses-per-opcode-for-memory-efficiency-and-code-clarity
May 11, 2026
Merged

Refactor tuples into typed opcode subclasses#473
bertysentry merged 3 commits into
mainfrom
470-refactor-tuple-typed-subclasses-per-opcode-for-memory-efficiency-and-code-clarity

Conversation

@bertysentry
Copy link
Copy Markdown
Contributor

Summary

  • Replace the monolithic Tuple storage model with typed tuple subclasses tailored to each opcode or opcode group.
  • Update AwkTuples, PositionTracker, and AVM to construct and consume the new tuple types with named accessors.
  • Reduce tuple heap footprint and remove fragile positional operand access.
  • Extract several larger opcode bodies out of executeTuples() to keep the dispatch loop smaller and friendlier to JIT optimization.
  • Add/update tuple optimization coverage in AwkTupleOptimizationTest.

Testing

  • mvn test passed.
  • mvn verify passed; the existing compatibility-suite failures remain expected and unchanged.
  • Local mandelbrot profiling and wall-clock checks showed the refactor no longer regresses performance and now outperforms the 6.3.00 baseline in the same WSL setup.

Copy link
Copy Markdown
Contributor

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

This PR refactors Jawk’s intermediate “tuple” instruction stream from a monolithic, positional-operand Tuple representation into typed opcode-specific tuple subclasses, and updates the execution/optimization code paths to use named accessors. This reduces reliance on fragile operand indexing and supports a smaller, more JIT-friendly dispatch loop in the AVM.

Changes:

  • Introduces Tuple as a typed instruction hierarchy (e.g., PushLongTuple, AddressTuple, VariableTuple, etc.) and updates tuple construction accordingly.
  • Updates PositionTracker and AVM to consume typed tuples via PositionTracker.current() and new accessors, extracting larger opcode bodies into helper methods.
  • Updates tuple optimization tests and peephole optimization logic to work with typed tuples and new index access (currentIndex()).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/test/java/io/jawk/AwkTupleOptimizationTest.java Updates tuple optimization assertions to use typed tuples and a typed literal extractor.
src/main/java/io/jawk/intermediate/Tuple.java Replaces the monolithic tuple storage with a typed tuple class hierarchy and named accessors.
src/main/java/io/jawk/intermediate/PositionTracker.java Removes positional operand accessors and exposes the current typed tuple plus currentIndex().
src/main/java/io/jawk/intermediate/AwkTuples.java Updates tuple emission and peephole folding to construct/inspect typed tuples.
src/main/java/io/jawk/backend/AVM.java Switches execution to typed tuple casts/accessors and extracts several opcode implementations into helpers.

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

Comment thread src/main/java/io/jawk/intermediate/Tuple.java
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/main/java/io/jawk/intermediate/AwkTuples.java Outdated
Comment thread src/main/java/io/jawk/intermediate/PositionTracker.java Outdated
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@bertysentry bertysentry merged commit 0d3fbd3 into main May 11, 2026
9 checks passed
@bertysentry bertysentry deleted the 470-refactor-tuple-typed-subclasses-per-opcode-for-memory-efficiency-and-code-clarity branch May 11, 2026 19:21
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.

Refactor Tuple: typed subclasses per opcode for memory efficiency and code clarity

2 participants