@@ -1854,42 +1854,8 @@ int bitLength(PInt argument) {
1854
1854
1855
1855
@ GenerateNodeFactory
1856
1856
@ Builtin (name = "real" , fixedNumOfArguments = 1 , isGetter = true , doc = "the real part of a complex number" )
1857
- static abstract class RealNode extends PythonBuiltinNode {
1857
+ static abstract class RealNode extends IntNode {
1858
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
-
1869
- @ Specialization
1870
- int get (boolean self ) {
1871
- return self ? 1 : 0 ;
1872
- }
1873
-
1874
- @ Specialization
1875
- int get (int self ) {
1876
- return self ;
1877
- }
1878
-
1879
- @ Specialization
1880
- long get (long self ) {
1881
- return self ;
1882
- }
1883
-
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 ) {
1891
- return factory ().createInt (self .getValue ());
1892
- }
1893
1859
}
1894
1860
1895
1861
@ GenerateNodeFactory
@@ -1903,13 +1869,13 @@ int get(@SuppressWarnings("unused") Object self) {
1903
1869
1904
1870
@ GenerateNodeFactory
1905
1871
@ Builtin (name = "numerator" , fixedNumOfArguments = 1 , isGetter = true , doc = "the numerator of a rational number in lowest terms" )
1906
- static abstract class NumeratorNode extends RealNode {
1872
+ static abstract class NumeratorNode extends IntNode {
1907
1873
1908
1874
}
1909
1875
1910
1876
@ GenerateNodeFactory
1911
1877
@ Builtin (name = "conjugate" , fixedNumOfArguments = 1 , doc = "Returns self, the complex conjugate of any int." )
1912
- static abstract class ConjugateNode extends RealNode {
1878
+ static abstract class ConjugateNode extends IntNode {
1913
1879
1914
1880
}
1915
1881
@@ -1925,6 +1891,21 @@ int get(@SuppressWarnings("unused") Object self) {
1925
1891
@ Builtin (name = SpecialMethodNames .__INT__ , fixedNumOfArguments = 1 )
1926
1892
@ GenerateNodeFactory
1927
1893
abstract static class IntNode extends PythonBuiltinNode {
1894
+ @ Child private GetClassNode getClassNode ;
1895
+
1896
+ protected PythonClass getClass (Object value ) {
1897
+ if (getClassNode == null ) {
1898
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1899
+ getClassNode = insert (GetClassNode .create ());
1900
+ }
1901
+ return getClassNode .execute (value );
1902
+ }
1903
+
1904
+ @ Specialization
1905
+ int doB (boolean self ) {
1906
+ return self ? 1 : 0 ;
1907
+ }
1908
+
1928
1909
@ Specialization
1929
1910
int doI (int self ) {
1930
1911
return self ;
@@ -1935,8 +1916,13 @@ long doL(long self) {
1935
1916
return self ;
1936
1917
}
1937
1918
1938
- @ Specialization
1939
- PInt doPi (PInt self ) {
1919
+ @ Specialization (guards = "cannotBeOverridden(getClass(self))" )
1920
+ PInt doPInt (PInt self ) {
1921
+ return self ;
1922
+ }
1923
+
1924
+ @ Specialization (guards = "!cannotBeOverridden(getClass(self))" )
1925
+ PInt doPIntOverriden (PInt self ) {
1940
1926
return factory ().createInt (self .getValue ());
1941
1927
}
1942
1928
}
0 commit comments