More parse and compile script to main thread

This commit is contained in:
iabdalkader 2015-07-13 07:50:39 +02:00
parent e2f634675f
commit f7d71cd594
3 changed files with 11 additions and 11 deletions

View File

@ -320,7 +320,12 @@ soft_reset:
if (nlr_push(&nlr) == 0) { if (nlr_push(&nlr) == 0) {
while (usbdbg_script_ready()) { while (usbdbg_script_ready()) {
nlr_buf_t nlr; nlr_buf_t nlr;
mp_obj_t script= usbdbg_get_script(); vstr_t *script_buf = usbdbg_get_script();
// parse and compile script
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_,
vstr_str(script_buf), vstr_len(script_buf), 0);
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_obj_t script = mp_compile(pn, lex->source_name, MP_EMIT_OPT_NONE, false);
// clear script flag // clear script flag
usbdbg_clr_script(); usbdbg_clr_script();

View File

@ -25,7 +25,6 @@ static int xfer_length;
static enum usbdbg_cmd cmd; static enum usbdbg_cmd cmd;
static vstr_t script_buf; static vstr_t script_buf;
static mp_obj_t script;
static int script_ready=0; static int script_ready=0;
mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL; mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
@ -45,9 +44,11 @@ int usbdbg_script_ready()
return script_ready; return script_ready;
} }
mp_obj_t usbdbg_get_script() vstr_t *usbdbg_get_script()
{ {
return script; vstr_t *scr = vstr_new();
vstr_add_strn(scr, vstr_str(&script_buf), vstr_len(&script_buf));
return scr;
} }
void usbdbg_clr_script() void usbdbg_clr_script()
@ -131,12 +132,6 @@ void usbdbg_data_out(void *buffer, int length)
// set script ready flag // set script ready flag
script_ready = 1; script_ready = 1;
// parse and compile script
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_,
vstr_str(&script_buf), vstr_len(&script_buf), 0);
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
script = mp_compile(pn, lex->source_name, MP_EMIT_OPT_NONE, false);
// interrupt running script/REPL // interrupt running script/REPL
mp_obj_exception_clear_traceback(mp_const_ide_interrupt); mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
pendsv_nlr_jump_hard(mp_const_ide_interrupt); pendsv_nlr_jump_hard(mp_const_ide_interrupt);

View File

@ -50,6 +50,6 @@ enum usbdbg_cmd {
}; };
void usbdbg_init(); void usbdbg_init();
int usbdbg_script_ready(); int usbdbg_script_ready();
mp_obj_t usbdbg_get_script(); vstr_t *usbdbg_get_script();
void usbdbg_clr_script(); void usbdbg_clr_script();
#endif /* __USBDBG_H__ */ #endif /* __USBDBG_H__ */