diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-22 16:39:45 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-22 16:39:45 +0200 |
commit | 56e5ef203b01ac8dfb1cb46143f6f7c53237b79d (patch) | |
tree | a1c2267a2e6b657d29be82ac177f21e74af24707 /py/parse.c | |
parent | bbf0e2fe120f095ce09fcb7eb631c9fd04bd9760 (diff) | |
download | micropython-56e5ef203b01ac8dfb1cb46143f6f7c53237b79d.tar.gz micropython-56e5ef203b01ac8dfb1cb46143f6f7c53237b79d.zip |
parse: Refactor parse node encoding to support full range of small ints.
Based on suggestion by @dpgeorge at
https://github.com/micropython/micropython/pull/313
Diffstat (limited to 'py/parse.c')
-rw-r--r-- | py/parse.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/py/parse.c b/py/parse.c index 57d78a05b1..e70456e814 100644 --- a/py/parse.c +++ b/py/parse.c @@ -125,7 +125,10 @@ STATIC void pop_rule(parser_t *parser, const rule_t **rule, uint *arg_i, uint *s } mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg) { - return (mp_parse_node_t)(kind | (arg << 4)); + if (kind == MP_PARSE_NODE_SMALL_INT) { + return (mp_parse_node_t)(kind | (arg << 1)); + } + return (mp_parse_node_t)(kind | (arg << 5)); } //int num_parse_nodes_allocated = 0; @@ -171,11 +174,13 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) { } if (MP_PARSE_NODE_IS_NULL(pn)) { printf("NULL\n"); + } else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { + machine_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); + printf("int(" INT_FMT ")\n", arg); } else if (MP_PARSE_NODE_IS_LEAF(pn)) { - machine_int_t arg = MP_PARSE_NODE_LEAF_ARG(pn); + machine_uint_t arg = MP_PARSE_NODE_LEAF_ARG(pn); switch (MP_PARSE_NODE_LEAF_KIND(pn)) { case MP_PARSE_NODE_ID: printf("id(%s)\n", qstr_str(arg)); break; - case MP_PARSE_NODE_SMALL_INT: printf("int(" INT_FMT ")\n", arg); break; case MP_PARSE_NODE_INTEGER: printf("int(%s)\n", qstr_str(arg)); break; case MP_PARSE_NODE_DECIMAL: printf("dec(%s)\n", qstr_str(arg)); break; case MP_PARSE_NODE_STRING: printf("str(%s)\n", qstr_str(arg)); break; |