Commit cb78f862 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py: Allow to disable array module and bytearray type.

array.array and bytearray share big deal of code, so to get real savings,
both need to be disabled.
parent 0a1ea402
...@@ -43,7 +43,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = { ...@@ -43,7 +43,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
// built-in types // built-in types
{ MP_OBJ_NEW_QSTR(MP_QSTR_bool), (mp_obj_t)&mp_type_bool }, { MP_OBJ_NEW_QSTR(MP_QSTR_bool), (mp_obj_t)&mp_type_bool },
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytes), (mp_obj_t)&mp_type_bytes }, { MP_OBJ_NEW_QSTR(MP_QSTR_bytes), (mp_obj_t)&mp_type_bytes },
#if MICROPY_PY_BUILTINS_BYTEARRAY
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytearray), (mp_obj_t)&mp_type_bytearray }, { MP_OBJ_NEW_QSTR(MP_QSTR_bytearray), (mp_obj_t)&mp_type_bytearray },
#endif
#if MICROPY_PY_BUILTINS_COMPLEX #if MICROPY_PY_BUILTINS_COMPLEX
{ MP_OBJ_NEW_QSTR(MP_QSTR_complex), (mp_obj_t)&mp_type_complex }, { MP_OBJ_NEW_QSTR(MP_QSTR_complex), (mp_obj_t)&mp_type_complex },
#endif #endif
...@@ -160,7 +162,9 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = { ...@@ -160,7 +162,9 @@ STATIC const mp_map_elem_t mp_builtin_module_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___main__), (mp_obj_t)&mp_module___main__ }, { MP_OBJ_NEW_QSTR(MP_QSTR___main__), (mp_obj_t)&mp_module___main__ },
{ MP_OBJ_NEW_QSTR(MP_QSTR_micropython), (mp_obj_t)&mp_module_micropython }, { MP_OBJ_NEW_QSTR(MP_QSTR_micropython), (mp_obj_t)&mp_module_micropython },
#if MICROPY_PY_ARRAY
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_module_array }, { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_module_array },
#endif
#if MICROPY_PY_IO #if MICROPY_PY_IO
{ MP_OBJ_NEW_QSTR(MP_QSTR__io), (mp_obj_t)&mp_module_io }, { MP_OBJ_NEW_QSTR(MP_QSTR__io), (mp_obj_t)&mp_module_io },
#endif #endif
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "obj.h" #include "obj.h"
#include "builtin.h" #include "builtin.h"
#if MICROPY_PY_ARRAY
STATIC const mp_map_elem_t mp_module_array_globals_table[] = { STATIC const mp_map_elem_t mp_module_array_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_array) }, { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_array) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_type_array }, { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_type_array },
...@@ -51,3 +53,5 @@ const mp_obj_module_t mp_module_array = { ...@@ -51,3 +53,5 @@ const mp_obj_module_t mp_module_array = {
.name = MP_QSTR_array, .name = MP_QSTR_array,
.globals = (mp_obj_dict_t*)&mp_module_array_globals, .globals = (mp_obj_dict_t*)&mp_module_array_globals,
}; };
#endif
...@@ -249,6 +249,11 @@ typedef double mp_float_t; ...@@ -249,6 +249,11 @@ typedef double mp_float_t;
/*****************************************************************************/ /*****************************************************************************/
/* Fine control over Python builtins, classes, modules, etc */ /* Fine control over Python builtins, classes, modules, etc */
// Whether to support bytearray object
#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
#endif
// Whether to support set object // Whether to support set object
#ifndef MICROPY_PY_BUILTINS_SET #ifndef MICROPY_PY_BUILTINS_SET
#define MICROPY_PY_BUILTINS_SET (1) #define MICROPY_PY_BUILTINS_SET (1)
...@@ -269,6 +274,13 @@ typedef double mp_float_t; ...@@ -269,6 +274,13 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_PROPERTY (1) #define MICROPY_PY_BUILTINS_PROPERTY (1)
#endif #endif
// Whether to provide "array" module. Note that large chunk of the
// underlying code is shared with "bytearray" builtin type, so to
// get real savings, it should be disabled too.
#ifndef MICROPY_PY_ARRAY
#define MICROPY_PY_ARRAY (1)
#endif
// Whether to provide "collections" module // Whether to provide "collections" module
#ifndef MICROPY_PY_COLLECTIONS #ifndef MICROPY_PY_COLLECTIONS
#define MICROPY_PY_COLLECTIONS (1) #define MICROPY_PY_COLLECTIONS (1)
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "runtime.h" #include "runtime.h"
#include "binary.h" #include "binary.h"
#if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY
typedef struct _mp_obj_array_t { typedef struct _mp_obj_array_t {
mp_obj_base_t base; mp_obj_base_t base;
machine_uint_t typecode : 8; machine_uint_t typecode : 8;
...@@ -310,3 +312,5 @@ STATIC mp_obj_t array_iterator_new(mp_obj_t array_in) { ...@@ -310,3 +312,5 @@ STATIC mp_obj_t array_iterator_new(mp_obj_t array_in) {
o->cur = 0; o->cur = 0;
return o; return o;
} }
#endif // MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment