@@ -8,29 +8,23 @@ impl Node for ast::BoolOp {
88 Self :: And => pyast:: NodeBoolOpAnd :: static_type ( ) ,
99 Self :: Or => pyast:: NodeBoolOpOr :: static_type ( ) ,
1010 } ;
11- if let Some ( instance) = node_type. get_attr ( vm. ctx . intern_str ( "_instance" ) ) {
12- return instance;
13- }
14- NodeAst
15- . into_ref_with_type ( vm, node_type. to_owned ( ) )
16- . unwrap ( )
17- . into ( )
11+ singleton_node_to_object ( vm, node_type)
1812 }
1913
2014 fn ast_from_object (
21- _vm : & VirtualMachine ,
15+ vm : & VirtualMachine ,
2216 _source_file : & SourceFile ,
23- _object : PyObjectRef ,
17+ object : PyObjectRef ,
2418 ) -> PyResult < Self > {
25- let _cls = _object . class ( ) ;
26- Ok ( if _cls . is ( pyast:: NodeBoolOpAnd :: static_type ( ) ) {
19+ let cls = object . class ( ) ;
20+ Ok ( if cls . is ( pyast:: NodeBoolOpAnd :: static_type ( ) ) {
2721 Self :: And
28- } else if _cls . is ( pyast:: NodeBoolOpOr :: static_type ( ) ) {
22+ } else if cls . is ( pyast:: NodeBoolOpOr :: static_type ( ) ) {
2923 Self :: Or
3024 } else {
31- return Err ( _vm . new_type_error ( format ! (
25+ return Err ( vm . new_type_error ( format ! (
3226 "expected some sort of boolop, but got {}" ,
33- _object . repr( _vm ) ?
27+ object . repr( vm ) ?
3428 ) ) ) ;
3529 } )
3630 }
@@ -54,51 +48,45 @@ impl Node for ast::Operator {
5448 Self :: BitAnd => pyast:: NodeOperatorBitAnd :: static_type ( ) ,
5549 Self :: FloorDiv => pyast:: NodeOperatorFloorDiv :: static_type ( ) ,
5650 } ;
57- if let Some ( instance) = node_type. get_attr ( vm. ctx . intern_str ( "_instance" ) ) {
58- return instance;
59- }
60- NodeAst
61- . into_ref_with_type ( vm, node_type. to_owned ( ) )
62- . unwrap ( )
63- . into ( )
51+ singleton_node_to_object ( vm, node_type)
6452 }
6553
6654 fn ast_from_object (
67- _vm : & VirtualMachine ,
55+ vm : & VirtualMachine ,
6856 _source_file : & SourceFile ,
69- _object : PyObjectRef ,
57+ object : PyObjectRef ,
7058 ) -> PyResult < Self > {
71- let _cls = _object . class ( ) ;
72- Ok ( if _cls . is ( pyast:: NodeOperatorAdd :: static_type ( ) ) {
59+ let cls = object . class ( ) ;
60+ Ok ( if cls . is ( pyast:: NodeOperatorAdd :: static_type ( ) ) {
7361 Self :: Add
74- } else if _cls . is ( pyast:: NodeOperatorSub :: static_type ( ) ) {
62+ } else if cls . is ( pyast:: NodeOperatorSub :: static_type ( ) ) {
7563 Self :: Sub
76- } else if _cls . is ( pyast:: NodeOperatorMult :: static_type ( ) ) {
64+ } else if cls . is ( pyast:: NodeOperatorMult :: static_type ( ) ) {
7765 Self :: Mult
78- } else if _cls . is ( pyast:: NodeOperatorMatMult :: static_type ( ) ) {
66+ } else if cls . is ( pyast:: NodeOperatorMatMult :: static_type ( ) ) {
7967 Self :: MatMult
80- } else if _cls . is ( pyast:: NodeOperatorDiv :: static_type ( ) ) {
68+ } else if cls . is ( pyast:: NodeOperatorDiv :: static_type ( ) ) {
8169 Self :: Div
82- } else if _cls . is ( pyast:: NodeOperatorMod :: static_type ( ) ) {
70+ } else if cls . is ( pyast:: NodeOperatorMod :: static_type ( ) ) {
8371 Self :: Mod
84- } else if _cls . is ( pyast:: NodeOperatorPow :: static_type ( ) ) {
72+ } else if cls . is ( pyast:: NodeOperatorPow :: static_type ( ) ) {
8573 Self :: Pow
86- } else if _cls . is ( pyast:: NodeOperatorLShift :: static_type ( ) ) {
74+ } else if cls . is ( pyast:: NodeOperatorLShift :: static_type ( ) ) {
8775 Self :: LShift
88- } else if _cls . is ( pyast:: NodeOperatorRShift :: static_type ( ) ) {
76+ } else if cls . is ( pyast:: NodeOperatorRShift :: static_type ( ) ) {
8977 Self :: RShift
90- } else if _cls . is ( pyast:: NodeOperatorBitOr :: static_type ( ) ) {
78+ } else if cls . is ( pyast:: NodeOperatorBitOr :: static_type ( ) ) {
9179 Self :: BitOr
92- } else if _cls . is ( pyast:: NodeOperatorBitXor :: static_type ( ) ) {
80+ } else if cls . is ( pyast:: NodeOperatorBitXor :: static_type ( ) ) {
9381 Self :: BitXor
94- } else if _cls . is ( pyast:: NodeOperatorBitAnd :: static_type ( ) ) {
82+ } else if cls . is ( pyast:: NodeOperatorBitAnd :: static_type ( ) ) {
9583 Self :: BitAnd
96- } else if _cls . is ( pyast:: NodeOperatorFloorDiv :: static_type ( ) ) {
84+ } else if cls . is ( pyast:: NodeOperatorFloorDiv :: static_type ( ) ) {
9785 Self :: FloorDiv
9886 } else {
99- return Err ( _vm . new_type_error ( format ! (
87+ return Err ( vm . new_type_error ( format ! (
10088 "expected some sort of operator, but got {}" ,
101- _object . repr( _vm ) ?
89+ object . repr( vm ) ?
10290 ) ) ) ;
10391 } )
10492 }
@@ -113,33 +101,27 @@ impl Node for ast::UnaryOp {
113101 Self :: UAdd => pyast:: NodeUnaryOpUAdd :: static_type ( ) ,
114102 Self :: USub => pyast:: NodeUnaryOpUSub :: static_type ( ) ,
115103 } ;
116- if let Some ( instance) = node_type. get_attr ( vm. ctx . intern_str ( "_instance" ) ) {
117- return instance;
118- }
119- NodeAst
120- . into_ref_with_type ( vm, node_type. to_owned ( ) )
121- . unwrap ( )
122- . into ( )
104+ singleton_node_to_object ( vm, node_type)
123105 }
124106
125107 fn ast_from_object (
126- _vm : & VirtualMachine ,
108+ vm : & VirtualMachine ,
127109 _source_file : & SourceFile ,
128- _object : PyObjectRef ,
110+ object : PyObjectRef ,
129111 ) -> PyResult < Self > {
130- let _cls = _object . class ( ) ;
131- Ok ( if _cls . is ( pyast:: NodeUnaryOpInvert :: static_type ( ) ) {
112+ let cls = object . class ( ) ;
113+ Ok ( if cls . is ( pyast:: NodeUnaryOpInvert :: static_type ( ) ) {
132114 Self :: Invert
133- } else if _cls . is ( pyast:: NodeUnaryOpNot :: static_type ( ) ) {
115+ } else if cls . is ( pyast:: NodeUnaryOpNot :: static_type ( ) ) {
134116 Self :: Not
135- } else if _cls . is ( pyast:: NodeUnaryOpUAdd :: static_type ( ) ) {
117+ } else if cls . is ( pyast:: NodeUnaryOpUAdd :: static_type ( ) ) {
136118 Self :: UAdd
137- } else if _cls . is ( pyast:: NodeUnaryOpUSub :: static_type ( ) ) {
119+ } else if cls . is ( pyast:: NodeUnaryOpUSub :: static_type ( ) ) {
138120 Self :: USub
139121 } else {
140- return Err ( _vm . new_type_error ( format ! (
122+ return Err ( vm . new_type_error ( format ! (
141123 "expected some sort of unaryop, but got {}" ,
142- _object . repr( _vm ) ?
124+ object . repr( vm ) ?
143125 ) ) ) ;
144126 } )
145127 }
@@ -160,45 +142,39 @@ impl Node for ast::CmpOp {
160142 Self :: In => pyast:: NodeCmpOpIn :: static_type ( ) ,
161143 Self :: NotIn => pyast:: NodeCmpOpNotIn :: static_type ( ) ,
162144 } ;
163- if let Some ( instance) = node_type. get_attr ( vm. ctx . intern_str ( "_instance" ) ) {
164- return instance;
165- }
166- NodeAst
167- . into_ref_with_type ( vm, node_type. to_owned ( ) )
168- . unwrap ( )
169- . into ( )
145+ singleton_node_to_object ( vm, node_type)
170146 }
171147
172148 fn ast_from_object (
173- _vm : & VirtualMachine ,
149+ vm : & VirtualMachine ,
174150 _source_file : & SourceFile ,
175- _object : PyObjectRef ,
151+ object : PyObjectRef ,
176152 ) -> PyResult < Self > {
177- let _cls = _object . class ( ) ;
178- Ok ( if _cls . is ( pyast:: NodeCmpOpEq :: static_type ( ) ) {
153+ let cls = object . class ( ) ;
154+ Ok ( if cls . is ( pyast:: NodeCmpOpEq :: static_type ( ) ) {
179155 Self :: Eq
180- } else if _cls . is ( pyast:: NodeCmpOpNotEq :: static_type ( ) ) {
156+ } else if cls . is ( pyast:: NodeCmpOpNotEq :: static_type ( ) ) {
181157 Self :: NotEq
182- } else if _cls . is ( pyast:: NodeCmpOpLt :: static_type ( ) ) {
158+ } else if cls . is ( pyast:: NodeCmpOpLt :: static_type ( ) ) {
183159 Self :: Lt
184- } else if _cls . is ( pyast:: NodeCmpOpLtE :: static_type ( ) ) {
160+ } else if cls . is ( pyast:: NodeCmpOpLtE :: static_type ( ) ) {
185161 Self :: LtE
186- } else if _cls . is ( pyast:: NodeCmpOpGt :: static_type ( ) ) {
162+ } else if cls . is ( pyast:: NodeCmpOpGt :: static_type ( ) ) {
187163 Self :: Gt
188- } else if _cls . is ( pyast:: NodeCmpOpGtE :: static_type ( ) ) {
164+ } else if cls . is ( pyast:: NodeCmpOpGtE :: static_type ( ) ) {
189165 Self :: GtE
190- } else if _cls . is ( pyast:: NodeCmpOpIs :: static_type ( ) ) {
166+ } else if cls . is ( pyast:: NodeCmpOpIs :: static_type ( ) ) {
191167 Self :: Is
192- } else if _cls . is ( pyast:: NodeCmpOpIsNot :: static_type ( ) ) {
168+ } else if cls . is ( pyast:: NodeCmpOpIsNot :: static_type ( ) ) {
193169 Self :: IsNot
194- } else if _cls . is ( pyast:: NodeCmpOpIn :: static_type ( ) ) {
170+ } else if cls . is ( pyast:: NodeCmpOpIn :: static_type ( ) ) {
195171 Self :: In
196- } else if _cls . is ( pyast:: NodeCmpOpNotIn :: static_type ( ) ) {
172+ } else if cls . is ( pyast:: NodeCmpOpNotIn :: static_type ( ) ) {
197173 Self :: NotIn
198174 } else {
199- return Err ( _vm . new_type_error ( format ! (
175+ return Err ( vm . new_type_error ( format ! (
200176 "expected some sort of cmpop, but got {}" ,
201- _object . repr( _vm ) ?
177+ object . repr( vm ) ?
202178 ) ) ) ;
203179 } )
204180 }
0 commit comments