From 1a1ba4d555146fe3bf0cd32906c77f5d918423ca Mon Sep 17 00:00:00 2001 From: mux Date: Fri, 3 Jan 2014 08:51:02 +0200 Subject: Change dfu.py to be Python 2/3 compatible * Chane dfu.py to use Python 3 syntax to avoid dependency on Python 2. * Update Makefile to call python instead of python2 * Fix #33 --- stm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index 6868f85ba..cfd8f5eef 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -147,7 +147,7 @@ OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(PY_O) $(SRC_FATFS:. all: $(BUILD) $(BUILD)/flash.dfu $(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin - python2 $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@ + python $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@ $(BUILD)/flash0.bin: $(BUILD)/flash.elf arm-none-eabi-objcopy -O binary -j .isr_vector $^ $@ -- cgit v1.2.3 From 66028ab6dcd1b2ec9504c3473d817649935a4a1e Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Jan 2014 14:03:48 +0000 Subject: Basic implementation of import. import works for simple cases. Still work to do on finding the right script, and setting globals/locals correctly when running an imported function. --- stm/Makefile | 1 + stm/lexerstm.c | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index 6868f85ba..be4ca8b3a 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -82,6 +82,7 @@ PY_O = \ objtuple.o \ objtype.o \ builtin.o \ + builtinimport.o \ vm.o \ repl.o \ diff --git a/stm/lexerstm.c b/stm/lexerstm.c index dfb84cca1..661dfb016 100644 --- a/stm/lexerstm.c +++ b/stm/lexerstm.c @@ -61,3 +61,8 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb fb->pos = 0; return mp_lexer_new(filename, fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close); } + +mp_lexer_t *mp_import_open_file(qstr mod_name) { + printf("import not implemented\n"); + return NULL; +} -- cgit v1.2.3 From 1fb031744f5584d1bd0c88d28fbe7e261832c7a8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Jan 2014 14:22:03 +0000 Subject: Change mp_compile so that it returns a function object for the module. --- stm/audio.c | 1 - stm/lcd.c | 1 - stm/main.c | 48 +++++++++++++++++++----------------------------- stm/pybwlan.c | 1 - stm/timer.c | 1 - 5 files changed, 19 insertions(+), 33 deletions(-) (limited to 'stm') diff --git a/stm/audio.c b/stm/audio.c index 38e0012b4..34adefbcd 100644 --- a/stm/audio.c +++ b/stm/audio.c @@ -8,7 +8,6 @@ #include "misc.h" #include "mpconfig.h" #include "parse.h" -#include "compile.h" #include "obj.h" #include "runtime.h" diff --git a/stm/lcd.c b/stm/lcd.c index 9f5a157d0..70d1a2642 100644 --- a/stm/lcd.c +++ b/stm/lcd.c @@ -5,7 +5,6 @@ #include "misc.h" #include "mpconfig.h" #include "parse.h" -#include "compile.h" #include "obj.h" #include "runtime.h" diff --git a/stm/main.c b/stm/main.c index f16ce252d..e8db2be2c 100644 --- a/stm/main.c +++ b/stm/main.c @@ -20,8 +20,8 @@ #include "lexer.h" #include "lexerstm.h" #include "parse.h" -#include "compile.h" #include "obj.h" +#include "compile.h" #include "runtime0.h" #include "runtime.h" #include "repl.h" @@ -489,25 +489,22 @@ void do_repl(void) { mp_lexer_free(lex); if (pn != MP_PARSE_NODE_NULL) { - 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; - uint32_t start = sys_tick_counter; - if (nlr_push(&nlr) == 0) { - rt_call_function_0(module_fun); - nlr_pop(); - // optional timing - if (0) { - uint32_t ticks = sys_tick_counter - start; // TODO implement a function that does this properly - printf("(took %lu ms)\n", ticks); - } - } 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; + uint32_t start = sys_tick_counter; + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + // optional timing + if (0) { + uint32_t ticks = sys_tick_counter - start; // TODO implement a function that does this properly + printf("(took %lu ms)\n", ticks); } + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\n"); } } } @@ -532,12 +529,7 @@ bool do_file(const char *filename) { return false; } - bool comp_ok = mp_compile(pn, false); - if (!comp_ok) { - return false; - } - - mp_obj_t module_fun = rt_make_function_from_id(1); + mp_obj_t module_fun = mp_compile(pn, false); if (module_fun == mp_const_none) { return false; } @@ -1133,17 +1125,15 @@ soft_reset: printf("pars;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); //parse_node_show(pn, 0); - bool comp_ok = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, false); printf("comp;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); - if (!comp_ok) { + if (module_fun == mp_const_none) { printf("compile error\n"); } else { // execute it! - mp_obj_t module_fun = rt_make_function_from_id(1); - // flash once led_state(PYB_LED_G1, 1); sys_tick_delay_ms(100); diff --git a/stm/pybwlan.c b/stm/pybwlan.c index 6341d0676..6988f1c84 100644 --- a/stm/pybwlan.c +++ b/stm/pybwlan.c @@ -18,7 +18,6 @@ #include "misc.h" #include "lexer.h" #include "parse.h" -#include "compile.h" #include "obj.h" #include "map.h" #include "runtime.h" diff --git a/stm/timer.c b/stm/timer.c index 28148b0c1..2605d4b4b 100644 --- a/stm/timer.c +++ b/stm/timer.c @@ -9,7 +9,6 @@ #include "misc.h" #include "mpconfig.h" #include "parse.h" -#include "compile.h" #include "obj.h" #include "runtime.h" -- cgit v1.2.3 From b372bfca21ccab593359ef25a0a0c6bf697c8586 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 3 Jan 2014 17:15:53 +0200 Subject: Rename default config file to mpconfig.h, and port's to mpconfigport.h. mpconfig.h will automatically pull mpconfigport.h. --- stm/Makefile | 2 +- stm/mpconfig.h | 19 ------------------- stm/mpconfigport.h | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 stm/mpconfig.h create mode 100644 stm/mpconfigport.h (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index 018d31f49..d6c77e2bd 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -187,7 +187,7 @@ $(BUILD)/%.o: $(PYSRC)/%.s $(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)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h diff --git a/stm/mpconfig.h b/stm/mpconfig.h deleted file mode 100644 index 1f9529e11..000000000 --- a/stm/mpconfig.h +++ /dev/null @@ -1,19 +0,0 @@ -// options to control how Micro Python is built - -#define MICROPY_ENABLE_FLOAT (1) -#define MICROPY_EMIT_CPYTHON (0) -#define MICROPY_EMIT_X64 (0) -#define MICROPY_EMIT_THUMB (1) -#define MICROPY_EMIT_INLINE_THUMB (1) - -// type definitions for the specific machine - -#define BYTES_PER_WORD (4) - -typedef int32_t machine_int_t; // must be pointer size -typedef uint32_t machine_uint_t; // must be pointer size -typedef void *machine_ptr_t; // must be of pointer size -typedef const void *machine_const_ptr_t; // must be of pointer size -typedef float machine_float_t; - -machine_float_t machine_sqrt(machine_float_t x); diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h new file mode 100644 index 000000000..4cea332f3 --- /dev/null +++ b/stm/mpconfigport.h @@ -0,0 +1,21 @@ +#include + +// options to control how Micro Python is built + +#define MICROPY_ENABLE_FLOAT (1) +#define MICROPY_EMIT_CPYTHON (0) +#define MICROPY_EMIT_X64 (0) +#define MICROPY_EMIT_THUMB (1) +#define MICROPY_EMIT_INLINE_THUMB (1) + +// type definitions for the specific machine + +#define BYTES_PER_WORD (4) + +typedef int32_t machine_int_t; // must be pointer size +typedef uint32_t machine_uint_t; // must be pointer size +typedef void *machine_ptr_t; // must be of pointer size +typedef const void *machine_const_ptr_t; // must be of pointer size +typedef float machine_float_t; + +machine_float_t machine_sqrt(machine_float_t x); -- cgit v1.2.3