Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/main/java/org/perlonjava/core/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Configuration {
* Automatically populated by Gradle/Maven during build.
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String gitCommitId = "2cc770db1";
public static final String gitCommitId = "6d48b1ad0";

/**
* Git commit date of the build (ISO format: YYYY-MM-DD).
Expand All @@ -48,7 +48,7 @@ public final class Configuration {
* Parsed by App::perlbrew and other tools via: perl -V | grep "Compiled at"
* DO NOT EDIT MANUALLY - this value is replaced at build time.
*/
public static final String buildTimestamp = "Apr 21 2026 19:57:31";
public static final String buildTimestamp = "Apr 21 2026 21:54:08";

// Prevent instantiation
private Configuration() {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/perlonjava/frontend/parser/SubroutineParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,9 +1157,19 @@ public static ListNode handleNamedSubWithFilter(Parser parser, String subName, S
entry.perlPackage());
} else {
OperatorNode ast = entry.ast();
int beginId = RuntimeCode.evalBeginIds.computeIfAbsent(
ast,
k -> EmitterMethodCreator.classCounter++);
// For state variables, the persistent-variable id is already
// assigned (see OperatorParser "state" handling). Reuse it so
// that the storage key here matches the key used by the state
// initializer / retrieveStateScalar (which also use ast.id).
int beginId;
if ("state".equals(entry.decl()) && ast != null && ast.id != 0) {
beginId = ast.id;
RuntimeCode.evalBeginIds.putIfAbsent(ast, beginId);
} else {
beginId = RuntimeCode.evalBeginIds.computeIfAbsent(
ast,
k -> EmitterMethodCreator.classCounter++);
}
variableName = NameNormalizer.normalizeVariableName(
entry.name().substring(1),
PersistentVariable.beginPackage(beginId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ public static RuntimeScalar retrieveStateScalar(RuntimeScalar codeRef, String va
// Retrieve variable in the specific code context.
RuntimeCode code = (RuntimeCode) codeRef.value;
RuntimeScalar variable = code.stateVariable.get(beginVar);
if (variable == null) {
variable = new RuntimeScalar();
code.stateVariable.put(beginVar, variable);
if (variable != null) {
return variable;
}
// Fallback: the state variable may have been declared in an
// enclosing scope outside any sub (then stored globally with the
// same beginVar key). Check the global storage before allocating
// a fresh per-sub entry so that a state var shared between the
// enclosing scope and an inner sub refers to the same storage.
if (GlobalVariable.existsGlobalVariable(beginVar)) {
return GlobalVariable.getGlobalVariable(beginVar);
}
variable = new RuntimeScalar();
code.stateVariable.put(beginVar, variable);
return variable;
}
}
Expand All @@ -142,10 +151,16 @@ public static RuntimeArray retrieveStateArray(RuntimeScalar codeRef, String var,
// Retrieve array in the specific code context.
RuntimeCode code = (RuntimeCode) codeRef.value;
RuntimeArray variable = code.stateArray.get(beginVar);
if (variable == null) {
variable = new RuntimeArray();
code.stateArray.put(beginVar, variable);
if (variable != null) {
return variable;
}
// Fallback: the state variable may have been declared in an
// enclosing scope outside any sub (stored globally).
if (GlobalVariable.existsGlobalArray(beginVar)) {
return GlobalVariable.getGlobalArray(beginVar);
}
variable = new RuntimeArray();
code.stateArray.put(beginVar, variable);
return variable;
}
}
Expand All @@ -167,10 +182,16 @@ public static RuntimeHash retrieveStateHash(RuntimeScalar codeRef, String var, i
// Retrieve hash in the specific code context.
RuntimeCode code = (RuntimeCode) codeRef.value;
RuntimeHash variable = code.stateHash.get(beginVar);
if (variable == null) {
variable = new RuntimeHash();
code.stateHash.put(beginVar, variable);
if (variable != null) {
return variable;
}
// Fallback: the state variable may have been declared in an
// enclosing scope outside any sub (stored globally).
if (GlobalVariable.existsGlobalHash(beginVar)) {
return GlobalVariable.getGlobalHash(beginVar);
}
variable = new RuntimeHash();
code.stateHash.put(beginVar, variable);
return variable;
}
}
Expand Down
Loading