summaryrefslogtreecommitdiff
path: root/sources/scala
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scala')
-rw-r--r--sources/scala/tools/nsc/backend/icode/BasicBlocks.scala29
-rw-r--r--sources/scala/tools/nsc/backend/icode/GenICode.scala11
-rw-r--r--sources/scala/tools/nsc/backend/icode/Printers.scala2
-rw-r--r--sources/scala/tools/nsc/backend/jvm/GenJVM.scala4
4 files changed, 35 insertions, 11 deletions
diff --git a/sources/scala/tools/nsc/backend/icode/BasicBlocks.scala b/sources/scala/tools/nsc/backend/icode/BasicBlocks.scala
index 43b0199702..50f3c75a3a 100644
--- a/sources/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/sources/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -114,17 +114,32 @@ trait BasicBlocks: ICodes {
}
/** Replace all instructions found in the map. */
- def subst(map: Map[Instruction, Instruction]) = {
- var i = 0;
- while (i < instrs.length) {
- map get instrs(i) match {
- case Some(instr) => replaceInstruction(i, instr);
- case None => ();
+ def subst(map: Map[Instruction, Instruction]) =
+ if (!closed) substOnList(map) else {
+ var i = 0;
+ while (i < instrs.length) {
+ map get instrs(i) match {
+ case Some(instr) => replaceInstruction(i, instr);
+ case None => ();
+ }
+ i = i + 1;
}
- i = i + 1;
}
+
+ private def substOnList(map: Map[Instruction, Instruction]): Unit = {
+ def subst(l: List[Instruction]): List[Instruction] = l match {
+ case Nil => Nil
+ case x :: xs =>
+ map.get(x) match {
+ case Some(newInstr) => newInstr :: subst(xs);
+ case None => x :: subst(xs);
+ }
+ }
+
+ instructionList = subst(instructionList);
}
+
/** Add a new instruction at the end of the block,
* using the same source position as the last emitted instruction
*/
diff --git a/sources/scala/tools/nsc/backend/icode/GenICode.scala b/sources/scala/tools/nsc/backend/icode/GenICode.scala
index 68910ca1bc..5339443800 100644
--- a/sources/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/sources/scala/tools/nsc/backend/icode/GenICode.scala
@@ -337,13 +337,15 @@ abstract class GenICode extends SubComponent {
// genLoad
val resCtx: Context = tree match {
case LabelDef(name, params, rhs) =>
- ctx.method.addLocals(params map (p => new Local(p.symbol, toTypeKind(p.symbol.info))));
val ctx1 = ctx.newBlock;
ctx1.labels.get(tree.symbol) match {
- case Some(label) => label.anchor(ctx1.bb);
+ case Some(label) =>
+ label.anchor(ctx1.bb);
+ label.patch(ctx.method.code);
case None =>
ctx1.labels += tree.symbol -> (new Label(tree.symbol) anchor ctx1.bb setParams (params map (.symbol)));
+ ctx.method.addLocals(params map (p => new Local(p.symbol, toTypeKind(p.symbol.info))));
if (settings.debug.value)
log("Adding label " + tree.symbol);
}
@@ -572,7 +574,9 @@ abstract class GenICode extends SubComponent {
log("Performing scan for label because of forward jump.");
scanForLabels(ctx.defdef, ctx);
ctx.labels.get(sym) match {
- case Some(l) => l;
+ case Some(l) =>
+ log("Found label: " + l);
+ l
case _ => abort("Unknown label target: " + sym + " at: " + unit.position(fun.pos) + ": ctx: " + ctx);
}
}
@@ -1103,6 +1107,7 @@ abstract class GenICode extends SubComponent {
case LabelDef(name, params, rhs) =>
ctx.labels += tree.symbol -> (new Label(tree.symbol) setParams(params map (.symbol)));
+ ctx.method.addLocals(params map (p => new Local(p.symbol, toTypeKind(p.symbol.info))));
//super.traverse(rhs);
case _ => super.traverse(tree);
diff --git a/sources/scala/tools/nsc/backend/icode/Printers.scala b/sources/scala/tools/nsc/backend/icode/Printers.scala
index 63ad1e4ed6..8a562f73fd 100644
--- a/sources/scala/tools/nsc/backend/icode/Printers.scala
+++ b/sources/scala/tools/nsc/backend/icode/Printers.scala
@@ -85,6 +85,8 @@ abstract class Printers {
if (!m.isDeferred) {
println(" {");
+ println("locals: " + m.locals.mkString("", ", ", ""));
+ println;
linearizer.linearize(m) foreach printBlock;
println("}");
diff --git a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
index d03e647616..1aea04fa51 100644
--- a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -154,8 +154,10 @@ abstract class GenJVM extends SubComponent {
new Array[Byte](0)));
if (!jmethod.isAbstract()) {
- for (val local <- m.locals; !local.sym.isValueParameter)
+ for (val local <- m.locals; (! m.params.contains(local))) {
+ log("add local var: " + local);
jmethod.addNewLocalVariable(javaType(local.kind), javaName(local.sym));
+ }
jcode = jmethod.getCode().asInstanceOf[JExtendedCode];
genCode(m);