47
47
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
48
48
import com .oracle .graal .python .builtins .modules .WarningsModuleBuiltins ;
49
49
import com .oracle .graal .python .builtins .objects .PNone ;
50
- import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
51
50
import com .oracle .graal .python .builtins .objects .floats .PFloat ;
52
51
import com .oracle .graal .python .nodes .ErrorMessages ;
53
52
import com .oracle .graal .python .nodes .PGuards ;
59
58
import com .oracle .graal .python .nodes .object .GetClassNode ;
60
59
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
61
60
import com .oracle .graal .python .nodes .util .CastToJavaDoubleNode ;
62
- import com .oracle .truffle .api .dsl .Bind ;
63
61
import com .oracle .truffle .api .dsl .Cached ;
64
62
import com .oracle .truffle .api .dsl .GenerateUncached ;
65
63
import com .oracle .truffle .api .dsl .ImportStatic ;
@@ -103,11 +101,11 @@ public abstract class PyFloatAsDoubleNode extends PNodeWithContext {
103
101
return object ? 1.0 : 0.0 ;
104
102
}
105
103
106
- @ Specialization (guards = {"!isDouble(object)" , "!isInteger(object)" , "!isBoolean(object)" , "!isPFloat(object)" , "!isNativeObject(object) || !isSubtypeNode.execute(type, PFloat)" }, limit = "1" )
104
+ // TODO When we implement casting native floats, this should cast them directly instead of
105
+ // calling their __float__
106
+ @ Specialization (guards = {"!isDouble(object)" , "!isInteger(object)" , "!isBoolean(object)" , "!isPFloat(object)" })
107
107
double doObject (VirtualFrame frame , Object object ,
108
- @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ,
109
- @ SuppressWarnings ("unused" ) @ Cached IsSubtypeNode isSubtypeNode ,
110
- @ Bind ("getClassNode.execute(object)" ) Object type ,
108
+ @ Cached GetClassNode getClassNode ,
111
109
@ Cached LookupSpecialMethodNode .Dynamic lookup ,
112
110
@ Cached CallUnaryMethodNode call ,
113
111
@ Cached GetClassNode resultClassNode ,
@@ -118,6 +116,7 @@ public abstract class PyFloatAsDoubleNode extends PNodeWithContext {
118
116
@ Cached CastToJavaDoubleNode cast ,
119
117
@ Cached WarningsModuleBuiltins .WarnNode warnNode ,
120
118
@ Cached PRaiseNode raiseNode ) {
119
+ Object type = getClassNode .execute (object );
121
120
Object floatDescr = lookup .execute (frame , type , __FLOAT__ , object , false );
122
121
if (floatDescr != PNone .NO_VALUE ) {
123
122
Object result = call .executeObject (frame , floatDescr , object );
@@ -139,14 +138,6 @@ public abstract class PyFloatAsDoubleNode extends PNodeWithContext {
139
138
throw raiseNode .raise (TypeError , ErrorMessages .MUST_BE_REAL_NUMBER , object );
140
139
}
141
140
142
- @ Specialization (guards = "isSubtypeNode.execute(getClassNode.execute(object), PFloat)" , limit = "1" )
143
- double doNativeObject (@ SuppressWarnings ("unused" ) PythonAbstractNativeObject object ,
144
- @ SuppressWarnings ("unused" ) @ Cached GetClassNode getClassNode ,
145
- @ SuppressWarnings ("unused" ) @ Cached IsSubtypeNode isSubtypeNode ,
146
- @ Cached CastToJavaDoubleNode cast ) {
147
- return cast .execute (object );
148
- }
149
-
150
141
public static PyFloatAsDoubleNode create () {
151
142
return PyFloatAsDoubleNodeGen .create ();
152
143
}
0 commit comments