aboutsummaryrefslogtreecommitdiff
path: root/py/parse.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-01-07 14:40:35 +0000
committerDamien George <damien.p.george@gmail.com>2016-01-07 14:40:35 +0000
commit22b2265053ef9fec4b1aedab770b32f71b0c85f7 (patch)
tree82e94c32d781d91faa03203bfc463336839d39e7 /py/parse.h
parentd6b31e4578a9f7ed4f970774fe91eeb811b1d475 (diff)
py/parse: Improve constant folding to operate on small and big ints.
Constant folding in the parser can now operate on big ints, whatever their representation. This is now possible because the parser can create parse nodes holding arbitrary objects. For the case of small ints the folding is still efficient in RAM because the folded small int is stored inplace in the parse node. Adds 48 bytes to code size on Thumb2 architecture. Helps reduce heap usage because more constants can be computed at compile time, leading to a smaller parse tree, and most importantly means that the constants don't have to be computed at runtime (perhaps more than once). Parser will now be a little slower when folding due to calls to runtime to do the arithmetic.
Diffstat (limited to 'py/parse.h')
-rw-r--r--py/parse.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/py/parse.h b/py/parse.h
index 4208ce10a..f518b9bb6 100644
--- a/py/parse.h
+++ b/py/parse.h
@@ -29,7 +29,7 @@
#include <stddef.h>
#include <stdint.h>
-#include "py/mpconfig.h"
+#include "py/obj.h"
struct _mp_lexer_t;
@@ -77,6 +77,7 @@ typedef struct _mp_parse_node_struct_t {
#define MP_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8)
mp_parse_node_t mp_parse_node_new_leaf(size_t kind, mp_int_t arg);
+bool mp_parse_node_get_int_maybe(mp_parse_node_t pn, mp_obj_t *o);
int mp_parse_node_extract_list(mp_parse_node_t *pn, size_t pn_kind, mp_parse_node_t **nodes);
void mp_parse_node_print(mp_parse_node_t pn, size_t indent);