summaryrefslogtreecommitdiffstatshomepage
path: root/py/mpconfig.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-05 13:19:03 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-05 13:19:03 +0100
commit66e18f04d811197854c0ce970b2dc8ac17deaebc (patch)
tree8da2e98666c5525522753207131f3f309e58b10c /py/mpconfig.h
parentf01fa458d869d6f89f65ba3ad163730b1e2451d6 (diff)
downloadmicropython-66e18f04d811197854c0ce970b2dc8ac17deaebc.tar.gz
micropython-66e18f04d811197854c0ce970b2dc8ac17deaebc.zip
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory allocation is not precise. In the parser it's the rule stack and result stack, in the compiler it's the array for the identifiers in the current scope. All other mallocs are exact (ie they don't allocate more than is needed). This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3 inexact allocations. The inexact allocations in the parser should actually be close to logarithmic: you need an exponentially larger script (absent pathological cases) to use up more room on the rule and result stacks. As such, the default allocation policy for these is now to start with a modest sized stack, but grow only in small increments. For the identifier arrays in the compiler, these now start out quite small (4 entries, since most functions don't have that many ids), and grow incrementally by 6 (since if you have more ids than 4, you probably have quite a few more, but it wouldn't be exponentially more). Partially addresses issue #560.
Diffstat (limited to 'py/mpconfig.h')
-rw-r--r--py/mpconfig.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 78147609ca..435140dc72 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -34,6 +34,39 @@
// values below.
/*****************************************************************************/
+/* Memory allocation policy */
+
+// Initial amount for parse rule stack
+#ifndef MP_ALLOC_PARSE_RULE_INIT
+#define MP_ALLOC_PARSE_RULE_INIT (64)
+#endif
+
+// Increment for parse rule stack
+#ifndef MP_ALLOC_PARSE_RULE_INC
+#define MP_ALLOC_PARSE_RULE_INC (16)
+#endif
+
+// Initial amount for parse result stack
+#ifndef MP_ALLOC_PARSE_RESULT_INIT
+#define MP_ALLOC_PARSE_RESULT_INIT (32)
+#endif
+
+// Increment for parse result stack
+#ifndef MP_ALLOC_PARSE_RESULT_INC
+#define MP_ALLOC_PARSE_RESULT_INC (16)
+#endif
+
+// Initial amount for ids in a scope
+#ifndef MP_ALLOC_SCOPE_ID_INIT
+#define MP_ALLOC_SCOPE_ID_INIT (4)
+#endif
+
+// Increment for ids in a scope
+#ifndef MP_ALLOC_SCOPE_ID_INC
+#define MP_ALLOC_SCOPE_ID_INC (6)
+#endif
+
+/*****************************************************************************/
/* Micro Python emitters */
// Whether to emit CPython byte codes (for debugging/testing)