summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-02-27 15:09:15 +1100
committerDamien George <damien.p.george@gmail.com>2017-02-27 15:09:15 +1100
commitad81a2e6cf349cba514e73dc4fe18b1d512b7ce4 (patch)
tree37cb0aa48de7a3163bd97fb15dd07b426d744f48
parent3b2fd4df31fad39b66eadefc2b95b143c1b67add (diff)
downloadmicropython-ad81a2e6cf349cba514e73dc4fe18b1d512b7ce4.tar.gz
micropython-ad81a2e6cf349cba514e73dc4fe18b1d512b7ce4.zip
minimal: Add ability and description to build without the compiler.
-rw-r--r--minimal/README.md12
-rw-r--r--minimal/main.c6
-rw-r--r--minimal/mpconfigport.h5
3 files changed, 23 insertions, 0 deletions
diff --git a/minimal/README.md b/minimal/README.md
index 7c42e082ef..14b8c00a30 100644
--- a/minimal/README.md
+++ b/minimal/README.md
@@ -33,3 +33,15 @@ This version of the build will work out-of-the-box on a pyboard (and
anything similar), and will give you a MicroPython REPL on UART1 at 9600
baud. Pin PA13 will also be driven high, and this turns on the red LED on
the pyboard.
+
+## Building without the built-in MicroPython compiler
+
+This minimal port can be built with the built-in MicroPython compiler
+disabled. This will reduce the firmware by about 20k on a Thumb2 machine,
+and by about 40k on 32-bit x86. Without the compiler the REPL will be
+disabled, but pre-compiled scripts can still be executed.
+
+To test out this feature, change the `MICROPY_ENABLE_COMPILER` config
+option to "0" in the mpconfigport.h file in this directory. Then
+recompile and run the firmware and it will execute the frozentest.py
+file.
diff --git a/minimal/main.c b/minimal/main.c
index 5e104e7e83..6b77b1a425 100644
--- a/minimal/main.c
+++ b/minimal/main.c
@@ -9,6 +9,7 @@
#include "py/gc.h"
#include "lib/utils/pyexec.h"
+#if MICROPY_ENABLE_COMPILER
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
@@ -28,6 +29,7 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
}
}
+#endif
static char *stack_top;
static char heap[2048];
@@ -40,6 +42,7 @@ int main(int argc, char **argv) {
gc_init(heap, heap + sizeof(heap));
#endif
mp_init();
+ #if MICROPY_ENABLE_COMPILER
#if MICROPY_REPL_EVENT_DRIVEN
pyexec_event_repl_init();
for (;;) {
@@ -53,6 +56,9 @@ int main(int argc, char **argv) {
#endif
//do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
//do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
+ #else
+ pyexec_frozen_module("frozentest.py");
+ #endif
mp_deinit();
return 0;
}
diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h
index 5236babf68..e08943860b 100644
--- a/minimal/mpconfigport.h
+++ b/minimal/mpconfigport.h
@@ -2,6 +2,11 @@
// options to control how Micro Python is built
+// You can disable the built-in MicroPython compiler by setting the following
+// config option to 0. If you do this then you won't get a REPL prompt, but you
+// will still be able to execute pre-compiled scripts, compiled with mpy-cross.
+#define MICROPY_ENABLE_COMPILER (1)
+
#define MICROPY_QSTR_BYTES_IN_HASH (1)
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
#define MICROPY_ALLOC_PATH_MAX (256)