9393 dict_rprimitive ,
9494 float_rprimitive ,
9595 int_rprimitive ,
96- is_bit_rprimitive ,
97- is_bool_rprimitive ,
96+ is_bool_or_bit_rprimitive ,
9897 is_bytes_rprimitive ,
9998 is_dict_rprimitive ,
10099 is_fixed_width_rtype ,
@@ -381,16 +380,12 @@ def coerce(
381380 ):
382381 # Equivalent types
383382 return src
384- elif (is_bool_rprimitive (src_type ) or is_bit_rprimitive (src_type )) and is_tagged (
385- target_type
386- ):
383+ elif is_bool_or_bit_rprimitive (src_type ) and is_tagged (target_type ):
387384 shifted = self .int_op (
388385 bool_rprimitive , src , Integer (1 , bool_rprimitive ), IntOp .LEFT_SHIFT
389386 )
390387 return self .add (Extend (shifted , target_type , signed = False ))
391- elif (
392- is_bool_rprimitive (src_type ) or is_bit_rprimitive (src_type )
393- ) and is_fixed_width_rtype (target_type ):
388+ elif is_bool_or_bit_rprimitive (src_type ) and is_fixed_width_rtype (target_type ):
394389 return self .add (Extend (src , target_type , signed = False ))
395390 elif isinstance (src , Integer ) and is_float_rprimitive (target_type ):
396391 if is_tagged (src_type ):
@@ -1341,7 +1336,11 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13411336 return self .compare_strings (lreg , rreg , op , line )
13421337 if is_bytes_rprimitive (ltype ) and is_bytes_rprimitive (rtype ) and op in ("==" , "!=" ):
13431338 return self .compare_bytes (lreg , rreg , op , line )
1344- if is_bool_rprimitive (ltype ) and is_bool_rprimitive (rtype ) and op in BOOL_BINARY_OPS :
1339+ if (
1340+ is_bool_or_bit_rprimitive (ltype )
1341+ and is_bool_or_bit_rprimitive (rtype )
1342+ and op in BOOL_BINARY_OPS
1343+ ):
13451344 if op in ComparisonOp .signed_ops :
13461345 return self .bool_comparison_op (lreg , rreg , op , line )
13471346 else :
@@ -1355,7 +1354,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13551354 op_id = int_op_to_id [op ]
13561355 else :
13571356 op_id = IntOp .DIV
1358- if is_bool_rprimitive ( rtype ) or is_bit_rprimitive (rtype ):
1357+ if is_bool_or_bit_rprimitive (rtype ):
13591358 rreg = self .coerce (rreg , ltype , line )
13601359 rtype = ltype
13611360 if is_fixed_width_rtype (rtype ) or is_tagged (rtype ):
@@ -1367,7 +1366,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13671366 elif op in ComparisonOp .signed_ops :
13681367 if is_int_rprimitive (rtype ):
13691368 rreg = self .coerce_int_to_fixed_width (rreg , ltype , line )
1370- elif is_bool_rprimitive ( rtype ) or is_bit_rprimitive (rtype ):
1369+ elif is_bool_or_bit_rprimitive (rtype ):
13711370 rreg = self .coerce (rreg , ltype , line )
13721371 op_id = ComparisonOp .signed_ops [op ]
13731372 if is_fixed_width_rtype (rreg .type ):
@@ -1387,13 +1386,13 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13871386 )
13881387 if is_tagged (ltype ):
13891388 return self .fixed_width_int_op (rtype , lreg , rreg , op_id , line )
1390- if is_bool_rprimitive ( ltype ) or is_bit_rprimitive (ltype ):
1389+ if is_bool_or_bit_rprimitive (ltype ):
13911390 lreg = self .coerce (lreg , rtype , line )
13921391 return self .fixed_width_int_op (rtype , lreg , rreg , op_id , line )
13931392 elif op in ComparisonOp .signed_ops :
13941393 if is_int_rprimitive (ltype ):
13951394 lreg = self .coerce_int_to_fixed_width (lreg , rtype , line )
1396- elif is_bool_rprimitive ( ltype ) or is_bit_rprimitive (ltype ):
1395+ elif is_bool_or_bit_rprimitive (ltype ):
13971396 lreg = self .coerce (lreg , rtype , line )
13981397 op_id = ComparisonOp .signed_ops [op ]
13991398 if isinstance (lreg , Integer ):
@@ -1544,7 +1543,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15441543 compare = self .binary_op (lhs_item , rhs_item , op , line )
15451544 # Cast to bool if necessary since most types uses comparison returning a object type
15461545 # See generic_ops.py for more information
1547- if not ( is_bool_rprimitive ( compare .type ) or is_bit_rprimitive ( compare . type ) ):
1546+ if not is_bool_or_bit_rprimitive ( compare .type ):
15481547 compare = self .primitive_op (bool_op , [compare ], line )
15491548 if i < len (lhs .type .types ) - 1 :
15501549 branch = Branch (compare , early_stop , check_blocks [i + 1 ], Branch .BOOL )
@@ -1563,7 +1562,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15631562
15641563 def translate_instance_contains (self , inst : Value , item : Value , op : str , line : int ) -> Value :
15651564 res = self .gen_method_call (inst , "__contains__" , [item ], None , line )
1566- if not is_bool_rprimitive (res .type ):
1565+ if not is_bool_or_bit_rprimitive (res .type ):
15671566 res = self .primitive_op (bool_op , [res ], line )
15681567 if op == "not in" :
15691568 res = self .bool_bitwise_op (res , Integer (1 , rtype = bool_rprimitive ), "^" , line )
@@ -1590,7 +1589,7 @@ def unary_not(self, value: Value, line: int) -> Value:
15901589
15911590 def unary_op (self , value : Value , expr_op : str , line : int ) -> Value :
15921591 typ = value .type
1593- if is_bool_rprimitive ( typ ) or is_bit_rprimitive (typ ):
1592+ if is_bool_or_bit_rprimitive (typ ):
15941593 if expr_op == "not" :
15951594 return self .unary_not (value , line )
15961595 if expr_op == "+" :
@@ -1748,7 +1747,7 @@ def bool_value(self, value: Value) -> Value:
17481747
17491748 The result type can be bit_rprimitive or bool_rprimitive.
17501749 """
1751- if is_bool_rprimitive ( value . type ) or is_bit_rprimitive (value .type ):
1750+ if is_bool_or_bit_rprimitive (value .type ):
17521751 result = value
17531752 elif is_runtime_subtype (value .type , int_rprimitive ):
17541753 zero = Integer (0 , short_int_rprimitive )
0 commit comments