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:
parent
3c7cab4e98
commit
962ad8622e
16
py/compile.c
16
py/compile.c
|
@ -2790,23 +2790,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
|||
// pass
|
||||
} else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) {
|
||||
mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn);
|
||||
#if MICROPY_DYNAMIC_COMPILER
|
||||
mp_uint_t sign_mask = -((mp_uint_t)1 << (mp_dynamic_compiler.small_int_bits - 1));
|
||||
if ((arg & sign_mask) == 0 || (arg & sign_mask) == sign_mask) {
|
||||
// integer fits in target runtime's small-int
|
||||
EMIT_ARG(load_const_small_int, arg);
|
||||
} else {
|
||||
// integer doesn't fit, so create a multi-precision int object
|
||||
// (but only create the actual object on the last pass)
|
||||
if (comp->pass != MP_PASS_EMIT) {
|
||||
EMIT_ARG(load_const_obj, mp_const_none);
|
||||
} else {
|
||||
EMIT_ARG(load_const_obj, mp_obj_new_int_from_ll(arg));
|
||||
}
|
||||
}
|
||||
#else
|
||||
EMIT_ARG(load_const_small_int, arg);
|
||||
#endif
|
||||
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
|
||||
uintptr_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
|
||||
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -536,7 +536,7 @@ STATIC void save_obj(mp_print_t *print, mp_obj_t o) {
|
|||
// we save numbers using a simplistic text representation
|
||||
// TODO could be improved
|
||||
byte obj_type;
|
||||
if (mp_obj_is_type(o, &mp_type_int)) {
|
||||
if (mp_obj_is_int(o)) {
|
||||
obj_type = 'i';
|
||||
#if MICROPY_PY_BUILTINS_COMPLEX
|
||||
} else if (mp_obj_is_type(o, &mp_type_complex)) {
|
||||
|
|
Loading…
Reference in New Issue