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 ,
@@ -376,16 +375,12 @@ def coerce(
376375 ):
377376 # Equivalent types
378377 return src
379- elif (is_bool_rprimitive (src_type ) or is_bit_rprimitive (src_type )) and is_tagged (
380- target_type
381- ):
378+ elif is_bool_or_bit_rprimitive (src_type ) and is_tagged (target_type ):
382379 shifted = self .int_op (
383380 bool_rprimitive , src , Integer (1 , bool_rprimitive ), IntOp .LEFT_SHIFT
384381 )
385382 return self .add (Extend (shifted , target_type , signed = False ))
386- elif (
387- is_bool_rprimitive (src_type ) or is_bit_rprimitive (src_type )
388- ) and is_fixed_width_rtype (target_type ):
383+ elif is_bool_or_bit_rprimitive (src_type ) and is_fixed_width_rtype (target_type ):
389384 return self .add (Extend (src , target_type , signed = False ))
390385 elif isinstance (src , Integer ) and is_float_rprimitive (target_type ):
391386 if is_tagged (src_type ):
@@ -1336,7 +1331,11 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13361331 return self .compare_strings (lreg , rreg , op , line )
13371332 if is_bytes_rprimitive (ltype ) and is_bytes_rprimitive (rtype ) and op in ("==" , "!=" ):
13381333 return self .compare_bytes (lreg , rreg , op , line )
1339- if is_bool_rprimitive (ltype ) and is_bool_rprimitive (rtype ) and op in BOOL_BINARY_OPS :
1334+ if (
1335+ is_bool_or_bit_rprimitive (ltype )
1336+ and is_bool_or_bit_rprimitive (rtype )
1337+ and op in BOOL_BINARY_OPS
1338+ ):
13401339 if op in ComparisonOp .signed_ops :
13411340 return self .bool_comparison_op (lreg , rreg , op , line )
13421341 else :
@@ -1350,7 +1349,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13501349 op_id = int_op_to_id [op ]
13511350 else :
13521351 op_id = IntOp .DIV
1353- if is_bool_rprimitive ( rtype ) or is_bit_rprimitive (rtype ):
1352+ if is_bool_or_bit_rprimitive (rtype ):
13541353 rreg = self .coerce (rreg , ltype , line )
13551354 rtype = ltype
13561355 if is_fixed_width_rtype (rtype ) or is_tagged (rtype ):
@@ -1362,7 +1361,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13621361 elif op in ComparisonOp .signed_ops :
13631362 if is_int_rprimitive (rtype ):
13641363 rreg = self .coerce_int_to_fixed_width (rreg , ltype , line )
1365- elif is_bool_rprimitive ( rtype ) or is_bit_rprimitive (rtype ):
1364+ elif is_bool_or_bit_rprimitive (rtype ):
13661365 rreg = self .coerce (rreg , ltype , line )
13671366 op_id = ComparisonOp .signed_ops [op ]
13681367 if is_fixed_width_rtype (rreg .type ):
@@ -1382,13 +1381,13 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13821381 )
13831382 if is_tagged (ltype ):
13841383 return self .fixed_width_int_op (rtype , lreg , rreg , op_id , line )
1385- if is_bool_rprimitive ( ltype ) or is_bit_rprimitive (ltype ):
1384+ if is_bool_or_bit_rprimitive (ltype ):
13861385 lreg = self .coerce (lreg , rtype , line )
13871386 return self .fixed_width_int_op (rtype , lreg , rreg , op_id , line )
13881387 elif op in ComparisonOp .signed_ops :
13891388 if is_int_rprimitive (ltype ):
13901389 lreg = self .coerce_int_to_fixed_width (lreg , rtype , line )
1391- elif is_bool_rprimitive ( ltype ) or is_bit_rprimitive (ltype ):
1390+ elif is_bool_or_bit_rprimitive (ltype ):
13921391 lreg = self .coerce (lreg , rtype , line )
13931392 op_id = ComparisonOp .signed_ops [op ]
13941393 if isinstance (lreg , Integer ):
@@ -1534,7 +1533,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15341533 compare = self .binary_op (lhs_item , rhs_item , op , line )
15351534 # Cast to bool if necessary since most types uses comparison returning a object type
15361535 # See generic_ops.py for more information
1537- if not ( is_bool_rprimitive ( compare .type ) or is_bit_rprimitive ( compare . type ) ):
1536+ if not is_bool_or_bit_rprimitive ( compare .type ):
15381537 compare = self .primitive_op (bool_op , [compare ], line )
15391538 if i < len (lhs .type .types ) - 1 :
15401539 branch = Branch (compare , early_stop , check_blocks [i + 1 ], Branch .BOOL )
@@ -1553,7 +1552,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15531552
15541553 def translate_instance_contains (self , inst : Value , item : Value , op : str , line : int ) -> Value :
15551554 res = self .gen_method_call (inst , "__contains__" , [item ], None , line )
1556- if not is_bool_rprimitive (res .type ):
1555+ if not is_bool_or_bit_rprimitive (res .type ):
15571556 res = self .primitive_op (bool_op , [res ], line )
15581557 if op == "not in" :
15591558 res = self .bool_bitwise_op (res , Integer (1 , rtype = bool_rprimitive ), "^" , line )
@@ -1580,7 +1579,7 @@ def unary_not(self, value: Value, line: int) -> Value:
15801579
15811580 def unary_op (self , value : Value , expr_op : str , line : int ) -> Value :
15821581 typ = value .type
1583- if is_bool_rprimitive ( typ ) or is_bit_rprimitive (typ ):
1582+ if is_bool_or_bit_rprimitive (typ ):
15841583 if expr_op == "not" :
15851584 return self .unary_not (value , line )
15861585 if expr_op == "+" :
@@ -1738,7 +1737,7 @@ def bool_value(self, value: Value) -> Value:
17381737
17391738 The result type can be bit_rprimitive or bool_rprimitive.
17401739 """
1741- if is_bool_rprimitive ( value . type ) or is_bit_rprimitive (value .type ):
1740+ if is_bool_or_bit_rprimitive (value .type ):
17421741 result = value
17431742 elif is_runtime_subtype (value .type , int_rprimitive ):
17441743 zero = Integer (0 , short_int_rprimitive )
0 commit comments