py/emitbc: Rewrite switch in load_const_tok to reduce code size.

This commit is contained in:
Damien George 2019-08-22 14:36:27 +10:00
parent 96ace8082e
commit 3d9bd80447

View File

@ -524,15 +524,13 @@ void mp_emit_bc_import(emit_t *emit, qstr qst, int kind) {
} }
void mp_emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) { void mp_emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
MP_STATIC_ASSERT(MP_BC_LOAD_CONST_FALSE + (MP_TOKEN_KW_NONE - MP_TOKEN_KW_FALSE) == MP_BC_LOAD_CONST_NONE);
MP_STATIC_ASSERT(MP_BC_LOAD_CONST_FALSE + (MP_TOKEN_KW_TRUE - MP_TOKEN_KW_FALSE) == MP_BC_LOAD_CONST_TRUE);
emit_bc_pre(emit, 1); emit_bc_pre(emit, 1);
switch (tok) { if (tok == MP_TOKEN_ELLIPSIS) {
case MP_TOKEN_KW_FALSE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_FALSE); break;
case MP_TOKEN_KW_NONE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_NONE); break;
case MP_TOKEN_KW_TRUE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_TRUE); break;
default:
assert(tok == MP_TOKEN_ELLIPSIS);
emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj)); emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj));
break; } else {
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_FALSE + (tok - MP_TOKEN_KW_FALSE));
} }
} }