@@ -1985,15 +1985,6 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
19851985 }
19861986}
19871987
1988- STATIC void c_binary_op (compiler_t * comp , mp_parse_node_struct_t * pns , mp_binary_op_t binary_op ) {
1989- int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES (pns );
1990- compile_node (comp , pns -> nodes [0 ]);
1991- for (int i = 1 ; i < num_nodes ; i += 1 ) {
1992- compile_node (comp , pns -> nodes [i ]);
1993- EMIT_ARG (binary_op , binary_op );
1994- }
1995- }
1996-
19971988STATIC void compile_test_if_expr (compiler_t * comp , mp_parse_node_struct_t * pns ) {
19981989 assert (MP_PARSE_NODE_IS_STRUCT_KIND (pns -> nodes [1 ], PN_test_if_else ));
19991990 mp_parse_node_struct_t * pns_test_if_else = (mp_parse_node_struct_t * )pns -> nodes [1 ];
@@ -2102,16 +2093,16 @@ STATIC void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
21022093 compile_syntax_error (comp , (mp_parse_node_t )pns , "*x must be assignment target" );
21032094}
21042095
2105- STATIC void compile_expr (compiler_t * comp , mp_parse_node_struct_t * pns ) {
2106- c_binary_op ( comp , pns , MP_BINARY_OP_OR );
2107- }
2108-
2109- STATIC void compile_xor_expr ( compiler_t * comp , mp_parse_node_struct_t * pns ) {
2110- c_binary_op (comp , pns , MP_BINARY_OP_XOR );
2111- }
2112-
2113- STATIC void compile_and_expr ( compiler_t * comp , mp_parse_node_struct_t * pns ) {
2114- c_binary_op ( comp , pns , MP_BINARY_OP_AND );
2096+ STATIC void compile_binary_op (compiler_t * comp , mp_parse_node_struct_t * pns ) {
2097+ MP_STATIC_ASSERT ( MP_BINARY_OP_OR + PN_xor_expr - PN_expr == MP_BINARY_OP_XOR );
2098+ MP_STATIC_ASSERT ( MP_BINARY_OP_OR + PN_and_expr - PN_expr == MP_BINARY_OP_AND );
2099+ mp_binary_op_t binary_op = MP_BINARY_OP_OR + MP_PARSE_NODE_STRUCT_KIND ( pns ) - PN_expr ;
2100+ int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES ( pns );
2101+ compile_node (comp , pns -> nodes [ 0 ] );
2102+ for ( int i = 1 ; i < num_nodes ; ++ i ) {
2103+ compile_node ( comp , pns -> nodes [ i ]);
2104+ EMIT_ARG ( binary_op , binary_op );
2105+ }
21152106}
21162107
21172108STATIC void compile_term (compiler_t * comp , mp_parse_node_struct_t * pns ) {
0 commit comments