Search in sources :

Example 1 with CompileStack

use of org.codehaus.groovy.classgen.asm.CompileStack in project groovy-core by groovy.

the class InvokeDynamicWriter method finishIndyCall.

private void finishIndyCall(Handle bsmHandle, String methodName, String sig, int numberOfArguments, Object... bsmArgs) {
    CompileStack compileStack = controller.getCompileStack();
    OperandStack operandStack = controller.getOperandStack();
    controller.getMethodVisitor().visitInvokeDynamicInsn(methodName, sig, bsmHandle, bsmArgs);
    operandStack.replace(ClassHelper.OBJECT_TYPE, numberOfArguments);
    compileStack.popLHS();
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) CompileStack(org.codehaus.groovy.classgen.asm.CompileStack)

Example 2 with CompileStack

use of org.codehaus.groovy.classgen.asm.CompileStack in project groovy-core by groovy.

the class InvokeDynamicWriter method prepareIndyCall.

private String prepareIndyCall(Expression receiver, boolean implicitThis) {
    CompileStack compileStack = controller.getCompileStack();
    OperandStack operandStack = controller.getOperandStack();
    compileStack.pushLHS(false);
    // load normal receiver as first argument
    compileStack.pushImplicitThis(implicitThis);
    receiver.visit(controller.getAcg());
    compileStack.popImplicitThis();
    return "(" + getTypeDescription(operandStack.getTopOperand());
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) CompileStack(org.codehaus.groovy.classgen.asm.CompileStack)

Example 3 with CompileStack

use of org.codehaus.groovy.classgen.asm.CompileStack in project groovy by apache.

the class InvokeDynamicWriter method prepareIndyCall.

private String prepareIndyCall(Expression receiver, boolean implicitThis) {
    CompileStack compileStack = controller.getCompileStack();
    OperandStack operandStack = controller.getOperandStack();
    compileStack.pushLHS(false);
    // load normal receiver as first argument
    compileStack.pushImplicitThis(implicitThis);
    receiver.visit(controller.getAcg());
    compileStack.popImplicitThis();
    return "(" + getTypeDescription(operandStack.getTopOperand());
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) CompileStack(org.codehaus.groovy.classgen.asm.CompileStack)

Example 4 with CompileStack

use of org.codehaus.groovy.classgen.asm.CompileStack in project groovy by apache.

the class InvokeDynamicWriter method finishIndyCall.

private void finishIndyCall(Handle bsmHandle, String methodName, String sig, int numberOfArguments, Object... bsmArgs) {
    CompileStack compileStack = controller.getCompileStack();
    OperandStack operandStack = controller.getOperandStack();
    controller.getMethodVisitor().visitInvokeDynamicInsn(methodName, sig, bsmHandle, bsmArgs);
    operandStack.replace(ClassHelper.OBJECT_TYPE, numberOfArguments);
    compileStack.popLHS();
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) CompileStack(org.codehaus.groovy.classgen.asm.CompileStack)

Example 5 with CompileStack

use of org.codehaus.groovy.classgen.asm.CompileStack in project groovy by apache.

the class StaticTypesStatementWriter method writeForInLoop.

@Override
protected void writeForInLoop(final ForStatement loop) {
    controller.getAcg().onLineNumber(loop, "visitForLoop");
    writeStatementLabel(loop);
    CompileStack compileStack = controller.getCompileStack();
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack operandStack = controller.getOperandStack();
    compileStack.pushLoop(loop.getVariableScope(), loop.getStatementLabels());
    // Identify type of collection
    TypeChooser typeChooser = controller.getTypeChooser();
    Expression collectionExpression = loop.getCollectionExpression();
    ClassNode collectionType = typeChooser.resolveType(collectionExpression, controller.getClassNode());
    Parameter loopVariable = loop.getVariable();
    int size = operandStack.getStackLength();
    if (collectionType.isArray() && loopVariable.getOriginType().equals(collectionType.getComponentType())) {
        writeOptimizedForEachLoop(compileStack, operandStack, mv, loop, collectionExpression, collectionType, loopVariable);
    } else if (ENUMERATION_CLASSNODE.equals(collectionType)) {
        writeEnumerationBasedForEachLoop(compileStack, operandStack, mv, loop, collectionExpression, collectionType, loopVariable);
    } else {
        writeIteratorBasedForEachLoop(compileStack, operandStack, mv, loop, collectionExpression, collectionType, loopVariable);
    }
    operandStack.popDownTo(size);
    compileStack.pop();
}
Also used : OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) ClassNode(org.codehaus.groovy.ast.ClassNode) TypeChooser(org.codehaus.groovy.classgen.asm.TypeChooser) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) Parameter(org.codehaus.groovy.ast.Parameter) CompileStack(org.codehaus.groovy.classgen.asm.CompileStack) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

CompileStack (org.codehaus.groovy.classgen.asm.CompileStack)5 OperandStack (org.codehaus.groovy.classgen.asm.OperandStack)5 ClassNode (org.codehaus.groovy.ast.ClassNode)1 Parameter (org.codehaus.groovy.ast.Parameter)1 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)1 Expression (org.codehaus.groovy.ast.expr.Expression)1 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)1 TypeChooser (org.codehaus.groovy.classgen.asm.TypeChooser)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1