/** * Generates the instructions to load the given method arguments on the stack. * * @param arg the index of the first method argument to be loaded. * @param count the number of method arguments to be loaded. */ public void loadArgs(final int arg, final int count) { int index = getArgIndex(arg); for (int i = 0; i < count; ++i) { Type t = argumentTypes[arg + i]; loadInsn(t, index); index += t.getSize(); } }
/** * Generates the instructions to swap the top two stack values. * * @param prev type of the top - 1 stack value. * @param type type of the top stack value. */ public void swap(final Type prev, final Type type) { if (type.getSize() == 1) { if (prev.getSize() == 1) { swap(); // same as dupX1(), pop(); } else { dupX2(); pop(); } } else { if (prev.getSize() == 1) { dup2X1(); pop2(); } else { dup2X2(); pop2(); } } }
/** * Generates the instructions to box the top stack value. This value is replaced by its boxed * equivalent on top of the stack. * * @param type the type of the top stack value. */ public void box(final Type type) { if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) { return; } if (type == Type.VOID_TYPE) { push((String) null); } else { Type boxed = type; switch (type.getSort()) { case Type.BYTE: boxed = BYTE_TYPE; break; case Type.BOOLEAN: boxed = BOOLEAN_TYPE; break; case Type.SHORT: boxed = SHORT_TYPE; break; case Type.CHAR: boxed = CHARACTER_TYPE; break; case Type.INT: boxed = INTEGER_TYPE; break; case Type.FLOAT: boxed = FLOAT_TYPE; break; case Type.LONG: boxed = LONG_TYPE; break; case Type.DOUBLE: boxed = DOUBLE_TYPE; break; } newInstance(boxed); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o dupX2(); dupX2(); pop(); } else { // p -> po -> opo -> oop -> o dupX1(); swap(); } invokeConstructor(boxed, new Method("<init>", Type.VOID_TYPE, new Type[] {type})); } }