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,25 +351,16 @@ 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
- if (CompilerDirectives .inInterpreter ()) {
368
- return doIntegerSmall (cextContext , i , contextRef );
369
- } else {
370
- // for explanation: see method doc
371
- return doIntegerSmall (cextContext , i , contextRef ).copy ();
372
- }
363
+ return doIntegerSmall (cextContext , i , contextRef );
373
364
}
374
365
return PrimitiveNativeWrapper .createInt (i );
375
366
}
@@ -384,16 +375,16 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
384
375
return PrimitiveNativeWrapper .createLong (l );
385
376
}
386
377
387
- @ Specialization (replaces = "doLongSmall" )
388
- 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 ,
389
385
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
390
386
if (CApiGuards .isSmallLong (l )) {
391
- // for explanation of this construct: see 'ToSulongNode.doInteger'
392
- if (CompilerDirectives .inInterpreter ()) {
393
- return doLongSmall (cextContext , l , contextRef );
394
- } else {
395
- return doLongSmall (cextContext , l , contextRef ).copy ();
396
- }
387
+ return doLongSmall (cextContext , l , contextRef );
397
388
}
398
389
return PrimitiveNativeWrapper .createLong (l );
399
390
}
@@ -606,6 +597,20 @@ static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtCon
606
597
return PrimitiveNativeWrapper .createInt (i );
607
598
}
608
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
+
609
614
@ Specialization (guards = "isSmallLong(l)" )
610
615
static PrimitiveNativeWrapper doLongSmall (@ SuppressWarnings ("unused" ) CExtContext cextContext , long l ,
611
616
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
@@ -618,30 +623,16 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
618
623
return PrimitiveNativeWrapper .createLong (l );
619
624
}
620
625
621
- @ Specialization (replaces = "doIntegerSmall" )
622
- static PrimitiveNativeWrapper doInteger (CExtContext cextContext , int i ,
623
- @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
624
- if (CApiGuards .isSmallInteger (i )) {
625
- // for explanation of this construct: see 'ToSulongNode.doInteger'
626
- if (CompilerDirectives .inInterpreter ()) {
627
- return doIntegerSmall (cextContext , i , contextRef );
628
- } else {
629
- return doIntegerSmall (cextContext , i , contextRef ).copy ();
630
- }
631
- }
632
- 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 );
633
629
}
634
630
635
- @ Specialization (replaces = "doLongSmall" )
636
- static PrimitiveNativeWrapper doLong (CExtContext cextContext , long l ,
631
+ @ Specialization (replaces = { "doLongSmall" , "doLong" } )
632
+ static PrimitiveNativeWrapper doLongGeneric (CExtContext cextContext , long l ,
637
633
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
638
634
if (CApiGuards .isSmallLong (l )) {
639
- // for explanation of this construct: see 'ToSulongNode.doInteger'
640
- if (CompilerDirectives .inInterpreter ()) {
641
- return doLongSmall (cextContext , l , contextRef );
642
- } else {
643
- return doLongSmall (cextContext , l , contextRef ).copy ();
644
- }
635
+ return doLongSmall (cextContext , l , contextRef );
645
636
}
646
637
return PrimitiveNativeWrapper .createLong (l );
647
638
}
@@ -808,34 +799,44 @@ static Object doString(CExtContext cextContext, String str,
808
799
}
809
800
810
801
@ Specialization
811
- static Object doBoolean (@ SuppressWarnings ( "unused" ) CExtContext cextContext , boolean b ,
802
+ static Object doBoolean (CExtContext cextContext , boolean b ,
812
803
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ,
813
804
@ Cached ("createBinaryProfile()" ) ConditionProfile profile ) {
814
805
return ToNewRefNode .doBoolean (cextContext , b , contextRef , profile );
815
806
}
816
807
817
808
@ Specialization (guards = "isSmallInteger(i)" )
818
- static PrimitiveNativeWrapper doIntegerSmall (@ SuppressWarnings ( "unused" ) CExtContext cextContext , int i ,
809
+ static PrimitiveNativeWrapper doIntegerSmall (CExtContext cextContext , int i ,
819
810
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
820
811
return ToNewRefNode .doIntegerSmall (cextContext , i , contextRef );
821
812
}
822
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
+
823
825
@ Specialization (guards = "isSmallLong(l)" )
824
- static PrimitiveNativeWrapper doLongSmall (@ SuppressWarnings ( "unused" ) CExtContext cextContext , long l ,
826
+ static PrimitiveNativeWrapper doLongSmall (CExtContext cextContext , long l ,
825
827
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
826
828
return ToNewRefNode .doLongSmall (cextContext , l , contextRef );
827
829
}
828
830
829
- @ Specialization (replaces = "doIntegerSmall" )
830
- static PrimitiveNativeWrapper doInteger (CExtContext cextContext , int i ,
831
- @ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
832
- 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 );
833
834
}
834
835
835
- @ Specialization (replaces = "doLongSmall" )
836
- static PrimitiveNativeWrapper doLong (CExtContext cextContext , long l ,
836
+ @ Specialization (replaces = { "doLongSmall" , "doLong" } )
837
+ static PrimitiveNativeWrapper doLongGeneric (CExtContext cextContext , long l ,
837
838
@ Shared ("contextRef" ) @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ) {
838
- return ToNewRefNode .doLong (cextContext , l , contextRef );
839
+ return ToNewRefNode .doLongGeneric (cextContext , l , contextRef );
839
840
}
840
841
841
842
@ Specialization (guards = "!isNaN(d)" )
0 commit comments