diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2005-10-15 16:45:59 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2005-10-15 16:45:59 +0000 |
commit | d8522ed174ce5a098634b2b4a26d83a04a81554a (patch) | |
tree | b92eee6608d1cfa51674b4175fb8cd4b5ff095a4 /sources/scala/tools/nsc/backend/icode/GenICode.scala | |
parent | 11a9eecb4d8b406690b76230ff91e1fac01651a6 (diff) | |
download | scala-d8522ed174ce5a098634b2b4a26d83a04a81554a.tar.gz scala-d8522ed174ce5a098634b2b4a26d83a04a81554a.tar.bz2 scala-d8522ed174ce5a098634b2b4a26d83a04a81554a.zip |
Special treatment of scala.All and scala.AllRef...
Special treatment of scala.All and scala.AllRef in GenICode.
Diffstat (limited to 'sources/scala/tools/nsc/backend/icode/GenICode.scala')
-rw-r--r-- | sources/scala/tools/nsc/backend/icode/GenICode.scala | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/sources/scala/tools/nsc/backend/icode/GenICode.scala b/sources/scala/tools/nsc/backend/icode/GenICode.scala index e170dfd5e7..1b84f0250c 100644 --- a/sources/scala/tools/nsc/backend/icode/GenICode.scala +++ b/sources/scala/tools/nsc/backend/icode/GenICode.scala @@ -40,8 +40,9 @@ abstract class GenICode extends SubComponent { // this depends on the backend! should be changed. val ANY_REF_CLASS = REFERENCE(definitions.ObjectClass); - val SCALA_ALL = REFERENCE(definitions.AllClass); - val THROWABLE = REFERENCE(definitions.ThrowableClass); + val SCALA_ALL = REFERENCE(definitions.AllClass); + val SCALA_ALLREF = REFERENCE(definitions.AllRefClass); + val THROWABLE = REFERENCE(definitions.ThrowableClass); /////////////////////////////////////////////////////////// @@ -96,15 +97,15 @@ abstract class GenICode extends SubComponent { log("Entering method " + name); val m = new IMethod(tree.symbol); m.sourceFile = unit.source.toString(); + m.returnType = if (tree.symbol.isConstructor) UNIT + else toTypeKind(tree.symbol.info.resultType); ctx.clazz.addMethod(m); var ctx1 = ctx.enterMethod(m, tree.asInstanceOf[DefDef]); addMethodParams(ctx1, vparamss); - val resTpe = if (tree.symbol.isConstructor) UNIT - else toTypeKind(ctx1.method.symbol.info.resultType); if (!m.isDeferred) { - ctx1 = genLoad(rhs, ctx1, resTpe); + ctx1 = genLoad(rhs, ctx1, m.returnType); // reverse the order of the local variables, to match the source-order m.locals = m.locals.reverse; @@ -112,7 +113,7 @@ abstract class GenICode extends SubComponent { rhs match { case Block(_, Return(_)) => (); case Return(_) => (); - case _ => ctx1.bb.emit(RETURN(resTpe), tree.pos); + case _ => ctx1.bb.emit(RETURN(m.returnType), rhs.pos); } ctx1.bb.close; } else @@ -222,8 +223,8 @@ abstract class GenICode extends SubComponent { ctx1 = genLoad(larg, ctx1, resKind); code match { case scalaPrimitives.POS => (); // nothing - case scalaPrimitives.NEG => ctx1.bb.emit(CALL_PRIMITIVE(Negation(resKind)), tree.pos); - case scalaPrimitives.NOT => ctx1.bb.emit(CALL_PRIMITIVE(Arithmetic(NOT, resKind)), tree.pos); + case scalaPrimitives.NEG => ctx1.bb.emit(CALL_PRIMITIVE(Negation(resKind)), larg.pos); + case scalaPrimitives.NOT => ctx1.bb.emit(CALL_PRIMITIVE(Arithmetic(NOT, resKind)), larg.pos); case _ => abort("Unknown unary operation: " + fun.symbol.fullNameString + " code: " + code); } generatedType = resKind; @@ -765,8 +766,17 @@ abstract class GenICode extends SubComponent { assert(generatedType != UNIT, "Can't convert from UNIT to " + expectedType); resCtx.bb.emit(CALL_PRIMITIVE(Conversion(generatedType, expectedType)), tree.pos); } - } else if (generatedType == SCALA_ALL && expectedType == UNIT) +// } else if (generatedType == SCALA_ALL && expectedType == UNIT) +// resCtx.bb.emit(DROP(generatedType)); + } else if (generatedType == SCALA_ALL) { resCtx.bb.emit(DROP(generatedType)); + resCtx.bb.emit(getZeroOf(ctx.method.returnType)); + resCtx.bb.emit(RETURN(ctx.method.returnType)); + resCtx.bb.enterIgnoreMode; + } else if (generatedType == SCALA_ALLREF) { + resCtx.bb.emit(DROP(generatedType)); + resCtx.bb.emit(CONSTANT(Constant(null))); + } resCtx; } @@ -858,6 +868,21 @@ abstract class GenICode extends SubComponent { case ARRAY(elem) => Literal(null: Any); } + def getZeroOf(k: TypeKind): Instruction = k match { + case UNIT => CONSTANT(Constant(())); + case BOOL => CONSTANT(Constant(false)); + case BYTE => CONSTANT(Constant(0: Byte)); + case SHORT => CONSTANT(Constant(0: Short)); + case CHAR => CONSTANT(Constant(0: Char)); + case INT => CONSTANT(Constant(0: Int)); + case LONG => CONSTANT(Constant(0: Long)); + case FLOAT => CONSTANT(Constant(0.0f)); + case DOUBLE => CONSTANT(Constant(0.0d)); + case REFERENCE(cls) => CONSTANT(Constant(null: Any)); + case ARRAY(elem) => CONSTANT(Constant(null: Any)); + } + + /** Is the given symbol a primitive operation? */ def isPrimitive(fun: Symbol): Boolean = { import scalaPrimitives._; |