py/emitbc: Rewrite switch in load_const_tok to reduce code size.
This commit is contained in:
parent
96ace8082e
commit
3d9bd80447
14
py/emitbc.c
14
py/emitbc.c
@ -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;
|
emit_write_bytecode_byte_obj(emit, MP_BC_LOAD_CONST_OBJ, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj));
|
||||||
case MP_TOKEN_KW_NONE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_NONE); break;
|
} else {
|
||||||
case MP_TOKEN_KW_TRUE: emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_TRUE); break;
|
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_FALSE + (tok - MP_TOKEN_KW_FALSE));
|
||||||
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));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user