summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/compile.c7
-rw-r--r--py/parse.c12
-rw-r--r--py/parse.h11
3 files changed, 16 insertions, 14 deletions
diff --git a/py/compile.c b/py/compile.c
index e4ead7f1a..6bb601b92 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2763,12 +2763,7 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn
#endif
STATIC mp_obj_t get_const_object(mp_parse_node_struct_t *pns) {
- #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
- // nodes are 32-bit pointers, but need to extract 64-bit object
- return (uint64_t)pns->nodes[0] | ((uint64_t)pns->nodes[1] << 32);
- #else
- return (mp_obj_t)pns->nodes[0];
- #endif
+ return mp_parse_node_extract_const_object(pns);
}
STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) {
diff --git a/py/parse.c b/py/parse.c
index 233cba11b..f0e0a165c 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -333,12 +333,7 @@ bool mp_parse_node_get_int_maybe(mp_parse_node_t pn, mp_obj_t *o) {
return true;
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, RULE_const_object)) {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn;
- #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
- // nodes are 32-bit pointers, but need to extract 64-bit object
- *o = (uint64_t)pns->nodes[0] | ((uint64_t)pns->nodes[1] << 32);
- #else
- *o = (mp_obj_t)pns->nodes[0];
- #endif
+ *o = mp_parse_node_extract_const_object(pns);
return mp_obj_is_int(*o);
} else {
return false;
@@ -397,10 +392,11 @@ void mp_parse_node_print(const mp_print_t *print, mp_parse_node_t pn, size_t ind
// node must be a mp_parse_node_struct_t
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn;
if (MP_PARSE_NODE_STRUCT_KIND(pns) == RULE_const_object) {
+ mp_obj_t obj = mp_parse_node_extract_const_object(pns);
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
- mp_printf(print, "literal const(%016llx)\n", (uint64_t)pns->nodes[0] | ((uint64_t)pns->nodes[1] << 32));
+ mp_printf(print, "literal const(%016llx)\n", obj);
#else
- mp_printf(print, "literal const(%p)\n", (mp_obj_t)pns->nodes[0]);
+ mp_printf(print, "literal const(%p)\n", obj);
#endif
} else {
size_t n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
diff --git a/py/parse.h b/py/parse.h
index 9c327c28b..5531e35cb 100644
--- a/py/parse.h
+++ b/py/parse.h
@@ -77,9 +77,20 @@ typedef struct _mp_parse_node_struct_t {
static inline mp_parse_node_t mp_parse_node_new_small_int(mp_int_t val) {
return (mp_parse_node_t)(MP_PARSE_NODE_SMALL_INT | ((mp_uint_t)val << 1));
}
+
static inline mp_parse_node_t mp_parse_node_new_leaf(size_t kind, mp_int_t arg) {
return (mp_parse_node_t)(kind | ((mp_uint_t)arg << 4));
}
+
+static inline mp_obj_t mp_parse_node_extract_const_object(mp_parse_node_struct_t *pns) {
+ #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
+ // nodes are 32-bit pointers, but need to extract 64-bit object
+ return (uint64_t)pns->nodes[0] | ((uint64_t)pns->nodes[1] << 32);
+ #else
+ return (mp_obj_t)pns->nodes[0];
+ #endif
+}
+
bool mp_parse_node_is_const_false(mp_parse_node_t pn);
bool mp_parse_node_is_const_true(mp_parse_node_t pn);
bool mp_parse_node_get_int_maybe(mp_parse_node_t pn, mp_obj_t *o);