Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public class EvalStringHandler {
* @param registers Current register array (for variable access)
* @param sourceName Source name for error messages
* @param sourceLine Source line for error messages
* @param callContext The calling context (VOID/SCALAR/LIST) for wantarray inside eval
* @return RuntimeScalar result of evaluation (undef on error)
*/
public static RuntimeScalar evalString(String perlCode,
InterpretedCode currentCode,
RuntimeBase[] registers,
String sourceName,
int sourceLine) {
int sourceLine,
int callContext) {
try {
// Step 1: Clear $@ at start of eval
GlobalVariable.getGlobalVariable("main::@").set("");
Expand Down Expand Up @@ -196,8 +198,10 @@ public static RuntimeScalar evalString(String perlCode,
}

// Step 6: Execute the compiled code
// Use the true outer call context so wantarray() inside the eval body
// returns the correct value (undef for void, false for scalar, true for list).
RuntimeArray args = new RuntimeArray(); // Empty @_
RuntimeList result = evalCode.apply(args, RuntimeContextType.SCALAR);
RuntimeList result = evalCode.apply(args, callContext);

// Step 7: Return scalar result
return result.scalar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,19 @@ public static int executeEvalString(
}
String perlCode = codeScalar.toString();

// Read outer wantarray from register 2 (set by BytecodeInterpreter from the call site context).
// This is the true calling context (VOID/SCALAR/LIST) that wantarray() inside the
// eval body must reflect — exactly as evalStringWithInterpreter receives callContext.
int callContext = ((RuntimeScalar) registers[2]).getInt();

// Call EvalStringHandler to parse, compile, and execute
RuntimeScalar result = EvalStringHandler.evalString(
perlCode,
code, // Current InterpretedCode for context
registers, // Current registers for variable access
code.sourceName,
code.sourceLine
code.sourceLine,
callContext // True outer context for wantarray inside eval body
);

registers[rd] = result;
Expand Down