summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTom Soulanille <soul@prama.com>2015-08-22 13:11:02 -0400
committerDamien George <damien.p.george@gmail.com>2015-09-12 22:53:54 +0100
commit7731edf2f5cf7227a58315853d6351d4d4516f81 (patch)
treea42e1792a54060dbc7c936e15cf69ce194a58947
parent229b908d2e459f350f958954dfbd6a0f093033c5 (diff)
downloadmicropython-7731edf2f5cf7227a58315853d6351d4d4516f81.tar.gz
micropython-7731edf2f5cf7227a58315853d6351d4d4516f81.zip
stmhal: Add "opt" arg to pyb.main, to set mp_optimise_value.
Use this to set the global optimisation value when executing the main script (and all scripts it imports).
-rw-r--r--stmhal/main.c17
-rw-r--r--stmhal/qstrdefsport.h1
2 files changed, 14 insertions, 4 deletions
diff --git a/stmhal/main.c b/stmhal/main.c
index 1413c59622..d6ae3d61f9 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -114,13 +114,22 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
}
#endif
-STATIC mp_obj_t pyb_main(mp_obj_t main) {
- if (MP_OBJ_IS_STR(main)) {
- MP_STATE_PORT(pyb_config_main) = main;
+STATIC mp_obj_t pyb_main(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} }
+ };
+
+ if (MP_OBJ_IS_STR(pos_args[0])) {
+ MP_STATE_PORT(pyb_config_main) = pos_args[0];
+
+ // parse args
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+ MP_STATE_VM(mp_optimise_value) = args[0].u_int;
}
return mp_const_none;
}
-MP_DEFINE_CONST_FUN_OBJ_1(pyb_main_obj, pyb_main);
+MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main);
static const char fresh_boot_py[] =
"# boot.py -- run on boot-up\r\n"
diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h
index ee7c6fe066..1fa74e8368 100644
--- a/stmhal/qstrdefsport.h
+++ b/stmhal/qstrdefsport.h
@@ -41,6 +41,7 @@ Q(enable_irq)
Q(stop)
Q(standby)
Q(main)
+Q(opt)
Q(sync)
Q(gc)
Q(repl_info)