63
63
64
64
import com .oracle .graal .python .builtins .Builtin ;
65
65
import com .oracle .graal .python .builtins .CoreFunctions ;
66
- import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
67
66
import com .oracle .graal .python .builtins .PythonBuiltins ;
68
67
import com .oracle .graal .python .builtins .modules .MathGuards ;
69
68
import com .oracle .graal .python .builtins .objects .PNone ;
70
69
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
71
70
import com .oracle .graal .python .builtins .objects .cext .CExtNodes .FromNativeSubclassNode ;
72
- import com .oracle .graal .python .builtins .objects .cext .NativeCAPISymbols ;
73
71
import com .oracle .graal .python .builtins .objects .cext .PythonNativeObject ;
74
72
import com .oracle .graal .python .builtins .objects .ints .PInt ;
75
73
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
95
93
96
94
@ CoreFunctions (extendClasses = PFloat .class )
97
95
public final class FloatBuiltins extends PythonBuiltins {
98
-
99
96
@ Override
100
97
protected List <? extends NodeFactory <? extends PythonBuiltinBaseNode >> getNodeFactories () {
101
98
return FloatBuiltinsFactory .getFactories ();
@@ -177,19 +174,15 @@ PFloat doPFloat(PFloat self) {
177
174
return self ;
178
175
}
179
176
180
- protected static FromNativeSubclassNode cacheGetFloat () {
181
- return FromNativeSubclassNode .create (PythonBuiltinClassType .PFloat , NativeCAPISymbols .FUN_PY_FLOAT_AS_DOUBLE );
177
+ @ Specialization (guards = "getFloat.isSubtype(possibleBase)" , limit = "1" )
178
+ PythonNativeObject doNativeFloat (PythonNativeObject possibleBase ,
179
+ @ SuppressWarnings ("unused" ) @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > getFloat ) {
180
+ return possibleBase ;
182
181
}
183
182
184
- @ Specialization
185
- Object doNativeFloat (PythonNativeObject possibleBase ,
186
- @ Cached ("cacheGetFloat()" ) FromNativeSubclassNode getFloat ) {
187
- Object convertedFloat = getFloat .execute (possibleBase );
188
- if (convertedFloat instanceof Double ) {
189
- return possibleBase ;
190
- } else {
191
- throw raise (PythonErrorType .TypeError , "must be real number, not %p" , possibleBase );
192
- }
183
+ @ Fallback
184
+ Object doFallback (Object possibleBase ) {
185
+ throw raise (PythonErrorType .TypeError , "must be real number, not %p" , possibleBase );
193
186
}
194
187
}
195
188
@@ -295,16 +288,12 @@ abstract static class MulNode extends PythonBinaryBuiltinNode {
295
288
return left * right .doubleValue ();
296
289
}
297
290
298
- protected static FromNativeSubclassNode cacheGetFloat () {
299
- return FromNativeSubclassNode .create (PythonBuiltinClassType .PFloat , NativeCAPISymbols .FUN_PY_FLOAT_AS_DOUBLE );
300
- }
301
-
302
291
@ Specialization
303
292
Object doDP (PythonNativeObject left , double right ,
304
- @ Cached ("cacheGetFloat ()" ) FromNativeSubclassNode getFloat ) {
305
- Object leftPrimitive = getFloat .execute (left );
306
- if (leftPrimitive != null && leftPrimitive instanceof Double ) {
307
- return (( double ) leftPrimitive ) * right ;
293
+ @ Cached ("nativeFloat ()" ) FromNativeSubclassNode < Double > getFloat ) {
294
+ Double leftPrimitive = getFloat .execute (left );
295
+ if (leftPrimitive != null ) {
296
+ return leftPrimitive * right ;
308
297
} else {
309
298
return PNotImplemented .NOT_IMPLEMENTED ;
310
299
}
@@ -811,6 +800,31 @@ boolean doDL(double x, long y) {
811
800
return x < y ;
812
801
}
813
802
803
+ @ Specialization (guards = "fromNativeNode.isSubtype(y)" , limit = "1" )
804
+ boolean doDN (double x , PythonNativeObject y ,
805
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
806
+ return x < fromNativeNode .execute (y );
807
+ }
808
+
809
+ @ Specialization (guards = {"nativeLeft.isSubtype(x)" , "nativeRight.isSubtype(y)" }, limit = "1" )
810
+ boolean doDN (PythonNativeObject x , PythonNativeObject y ,
811
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeLeft ,
812
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeRight ) {
813
+ return nativeLeft .execute (x ) < nativeRight .execute (y );
814
+ }
815
+
816
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
817
+ boolean doDN (PythonNativeObject x , double y ,
818
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
819
+ return fromNativeNode .execute (x ) < y ;
820
+ }
821
+
822
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
823
+ boolean doDN (PythonNativeObject x , long y ,
824
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
825
+ return fromNativeNode .execute (x ) < y ;
826
+ }
827
+
814
828
@ Fallback
815
829
@ SuppressWarnings ("unused" )
816
830
PNotImplemented doGeneric (Object a , Object b ) {
@@ -832,6 +846,31 @@ boolean doDL(double x, long y) {
832
846
return x <= y ;
833
847
}
834
848
849
+ @ Specialization (guards = "fromNativeNode.isSubtype(y)" , limit = "1" )
850
+ boolean doDN (double x , PythonNativeObject y ,
851
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
852
+ return x <= fromNativeNode .execute (y );
853
+ }
854
+
855
+ @ Specialization (guards = {"nativeLeft.isSubtype(x)" , "nativeRight.isSubtype(y)" }, limit = "1" )
856
+ boolean doNN (PythonNativeObject x , PythonNativeObject y ,
857
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeLeft ,
858
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeRight ) {
859
+ return nativeLeft .execute (x ) <= nativeRight .execute (y );
860
+ }
861
+
862
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
863
+ boolean doND (PythonNativeObject x , double y ,
864
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
865
+ return fromNativeNode .execute (x ) <= y ;
866
+ }
867
+
868
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
869
+ boolean doNL (PythonNativeObject x , long y ,
870
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
871
+ return fromNativeNode .execute (x ) <= y ;
872
+ }
873
+
835
874
@ Fallback
836
875
@ SuppressWarnings ("unused" )
837
876
PNotImplemented doGeneric (Object a , Object b ) {
@@ -853,6 +892,31 @@ boolean doDL(double x, long y) {
853
892
return x > y ;
854
893
}
855
894
895
+ @ Specialization (guards = "fromNativeNode.isSubtype(y)" , limit = "1" )
896
+ boolean doDN (double x , PythonNativeObject y ,
897
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
898
+ return x > fromNativeNode .execute (y );
899
+ }
900
+
901
+ @ Specialization (guards = {"nativeLeft.isSubtype(x)" , "nativeRight.isSubtype(y)" }, limit = "1" )
902
+ boolean doNN (PythonNativeObject x , PythonNativeObject y ,
903
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeLeft ,
904
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > nativeRight ) {
905
+ return nativeLeft .execute (x ) > nativeRight .execute (y );
906
+ }
907
+
908
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
909
+ boolean doND (PythonNativeObject x , double y ,
910
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
911
+ return fromNativeNode .execute (x ) > y ;
912
+ }
913
+
914
+ @ Specialization (guards = "fromNativeNode.isSubtype(x)" , limit = "1" )
915
+ boolean doNL (PythonNativeObject x , long y ,
916
+ @ Cached ("nativeFloat()" ) FromNativeSubclassNode <Double > fromNativeNode ) {
917
+ return fromNativeNode .execute (x ) > y ;
918
+ }
919
+
856
920
@ Fallback
857
921
@ SuppressWarnings ("unused" )
858
922
PNotImplemented doGeneric (Object a , Object b ) {
0 commit comments