diff options
Diffstat (limited to 'unix')
| -rw-r--r-- | unix/Makefile | 5 | ||||
| -rw-r--r-- | unix/main.c | 60 | ||||
| -rw-r--r-- | unix/mpconfigport.h (renamed from unix/mpconfig.h) | 0 |
3 files changed, 36 insertions, 29 deletions
diff --git a/unix/Makefile b/unix/Makefile index b8955d11a..fd5b6b43e 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -54,6 +54,7 @@ PY_O = \ objtuple.o \ objtype.o \ builtin.o \ + builtinimport.o \ vm.o \ showbc.o \ repl.o \ @@ -78,7 +79,7 @@ $(BUILD)/%.o: %.c $(BUILD)/%.o: $(PYSRC)/%.S $(CC) $(CFLAGS) -c -o $@ $< -$(BUILD)/%.o: $(PYSRC)/%.c mpconfig.h +$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h $(CC) $(CFLAGS) -c -o $@ $< $(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h @@ -91,7 +92,7 @@ $(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h $(BUILD)/vm.o: $(PYSRC)/vm.c $(CC) $(CFLAGS) -O3 -c -o $@ $< -$(BUILD)/main.o: mpconfig.h +$(BUILD)/main.o: mpconfigport.h $(BUILD)/parse.o: $(PYSRC)/grammar.h $(BUILD)/compile.o: $(PYSRC)/grammar.h $(BUILD)/emitcpy.o: $(PYSRC)/emit.h diff --git a/unix/main.c b/unix/main.c index 376dbc0c0..1aa333120 100644 --- a/unix/main.c +++ b/unix/main.c @@ -9,8 +9,8 @@ #include "lexer.h" #include "lexerunix.h" #include "parse.h" -#include "compile.h" #include "obj.h" +#include "compile.h" #include "runtime0.h" #include "runtime.h" #include "repl.h" @@ -85,19 +85,16 @@ static void do_repl(void) { if (pn != MP_PARSE_NODE_NULL) { //mp_parse_node_show(pn, 0); - bool comp_ok = mp_compile(pn, true); - if (comp_ok) { - mp_obj_t module_fun = rt_make_function_from_id(1); - if (module_fun != mp_const_none) { - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - rt_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - mp_obj_print((mp_obj_t)nlr.ret_val); - printf("\n"); - } + mp_obj_t module_fun = mp_compile(pn, true); + if (module_fun != mp_const_none) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\n"); } } } @@ -105,6 +102,18 @@ static void do_repl(void) { } void do_file(const char *file) { + // hack: set dir for import based on where this file is + { + const char * s = strrchr(file, '/'); + if (s != NULL) { + int len = s - file; + char *dir = m_new(char, len + 1); + memcpy(dir, file, len); + dir[len] = '\0'; + mp_import_set_directory(dir); + } + } + mp_lexer_t *lex = mp_lexer_new_from_file(file); //const char *pysrc = "def f():\n x=x+1\n print(42)\n"; //mp_lexer_t *lex = mp_lexer_from_str_len("<>", pysrc, strlen(pysrc), false); @@ -130,7 +139,7 @@ void do_file(const char *file) { //printf("----------------\n"); //parse_node_show(pn, 0); //printf("----------------\n"); - bool comp_ok = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, false); //printf("----------------\n"); #if MICROPY_EMIT_CPYTHON @@ -138,19 +147,16 @@ void do_file(const char *file) { printf("compile error\n"); } #else - if (1 && comp_ok) { + if (1 && module_fun != mp_const_none) { // execute it - mp_obj_t module_fun = rt_make_function_from_id(1); - if (module_fun != mp_const_none) { - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - rt_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - mp_obj_print((mp_obj_t)nlr.ret_val); - printf("\n"); - } + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\n"); } } #endif diff --git a/unix/mpconfig.h b/unix/mpconfigport.h index 3d0dc8a56..3d0dc8a56 100644 --- a/unix/mpconfig.h +++ b/unix/mpconfigport.h |
