diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2007-03-21 19:54:18 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2007-03-21 19:54:18 +0000 |
commit | 8e890c848ff68e69342d0f340df40f926857c861 (patch) | |
tree | bb40617593455d7f0341542804d54f37ae7b78de /src | |
parent | 6a2134b1b056da1c32115b4ab87e11c7b78b53ab (diff) | |
download | scala-8e890c848ff68e69342d0f340df40f926857c861.tar.gz scala-8e890c848ff68e69342d0f340df40f926857c861.tar.bz2 scala-8e890c848ff68e69342d0f340df40f926857c861.zip |
Added support in the backend for assignments th...
Added support in the backend for assignments that carry the value of
their right hand side.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 0dab705502..bd18576e3a 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -142,48 +142,12 @@ abstract class GenICode extends SubComponent { var currentCtx = ctx for (val t <- trees) - currentCtx = genStat(t, currentCtx) + currentCtx = genLoad(t, currentCtx, UNIT) currentCtx } /** - * Generate code for the given tree. The trees should contain statements - * and not produce any value. Use genLoad for expressions which leave - * a value on top of the stack. - * - * @param tree ... - * @param ctx ... - * @return a new context. This is necessary for control flow instructions - * which may change the current basic block. - */ - private def genStat(tree: Tree, ctx: Context): Context = { - - tree match { - case Assign(lhs @ Select(_, _), rhs) => - if (isStaticSymbol(lhs.symbol)) { - val ctx1 = genLoad(rhs, ctx, toTypeKind(lhs.symbol.info)) - ctx1.bb.emit(STORE_FIELD(lhs.symbol, true), tree.pos) - ctx1 - } else { - var ctx1 = genLoadQualifier(lhs, ctx) - ctx1 = genLoad(rhs, ctx1, toTypeKind(lhs.symbol.info)) - ctx1.bb.emit(STORE_FIELD(lhs.symbol, false), tree.pos) - ctx1 - } - - case Assign(lhs, rhs) => - val ctx1 = genLoad(rhs, ctx, toTypeKind(lhs.symbol.info)) - val Some(l) = ctx.method.lookupLocal(lhs.symbol) - ctx1.bb.emit(STORE_LOCAL(l), tree.pos) - ctx1 - - case _ => - genLoad(tree, ctx, UNIT) - } - } - - /** * Generate code for trees that produce values on the stack * * @param tree The tree to be translated @@ -899,10 +863,38 @@ abstract class GenICode extends SubComponent { case Typed(expr, _) => genLoad(expr, ctx, expectedType) + case Assign(lhs @ Select(_, _), rhs) => + generatedType = UNIT + val rhsType = toTypeKind(lhs.symbol.info) + val static = isStaticSymbol(lhs.symbol) + var ctx1: Context = ctx + + if (!static) + ctx1 = genLoadQualifier(lhs, ctx) + ctx1 = genLoad(rhs, ctx1, rhsType) + if (expectedType == rhsType) { + ctx1.bb.emit(DUP(rhsType)) + generatedType = rhsType + } + ctx1.bb.emit(STORE_FIELD(lhs.symbol, static), tree.pos) + ctx1 + + case Assign(lhs, rhs) => + generatedType = UNIT + val rhsType = toTypeKind(lhs.symbol.info) + val ctx1 = genLoad(rhs, ctx, rhsType) + if (expectedType == rhsType) { + ctx1.bb.emit(DUP(rhsType)) + generatedType = rhsType + } + val Some(l) = ctx.method.lookupLocal(lhs.symbol) + ctx1.bb.emit(STORE_LOCAL(l), tree.pos) + ctx1 +/* case Assign(_, _) => generatedType = UNIT genStat(tree, ctx) - +*/ case ArrayValue(tpt @ TypeTree(), elems) => var ctx1 = ctx val elmKind = toTypeKind(tpt.tpe) |