|
141 | 141 | import com.oracle.truffle.api.interop.ArityException;
|
142 | 142 | import com.oracle.truffle.api.interop.InteropLibrary;
|
143 | 143 | import com.oracle.truffle.api.interop.TruffleObject;
|
144 |
| -import com.oracle.truffle.api.interop.UnknownIdentifierException; |
145 | 144 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
146 | 145 | import com.oracle.truffle.api.interop.UnsupportedTypeException;
|
147 | 146 | import com.oracle.truffle.api.library.CachedLibrary;
|
148 | 147 | import com.oracle.truffle.api.nodes.ExplodeLoop;
|
149 | 148 | import com.oracle.truffle.api.nodes.Node;
|
150 |
| -import com.oracle.truffle.api.nodes.NodeCost; |
151 | 149 | import com.oracle.truffle.api.nodes.NodeUtil;
|
152 | 150 | import com.oracle.truffle.api.profiles.BranchProfile;
|
153 | 151 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
@@ -707,143 +705,59 @@ protected static boolean isNaN(PrimitiveNativeWrapper object) {
|
707 | 705 | */
|
708 | 706 | @GenerateUncached
|
709 | 707 | public abstract static class ToJavaNode extends CExtToJavaNode {
|
710 |
| -// abstract static class ToJavaCachedNode extends ToJavaNode { |
711 | 708 |
|
712 |
| - @Specialization |
713 |
| - static PythonAbstractObject doPythonObject(@SuppressWarnings("unused") CExtContext nativeContext, PythonAbstractObject value) { |
714 |
| - return value; |
715 |
| - } |
716 |
| - |
717 |
| - @Specialization |
718 |
| - static Object doWrapper(@SuppressWarnings("unused") CExtContext nativeContext, PythonNativeWrapper value, |
719 |
| - @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
720 |
| - return toJavaNode.execute(value); |
721 |
| - } |
| 709 | + @Specialization |
| 710 | + static PythonAbstractObject doPythonObject(@SuppressWarnings("unused") CExtContext nativeContext, PythonAbstractObject value) { |
| 711 | + return value; |
| 712 | + } |
722 | 713 |
|
723 |
| - @Specialization |
724 |
| - static String doString(@SuppressWarnings("unused") CExtContext nativeContext, String object) { |
725 |
| - return object; |
726 |
| - } |
| 714 | + @Specialization |
| 715 | + static Object doWrapper(@SuppressWarnings("unused") CExtContext nativeContext, PythonNativeWrapper value, |
| 716 | + @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
| 717 | + return toJavaNode.execute(value); |
| 718 | + } |
727 | 719 |
|
728 |
| - @Specialization |
729 |
| - static boolean doBoolean(@SuppressWarnings("unused") CExtContext nativeContext, boolean b) { |
730 |
| - return b; |
731 |
| - } |
| 720 | + @Specialization |
| 721 | + static String doString(@SuppressWarnings("unused") CExtContext nativeContext, String object) { |
| 722 | + return object; |
| 723 | + } |
732 | 724 |
|
733 |
| - @Specialization |
734 |
| - static int doInt(@SuppressWarnings("unused") CExtContext nativeContext, int i) { |
735 |
| - // Note: Sulong guarantees that an integer won't be a pointer |
736 |
| - return i; |
737 |
| - } |
| 725 | + @Specialization |
| 726 | + static boolean doBoolean(@SuppressWarnings("unused") CExtContext nativeContext, boolean b) { |
| 727 | + return b; |
| 728 | + } |
738 | 729 |
|
739 |
| - @Specialization |
740 |
| - static Object doLong(@SuppressWarnings("unused") CExtContext nativeContext, long l, |
741 |
| - @Exclusive @Cached PCallCapiFunction callNativeNode, |
742 |
| - @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
743 |
| - // Unfortunately, a long could be a native pointer and therefore a handle. So, we |
744 |
| - // must try resolving it. At least we know that it's not a native type. |
745 |
| - return toJavaNode.execute(callNativeNode.call(FUN_NATIVE_LONG_TO_JAVA, l)); |
746 |
| - } |
| 730 | + @Specialization |
| 731 | + static int doInt(@SuppressWarnings("unused") CExtContext nativeContext, int i) { |
| 732 | + // Note: Sulong guarantees that an integer won't be a pointer |
| 733 | + return i; |
| 734 | + } |
747 | 735 |
|
748 |
| - @Specialization |
749 |
| - static byte doByte(@SuppressWarnings("unused") CExtContext nativeContext, byte b) { |
750 |
| - return b; |
751 |
| - } |
| 736 | + @Specialization |
| 737 | + static Object doLong(@SuppressWarnings("unused") CExtContext nativeContext, long l, |
| 738 | + @Exclusive @Cached PCallCapiFunction callNativeNode, |
| 739 | + @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
| 740 | + // Unfortunately, a long could be a native pointer and therefore a handle. So, we |
| 741 | + // must try resolving it. At least we know that it's not a native type. |
| 742 | + return toJavaNode.execute(callNativeNode.call(FUN_NATIVE_LONG_TO_JAVA, l)); |
| 743 | + } |
752 | 744 |
|
753 |
| - @Specialization(guards = "isForeignObject(value)") |
754 |
| - static Object doForeign(@SuppressWarnings("unused") CExtContext nativeContext, Object value, |
755 |
| - @Exclusive @Cached PCallCapiFunction callNativeNode, |
756 |
| - @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
757 |
| - return toJavaNode.execute(callNativeNode.call(FUN_NATIVE_TO_JAVA, value)); |
758 |
| - } |
| 745 | + @Specialization |
| 746 | + static byte doByte(@SuppressWarnings("unused") CExtContext nativeContext, byte b) { |
| 747 | + return b; |
| 748 | + } |
759 | 749 |
|
760 |
| - protected static boolean isForeignObject(Object obj) { |
761 |
| - return !(obj instanceof PythonAbstractObject || obj instanceof PythonNativeWrapper || obj instanceof String || obj instanceof Boolean || obj instanceof Integer || |
762 |
| - obj instanceof Long || obj instanceof Byte); |
763 |
| - } |
| 750 | + @Specialization(guards = "isForeignObject(value)") |
| 751 | + static Object doForeign(@SuppressWarnings("unused") CExtContext nativeContext, Object value, |
| 752 | + @Exclusive @Cached PCallCapiFunction callNativeNode, |
| 753 | + @Shared("toJavaNode") @Cached AsPythonObjectNode toJavaNode) { |
| 754 | + return toJavaNode.execute(callNativeNode.call(FUN_NATIVE_TO_JAVA, value)); |
| 755 | + } |
764 | 756 |
|
765 |
| -// } |
766 |
| -// |
767 |
| -// private static final class ToJavaUncachedNode extends ToJavaNode { |
768 |
| -// private static final ToJavaUncachedNode INSTANCE = new ToJavaUncachedNode(); |
769 |
| -// |
770 |
| -// @Override |
771 |
| -// public Object execute(CExtContext nativeContext, Object arg0Value) { |
772 |
| -// if (arg0Value instanceof PythonAbstractObject) { |
773 |
| -// PythonAbstractObject arg0Value_ = (PythonAbstractObject) arg0Value; |
774 |
| -// return ToJavaCachedNode.doPythonObject(nativeContext, arg0Value_); |
775 |
| -// } |
776 |
| -// if (arg0Value instanceof PythonNativeWrapper) { |
777 |
| -// PythonNativeWrapper arg0Value_ = (PythonNativeWrapper) arg0Value; |
778 |
| -// return ToJavaCachedNode.doWrapper(nativeContext, arg0Value_, (CExtNodesFactory.AsPythonObjectNodeGen.getUncached())); |
779 |
| -// } |
780 |
| -// if (arg0Value instanceof String) { |
781 |
| -// String arg0Value_ = (String) arg0Value; |
782 |
| -// return ToJavaCachedNode.doString(nativeContext, arg0Value_); |
783 |
| -// } |
784 |
| -// if (arg0Value instanceof Boolean) { |
785 |
| -// boolean arg0Value_ = (boolean) arg0Value; |
786 |
| -// return ToJavaCachedNode.doBoolean(nativeContext, arg0Value_); |
787 |
| -// } |
788 |
| -// if (arg0Value instanceof Integer) { |
789 |
| -// int arg0Value_ = (int) arg0Value; |
790 |
| -// return ToJavaCachedNode.doInt(nativeContext, arg0Value_); |
791 |
| -// } |
792 |
| -// if (arg0Value instanceof Long) { |
793 |
| -// long arg0Value_ = (long) arg0Value; |
794 |
| -// return ToJavaCachedNode.doLong(nativeContext, arg0Value_, (PCallCapiFunction.getUncached()), (CExtNodesFactory.AsPythonObjectNodeGen.getUncached())); |
795 |
| -// } |
796 |
| -// if (arg0Value instanceof Byte) { |
797 |
| -// byte arg0Value_ = (byte) arg0Value; |
798 |
| -// return ToJavaCachedNode.doByte(nativeContext, arg0Value_); |
799 |
| -// } |
800 |
| -// return ToJavaCachedNode.doForeign(nativeContext, arg0Value, (PCallCapiFunction.getUncached()), (CExtNodesFactory.AsPythonObjectNodeGen.getUncached())); |
801 |
| -// } |
802 |
| -// |
803 |
| -// @Override |
804 |
| -// public boolean executeBool(CExtContext nativeContext, boolean arg0Value) { |
805 |
| -// return ToJavaCachedNode.doBoolean(nativeContext, arg0Value); |
806 |
| -// } |
807 |
| -// |
808 |
| -// @Override |
809 |
| -// public byte executeByte(CExtContext nativeContext, byte arg0Value) { |
810 |
| -// return ToJavaCachedNode.doByte(nativeContext, arg0Value); |
811 |
| -// } |
812 |
| -// |
813 |
| -// @Override |
814 |
| -// public double executeDouble(CExtContext nativeContext, double arg0Value) { |
815 |
| -// return (double) ToJavaCachedNode.doForeign(nativeContext, arg0Value, (PCallCapiFunction.getUncached()), (CExtNodesFactory.AsPythonObjectNodeGen.getUncached())); |
816 |
| -// } |
817 |
| -// |
818 |
| -// @Override |
819 |
| -// public int executeInt(CExtContext nativeContext, int arg0Value) { |
820 |
| -// return ToJavaCachedNode.doInt(nativeContext, arg0Value); |
821 |
| -// } |
822 |
| -// |
823 |
| -// @Override |
824 |
| -// public long executeLong(CExtContext nativeContext, long arg0Value) { |
825 |
| -// return (long) ToJavaCachedNode.doLong(nativeContext, arg0Value, (PCallCapiFunction.getUncached()), (CExtNodesFactory.AsPythonObjectNodeGen.getUncached())); |
826 |
| -// } |
827 |
| -// |
828 |
| -// @Override |
829 |
| -// public NodeCost getCost() { |
830 |
| -// return NodeCost.MEGAMORPHIC; |
831 |
| -// } |
832 |
| -// |
833 |
| -// @Override |
834 |
| -// public boolean isAdoptable() { |
835 |
| -// return false; |
836 |
| -// } |
837 |
| -// |
838 |
| -// } |
839 |
| -// |
840 |
| -// public static ToJavaNode create() { |
841 |
| -// return ToJavaCachedNodeGen.create(); |
842 |
| -// } |
843 |
| -// |
844 |
| -// public static ToJavaNode getUncached() { |
845 |
| -// return ToJavaUncachedNode.INSTANCE; |
846 |
| -// } |
| 757 | + protected static boolean isForeignObject(Object obj) { |
| 758 | + return !(obj instanceof PythonAbstractObject || obj instanceof PythonNativeWrapper || obj instanceof String || obj instanceof Boolean || obj instanceof Integer || |
| 759 | + obj instanceof Long || obj instanceof Byte); |
| 760 | + } |
847 | 761 | }
|
848 | 762 |
|
849 | 763 | // -----------------------------------------------------------------------------------------------------------------
|
|
0 commit comments