@@ -1854,42 +1854,8 @@ int bitLength(PInt argument) {
18541854
18551855 @ GenerateNodeFactory
18561856 @ 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 {
18581858
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- }
18931859 }
18941860
18951861 @ GenerateNodeFactory
@@ -1903,13 +1869,13 @@ int get(@SuppressWarnings("unused") Object self) {
19031869
19041870 @ GenerateNodeFactory
19051871 @ 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 {
19071873
19081874 }
19091875
19101876 @ GenerateNodeFactory
19111877 @ 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 {
19131879
19141880 }
19151881
@@ -1925,6 +1891,21 @@ int get(@SuppressWarnings("unused") Object self) {
19251891 @ Builtin (name = SpecialMethodNames .__INT__ , fixedNumOfArguments = 1 )
19261892 @ GenerateNodeFactory
19271893 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+
19281909 @ Specialization
19291910 int doI (int self ) {
19301911 return self ;
@@ -1935,8 +1916,13 @@ long doL(long self) {
19351916 return self ;
19361917 }
19371918
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 ) {
19401926 return factory ().createInt (self .getValue ());
19411927 }
19421928 }
0 commit comments