Thanks. It worked for me. Now, when I pass my application code to do_str(), it fails returning name error. Here is my code for do_str():
Code: Select all
uint32_t do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_obj_t err_obj;
mp_obj_type_t *type;
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
printf("MemoryError: lexer could not allocate memory\n");
//return;
return MEMORY_ERROR;
}
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
qstr source_name = lex->source_name;
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
mp_call_function_0(module_fun);
nlr_pop();
return 0;
}
else // uncaught exception
{
err_obj = (mp_obj_t)nlr.ret_val;
type = mp_obj_get_type(err_obj);
}
}
Can you please help me in solving this?
Thanks,
Gaurav.