Skip to content

Fix interpreter eval regressions: compound assign, package block restore, bare block#236

Merged
fglock merged 2 commits into
masterfrom
fix-interpreter-eval-regressions-2
Feb 25, 2026
Merged

Fix interpreter eval regressions: compound assign, package block restore, bare block#236
fglock merged 2 commits into
masterfrom
fix-interpreter-eval-regressions-2

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Feb 25, 2026

Summary

Fixes multiple regressions when JPERL_EVAL_USE_INTERPRETER=1 is enabled.

Changes

1. For3Node bare block value propagation (BytecodeCompiler)

  • eval '{ q,bar, }' etc returned undef — isSimpleBlock path always set lastResultReg=-1
  • Fix: allocate outer register + MOVE before exitScope
  • Fixes: comp/parser.t 36, 38, 40

2. DO_FILE opcode (Opcodes, CompileOperator, BytecodeInterpreter)

  • do FILE inside eval STRING threw "Unsupported operator: doFile"
  • Fixes: op/do.t

3. LValueVisitor check on ListNode LHS (CompileAssignment)

  • eval q{($a ? $x : ($y)) = 5} silently succeeded instead of throwing
  • Fixes: comp/parser.t 53

4. Compound assignment for global vars (BytecodeCompiler.handleCompoundAssignment)

  • $x += 1 / $x .= 'a' in eval STRING loaded wrong global (name included sigil)
  • Strip sigil before normalizeVariableName; remove redundant STORE (live object mutated in-place)
  • Fixes: comp/package_block.t 1-3, 5 and many other tests

5. Package block runtime restore (Opcodes, BytecodeInterpreter, BlockNode, StatementParser)

  • eval("__PACKAGE__") after package Foo { } returned wrong package
  • Add GET_LOCAL_LEVEL opcode (341); StatementParser sets isScoped on package node
  • BlockNode.visit() brackets scoped package blocks with GET_LOCAL_LEVEL + POP_LOCAL_LEVEL
  • EvalStringHandler uses InterpreterState.currentPackage (runtime) for inner eval context
  • Fixes: comp/package_block.t 1, 3 (nested eval PACKAGE)

6. Disassembler cases (InterpretedCode)

  • Added GET_LOCAL_LEVEL, SET_PACKAGE, PUSH_PACKAGE, POP_PACKAGE, DO_FILE

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

…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)
@fglock fglock merged commit 5c7313e into master Feb 25, 2026
2 checks passed
@fglock fglock deleted the fix-interpreter-eval-regressions-2 branch February 25, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant