use of org.codehaus.groovy.classgen.asm.OperandStack 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();
}
use of org.codehaus.groovy.classgen.asm.OperandStack in project groovy by apache.
the class StaticTypesStatementWriter method loadFromArray.
private void loadFromArray(MethodVisitor mv, BytecodeVariable variable, int array, int iteratorIdx) {
OperandStack os = controller.getOperandStack();
mv.visitVarInsn(ALOAD, array);
mv.visitVarInsn(ILOAD, iteratorIdx);
ClassNode varType = variable.getType();
boolean primitiveType = ClassHelper.isPrimitiveType(varType);
boolean isByte = ClassHelper.byte_TYPE.equals(varType);
boolean isShort = ClassHelper.short_TYPE.equals(varType);
boolean isInt = ClassHelper.int_TYPE.equals(varType);
boolean isLong = ClassHelper.long_TYPE.equals(varType);
boolean isFloat = ClassHelper.float_TYPE.equals(varType);
boolean isDouble = ClassHelper.double_TYPE.equals(varType);
boolean isChar = ClassHelper.char_TYPE.equals(varType);
boolean isBoolean = ClassHelper.boolean_TYPE.equals(varType);
if (primitiveType) {
if (isByte) {
mv.visitInsn(BALOAD);
}
if (isShort) {
mv.visitInsn(SALOAD);
}
if (isInt || isChar || isBoolean) {
mv.visitInsn(isChar ? CALOAD : isBoolean ? BALOAD : IALOAD);
}
if (isLong) {
mv.visitInsn(LALOAD);
}
if (isFloat) {
mv.visitInsn(FALOAD);
}
if (isDouble) {
mv.visitInsn(DALOAD);
}
} else {
mv.visitInsn(AALOAD);
}
os.push(varType);
os.storeVar(variable);
}
use of org.codehaus.groovy.classgen.asm.OperandStack 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();
}
Aggregations