|
70 | 70 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
71 | 71 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
72 | 72 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CheckFunctionResultNodeGen;
|
73 |
| -import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.ExternalFunctionNodeGen; |
74 | 73 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.GetByteArrayNodeGen;
|
75 | 74 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.TrufflePInt_AsPrimitiveFactory;
|
| 75 | +import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.ExternalFunctionNodeGen; |
76 | 76 | import com.oracle.graal.python.builtins.objects.PNone;
|
77 | 77 | import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
|
78 | 78 | import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
|
|
153 | 153 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
|
154 | 154 | import com.oracle.graal.python.nodes.call.InvokeNode;
|
155 | 155 | import com.oracle.graal.python.nodes.call.PythonCallNode;
|
| 156 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode; |
| 157 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode; |
156 | 158 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
|
157 | 159 | import com.oracle.graal.python.nodes.datamodel.IsSequenceNode;
|
158 | 160 | import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
|
|
170 | 172 | import com.oracle.graal.python.nodes.truffle.PythonTypes;
|
171 | 173 | import com.oracle.graal.python.nodes.util.CastToByteNode;
|
172 | 174 | import com.oracle.graal.python.nodes.util.CastToIndexNode;
|
| 175 | +import com.oracle.graal.python.nodes.util.CastToStringNode; |
173 | 176 | import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
|
174 | 177 | import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
|
175 | 178 | import com.oracle.graal.python.runtime.PythonContext;
|
@@ -2688,6 +2691,59 @@ private static Number parse(String source) throws ParseException {
|
2688 | 2691 | }
|
2689 | 2692 | }
|
2690 | 2693 |
|
| 2694 | + @Builtin(name = "PyTruffle_OS_DoubleToString", minNumOfPositionalArgs = 5, declaresExplicitSelf = true) |
| 2695 | + @GenerateNodeFactory |
| 2696 | + @ImportStatic(SpecialMethodNames.class) |
| 2697 | + abstract static class PyTruffle_OS_DoubleToString extends NativeBuiltin { |
| 2698 | + |
| 2699 | + /* keep in sync with macro 'TRANSLATE_TYPE' in 'pystrtod.c' */ |
| 2700 | + private static final int Py_DTST_FINITE = 0; |
| 2701 | + private static final int Py_DTST_INFINITE = 1; |
| 2702 | + private static final int Py_DTST_NAN = 2; |
| 2703 | + |
| 2704 | + @Specialization(guards = "isReprFormatCode(formatCode)") |
| 2705 | + @SuppressWarnings("unused") |
| 2706 | + PTuple doRepr(VirtualFrame frame, Object module, double val, int formatCode, int precision, int flags, |
| 2707 | + @Cached("create(__REPR__)") LookupAndCallUnaryNode callReprNode, |
| 2708 | + @Cached CastToStringNode castToStringNode, |
| 2709 | + @Cached GetNativeNullNode getNativeNullNode) { |
| 2710 | + Object reprString = callReprNode.executeObject(frame, val); |
| 2711 | + return createResult(new CStringWrapper(castToStringNode.execute(frame, reprString)), val); |
| 2712 | + } |
| 2713 | + |
| 2714 | + @Specialization(guards = "!isReprFormatCode(formatCode)") |
| 2715 | + Object doGeneric(VirtualFrame frame, Object module, double val, int formatCode, int precision, @SuppressWarnings("unused") int flags, |
| 2716 | + @Cached("create(__FORMAT__)") LookupAndCallBinaryNode callReprNode, |
| 2717 | + @Cached CastToStringNode castToStringNode, |
| 2718 | + @Cached GetNativeNullNode getNativeNullNode) { |
| 2719 | + try { |
| 2720 | + Object reprString = callReprNode.executeObject(frame, val, "." + precision + Character.toString((char) formatCode)); |
| 2721 | + return createResult(new CStringWrapper(castToStringNode.execute(frame, reprString)), val); |
| 2722 | + } catch (PException e) { |
| 2723 | + transformToNative(frame, e); |
| 2724 | + return getNativeNullNode.execute(module); |
| 2725 | + } |
| 2726 | + } |
| 2727 | + |
| 2728 | + private PTuple createResult(Object str, double val) { |
| 2729 | + return factory().createTuple(new Object[]{str, getTypeCode(val)}); |
| 2730 | + } |
| 2731 | + |
| 2732 | + private static int getTypeCode(double val) { |
| 2733 | + if (Double.isInfinite(val)) { |
| 2734 | + return Py_DTST_INFINITE; |
| 2735 | + } else if (Double.isNaN(val)) { |
| 2736 | + return Py_DTST_NAN; |
| 2737 | + } |
| 2738 | + assert Double.isFinite(val); |
| 2739 | + return Py_DTST_FINITE; |
| 2740 | + } |
| 2741 | + |
| 2742 | + protected static boolean isReprFormatCode(int formatCode) { |
| 2743 | + return (char) formatCode == 'r'; |
| 2744 | + } |
| 2745 | + } |
| 2746 | + |
2691 | 2747 | @Builtin(name = "PyUnicode_Decode", minNumOfPositionalArgs = 5, declaresExplicitSelf = true)
|
2692 | 2748 | @GenerateNodeFactory
|
2693 | 2749 | abstract static class PyUnicode_Decode extends NativeUnicodeBuiltin {
|
|
0 commit comments