summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c39
1 files changed, 10 insertions, 29 deletions
diff --git a/py/compile.c b/py/compile.c
index e0a7711121..f284938f38 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2132,48 +2132,29 @@ STATIC void compile_and_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, MP_BINARY_OP_AND);
}
-STATIC void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
- int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
- compile_node(comp, pns->nodes[0]);
- for (int i = 1; i + 1 < num_nodes; i += 2) {
- compile_node(comp, pns->nodes[i + 1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_LESS)) {
- EMIT_ARG(binary_op, MP_BINARY_OP_LSHIFT);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_MORE)); // should be
- EMIT_ARG(binary_op, MP_BINARY_OP_RSHIFT);
- }
- }
-}
-
-STATIC void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
+STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]);
for (int i = 1; i + 1 < num_nodes; i += 2) {
compile_node(comp, pns->nodes[i + 1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PLUS)) {
EMIT_ARG(binary_op, MP_BINARY_OP_ADD);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_MINUS)); // should be
+ } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_MINUS)) {
EMIT_ARG(binary_op, MP_BINARY_OP_SUBTRACT);
- }
- }
-}
-
-STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
- int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
- compile_node(comp, pns->nodes[0]);
- for (int i = 1; i + 1 < num_nodes; i += 2) {
- compile_node(comp, pns->nodes[i + 1]);
- if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_STAR)) {
+ } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_STAR)) {
EMIT_ARG(binary_op, MP_BINARY_OP_MULTIPLY);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_SLASH)) {
EMIT_ARG(binary_op, MP_BINARY_OP_FLOOR_DIVIDE);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_SLASH)) {
EMIT_ARG(binary_op, MP_BINARY_OP_TRUE_DIVIDE);
- } else {
- assert(MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PERCENT)); // should be
+ } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PERCENT)) {
EMIT_ARG(binary_op, MP_BINARY_OP_MODULO);
+ } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_LESS)) {
+ EMIT_ARG(binary_op, MP_BINARY_OP_LSHIFT);
+ } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_MORE)) {
+ EMIT_ARG(binary_op, MP_BINARY_OP_RSHIFT);
+ } else {
+ assert(false);
}
}
}