Interpreter improvements: Additional fixes and tie operator support#216
Merged
Conversation
The interpreter was calling BitwiseOperators.bitwiseAndBinary() which skips the uninitialized value warning check. Changed to call bitwiseAnd() which includes the proper warning for using undefined values in bitwise AND operations. This matches the JVM compiler behavior and aligns with Perl semantics where bitwise AND (&) should warn about uninitialized values, while bitwise OR (|) and XOR (^) should not. Impact on perl5_t/t/op/assignwarn.t with JPERL_EVAL_USE_INTERPRETER=1: - Before: 75/116 passing (64.7%) - After: 77/116 passing (66.4%) - Fixed: +2 tests (tests 28 and 58 for $x &= 1 and $x &= 'x' warnings) Remaining 39 failures are due to 'tie' operator not being implemented yet. Compiler still passes: 116/116 (100.0%) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Added support for Perl's tie(), untie(), and tied() built-in functions in the bytecode interpreter. These operators allow binding variables to package classes that provide custom implementations. Implementation: 1. Added TIE, UNTIE, TIED opcodes (238, 239, 240) to Opcodes.java 2. Updated LASTOP to 240 3. Added handlers in CompileOperator.java for "tie", "untie", "tied" 4. Added execution logic in BytecodeInterpreter.java that calls TieOperators The implementation follows the same pattern as other operators that call runtime classes, compiling arguments as a list and passing them to the appropriate TieOperators method along with the calling context. Impact on perl5_t/t/op/assignwarn.t with JPERL_EVAL_USE_INTERPRETER=1: - Before: 77/116 passing (66.4%) - tie not implemented, 39 tests failing - After: 116/116 passing (100.0%) ✓ All tests pass! - Fixed: +39 tests Compiler still passes: 116/116 (100.0%) ✓ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR continues the interpreter improvements with additional bug fixes and implements tie/untie/tied operator support. Following the merge of PR #215, this PR addresses remaining test failures and achieves 100% pass rate on multiple test files.
Key Achievements
✅ op/assignwarn.t: 100% pass rate (116/116) with interpreter - matches compiler
✅ re/regexp.t: 80.8% pass rate (1786/2210) - maintained from previous PR
✅ op/decl-refs.t: 66.7% pass rate (272/408) - 2 tests better than compiler
✅ Implemented tie/untie/tied operators - full Perl tie semantics support
Changes
1. Scalar Reference Dereference Fixes (#ebc92fa, #7f14e66)
Problem: The
${\...}syntax (inline scalar reference dereference) wasn't working in eval STRING with the interpreter.Solution:
DEREFopcode behavior by callingscalarDeref()LOAD_SYMBOLIC_SCALARto check if block result is a REFERENCE typeImpact:
re/regexp.t: Fixed test #1459 using${\(defined($1)?1:0)}op/decl-refs.t: Fixed crash with declared reference lists likemy (\$f, $g)2. Error Message Cleanup (#ad5807d)
Problem: Interpreter was adding "Interpreter error in (eval N) line X (pc=Y):" prefix to exceptions from eval'd code, breaking tests that check $@ error messages.
Solution:
Impact:
re/regexp.t: +47 tests (1738 → 1785 passing)3. matchRegex Fix (#c7920c1)
Problem: When using
$string =~ m/pattern/with interpreter, it returned the regex object instead of performing the match.Solution:
matchRegexhandler in CompileOperator.java to check if string is provided via=~bindingImpact:
re/regexp.t: +1391 tests (395 → 1786 passing)4. Bitwise AND Warning Fix (#8aed892)
Problem: Interpreter's
&=operator wasn't warning about uninitialized values.Solution:
executeBitwiseAndAssign()to callBitwiseOperators.bitwiseAnd()instead ofbitwiseAndBinary()bitwiseAnd()includes uninitialized value warning check (lines 32-39)bitwiseAndBinary()skips the check for performanceImpact:
op/assignwarn.t: +2 tests (75 → 77 passing)5. Tie/Untie/Tied Operators (#571d939)
Problem: Tie operators weren't implemented in the interpreter, causing 39 test failures.
Solution:
Features:
tie($var, $classname, @args)- Bind variable to package classuntie($var)- Break binding between variable and classtied($var)- Return object underlying tied variableImpact:
op/assignwarn.t: +39 tests (77 → 116 passing, 100%)Testing
make test)op/assignwarn.t: 116/116 (100.0%) with interpreter (was 75/116)re/regexp.t: 1786/2210 (80.8%) with interpreter (maintained)op/decl-refs.t: 272/408 (66.7%) with interpreter vs 270/408 with compiler (+2 tests better!)Detailed Impact
op/assignwarn.t - Progressive Improvement
re/regexp.t - Maintained Excellence
op/decl-refs.t - Surpassing Compiler
Technical Notes
Opcode Additions
The tie operators were added as manually-assigned opcodes (238-240) before the GENERATED_OPCODES region, following the project's convention. LASTOP was updated to 240.
Pattern Consistency
The implementation follows the established pattern of:
This ensures consistency with other operators and maintains the separation between compilation and execution logic.
🤖 Generated with Claude Code