56
56
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
57
57
import com .oracle .graal .python .runtime .ArithmeticUtil ;
58
58
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
59
+ import com .oracle .truffle .api .CompilerDirectives ;
59
60
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
60
- import com .oracle .truffle .api .dsl .Cached ;
61
61
import com .oracle .truffle .api .dsl .Fallback ;
62
62
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
63
63
import com .oracle .truffle .api .dsl .NodeFactory ;
@@ -1855,6 +1855,17 @@ int bitLength(PInt argument) {
1855
1855
@ GenerateNodeFactory
1856
1856
@ Builtin (name = "real" , fixedNumOfArguments = 1 , isGetter = true , doc = "the real part of a complex number" )
1857
1857
static abstract class RealNode extends PythonBuiltinNode {
1858
+
1859
+ @ Child private GetClassNode getClassNode ;
1860
+
1861
+ protected PythonClass getClass (Object value ) {
1862
+ if (getClassNode == null ) {
1863
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1864
+ getClassNode = insert (GetClassNode .create ());
1865
+ }
1866
+ return getClassNode .execute (value );
1867
+ }
1868
+
1858
1869
@ Specialization
1859
1870
int get (boolean self ) {
1860
1871
return self ? 1 : 0 ;
@@ -1870,13 +1881,13 @@ long get(long self) {
1870
1881
return self ;
1871
1882
}
1872
1883
1873
- @ Specialization
1874
- PInt get (PInt self ,
1875
- @ Cached ( "create()" ) GetClassNode clazzNode ) {
1876
- PythonClass clazz = clazzNode . execute ( self );
1877
- if ( clazz . isBuiltin ()) {
1878
- return self ;
1879
- }
1884
+ @ Specialization ( guards = "cannotBeOverridden(getClass(self))" )
1885
+ PInt getPInt (PInt self ) {
1886
+ return self ;
1887
+ }
1888
+
1889
+ @ Specialization ( guards = "!cannotBeOverridden(getClass( self))" )
1890
+ PInt getPIntOverriden ( PInt self ) {
1880
1891
return factory ().createInt (self .getValue ());
1881
1892
}
1882
1893
}
@@ -1885,22 +1896,7 @@ PInt get(PInt self,
1885
1896
@ Builtin (name = "imag" , fixedNumOfArguments = 1 , isGetter = true , doc = "the imaginary part of a complex number" )
1886
1897
static abstract class ImagNode extends PythonBuiltinNode {
1887
1898
@ Specialization
1888
- int get (@ SuppressWarnings ("unused" ) boolean self ) {
1889
- return 0 ;
1890
- }
1891
-
1892
- @ Specialization
1893
- int get (@ SuppressWarnings ("unused" ) int self ) {
1894
- return 0 ;
1895
- }
1896
-
1897
- @ Specialization
1898
- int get (@ SuppressWarnings ("unused" ) long self ) {
1899
- return 0 ;
1900
- }
1901
-
1902
- @ Specialization
1903
- int get (@ SuppressWarnings ("unused" ) PInt self ) {
1899
+ int get (@ SuppressWarnings ("unused" ) Object self ) {
1904
1900
return 0 ;
1905
1901
}
1906
1902
}
@@ -1915,27 +1911,11 @@ static abstract class NumeratorNode extends RealNode {
1915
1911
@ Builtin (name = "denominator" , fixedNumOfArguments = 1 , isGetter = true , doc = "the denominator of a rational number in lowest terms" )
1916
1912
static abstract class DenominatorNode extends PythonBuiltinNode {
1917
1913
@ Specialization
1918
- int get (@ SuppressWarnings ("unused" ) boolean self ) {
1919
- return 1 ;
1920
- }
1921
-
1922
- @ Specialization
1923
- int get (@ SuppressWarnings ("unused" ) int self ) {
1924
- return 1 ;
1925
- }
1926
-
1927
- @ Specialization
1928
- int get (@ SuppressWarnings ("unused" ) long self ) {
1929
- return 1 ;
1930
- }
1931
-
1932
- @ Specialization
1933
- int get (@ SuppressWarnings ("unused" ) PInt self ) {
1914
+ int get (@ SuppressWarnings ("unused" ) Object self ) {
1934
1915
return 1 ;
1935
1916
}
1936
1917
}
1937
1918
1938
-
1939
1919
@ Builtin (name = SpecialMethodNames .__INT__ , fixedNumOfArguments = 1 )
1940
1920
@ GenerateNodeFactory
1941
1921
abstract static class IntNode extends PythonBuiltinNode {
0 commit comments