You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
grep -E "^\s+[a-z].*line:"| sed 's/line:.*//'| sort | uniq -c | sort -rn | head -20
167
186
```
168
187
169
-
### 8. Add debug prints (if needed)
188
+
### 7. Add debug prints (if needed)
170
189
In Java source, add:
171
190
```java
172
191
System.err.println("DEBUG: var="+var);
173
192
```
174
193
Then rebuild with `mvn package -q -DskipTests`.
175
194
176
-
### 9. Fix and verify
195
+
### 8. Fix and verify
177
196
```bash
178
197
# After fixing
179
198
mvn package -q -DskipTests
@@ -258,6 +277,50 @@ Both backends share the parser (same AST) and runtime (same operators, same Runt
258
277
259
278
All paths relative to `src/main/java/org/perlonjava/`.
260
279
280
+
## CRITICAL: Investigate JVM Backend First
281
+
282
+
**When fixing interpreter bugs, ALWAYS investigate how the JVM backend handles the same operation before implementing a fix.**
283
+
284
+
The interpreter and JVM backends share the same runtime classes (`RuntimeScalar`, `RuntimeArray`, `RuntimeHash`, `RuntimeList`, `PerlRange`, etc.). The JVM backend is the reference implementation - if the interpreter handles something differently, it's likely wrong.
285
+
286
+
### How to investigate JVM behavior
287
+
288
+
1.**Disassemble the JVM bytecode** to see what runtime methods it calls:
289
+
```bash
290
+
./jperl --disassemble -e 'code that works'
291
+
```
292
+
293
+
2.**Look for the runtime method calls** in the disassembly (INVOKEVIRTUAL, INVOKESTATIC):
elseif (valuesBase instanceofPerlRange) { ... } // BAD: special case
312
+
else { ... }
313
+
```
314
+
315
+
**Correct approach** (use same runtime methods as JVM):
316
+
```java
317
+
// JVM calls addToArray() which handles all types uniformly
318
+
RuntimeArray valuesArray =newRuntimeArray();
319
+
valuesBase.addToArray(valuesArray); // Works for RuntimeList, RuntimeArray, PerlRange, etc.
320
+
```
321
+
322
+
The JVM's `setFromList()` → `addToArray()` chain already handles `PerlRange` correctly via `PerlRange.addToArray()` → `toList().addToArray()`. The interpreter should use the same mechanism.
0 commit comments