Skip to content

Commit 7731edf

Browse files
pramasouldpgeorge
authored andcommitted
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).
1 parent 229b908 commit 7731edf

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

stmhal/main.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,22 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
114114
}
115115
#endif
116116

117-
STATIC mp_obj_t pyb_main(mp_obj_t main) {
118-
if (MP_OBJ_IS_STR(main)) {
119-
MP_STATE_PORT(pyb_config_main) = main;
117+
STATIC mp_obj_t pyb_main(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
118+
static const mp_arg_t allowed_args[] = {
119+
{ MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} }
120+
};
121+
122+
if (MP_OBJ_IS_STR(pos_args[0])) {
123+
MP_STATE_PORT(pyb_config_main) = pos_args[0];
124+
125+
// parse args
126+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
127+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
128+
MP_STATE_VM(mp_optimise_value) = args[0].u_int;
120129
}
121130
return mp_const_none;
122131
}
123-
MP_DEFINE_CONST_FUN_OBJ_1(pyb_main_obj, pyb_main);
132+
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main);
124133

125134
static const char fresh_boot_py[] =
126135
"# boot.py -- run on boot-up\r\n"

stmhal/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Q(enable_irq)
4141
Q(stop)
4242
Q(standby)
4343
Q(main)
44+
Q(opt)
4445
Q(sync)
4546
Q(gc)
4647
Q(repl_info)

0 commit comments

Comments
 (0)