93
93
dict_rprimitive ,
94
94
float_rprimitive ,
95
95
int_rprimitive ,
96
- is_bit_rprimitive ,
97
- is_bool_rprimitive ,
96
+ is_bool_or_bit_rprimitive ,
98
97
is_bytes_rprimitive ,
99
98
is_dict_rprimitive ,
100
99
is_fixed_width_rtype ,
@@ -381,16 +380,12 @@ def coerce(
381
380
):
382
381
# Equivalent types
383
382
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 ):
387
384
shifted = self .int_op (
388
385
bool_rprimitive , src , Integer (1 , bool_rprimitive ), IntOp .LEFT_SHIFT
389
386
)
390
387
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 ):
394
389
return self .add (Extend (src , target_type , signed = False ))
395
390
elif isinstance (src , Integer ) and is_float_rprimitive (target_type ):
396
391
if is_tagged (src_type ):
@@ -1341,7 +1336,11 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
1341
1336
return self .compare_strings (lreg , rreg , op , line )
1342
1337
if is_bytes_rprimitive (ltype ) and is_bytes_rprimitive (rtype ) and op in ("==" , "!=" ):
1343
1338
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
+ ):
1345
1344
if op in ComparisonOp .signed_ops :
1346
1345
return self .bool_comparison_op (lreg , rreg , op , line )
1347
1346
else :
@@ -1355,7 +1354,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
1355
1354
op_id = int_op_to_id [op ]
1356
1355
else :
1357
1356
op_id = IntOp .DIV
1358
- if is_bool_rprimitive ( rtype ) or is_bit_rprimitive (rtype ):
1357
+ if is_bool_or_bit_rprimitive (rtype ):
1359
1358
rreg = self .coerce (rreg , ltype , line )
1360
1359
rtype = ltype
1361
1360
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:
1367
1366
elif op in ComparisonOp .signed_ops :
1368
1367
if is_int_rprimitive (rtype ):
1369
1368
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 ):
1371
1370
rreg = self .coerce (rreg , ltype , line )
1372
1371
op_id = ComparisonOp .signed_ops [op ]
1373
1372
if is_fixed_width_rtype (rreg .type ):
@@ -1387,13 +1386,13 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
1387
1386
)
1388
1387
if is_tagged (ltype ):
1389
1388
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 ):
1391
1390
lreg = self .coerce (lreg , rtype , line )
1392
1391
return self .fixed_width_int_op (rtype , lreg , rreg , op_id , line )
1393
1392
elif op in ComparisonOp .signed_ops :
1394
1393
if is_int_rprimitive (ltype ):
1395
1394
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 ):
1397
1396
lreg = self .coerce (lreg , rtype , line )
1398
1397
op_id = ComparisonOp .signed_ops [op ]
1399
1398
if isinstance (lreg , Integer ):
@@ -1544,7 +1543,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
1544
1543
compare = self .binary_op (lhs_item , rhs_item , op , line )
1545
1544
# Cast to bool if necessary since most types uses comparison returning a object type
1546
1545
# 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 ):
1548
1547
compare = self .primitive_op (bool_op , [compare ], line )
1549
1548
if i < len (lhs .type .types ) - 1 :
1550
1549
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
1563
1562
1564
1563
def translate_instance_contains (self , inst : Value , item : Value , op : str , line : int ) -> Value :
1565
1564
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 ):
1567
1566
res = self .primitive_op (bool_op , [res ], line )
1568
1567
if op == "not in" :
1569
1568
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:
1590
1589
1591
1590
def unary_op (self , value : Value , expr_op : str , line : int ) -> Value :
1592
1591
typ = value .type
1593
- if is_bool_rprimitive ( typ ) or is_bit_rprimitive (typ ):
1592
+ if is_bool_or_bit_rprimitive (typ ):
1594
1593
if expr_op == "not" :
1595
1594
return self .unary_not (value , line )
1596
1595
if expr_op == "+" :
@@ -1748,7 +1747,7 @@ def bool_value(self, value: Value) -> Value:
1748
1747
1749
1748
The result type can be bit_rprimitive or bool_rprimitive.
1750
1749
"""
1751
- if is_bool_rprimitive ( value . type ) or is_bit_rprimitive (value .type ):
1750
+ if is_bool_or_bit_rprimitive (value .type ):
1752
1751
result = value
1753
1752
elif is_runtime_subtype (value .type , int_rprimitive ):
1754
1753
zero = Integer (0 , short_int_rprimitive )
0 commit comments