Skip to content

Commit 35d62ba

Browse files
committed
Merge branch 'debug-vars'
2 parents 97a0ee6 + 706ee90 commit 35d62ba

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTToJVMBytecode.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ private static boolean processMethod(BufferedReader in, ClassWriter c, String cl
144144
String curLine, methodName = null, returnType = null;
145145
String crName = null, crCuid = null, crOuter = null;
146146
boolean isStatic = false;
147-
List<String> argNames = new ArrayList<String>();
148147
List<Type> argTypes = new ArrayList<Type>();
149-
Map<String, Integer> argIndexes = new HashMap<String, Integer>();
150148
Map<String, VariableDef> localVariables = new HashMap<String, VariableDef>();
151149
Map<String, Label> labelMap = new HashMap<String, Label>();
152150
Stack<Label> tryStartStack = new Stack<Label>();
@@ -162,7 +160,6 @@ private static boolean processMethod(BufferedReader in, ClassWriter c, String cl
162160

163161
MethodVisitor m = null;
164162
boolean contAfter = false;
165-
166163
boolean inMethodHeader = true;
167164
while ((curLine = in.readLine()) != null) {
168165
// See if we need to move to the next method.
@@ -185,21 +182,16 @@ else if (curLine.equals("++ static")) {
185182
isStatic = true;
186183
curArgIndex = 0; /* No invocant. */
187184
}
188-
else if (curLine.startsWith("++ arg ")) {
189-
String[] bits = curLine.split("\\s", 4);
190-
Type t = processType(bits[3]);
191-
argNames.add(bits[2]);
192-
argTypes.add(t);
193-
argIndexes.put(bits[2], curArgIndex);
194-
curArgIndex += (t == Type.LONG_TYPE || t == Type.DOUBLE_TYPE ? 2 : 1);
195-
}
196-
else if (curLine.startsWith("++ local ")) {
185+
else if (curLine.startsWith("++ local ") || curLine.startsWith("++ arg")) {
197186
String[] bits = curLine.split("\\s", 4);
198187
if (localVariables.containsKey(bits[2]))
199188
throw new Exception("Duplicate local name: " + bits[2]);
200189
Type t = processType(bits[3]);
201190
localVariables.put(bits[2], new VariableDef(curArgIndex, t.getDescriptor(), beginAll, endAll));
202191
curArgIndex += (t == Type.LONG_TYPE || t == Type.DOUBLE_TYPE ? 2 : 1);
192+
if (curLine.startsWith("++ arg")) {
193+
argTypes.add(t);
194+
}
203195
}
204196
else if (curLine.startsWith("++ crname "))
205197
crName = curLine.substring("++ crname ".length());
@@ -275,7 +267,11 @@ else if (curLine.startsWith("++ handlers ")) {
275267
av.visit("handlers", crHandlers);
276268
av.visitEnd();
277269
}
278-
270+
271+
if (!isStatic) {
272+
localVariables.put("this", new VariableDef(0, "L"+className+";", beginAll, endAll));
273+
}
274+
279275
m.visitCode();
280276
m.visitLabel(beginAll);
281277
}
@@ -359,7 +355,7 @@ else if (curLine.startsWith(".line ")) {
359355
}
360356

361357
// Process line as an instruction.
362-
emitInstruction(in, m, labelMap, argIndexes, localVariables, curLine);
358+
emitInstruction(in, m, labelMap, localVariables, curLine);
363359
}
364360
if (inMethodHeader)
365361
throw new Exception("Unexpected end of file in method header");
@@ -370,12 +366,6 @@ else if (curLine.startsWith(".line ")) {
370366
VariableDef def = e.getValue();
371367
m.visitLocalVariable(e.getKey(), def.type, null, def.start, def.end, def.index);
372368
}
373-
if (!isStatic)
374-
m.visitLocalVariable("this", "L"+className+";", null, beginAll, endAll, 0);
375-
for (int i = 0; i < argTypes.size(); i++) {
376-
m.visitLocalVariable(argNames.get(i), argTypes.get(i).getDescriptor(), null,
377-
beginAll, endAll, argIndexes.get(argNames.get(i)));
378-
}
379369

380370
m.visitMaxs(0, 0);
381371
m.visitEnd();
@@ -406,7 +396,6 @@ private static String decodeString(String value) {
406396

407397
private static void emitInstruction(BufferedReader in, MethodVisitor m,
408398
Map<String, Label> labelMap,
409-
Map<String, Integer> argIndexes,
410399
Map<String, VariableDef> localVariables,
411400
String curLine) throws Exception {
412401
// Find instruction code and get rest of the string.
@@ -445,8 +434,6 @@ private static void emitInstruction(BufferedReader in, MethodVisitor m,
445434
case 0x19: // aload
446435
if (localVariables.containsKey(rest))
447436
m.visitVarInsn(instruction, localVariables.get(rest).index);
448-
else if (argIndexes.containsKey(rest))
449-
m.visitVarInsn(instruction, argIndexes.get(rest));
450437
else
451438
throw new Exception("Undeclared local variable: " + rest);
452439
break;
@@ -527,8 +514,6 @@ else if (argIndexes.containsKey(rest))
527514
case 0x3a: // astore
528515
if (localVariables.containsKey(rest))
529516
m.visitVarInsn(instruction, localVariables.get(rest).index);
530-
else if (argIndexes.containsKey(rest))
531-
m.visitVarInsn(instruction, argIndexes.get(rest));
532517
else
533518
throw new Exception("Undeclared local variable: " + rest);
534519
break;

0 commit comments

Comments
 (0)