py: Add option to disable set() object (enabled by default).

This commit is contained in:
Damien George 2014-06-01 13:46:47 +01:00
parent fb510b3bf9
commit 3ebd4d0cae
6 changed files with 17 additions and 0 deletions

View File

@ -64,7 +64,9 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_property), (mp_obj_t)&mp_type_property },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_range), (mp_obj_t)&mp_type_range },
#if MICROPY_PY_BUILTINS_SET
{ MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&mp_type_set },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_str), (mp_obj_t)&mp_type_str },
{ MP_OBJ_NEW_QSTR(MP_QSTR_super), (mp_obj_t)&mp_type_super },
{ MP_OBJ_NEW_QSTR(MP_QSTR_tuple), (mp_obj_t)&mp_type_tuple },

View File

@ -239,6 +239,11 @@ typedef double mp_float_t;
/*****************************************************************************/
/* Fine control over Python builtins, classes, modules, etc */
// Whether to support set object
#ifndef MICROPY_PY_BUILTINS_SET
#define MICROPY_PY_BUILTINS_SET (1)
#endif
// Whether to support slice subscript operators and slice object
#ifndef MICROPY_PY_BUILTINS_SLICE
#define MICROPY_PY_BUILTINS_SLICE (1)

View File

@ -37,6 +37,8 @@
#include "runtime0.h"
#include "builtin.h"
#if MICROPY_PY_BUILTINS_SET
typedef struct _mp_obj_set_t {
mp_obj_base_t base;
mp_set_t set;
@ -584,3 +586,5 @@ void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
mp_obj_set_t *self = self_in;
mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
}
#endif // MICROPY_PY_BUILTINS_SET

View File

@ -1173,8 +1173,10 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_obj_list_append,
mp_obj_new_dict,
mp_obj_dict_store,
#if MICROPY_PY_BUILTINS_SET
mp_obj_new_set,
mp_obj_set_store,
#endif
mp_make_function_from_raw_code,
mp_call_function_n_kw_for_native,
mp_call_method_n_kw,

View File

@ -115,8 +115,10 @@ typedef enum {
MP_F_LIST_APPEND,
MP_F_BUILD_MAP,
MP_F_STORE_MAP,
#if MICROPY_PY_BUILTINS_SET
MP_F_BUILD_SET,
MP_F_STORE_SET,
#endif
MP_F_MAKE_FUNCTION_FROM_RAW_CODE,
MP_F_CALL_FUNCTION_N_KW_FOR_NATIVE,
MP_F_CALL_METHOD_N_KW,

View File

@ -772,6 +772,7 @@ unwind_jump:
sp -= 2;
DISPATCH();
#if MICROPY_PY_BUILTINS_SET
ENTRY(MP_BC_BUILD_SET):
DECODE_UINT;
sp -= unum - 1;
@ -784,6 +785,7 @@ unwind_jump:
mp_obj_set_store(sp[-unum], sp[0]);
sp--;
DISPATCH();
#endif
#if MICROPY_PY_BUILTINS_SLICE
ENTRY(MP_BC_BUILD_SLICE):