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().
This commit is contained in:
parent
1d30b11685
commit
bbf0e2fe12
@ -117,7 +117,7 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
|
|||||||
assert(0);
|
assert(0);
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
if (MP_FIT_SMALL_INT(res)) {
|
if (MP_PARSE_FITS_SMALL_INT(res)) {
|
||||||
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, res);
|
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
|
|||||||
}
|
}
|
||||||
if (dec) {
|
if (dec) {
|
||||||
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_DECIMAL, qstr_from_strn(str, len));
|
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_DECIMAL, qstr_from_strn(str, len));
|
||||||
} else if (small_int && !overflow && MP_FIT_SMALL_INT(int_val)) {
|
} else if (small_int && !overflow && MP_PARSE_FITS_SMALL_INT(int_val)) {
|
||||||
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, int_val);
|
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, int_val);
|
||||||
} else {
|
} else {
|
||||||
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_INTEGER, qstr_from_strn(str, len));
|
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_INTEGER, qstr_from_strn(str, len));
|
||||||
|
@ -14,7 +14,8 @@ struct _mp_lexer_t;
|
|||||||
// makes sure the top 5 bits of x are all cleared (positive number) or all set (negavite number)
|
// makes sure the top 5 bits of x are all cleared (positive number) or all set (negavite number)
|
||||||
// these macros can probably go somewhere else because they are used more than just in the parser
|
// these macros can probably go somewhere else because they are used more than just in the parser
|
||||||
#define MP_UINT_HIGH_5_BITS (~((~((machine_uint_t)0)) >> 5))
|
#define MP_UINT_HIGH_5_BITS (~((~((machine_uint_t)0)) >> 5))
|
||||||
#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))
|
// parser's small ints are different from VM small int
|
||||||
|
#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))
|
||||||
|
|
||||||
#define MP_PARSE_NODE_NULL (0)
|
#define MP_PARSE_NODE_NULL (0)
|
||||||
#define MP_PARSE_NODE_ID (0x1)
|
#define MP_PARSE_NODE_ID (0x1)
|
||||||
|
Loading…
Reference in New Issue
Block a user