59
59
import com .oracle .graal .python .builtins .modules .PythonCextBuiltins ;
60
60
import com .oracle .graal .python .builtins .objects .PNone ;
61
61
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
62
- import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .PrimitiveNativeWrapper ;
63
- import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .PythonObjectNativeWrapper ;
64
62
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .AllToJavaNodeGen ;
65
63
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .AllToSulongNodeGen ;
66
64
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .AsPythonObjectNodeGen ;
77
75
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .TernaryFirstThirdToSulongNodeGen ;
78
76
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .TransformExceptionToNativeNodeGen ;
79
77
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .WrapVoidPtrNodeGen ;
78
+ import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .PrimitiveNativeWrapper ;
79
+ import com .oracle .graal .python .builtins .objects .cext .DynamicObjectNativeWrapper .PythonObjectNativeWrapper ;
80
80
import com .oracle .graal .python .builtins .objects .cext .capi .CApiContext ;
81
81
import com .oracle .graal .python .builtins .objects .cext .capi .NativeReferenceCache .ResolveNativeReferenceNode ;
82
82
import com .oracle .graal .python .builtins .objects .cext .capi .PyTruffleObjectFree .FreeNode ;
@@ -351,17 +351,13 @@ static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtCon
351
351
return PrimitiveNativeWrapper .createInt (i );
352
352
}
353
353
354
- /**
355
- * Generic integer conversion.<br/>
356
- * In the interpreter: we just lookup the cached primitive native wrapper and use this
357
- * instance. In compiled code, we do the same but create a fresh copy such that the compiler
358
- * always sees a fresh instance. This avoids a phi and certainly a real allocation. Note: it
359
- * is important to copy the existing cached wrapper because otherwise pointer equality is
360
- * not ensured (see also:
361
- * {@link AsPythonObjectBaseNode#mayUsePrimitive(IsPointerNode, PrimitiveNativeWrapper)}).
362
- */
363
- @ Specialization (replaces = "doIntegerSmall" )
364
- static PrimitiveNativeWrapper doInteger (@ SuppressWarnings ("unused" ) CExtContext cextContext , int i ,
354
+ @ Specialization (guards = "!isSmallInteger(i)" , replaces = "doIntegerSmall" )
355
+ static PrimitiveNativeWrapper doInteger (@ SuppressWarnings ("unused" ) CExtContext cextContext , int i ) {
356
+ return PrimitiveNativeWrapper .createInt (i );
357
+ }
358
+
359
+ @ Specialization (replaces = {"doIntegerSmall" , "doInteger" })
360
+ static PrimitiveNativeWrapper doIntegerGeneric (@ SuppressWarnings ("unused" ) CExtContext cextContext , int i ,
365
361
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
366
362
if (CApiGuards .isSmallInteger (i )) {
367
363
return doIntegerSmall (cextContext , i , contextRef );
@@ -379,8 +375,13 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
379
375
return PrimitiveNativeWrapper .createLong (l );
380
376
}
381
377
382
- @ Specialization (replaces = "doLongSmall" )
383
- static PrimitiveNativeWrapper doLong (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ,
378
+ @ Specialization (guards = "!isSmallLong(l)" , replaces = "doLongSmall" )
379
+ static PrimitiveNativeWrapper doLong (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ) {
380
+ return PrimitiveNativeWrapper .createLong (l );
381
+ }
382
+
383
+ @ Specialization (replaces = {"doLongSmall" , "doLong" })
384
+ static PrimitiveNativeWrapper doLongGeneric (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ,
384
385
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
385
386
if (CApiGuards .isSmallLong (l )) {
386
387
return doLongSmall (cextContext , l , contextRef );
@@ -596,6 +597,20 @@ static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtCon
596
597
return PrimitiveNativeWrapper .createInt (i );
597
598
}
598
599
600
+ @ Specialization (guards = "!isSmallInteger(i)" , replaces = "doIntegerSmall" )
601
+ static PrimitiveNativeWrapper doInteger (@ SuppressWarnings ("unused" ) CExtContext cextContext , int i ) {
602
+ return PrimitiveNativeWrapper .createInt (i );
603
+ }
604
+
605
+ @ Specialization (replaces = {"doIntegerSmall" , "doInteger" })
606
+ static PrimitiveNativeWrapper doIntegerGeneric (CExtContext cextContext , int i ,
607
+ @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
608
+ if (CApiGuards .isSmallInteger (i )) {
609
+ return doIntegerSmall (cextContext , i , contextRef );
610
+ }
611
+ return PrimitiveNativeWrapper .createInt (i );
612
+ }
613
+
599
614
@ Specialization (guards = "isSmallLong(l)" )
600
615
static PrimitiveNativeWrapper doLongSmall (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ,
601
616
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
@@ -608,17 +623,13 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
608
623
return PrimitiveNativeWrapper .createLong (l );
609
624
}
610
625
611
- @ Specialization (replaces = "doIntegerSmall" )
612
- static PrimitiveNativeWrapper doInteger (CExtContext cextContext , int i ,
613
- @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
614
- if (CApiGuards .isSmallInteger (i )) {
615
- return doIntegerSmall (cextContext , i , contextRef );
616
- }
617
- return PrimitiveNativeWrapper .createInt (i );
626
+ @ Specialization (guards = "!isSmallLong(l)" , replaces = "doLongSmall" )
627
+ static PrimitiveNativeWrapper doLong (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ) {
628
+ return PrimitiveNativeWrapper .createLong (l );
618
629
}
619
630
620
- @ Specialization (replaces = "doLongSmall" )
621
- static PrimitiveNativeWrapper doLong (CExtContext cextContext , long l ,
631
+ @ Specialization (replaces = { "doLongSmall" , "doLong" } )
632
+ static PrimitiveNativeWrapper doLongGeneric (CExtContext cextContext , long l ,
622
633
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
623
634
if (CApiGuards .isSmallLong (l )) {
624
635
return doLongSmall (cextContext , l , contextRef );
@@ -788,34 +799,44 @@ static Object doString(CExtContext cextContext, String str,
788
799
}
789
800
790
801
@ Specialization
791
- static Object doBoolean (@ SuppressWarnings ( "unused" ) CExtContext cextContext , boolean b ,
802
+ static Object doBoolean (CExtContext cextContext , boolean b ,
792
803
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ,
793
804
@ Cached ("createBinaryProfile()" ) ConditionProfile profile ) {
794
805
return ToNewRefNode .doBoolean (cextContext , b , contextRef , profile );
795
806
}
796
807
797
808
@ Specialization (guards = "isSmallInteger(i)" )
798
- static PrimitiveNativeWrapper doIntegerSmall (@ SuppressWarnings ( "unused" ) CExtContext cextContext , int i ,
809
+ static PrimitiveNativeWrapper doIntegerSmall (CExtContext cextContext , int i ,
799
810
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
800
811
return ToNewRefNode .doIntegerSmall (cextContext , i , contextRef );
801
812
}
802
813
814
+ @ Specialization (guards = "!isSmallInteger(i)" , replaces = "doIntegerSmall" )
815
+ static PrimitiveNativeWrapper doInteger (CExtContext cextContext , int i ) {
816
+ return ToNewRefNode .doInteger (cextContext , i );
817
+ }
818
+
819
+ @ Specialization (replaces = {"doIntegerSmall" , "doInteger" })
820
+ static PrimitiveNativeWrapper doIntegerGeneric (CExtContext cextContext , int i ,
821
+ @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
822
+ return ToNewRefNode .doIntegerGeneric (cextContext , i , contextRef );
823
+ }
824
+
803
825
@ Specialization (guards = "isSmallLong(l)" )
804
- static PrimitiveNativeWrapper doLongSmall (@ SuppressWarnings ( "unused" ) CExtContext cextContext , long l ,
826
+ static PrimitiveNativeWrapper doLongSmall (CExtContext cextContext , long l ,
805
827
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
806
828
return ToNewRefNode .doLongSmall (cextContext , l , contextRef );
807
829
}
808
830
809
- @ Specialization (replaces = "doIntegerSmall" )
810
- static PrimitiveNativeWrapper doInteger (CExtContext cextContext , int i ,
811
- @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
812
- return ToNewRefNode .doInteger (cextContext , i , contextRef );
831
+ @ Specialization (guards = "!isSmallLong(l)" , replaces = "doLongSmall" )
832
+ static PrimitiveNativeWrapper doLong (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ) {
833
+ return ToNewRefNode .doLong (cextContext , l );
813
834
}
814
835
815
- @ Specialization (replaces = "doLongSmall" )
816
- static PrimitiveNativeWrapper doLong (CExtContext cextContext , long l ,
836
+ @ Specialization (replaces = { "doLongSmall" , "doLong" } )
837
+ static PrimitiveNativeWrapper doLongGeneric (CExtContext cextContext , long l ,
817
838
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
818
- return ToNewRefNode .doLong (cextContext , l , contextRef );
839
+ return ToNewRefNode .doLongGeneric (cextContext , l , contextRef );
819
840
}
820
841
821
842
@ Specialization (guards = "!isNaN(d)" )
0 commit comments