py/parse: Handle check for target small-int size in parser.

This means that all constants for EMIT_ARG(load_const_obj, obj) are created
in the parser (rather than some in the compiler).

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2022-03-16 00:33:44 +11:00
parent 3c7cab4e98
commit 962ad8622e
3 changed files with 8 additions and 17 deletions

View File

@@ -471,6 +471,13 @@ STATIC mp_parse_node_t make_node_const_int(parser_t *parser, size_t src_line, mp
return make_node_const_object(parser, src_line, obj);
}
#endif
#if MICROPY_DYNAMIC_COMPILER
// Check that the integer value fits in target runtime's small-int
mp_uint_t sign_mask = -((mp_uint_t)1 << (mp_dynamic_compiler.small_int_bits - 1));
if (!((val & sign_mask) == 0 || (val & sign_mask) == sign_mask)) {
return make_node_const_object(parser, src_line, obj);
}
#endif
return mp_parse_node_new_small_int(val);
} else {
return make_node_const_object(parser, src_line, obj);