I am pretty happy with the Altera NIOS 2 port. So far things are working as expected.
What steps are needed to get the code to the micropython github repository, so others can try ?
On a side note, my application requires to load a python script from memory and run it.
I've successfully tested one line scripts, but now want to try more complex multi line ones,
such as this one:
Code: Select all
count = 0
while count < 5:
print count
count += 1
Thanks
-
Code: Select all
static char *stack_top;
static char heap[2048];
void do_str(const char *src)
{
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;
}
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
qstr source_name = lex->source_name;
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT);
mp_obj_t module_fun = mp_compile(pn, source_name, MP_EMIT_OPT_NONE, true);
mp_call_function_0(module_fun);
nlr_pop();
} else {
// uncaught exception
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
}
}
int main(int argc, char **argv)
{
int stack_dummy;
stack_top = (char*)&stack_dummy;
#if MICROPY_ENABLE_GC
gc_init(heap, heap + sizeof(heap));
#endif
mp_init();
do_str("count = 0");
do_str("while count < 5:");
do_str(" print count");
do_str(" count += 1");
mp_deinit();
return 0;
}