Skip to content

Commit a91a5bb

Browse files
fangerertimfel
authored andcommitted
Support native subclass in float.hex
1 parent 796b52e commit a91a5bb

File tree

1 file changed

+14
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats

1 file changed

+14
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
import com.oracle.truffle.api.nodes.UnexpectedResultException;
130130
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
131131
import com.oracle.truffle.api.strings.TruffleString;
132+
import com.oracle.truffle.api.strings.TruffleString.FromJavaStringNode;
132133

133134
@CoreFunctions(extendClasses = PythonBuiltinClassType.PFloat)
134135
public final class FloatBuiltins extends PythonBuiltins {
@@ -863,10 +864,21 @@ private static String makeHexNumber(double value) {
863864
}
864865

865866
@Specialization
866-
public static TruffleString hexD(double value,
867-
@Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
867+
static TruffleString doDouble(double value,
868+
@Shared @Cached FromJavaStringNode fromJavaStringNode) {
868869
return fromJavaStringNode.execute(makeHexNumber(value), TS_ENCODING);
869870
}
871+
872+
@Specialization
873+
TruffleString doNative(VirtualFrame frame, PythonAbstractNativeObject value,
874+
@Shared @Cached FromJavaStringNode fromJavaStringNode,
875+
@Cached FromNativeSubclassNode fromNativeSubclassNode) {
876+
Double dvalue = fromNativeSubclassNode.execute(frame, value);
877+
if (dvalue != null) {
878+
return fromJavaStringNode.execute(makeHexNumber(dvalue), TS_ENCODING);
879+
}
880+
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.DESCR_S_FOR_P_OBJ_DOESNT_APPLY_TO_P, "hex", 1.0, value);
881+
}
870882
}
871883

872884
@Builtin(name = J___RMOD__, minNumOfPositionalArgs = 2, reverseOperation = true)

0 commit comments

Comments
 (0)