augmented assignments via StackValue.store()
This commit is contained in:
@@ -785,27 +785,15 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generateAugmentedAssignment(JetBinaryExpression expression) {
|
private void generateAugmentedAssignment(JetBinaryExpression expression) {
|
||||||
|
DeclarationDescriptor op = bindingContext.resolveReferenceExpression(expression.getOperationReference());
|
||||||
final JetExpression lhs = expression.getLeft();
|
final JetExpression lhs = expression.getLeft();
|
||||||
if (lhs instanceof JetReferenceExpression) {
|
Type asmType = expressionType(lhs);
|
||||||
DeclarationDescriptor op = bindingContext.resolveReferenceExpression(expression.getOperationReference());
|
StackValue value = generateIntermediateValue(lhs);
|
||||||
final JetType leftType = bindingContext.getExpressionType(lhs);
|
value.put(asmType, v);
|
||||||
final Type asmType = typeMapper.mapType(leftType);
|
genToJVMStack(expression.getRight());
|
||||||
if (isNumberPrimitive(asmType)) {
|
v.visitInsn(asmType.getOpcode(opcodeForMethod(op.getName())));
|
||||||
final int index = indexOfLocal((JetReferenceExpression) lhs);
|
value = generateIntermediateValue(lhs);
|
||||||
assert index >= 0;
|
value.store(v, true);
|
||||||
v.load(index, asmType);
|
|
||||||
gen(expression.getRight(), asmType);
|
|
||||||
int opcode = opcodeForMethod(op.getName());
|
|
||||||
v.visitInsn(asmType.getOpcode(opcode));
|
|
||||||
v.store(index, asmType);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new UnsupportedOperationException("Don't know how to generate augmented assignment for non-numeric types");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new UnsupportedOperationException("Don't know how to generate augmented assignment to " + lhs.getText());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateConcatenation(JetBinaryExpression expression) {
|
private void generateConcatenation(JetBinaryExpression expression) {
|
||||||
|
|||||||
@@ -315,6 +315,16 @@ public class NamespaceGenTest extends CodegenTestCase {
|
|||||||
assertEquals(610, c.gridx);
|
assertEquals(610, c.gridx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFieldAugAssign() throws Exception {
|
||||||
|
loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx *= 2; return; }");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
final Method main = generateFunction();
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
c.gridx = 305;
|
||||||
|
main.invoke(null, c);
|
||||||
|
assertEquals(610, c.gridx);
|
||||||
|
}
|
||||||
|
|
||||||
public void testIncrementAsLastOperation() throws Exception {
|
public void testIncrementAsLastOperation() throws Exception {
|
||||||
loadText("fun foo() { var a = 0; a++; }");
|
loadText("fun foo() { var a = 0; a++; }");
|
||||||
generateFunction(); // make sure we're not falling off end of code
|
generateFunction(); // make sure we're not falling off end of code
|
||||||
|
|||||||
Reference in New Issue
Block a user