@@ -1133,6 +1133,44 @@ fn determine_comparison_op_jet(
11331133/// | `*` | `u(2N)` | `MultiplyN` | `uN` | no |
11341134/// | `/` | `uN` | `DivideN` | `uN` | no |
11351135/// | `%` | `uN` | `ModuloN` | `uN` | no |
1136+ /// Maps a bitwise infix operator and operand type to the corresponding Simplicity jet.
1137+ ///
1138+ /// | Operator | Output type | Jet | Input type |
1139+ /// |----------|-------------|--------|------------|
1140+ /// | `&` | `uN` | `AndN` | `uN` |
1141+ /// | `\|` | `uN` | `OrN` | `uN` |
1142+ /// | `^` | `uN` | `XorN` | `uN` |
1143+ fn determine_infix_bitwise_op_jet (
1144+ op : & parse:: InfixOp ,
1145+ ty : & ResolvedType ,
1146+ ) -> Result < Elements , Error > {
1147+ use parse:: InfixOp :: * ;
1148+ use UIntType :: * ;
1149+
1150+ let uint_ty = ty
1151+ . as_integer ( )
1152+ . ok_or_else ( || Error :: ExpressionUnexpectedType ( ty. clone ( ) ) ) ?;
1153+
1154+ match ( op, uint_ty) {
1155+ ( BitAnd , U1 ) => Ok ( Elements :: And1 ) ,
1156+ ( BitAnd , U8 ) => Ok ( Elements :: And8 ) ,
1157+ ( BitAnd , U16 ) => Ok ( Elements :: And16 ) ,
1158+ ( BitAnd , U32 ) => Ok ( Elements :: And32 ) ,
1159+ ( BitAnd , U64 ) => Ok ( Elements :: And64 ) ,
1160+ ( BitOr , U1 ) => Ok ( Elements :: Or1 ) ,
1161+ ( BitOr , U8 ) => Ok ( Elements :: Or8 ) ,
1162+ ( BitOr , U16 ) => Ok ( Elements :: Or16 ) ,
1163+ ( BitOr , U32 ) => Ok ( Elements :: Or32 ) ,
1164+ ( BitOr , U64 ) => Ok ( Elements :: Or64 ) ,
1165+ ( BitXor , U1 ) => Ok ( Elements :: Xor1 ) ,
1166+ ( BitXor , U8 ) => Ok ( Elements :: Xor8 ) ,
1167+ ( BitXor , U16 ) => Ok ( Elements :: Xor16 ) ,
1168+ ( BitXor , U32 ) => Ok ( Elements :: Xor32 ) ,
1169+ ( BitXor , U64 ) => Ok ( Elements :: Xor64 ) ,
1170+ _ => Err ( Error :: ExpressionUnexpectedType ( ty. clone ( ) ) ) ,
1171+ }
1172+ }
1173+
11361174fn determine_infix_arith_op_jet (
11371175 op : & parse:: InfixOp ,
11381176 ty : & ResolvedType ,
@@ -1411,6 +1449,29 @@ impl AbstractSyntaxTree for SingleExpression {
14111449 lhs_warnings,
14121450 )
14131451 }
1452+ BitAnd | BitOr | BitXor => {
1453+ // Bitwise operators: same input and output type, no carry or overflow
1454+ let jet =
1455+ determine_infix_bitwise_op_jet ( binary. op ( ) , ty) . with_span ( from) ?;
1456+ let ( lhs, mut lhs_warnings) =
1457+ Expression :: analyze ( binary. lhs ( ) , ty, scope) ?;
1458+ let ( rhs, mut rhs_warnings) =
1459+ Expression :: analyze ( binary. rhs ( ) , ty, scope) ?;
1460+ lhs_warnings. append ( & mut rhs_warnings) ;
1461+ scope. track_call ( from, TrackedCallName :: Jet ) ;
1462+ (
1463+ SingleExpressionInner :: BinaryOp {
1464+ jet,
1465+ lhs : Arc :: new ( lhs) ,
1466+ rhs : Arc :: new ( rhs) ,
1467+ assert_no_carry : false ,
1468+ swap_args : false ,
1469+ negate_result : false ,
1470+ check_nonzero_divisor : false ,
1471+ } ,
1472+ lhs_warnings,
1473+ )
1474+ }
14141475 Add | Sub | Mul | Div | Rem => {
14151476 // Arithmetic operators
14161477 let ( jet, arg_ty, assert_no_carry) =
0 commit comments