aboutsummaryrefslogtreecommitdiff
path: root/py/parse.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-03-16 00:33:44 +1100
committerDamien George <damien@micropython.org>2022-03-16 00:41:10 +1100
commit962ad8622e4c732f76ecbf8d5191ba8216d244d3 (patch)
tree069d1d397dc6eb27c23a96272f6a2d0bc0976c7f /py/parse.c
parent3c7cab4e98a31649ed1bc2e728d610856382d6f5 (diff)
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>
Diffstat (limited to 'py/parse.c')
-rw-r--r--py/parse.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/parse.c b/py/parse.c
index f18f03b3f..233cba11b 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -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);