コード例 #1
0
  protected void evaluateArrayAssignmentWithOperator(
      String method, BinaryExpression expression, BinaryExpression leftBinExpr) {
    CompileStack compileStack = getController().getCompileStack();
    AsmClassGenerator acg = getController().getAcg();
    OperandStack os = getController().getOperandStack();

    // e.g. x[a] += b
    // to avoid loading x and a twice we transform the expression to use
    // ExpressionAsVariableSlot
    // -> subscript=a, receiver=x, receiver[subscript]+b, =, receiver[subscript]
    // -> subscript=a, receiver=x, receiver#getAt(subscript)#plus(b), =, receiver#putAt(subscript)
    // -> subscript=a, receiver=x, receiver#putAt(subscript, receiver#getAt(subscript)#plus(b))
    // the result of x[a] += b is x[a]+b, thus:
    // -> subscript=a, receiver=x, receiver#putAt(subscript, ret=receiver#getAt(subscript)#plus(b)),
    // ret
    ExpressionAsVariableSlot subscript =
        new ExpressionAsVariableSlot(controller, leftBinExpr.getRightExpression(), "subscript");
    ExpressionAsVariableSlot receiver =
        new ExpressionAsVariableSlot(controller, leftBinExpr.getLeftExpression(), "receiver");
    MethodCallExpression getAt =
        new MethodCallExpression(receiver, "getAt", new ArgumentListExpression(subscript));
    MethodCallExpression operation =
        new MethodCallExpression(getAt, method, expression.getRightExpression());
    ExpressionAsVariableSlot ret = new ExpressionAsVariableSlot(controller, operation, "ret");
    MethodCallExpression putAt =
        new MethodCallExpression(receiver, "putAt", new ArgumentListExpression(subscript, ret));

    putAt.visit(acg);
    os.pop();
    os.load(ret.getType(), ret.getIndex());

    compileStack.removeVar(ret.getIndex());
    compileStack.removeVar(subscript.getIndex());
    compileStack.removeVar(receiver.getIndex());
  }
コード例 #2
0
  private void evaluatePostfixMethod(
      int op, String method, Expression expression, Expression orig) {
    CompileStack compileStack = controller.getCompileStack();
    final OperandStack operandStack = controller.getOperandStack();

    // load Expressions
    VariableSlotLoader usesSubscript = loadWithSubscript(expression);

    // save copy for later
    operandStack.dup();
    ClassNode expressionType = operandStack.getTopOperand();
    int tempIdx = compileStack.defineTemporaryVariable("postfix_" + method, expressionType, true);

    // execute Method
    execMethodAndStoreForSubscriptOperator(op, method, expression, usesSubscript, orig);

    // remove the result of the method call
    operandStack.pop();

    // reload saved value
    operandStack.load(expressionType, tempIdx);
    compileStack.removeVar(tempIdx);
    if (usesSubscript != null) compileStack.removeVar(usesSubscript.getIndex());
  }