diff options
author | Damien George <damien.p.george@gmail.com> | 2014-02-01 23:04:09 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-02-01 23:04:09 +0000 |
commit | 9aa2a527b532e31c77592cede3b38c018c83ac64 (patch) | |
tree | ea2c5431a7b645f4aba7d573086ada1109cbcdd1 /py/emitbc.c | |
parent | 7e5fb24e3bdd8a07e2c7f317ad44b62e85082547 (diff) |
py: Tidy up BINARY_OPs; negation done by special NOT bytecode.
IS_NOT and NOT_IN are now compiled to IS + NOT and IN + NOT, with a new
special NOT bytecode.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r-- | py/emitbc.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index a76e59336..e22a8b47a 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -600,13 +600,32 @@ static void emit_bc_pop_except(emit_t *emit) { } static void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) { - emit_pre(emit, 0); - emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, op); + if (op == RT_UNARY_OP_NOT) { + emit_pre(emit, 0); + emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, RT_UNARY_OP_BOOL); + emit_pre(emit, 0); + emit_write_byte_code_byte(emit, MP_BC_NOT); + } else { + emit_pre(emit, 0); + emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, op); + } } static void emit_bc_binary_op(emit_t *emit, rt_binary_op_t op) { + bool invert = false; + if (op == RT_BINARY_OP_NOT_IN) { + invert = true; + op = RT_BINARY_OP_IN; + } else if (op == RT_BINARY_OP_IS_NOT) { + invert = true; + op = RT_BINARY_OP_IS; + } emit_pre(emit, -1); emit_write_byte_code_byte_byte(emit, MP_BC_BINARY_OP, op); + if (invert) { + emit_pre(emit, 0); + emit_write_byte_code_byte(emit, MP_BC_NOT); + } } static void emit_bc_build_tuple(emit_t *emit, int n_args) { |