Skip to content

refactor: Split BytecodeCompiler and fix glob slot access#213

Merged
fglock merged 1 commit into
masterfrom
fix/test-regressions
Feb 19, 2026
Merged

refactor: Split BytecodeCompiler and fix glob slot access#213
fglock merged 1 commit into
masterfrom
fix/test-regressions

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Feb 19, 2026

Summary

This PR includes two improvements to the interpreter:

  1. Fix glob slot access (*X{HASH}): Interpreter now correctly handles glob slot access like *X{HASH} in eval STRING, matching baseline compiler behavior
  2. Refactor BytecodeCompiler: Split large BytecodeCompiler class into focused, maintainable classes

Changes

Glob Slot Access Fix

  • Added GLOB_SLOT_GET opcode (230) for direct glob slot access
  • Modified handleGeneralHashAccess() to detect *X{key} patterns
  • Implemented executeGlobSlotGet() in SlowOpcodeHandler
  • Test improvement: re/reg_namedcapture.t now 1/2 passing (was 0/2)

BytecodeCompiler Refactoring

Extracted compilation logic into specialized classes:

  • CompileOperator: Operator compilation (die, eval, require, package, etc.)
  • CompileBinaryOperator: Binary operator compilation (and/or, ternary, etc.)
  • CompileBinaryOperatorHelper: Helper methods for binary operators
  • CompileAssignment: Assignment and declaration compilation

Changed private fields to package-private for refactored class access:

  • symbolTable, sourceName, sourceLine
  • bytecode, variableScopes, allDeclaredVariables, capturedVarIndices

Code Organization

  • BytecodeCompiler reduced from ~9700 lines to ~4000 lines
  • New classes total ~4700 lines with clear responsibilities
  • Same bytecode generation behavior, improved maintainability

Test Results

  • ✓ All unit tests pass
  • ✓ Compilation succeeds
  • ✓ re/reg_namedcapture.t: 0/2 → 1/2 passing

🤖 Generated with Claude Code

Extracted compilation logic into separate, focused classes:
- CompileOperator: Handles operator compilation (die, eval, require, package, etc.)
- CompileBinaryOperator: Handles binary operator compilation (and/or, ternary, etc.)
- CompileBinaryOperatorHelper: Helper methods for binary operator compilation
- CompileAssignment: Handles assignment and declaration compilation

Changed private fields to package-private to allow refactored classes access:
- symbolTable, sourceName, sourceLine
- bytecode, variableScopes, allDeclaredVariables
- capturedVarIndices

This refactoring improves maintainability by organizing code by responsibility
while maintaining the same bytecode generation behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fglock fglock merged commit 12b84e7 into master Feb 19, 2026
2 checks passed
@fglock fglock deleted the fix/test-regressions branch February 19, 2026 17:46
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