Fix interpreter eval regressions: compound assign, package block restore, bare block#236
Merged
Merged
Conversation
…restore
- BytecodeCompiler.handleCompoundAssignment: strip sigil before normalizeVariableName
for LOAD_GLOBAL_SCALAR, so e.g. '$x += 1' loads 'main::x' not 'main::$x'
Also remove redundant STORE_GLOBAL_SCALAR (LOAD loads live object, mutated in-place)
Fixes: $x += 1, $x .= 'a' etc in eval STRING (comp/package_block.t 1-3,5)
- Add GET_LOCAL_LEVEL opcode (341): saves DynamicVariableManager.getLocalLevel() to register
- StatementParser: set isScoped annotation on packageNode for 'package Foo { }' blocks
- BlockNode.visit(): detect scoped package first-child, bracket with GET_LOCAL_LEVEL +
POP_LOCAL_LEVEL so PUSH_PACKAGE is restored after block exits
Fixes: runtime package restore after 'package Foo { }' in eval STRING
Fixes: eval("__PACKAGE__") returns correct value inside/outside package blocks
- EvalStringHandler: use InterpreterState.currentPackage (runtime) not compilePackage
for the inner eval compile context, so eval("__PACKAGE__") reflects call-site package
Files changed:
BytecodeCompiler.java, BytecodeInterpreter.java, InterpretedCode.java,
Opcodes.java, EvalStringHandler.java, StatementParser.java
- CompileAssignment: add 'state' alongside 'my' in all assignment LHS checks Fixes: op/state.t test 1 (CORE::state outside feature.pm scope) - Add LOCAL_GLOB opcode (342): localizes a typeglob via DynamicVariableManager BytecodeCompiler: handle 'local *GLOB' in the local operator switch BytecodeInterpreter + InterpretedCode: add handler + disassembler case Fixes: local *STDOUT (and similar) in eval STRING (op/yadayada.t 31-34) - Add FLIP_FLOP opcode (343): ScalarFlipFlopOperator.evaluate(id, left, right) CompileBinaryOperatorHelper: add '...' case, allocate per-call-site flipFlopId BytecodeInterpreter + InterpretedCode: add handler + disassembler case Fixes: '...' flip-flop operator in eval STRING (op/yadayada.t)
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
Fixes multiple regressions when
JPERL_EVAL_USE_INTERPRETER=1is enabled.Changes
1. For3Node bare block value propagation (BytecodeCompiler)
eval '{ q,bar, }'etc returned undef —isSimpleBlockpath always setlastResultReg=-12. DO_FILE opcode (Opcodes, CompileOperator, BytecodeInterpreter)
do FILEinside eval STRING threw "Unsupported operator: doFile"3. LValueVisitor check on ListNode LHS (CompileAssignment)
eval q{($a ? $x : ($y)) = 5}silently succeeded instead of throwing4. Compound assignment for global vars (BytecodeCompiler.handleCompoundAssignment)
$x += 1/$x .= 'a'in eval STRING loaded wrong global (name included sigil)5. Package block runtime restore (Opcodes, BytecodeInterpreter, BlockNode, StatementParser)
eval("__PACKAGE__")afterpackage Foo { }returned wrong package6. Disassembler cases (InterpretedCode)
Testing
make cd perl5_t/t JPERL_EVAL_USE_INTERPRETER=1 ../../jperl comp/parser.t JPERL_EVAL_USE_INTERPRETER=1 ../../jperl comp/package_block.t JPERL_EVAL_USE_INTERPRETER=1 ../../jperl op/do.t