Skip to content

Commit bbf0e2f

Browse files
committed
parse: Note that fact that parser's small ints are different than VM small int.
Specifically, VM's small ints are 31 bit, while parser's only 28. There's already MP_OBJ_FITS_SMALL_INT(), so, for clarity, rename MP_FIT_SMALL_INT() to MP_PARSE_FITS_SMALL_INT().
1 parent 1d30b11 commit bbf0e2f

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
117117
assert(0);
118118
res = 0;
119119
}
120-
if (MP_FIT_SMALL_INT(res)) {
120+
if (MP_PARSE_FITS_SMALL_INT(res)) {
121121
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, res);
122122
}
123123
}

py/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
279279
}
280280
if (dec) {
281281
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_DECIMAL, qstr_from_strn(str, len));
282-
} else if (small_int && !overflow && MP_FIT_SMALL_INT(int_val)) {
282+
} else if (small_int && !overflow && MP_PARSE_FITS_SMALL_INT(int_val)) {
283283
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, int_val);
284284
} else {
285285
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_INTEGER, qstr_from_strn(str, len));

py/parse.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ struct _mp_lexer_t;
1414
// makes sure the top 5 bits of x are all cleared (positive number) or all set (negavite number)
1515
// these macros can probably go somewhere else because they are used more than just in the parser
1616
#define MP_UINT_HIGH_5_BITS (~((~((machine_uint_t)0)) >> 5))
17-
#define MP_FIT_SMALL_INT(x) (((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == 0) || ((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == MP_UINT_HIGH_5_BITS))
17+
// parser's small ints are different from VM small int
18+
#define MP_PARSE_FITS_SMALL_INT(x) (((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == 0) || ((((machine_uint_t)(x)) & MP_UINT_HIGH_5_BITS) == MP_UINT_HIGH_5_BITS))
1819

1920
#define MP_PARSE_NODE_NULL (0)
2021
#define MP_PARSE_NODE_ID (0x1)

0 commit comments

Comments
 (0)