From 354e688d8ebf78d34577db4b45388dede4954b8d Mon Sep 17 00:00:00 2001 From: pohmelie Date: Mon, 7 Dec 2015 15:35:48 +0300 Subject: [PATCH] py: Add MICROPY_PY_BUILTINS_MIN_MAX, disable for minimal ports. --- minimal/mpconfigport.h | 1 + py/modbuiltins.c | 6 ++++++ py/mpconfig.h | 5 +++++ py/qstrdefs.h | 2 ++ unix/mpconfigport_minimal.h | 1 + 5 files changed, 15 insertions(+) diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h index caa31d3bda..f24b514262 100644 --- a/minimal/mpconfigport.h +++ b/minimal/mpconfigport.h @@ -31,6 +31,7 @@ #define MICROPY_PY_BUILTINS_SET (0) #define MICROPY_PY_BUILTINS_SLICE (0) #define MICROPY_PY_BUILTINS_PROPERTY (0) +#define MICROPY_PY_BUILTINS_MIN_MAX (0) #define MICROPY_PY___FILE__ (0) #define MICROPY_PY_GC (0) #define MICROPY_PY_ARRAY (0) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 36a3d9b685..23e08c015c 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -250,6 +250,8 @@ STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter); +#if MICROPY_PY_BUILTINS_MIN_MAX + STATIC mp_obj_t mp_builtin_min_max(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs, mp_uint_t op) { mp_map_elem_t *key_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_key), MP_MAP_LOOKUP); mp_obj_t key_fn = key_elem == NULL ? MP_OBJ_NULL : key_elem->value; @@ -295,6 +297,8 @@ STATIC mp_obj_t mp_builtin_min(mp_uint_t n_args, const mp_obj_t *args, mp_map_t } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_min_obj, 1, mp_builtin_min); +#endif + STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { mp_obj_t ret = mp_iternext_allow_raise(o); if (ret == MP_OBJ_STOP_ITERATION) { @@ -637,8 +641,10 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_iter), MP_ROM_PTR(&mp_builtin_iter_obj) }, { MP_ROM_QSTR(MP_QSTR_len), MP_ROM_PTR(&mp_builtin_len_obj) }, { MP_ROM_QSTR(MP_QSTR_locals), MP_ROM_PTR(&mp_builtin_locals_obj) }, + #if MICROPY_PY_BUILTINS_MIN_MAX { MP_ROM_QSTR(MP_QSTR_max), MP_ROM_PTR(&mp_builtin_max_obj) }, { MP_ROM_QSTR(MP_QSTR_min), MP_ROM_PTR(&mp_builtin_min_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_next), MP_ROM_PTR(&mp_builtin_next_obj) }, { MP_ROM_QSTR(MP_QSTR_oct), MP_ROM_PTR(&mp_builtin_oct_obj) }, { MP_ROM_QSTR(MP_QSTR_ord), MP_ROM_PTR(&mp_builtin_ord_obj) }, diff --git a/py/mpconfig.h b/py/mpconfig.h index 4d81f25d3f..c05f33c453 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -610,6 +610,11 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0) #endif +// Whether to support min/max functions +#ifndef MICROPY_PY_BUILTINS_MIN_MAX +#define MICROPY_PY_BUILTINS_MIN_MAX (1) +#endif + // Whether to set __file__ for imported modules #ifndef MICROPY_PY___FILE__ #define MICROPY_PY___FILE__ (1) diff --git a/py/qstrdefs.h b/py/qstrdefs.h index e6c0fdcf1a..7700937913 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -232,8 +232,10 @@ Q(len) Q(list) Q(locals) Q(map) +#if MICROPY_PY_BUILTINS_MIN_MAX Q(max) Q(min) +#endif Q(namedtuple) Q(next) Q(oct) diff --git a/unix/mpconfigport_minimal.h b/unix/mpconfigport_minimal.h index d7b908bc9a..09d5fbf6d3 100644 --- a/unix/mpconfigport_minimal.h +++ b/unix/mpconfigport_minimal.h @@ -57,6 +57,7 @@ #define MICROPY_PY_BUILTINS_SLICE (0) #define MICROPY_PY_BUILTINS_STR_UNICODE (0) #define MICROPY_PY_BUILTINS_PROPERTY (0) +#define MICROPY_PY_BUILTINS_MIN_MAX (0) #define MICROPY_PY___FILE__ (0) #define MICROPY_PY_MICROPYTHON_MEM_INFO (0) #define MICROPY_PY_GC (0)