summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2003-07-28 14:35:42 +0000
committerschinz <schinz@epfl.ch>2003-07-28 14:35:42 +0000
commit5107585f17fd04f3b1c1263c4224793d679980cd (patch)
treeab91ce569f07c64cd07ccbe961c0de799c367669 /sources
parent20410a6d32f69297ba7d52f162a91c18824aa575 (diff)
downloadscala-5107585f17fd04f3b1c1263c4224793d679980cd.tar.gz
scala-5107585f17fd04f3b1c1263c4224793d679980cd.tar.bz2
scala-5107585f17fd04f3b1c1263c4224793d679980cd.zip
- avoid creating several temporary variables wh...
- avoid creating several temporary variables when more than one call to "==" appears in a single method, - prepared for output of Scala attribute containing the symbol table
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/backend/jvm/GenJVM.java38
1 files changed, 14 insertions, 24 deletions
diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java
index 44079a6787..68ba41082c 100644
--- a/sources/scalac/backend/jvm/GenJVM.java
+++ b/sources/scalac/backend/jvm/GenJVM.java
@@ -44,8 +44,6 @@ import java.io.*;
* - initialisation of module instance variable.
*/
-// TODO generate line numbers
-
/**
* Backend generating JVM byte-codes.
*
@@ -182,7 +180,7 @@ class GenJVM {
leaveMethod(ctx1);
} break;
- case LabelDef(_, _):
+ case LabelDef(Tree.Ident[] params, Tree rhs):
global.fail("not implemented yet " + tree);
break;
@@ -732,8 +730,9 @@ class GenJVM {
}
}
- /** Counter for temporary variables */
- protected static int tempCounter = 1;
+ /** Variable in which temporary objects are stored by the
+ * implementation of == */
+ protected JLocalVariable eqEqTempVar;
/**
* Generate code for the given comparison primitive, applied on
@@ -785,17 +784,17 @@ class GenJVM {
// if (this == null) other == null else this.equals(other)
assert prim == Primitive.EQ || prim == Primitive.NE;
- // TODO we should be able to create only one such variable
- // per method.
- JLocalVariable var =
- ctx.method.addNewLocalVariable(JObjectType.JAVA_LANG_OBJECT,
- "temp" + tempCounter++);
- ctx.code.emitSTORE(var);
+ if (eqEqTempVar == null || eqEqTempVar.getOwner() != ctx.method)
+ eqEqTempVar =
+ ctx.method.addNewLocalVariable(JObjectType.JAVA_LANG_OBJECT,
+ "eqEqTemp$");
+
+ ctx.code.emitSTORE(eqEqTempVar);
ctx.code.emitDUP();
JLabel ifNonNullLabel = new JLabel();
ctx.code.emitIFNONNULL(ifNonNullLabel);
ctx.code.emitPOP();
- ctx.code.emitLOAD(var);
+ ctx.code.emitLOAD(eqEqTempVar);
if (when ^ (prim != Primitive.EQ))
ctx.code.emitIFNULL(target);
else
@@ -803,7 +802,7 @@ class GenJVM {
JLabel afterLabel = new JLabel();
ctx.code.emitGOTO(afterLabel);
ctx.code.anchorLabelToNext(ifNonNullLabel);
- ctx.code.emitLOAD(var);
+ ctx.code.emitLOAD(eqEqTempVar);
JMethodType equalsType =
new JMethodType(JType.BOOLEAN,
new JType[] { JObjectType.JAVA_LANG_OBJECT });
@@ -1183,17 +1182,8 @@ class GenJVM {
* symbol table is saved.
*/
protected void addScalaAttr(JClass cls) {
- // TODO
-// ConstantPoolGen poolGen = classGen.getConstantPool();
-
-// int scalaNameIndex =
-// poolGen.addUtf8(ClassfileConstants.SCALA_N.toString());
-// Unknown scalaAttr = new Unknown(scalaNameIndex,
-// 0,
-// null,
-// poolGen.getConstantPool());
-
-// classGen.addAttribute(scalaAttr);
+// JOtherAttribute scalaAttr = new JOtherAttribute(...);
+// cls.addAttribute(scalaAttr);
}
/// Names