Fix caller() and support local with method chain lvalues in interpreter#306
Merged
Conversation
5673ea9 to
674e132
Compare
The interpreter's caller() function was returning incorrect stack frames in two scenarios: 1. For regular subroutine calls (main calls outer() calls inner()), caller() returned no frames because all BytecodeInterpreter.execute frames were consecutive and the previous fix treated them as one call. 2. For use/require with import(), the stack order was wrong - the CallerStack entry (from parseUseDeclaration) was being added after interpreter frames instead of at the correct position. Fix: Use InterpretedCode.apply as the boundary marker. Each apply() call marks the END of a Perl subroutine execution. Multiple execute() frames within an apply() share one interpreter frame. Key changes to ExceptionFormatter.formatException(): - Track addedFrameForCurrentLevel flag - Only add one interpreter frame per call level - When we see InterpretedCode.apply, increment to next frame index - For innermost frame (index 0), use runtime currentPackage to reflect package declarations that executed at runtime Now both test cases work correctly: - Regular sub calls: caller(0)=main, caller(1)=main, depth=1 - use/import: caller(0)=NestedInstance, caller(1)=main Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
674e132 to
01eb2c6
Compare
Extend interpreter to handle `local $obj->method->{key}` syntax:
- BytecodeCompiler.java: Accept any BinaryOperatorNode as a general
fallback for local operands, matching JVM backend behavior
- CompileAssignment.java: Handle any BinaryOperatorNode for local
assignment expressions like `local $obj->method->{key} = value`
Both changes align with EmitOperatorLocal.java approach: compile
the lvalue expression and call pushLocalVariable on the result.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <noreply@cognition.ai>
01eb2c6 to
5506fe2
Compare
4 tasks
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 contains two related fixes for the bytecode interpreter:
Fix 1: caller() returning incorrect frames
The interpreter's
caller()function was returning incorrect stack frames, breaking Exporter and causing all ExifTool tests to fail with "Symbol not allowed for export" errors.Changes:
InterpretedCode.applyas the boundary marker for Perl call levelsaddedFrameForCurrentLevelflag to add only one interpreter frame per call levelcurrentPackageto reflectpackage Foo;declarationsFix 2: Support
local $obj->method->{key}syntaxExtend interpreter to handle localizing hash/array elements accessed through method chains.
Changes:
BinaryOperatorNodeas a general fallback forlocaloperandsBinaryOperatorNodefor local assignment expressionsBoth changes align with the JVM backend's behavior in
EmitOperatorLocal.java.Test Plan
./gradlew testpassesuse Test::Moreworks in interpreter modelocal $obj->hub->{ended} = 99works correctlyGenerated with Devin