Selaa lähdekoodia

【优化】MicroPython 配置,减少 mini 版资源占用。

Signed-off-by: armink <armink.ztl@gmail.com>
armink 8 vuotta sitten
vanhempi
sitoutus
35cd6dd4c1
4 muutettua tiedostoa jossa 12 lisäystä ja 4 poistoa
  1. 4 0
      lib/utils/pyexec.c
  2. 3 3
      port/mpconfigport.h
  3. 4 0
      py/builtinevex.c
  4. 1 1
      py/builtinimport.c

+ 4 - 0
lib/utils/pyexec.c

@@ -82,7 +82,11 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
                 const vstr_t *vstr = source;
                 lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr->buf, vstr->len, 0);
             } else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) {
+                #if MICROPY_PY_IO
                 lex = mp_lexer_new_from_file(source);
+                #else
+                mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
+                #endif
             } else {
                 lex = (mp_lexer_t*)source;
             }

+ 3 - 3
port/mpconfigport.h

@@ -79,8 +79,6 @@
 #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
 #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
 #define MICROPY_PY_ALL_SPECIAL_METHODS (1)
-#define MICROPY_PY_BUILTINS_COMPILE (1)
-#define MICROPY_PY_BUILTINS_EXECFILE (1)
 #define MICROPY_PY_BUILTINS_INPUT (1)
 #define MICROPY_PY_BUILTINS_POW3 (1)
 #define MICROPY_PY_BUILTINS_ENUMERATE (1)
@@ -115,7 +113,6 @@
 #define MICROPY_CPYTHON_COMPAT      (1)
 #define MICROPY_LONGINT_IMPL        (MICROPY_LONGINT_IMPL_MPZ)
 #define MICROPY_FLOAT_IMPL          (MICROPY_FLOAT_IMPL_DOUBLE)
-#define MICROPY_READER_POSIX        (1)
 #define MICROPY_READER_VFS          (0)
 #define MICROPY_PY_PIN              (1)
 #define MICROPY_PY_OS_DUPTERM       (1)
@@ -137,6 +134,9 @@
 #define MICROPY_PY_MODUOS           (1)
 #define MICROPY_PY_MODUOS_FILE      (1)
 #define MICROPY_PY_SYS_STDFILES     (1)
+#define MICROPY_READER_POSIX        (1)
+#define MICROPY_PY_BUILTINS_COMPILE (1)
+#define MICROPY_PY_BUILTINS_EXECFILE (1)
 #else
 #define MICROPY_PY_IO               (0)
 #define MICROPY_PY_MODUOS           (0)

+ 4 - 0
py/builtinevex.c

@@ -137,8 +137,12 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
     // MP_PARSE_SINGLE_INPUT is used to indicate a file input
     mp_lexer_t *lex;
     if (MICROPY_PY_BUILTINS_EXECFILE && parse_input_kind == MP_PARSE_SINGLE_INPUT) {
+        #if MICROPY_PY_IO
         lex = mp_lexer_new_from_file(str);
         parse_input_kind = MP_PARSE_FILE_INPUT;
+        #else
+        mp_raise_msg(&mp_type_RuntimeError, "script compilation not supported");
+        #endif
     } else {
         lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, str, str_len, 0);
     }

+ 1 - 1
py/builtinimport.c

@@ -222,7 +222,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
     #endif
 
     // If we can compile scripts then load the file and compile and execute it.
-    #if MICROPY_ENABLE_COMPILER
+    #if MICROPY_ENABLE_COMPILER && MICROPY_PY_IO
     {
         mp_lexer_t *lex = mp_lexer_new_from_file(file_str);
         do_load_from_lexer(module_obj, lex);