Implement Perl defer blocks (use feature 'defer')#301
Merged
Conversation
7d29419 to
b2f114c
Compare
Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
## defer blocks (use feature 'defer')
- Implement defer statement for scope-exit code execution
- DeferBlock class wraps code ref for DynamicVariableManager cleanup
- Defer blocks capture enclosing @_ (Perl semantics)
- Exception-safe: last exception wins when multiple defers throw
- Compile-time checks prevent return/goto/last/next/redo in defer
- Same checks added for finally blocks
## goto &sub tail call fixes
- Fix goto &sub to run defer/local cleanup before tail call
- Fix goto &sub in both JVM and interpreter backends
- Fix goto &{expr} symbolic code dereference
- Add TAILCALL trampoline for goto &sub in __WARN__/__DIE__ handlers
- Check AUTOLOAD before throwing undefined subroutine error
- Improve error messages for undefined subroutines
## Interpreter parity fixes
- Add interpreter fallback for ASM frame computation failures
- Fix bitwise ops (|=, ^=) to use polymorphic methods
- Fix bitwise complement (~) operator
- Fix tied() in scalar context
- Fix vec lvalue support
- Fix hash/array slice assignment with PerlRange values
- Add kill operator
## Other fixes
- Fix eval not catching exceptions from defer blocks
- Fix #line directive for warn/die location messages
- Fix undefined subroutine error message format
## Documentation
- Update debugging skills with critical reminders
- Add regression tracking to AGENTS.md
- Document eval STRING uses interpreter by default
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <noreply@cognition.ai>
80cb79b to
67c5ee0
Compare
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
Implements Perl's
deferstatement fromuse feature 'defer', which schedules code blocks to run at scope exit in LIFO order.Key Changes
DynamicStateto integrate with DynamicVariableManager cleanupparseDeferStatement()in StatementParser, registered via StatementResolverBug Fixes
goto &sub fixes
goto &subintoreturn &sub(@_), causingreturn inner()to be wrongly detected as a tail call. Now properly producesgotooperator.goto &{"subname"}(symbolic code dereference) was calling the function and using the return value as goto target instead of performing a tail call. AddedhandleGotoSubroutineBlock()in EmitControlFlow.java and corresponding support in interpreter.goto &subwith undefined subroutines.Interpreter parity fixes
tied()was used inside a ternary operator, the interpreter crashed with ClassCastException.veccase in CompileAssignment.java for interpreter support.bitwiseOr/bitwiseXorinstead of numeric-only ops.Test Results
Regression Analysis
All reported regressions have been investigated:
Known Limitations
last,next,redodon't trigger defer cleanup when jumping out of scope (documented in test)Test plan
./gradlew test)Generated with Devin