Implement interpreter array operators and fix type conversions#198
Merged
Implement interpreter array operators and fix type conversions#198
Conversation
…RAY_GET/ARRAY_SIZE enhancements - Add POW_SCALAR (22) opcode for exponentiation operator (**) - Fix ARRAY_SIZE to return count for RuntimeList instead of last element - Fix ARRAY_GET to handle both RuntimeArray and RuntimeList - Fix SLOWOP_LIST_SLICE_FROM to read correct number of shorts (2 instead of 4) - Add disassembler support for SCALAR_TO_LIST, LIST_TO_SCALAR, POW_SCALAR, and SLOWOP_LIST_SLICE_FROM - Improve interpreter error formatting to show PC and token index Progress: 3 subtests of demo.t now pass completely (26 tests passing) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eeMap Track line numbers like Perl codegen does: - Add line number tracking at each statement in BlockNode visitor - Use TreeMap for pcToTokenIndex (instead of HashMap) to enable floorEntry lookup - Use floorEntry to find nearest token index when exact PC match not found - Pass ErrorMessageUtil through InterpretedCode for line number conversion Error messages now show accurate source line numbers: Before: "Interpreter error in demo.t:1 at pc=724" and "demo.t:1446" After: "Interpreter error in demo.t line 112 (pc=724)" All line numbers are now within the actual file size and point to the correct source lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Make JOIN opcode handle non-scalar separators by converting to scalar - Make PRINT and SAY opcodes handle RuntimeArray in addition to RuntimeList/RuntimeScalar - Add ClassCastException handler to show bytecode context around errors - Display bytecode hex dump (10 bytes before, 5 after) to help debug opcode issues Error messages now show: - Bytecode context: [ ... >>> AE <<< ... ] - Helps identify undefined opcodes or PC misalignment issues Progress: 3 subtests passing (26/26 tests), working on opcode 0xAE issue Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rands - Add auto-conversion to scalar for all comparison operators (==, !=, <, >, <=>, cmp) - Implement missing COMPARE_STR (cmp) opcode in BytecodeInterpreter - Fix STORE_GLOBAL_SCALAR to convert non-scalar values before storing - All comparison operators now handle RuntimeArray/RuntimeList by converting to scalar This fixes the ClassCastException when comparing non-scalar values: - `keys %hash == 2` now works (keys returns array, converted to count for comparison) - String interpolation with arrays now works correctly Test Results: ✅ Subtest 1: Variable assignment (2/2) ✅ Subtest 2: List assignment in scalar context (13/13) ✅ Subtest 3: List assignment with lvalue array/hash (16/16) ✅ Subtest 4: Basic syntax tests ✅ Subtest 6: Map tests (2/2) ✅ Subtest 7: Grep tests (2/2)⚠️ Subtest 8: Sort tests (4/5 - one sort without block issue) ✅ Subtest 9: Object tests (2/2) Total: ~50+ tests passing (major progress from 26!) 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 implements missing Perl operators and features in the PerlOnJava interpreter, enabling complex test suites to run. Major focus on array/hash operations, type conversions, and error reporting.
Key Features Implemented
Operators (17 new)
($a, $b) = @arraywith proper scalar context@$arrayrefmy ($x, $y)Type System Improvements
Error Reporting
Bug Fixes
Test Results
Before: 0 tests passing in demo.t
After: 50+ tests passing (7+ subtests complete)
Benchmark Results
50 million iteration loop comparison:
Performance: Interpreter is ~7-10x slower than compiled mode, which is acceptable for debugging/development use cases.
Technical Details
Line Number Tracking
Implemented statement-level tracking in BlockNode visitor, matching codegen's approach:
Type Conversions
Consistent pattern across all operators:
Bytecode Architecture
rd = rs1 op rs2Performance Impact
Related Issues
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com