#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "py/compile.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/stackctrl.h"
static char heap[16384];
mp_obj_t execute_from_str(const char *str) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(0, str, strlen(str), false);
mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NONE, false);
mp_call_function_0(module_fun);
nlr_pop();
return 0;
} else {
return (mp_obj_t)nlr.ret_val;
}
}
int main() {
mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
gc_init(heap, heap + sizeof(heap));
mp_init();
const char str[] = "print('Hello world of easy embedding!')";
if (execute_from_str(str)) {
printf("Error\n");
}
}
uint mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
void nlr_jump_fail(void *val) {
printf("FATAL: uncaught NLR %p\n", val);
exit(1);
}