140
140
import com .oracle .graal .python .builtins .objects .cext .capi .UnicodeObjectNodesFactory .UnicodeAsWideCharNodeGen ;
141
141
import com .oracle .graal .python .builtins .objects .cext .common .CExtAsPythonObjectNode ;
142
142
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes ;
143
- import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .AsNativeDoubleNode ;
144
143
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .Charsets ;
145
144
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .CheckFunctionResultNode ;
146
145
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .ConvertPIntToPrimitiveNode ;
193
192
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
194
193
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroStorageNode ;
195
194
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
195
+ import com .oracle .graal .python .lib .PyFloatAsDoubleNode ;
196
196
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
197
+ import com .oracle .graal .python .lib .PyNumberFloatNode ;
197
198
import com .oracle .graal .python .nodes .BuiltinNames ;
198
199
import com .oracle .graal .python .nodes .ErrorMessages ;
199
200
import com .oracle .graal .python .nodes .PGuards ;
@@ -2375,25 +2376,13 @@ static double doDoubleNativeWrapper(DynamicObjectNativeWrapper.PrimitiveNativeWr
2375
2376
return object .getDouble ();
2376
2377
}
2377
2378
2378
- @ Specialization (rewriteOn = PException .class )
2379
- double doGeneric (VirtualFrame frame , Object object ,
2380
- @ Shared ("asPythonObjectNode" ) @ Cached AsPythonObjectNode asPythonObjectNode ,
2381
- @ Shared ("asDoubleNode" ) @ Cached AsNativeDoubleNode asDoubleNode ) {
2382
- Object state = IndirectCallContext .enter (frame , getContext (), this );
2383
- try {
2384
- return asDoubleNode .executeDouble (asPythonObjectNode .execute (object ));
2385
- } finally {
2386
- IndirectCallContext .exit (frame , getContext (), state );
2387
- }
2388
- }
2389
-
2390
- @ Specialization (replaces = "doGeneric" )
2379
+ @ Specialization
2391
2380
double doGenericErr (VirtualFrame frame , Object object ,
2392
- @ Shared ( "asPythonObjectNode" ) @ Cached AsPythonObjectNode asPythonObjectNode ,
2393
- @ Shared ( "asDoubleNode" ) @ Cached AsNativeDoubleNode asDoubleNode ,
2381
+ @ Cached AsPythonObjectNode asPythonObjectNode ,
2382
+ @ Cached PyFloatAsDoubleNode asDoubleNode ,
2394
2383
@ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ) {
2395
2384
try {
2396
- return doGeneric (frame , object , asPythonObjectNode , asDoubleNode );
2385
+ return asDoubleNode . execute (frame , asPythonObjectNode . execute ( object ) );
2397
2386
} catch (PException e ) {
2398
2387
transformExceptionToNativeNode .execute (frame , e );
2399
2388
return -1.0 ;
@@ -2406,8 +2395,6 @@ static double doDoubleNativeWrapper(DynamicObjectNativeWrapper.PrimitiveNativeWr
2406
2395
@ GenerateNodeFactory
2407
2396
abstract static class PyNumberFloat extends NativeBuiltin {
2408
2397
2409
- @ Child private BuiltinConstructors .FloatNode floatNode ;
2410
-
2411
2398
@ Specialization (guards = "object.isDouble()" )
2412
2399
static Object doDoubleNativeWrapper (@ SuppressWarnings ("unused" ) Object module , PrimitiveNativeWrapper object ,
2413
2400
@ Cached AddRefCntNode refCntNode ) {
@@ -2420,24 +2407,14 @@ static Object doLongNativeWrapper(@SuppressWarnings("unused") Object module, Pri
2420
2407
return primitiveToSulongNode .execute ((double ) object .getLong ());
2421
2408
}
2422
2409
2423
- @ Specialization (rewriteOn = PException .class )
2424
- Object doGeneric (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object module , Object object ,
2425
- @ Shared ("toNewRefNode" ) @ Cached ToNewRefNode toNewRefNode ,
2426
- @ Shared ("asPythonObjectNode" ) @ Cached AsPythonObjectNode asPythonObjectNode ) {
2427
- if (floatNode == null ) {
2428
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2429
- floatNode = insert (BuiltinConstructorsFactory .FloatNodeFactory .create ());
2430
- }
2431
- return toNewRefNode .execute (floatNode .executeWith (frame , PythonBuiltinClassType .PFloat , asPythonObjectNode .execute (object )));
2432
- }
2433
-
2434
- @ Specialization (replaces = "doGeneric" )
2435
- Object doGenericErr (VirtualFrame frame , Object module , Object object ,
2436
- @ Exclusive @ Cached GetNativeNullNode getNativeNullNode ,
2437
- @ Shared ("toNewRefNode" ) @ Cached ToNewRefNode toNewRefNode ,
2438
- @ Shared ("asPythonObjectNode" ) @ Cached AsPythonObjectNode asPythonObjectNode ) {
2410
+ @ Specialization
2411
+ Object doGeneric (VirtualFrame frame , Object module , Object object ,
2412
+ @ Cached GetNativeNullNode getNativeNullNode ,
2413
+ @ Cached ToNewRefNode toNewRefNode ,
2414
+ @ Cached AsPythonObjectNode asPythonObjectNode ,
2415
+ @ Cached PyNumberFloatNode pyNumberFloat ) {
2439
2416
try {
2440
- return doGeneric ( frame , module , object , toNewRefNode , asPythonObjectNode );
2417
+ return toNewRefNode . execute ( pyNumberFloat . execute ( frame , asPythonObjectNode . execute ( object )) );
2441
2418
} catch (PException e ) {
2442
2419
transformToNative (frame , e );
2443
2420
return toNewRefNode .execute (getNativeNullNode .execute (module ));
0 commit comments