aboutsummaryrefslogtreecommitdiff
path: root/py/emitinlinethumb.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-02-15 10:58:05 +1100
committerDamien George <damien.p.george@gmail.com>2017-02-16 19:45:06 +1100
commit71019ae4f5ba8819af27152198afc0274085c8a9 (patch)
treec7a076c2430feb0797aa58d0173b46f1896f2d2e /py/emitinlinethumb.c
parent7839b8b827199ce593bfb87bc62b426a2798fde6 (diff)
py/grammar: Group no-compile grammar rules together to shrink tables.
Grammar rules have 2 variants: ones that are attached to a specific compile function which is called to compile that grammar node, and ones that don't have a compile function and are instead just inspected to see what form they take. In the compiler there is a table of all grammar rules, with each entry having a pointer to the associated compile function. Those rules with no compile function have a null pointer. There are 120 such rules, so that's 120 words of essentially wasted code space. By grouping together the compile vs no-compile rules we can put all the no-compile rules at the end of the list of rules, and then we don't need to store the null pointers. We just have a truncated table and it's guaranteed that when indexing this table we only index the first half, the half with populated pointers. This patch implements such a grouping by having a specific macro for the compile vs no-compile grammar rules (DEF_RULE vs DEF_RULE_NC). It saves around 460 bytes of code on 32-bit archs.
Diffstat (limited to 'py/emitinlinethumb.c')
-rw-r--r--py/emitinlinethumb.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c
index 406272813..89bcebfea 100644
--- a/py/emitinlinethumb.c
+++ b/py/emitinlinethumb.c
@@ -36,10 +36,21 @@
#if MICROPY_EMIT_INLINE_THUMB
typedef enum {
+// define rules with a compile function
#define DEF_RULE(rule, comp, kind, ...) PN_##rule,
+#define DEF_RULE_NC(rule, kind, ...)
#include "py/grammar.h"
#undef DEF_RULE
- PN_maximum_number_of,
+#undef DEF_RULE_NC
+ PN_string, // special node for non-interned string
+ PN_bytes, // special node for non-interned bytes
+ PN_const_object, // special node for a constant, generic Python object
+// define rules without a compile function
+#define DEF_RULE(rule, comp, kind, ...)
+#define DEF_RULE_NC(rule, kind, ...) PN_##rule,
+#include "py/grammar.h"
+#undef DEF_RULE
+#undef DEF_RULE_NC
} pn_kind_t;
struct _emit_inline_asm_t {