MCPcopy Index your code
hub / github.com/clojure/clojure / cast

Method cast

src/jvm/clojure/asm/commons/GeneratorAdapter.java:742–793  ·  view source on GitHub ↗

Generates the instructions to cast a numerical value from one type to another. @param from the type of the top stack value @param to the type into which this value must be cast.

(final Type from, final Type to)

Source from the content-addressed store, hash-verified

740 * @param to the type into which this value must be cast.
741 */
742 public void cast(final Type from, final Type to) {
743 if (from != to) {
744 if (from.getSort() < Type.BOOLEAN
745 || from.getSort() > Type.DOUBLE
746 || to.getSort() < Type.BOOLEAN
747 || to.getSort() > Type.DOUBLE) {
748 throw new IllegalArgumentException();
749 }
750 if (from == Type.DOUBLE_TYPE) {
751 if (to == Type.FLOAT_TYPE) {
752 mv.visitInsn(Opcodes.D2F);
753 } else if (to == Type.LONG_TYPE) {
754 mv.visitInsn(Opcodes.D2L);
755 } else {
756 mv.visitInsn(Opcodes.D2I);
757 cast(Type.INT_TYPE, to);
758 }
759 } else if (from == Type.FLOAT_TYPE) {
760 if (to == Type.DOUBLE_TYPE) {
761 mv.visitInsn(Opcodes.F2D);
762 } else if (to == Type.LONG_TYPE) {
763 mv.visitInsn(Opcodes.F2L);
764 } else {
765 mv.visitInsn(Opcodes.F2I);
766 cast(Type.INT_TYPE, to);
767 }
768 } else if (from == Type.LONG_TYPE) {
769 if (to == Type.DOUBLE_TYPE) {
770 mv.visitInsn(Opcodes.L2D);
771 } else if (to == Type.FLOAT_TYPE) {
772 mv.visitInsn(Opcodes.L2F);
773 } else {
774 mv.visitInsn(Opcodes.L2I);
775 cast(Type.INT_TYPE, to);
776 }
777 } else {
778 if (to == Type.BYTE_TYPE) {
779 mv.visitInsn(Opcodes.I2B);
780 } else if (to == Type.CHAR_TYPE) {
781 mv.visitInsn(Opcodes.I2C);
782 } else if (to == Type.DOUBLE_TYPE) {
783 mv.visitInsn(Opcodes.I2D);
784 } else if (to == Type.FLOAT_TYPE) {
785 mv.visitInsn(Opcodes.I2F);
786 } else if (to == Type.LONG_TYPE) {
787 mv.visitInsn(Opcodes.I2L);
788 } else if (to == Type.SHORT_TYPE) {
789 mv.visitInsn(Opcodes.I2S);
790 }
791 }
792 }
793 }
794
795 // -----------------------------------------------------------------------------------------------
796 // Instructions to do boxing and unboxing operations

Callers 3

emitExprForIntsMethod · 0.80
emitThenForIntsMethod · 0.80
boxArgMethod · 0.80

Calls 2

getSortMethod · 0.45
visitInsnMethod · 0.45

Tested by

no test coverage detected