Merge map.h into obj.h.

Pretty much everyone needs to include map.h, since it's such an integral
part of the Micro Python object implementation.  Thus, the definitions
are now in obj.h instead.  map.h is removed.
travis
Damien George 2014-03-30 13:54:02 +01:00
parent d17926db71
commit df6567e634
57 changed files with 61 additions and 116 deletions

View File

@ -8,7 +8,6 @@
#include "obj.h"
#include "runtime0.h"
#include "runtime.h"
#include "map.h"
#include "builtin.h"
#if MICROPY_ENABLE_FLOAT

View File

@ -12,7 +12,6 @@
#include "compile.h"
#include "runtime0.h"
#include "runtime.h"
#include "map.h"
#include "builtin.h"
STATIC mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse_input_kind) {

View File

@ -17,7 +17,6 @@
#include "compile.h"
#include "runtime0.h"
#include "runtime.h"
#include "map.h"
#include "builtin.h"
#define PATH_SEP_CHAR '/'

View File

@ -5,13 +5,12 @@
#include "qstr.h"
#include "obj.h"
#include "runtime0.h"
#include "map.h"
// approximatelly doubling primes; made with Mathematica command: Table[Prime[Floor[(1.7)^n]], {n, 3, 24}]
// prefixed with zero for the empty case.
STATIC int doubling_primes[] = {0, 7, 19, 43, 89, 179, 347, 647, 1229, 2297, 4243, 7829, 14347, 26017, 47149, 84947, 152443, 273253, 488399, 869927, 1547173, 2745121, 4861607};
int get_doubling_prime_greater_or_equal_to(int x) {
STATIC int get_doubling_prime_greater_or_equal_to(int x) {
for (int i = 0; i < sizeof(doubling_primes) / sizeof(int); i++) {
if (doubling_primes[i] >= x) {
return doubling_primes[i];

View File

@ -1,48 +0,0 @@
typedef struct _mp_map_elem_t {
mp_obj_t key;
mp_obj_t value;
} mp_map_elem_t;
// TODO maybe have a truncated mp_map_t for fixed tables, since alloc=used
// put alloc last in the structure, so the truncated version does not need it
// this would save 1 ROM word for all ROM objects that have a locals_dict
// would also need a trucated dict structure
typedef struct _mp_map_t {
machine_uint_t all_keys_are_qstrs : 1;
machine_uint_t table_is_fixed_array : 1;
machine_uint_t used : (8 * sizeof(machine_uint_t) - 2);
machine_uint_t alloc;
mp_map_elem_t *table;
} mp_map_t;
typedef struct _mp_set_t {
machine_uint_t alloc;
machine_uint_t used;
mp_obj_t *table;
} mp_set_t;
typedef enum _mp_map_lookup_kind_t {
MP_MAP_LOOKUP, // 0
MP_MAP_LOOKUP_ADD_IF_NOT_FOUND, // 1
MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2
MP_MAP_LOOKUP_FIRST = 4,
} mp_map_lookup_kind_t;
typedef struct _mp_obj_dict_t {
mp_obj_base_t base;
mp_map_t map;
} mp_obj_dict_t;
int get_doubling_prime_greater_or_equal_to(int x);
void mp_map_init(mp_map_t *map, int n);
void mp_map_init_fixed_table(mp_map_t *map, int n, const mp_obj_t *table);
mp_map_t *mp_map_new(int n);
void mp_map_deinit(mp_map_t *map);
void mp_map_free(mp_map_t *map);
mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
void mp_map_clear(mp_map_t *map);
void mp_set_init(mp_set_t *set, int n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
void mp_set_clear(mp_set_t *set);

View File

@ -2,7 +2,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "builtin.h"
STATIC const mp_map_elem_t mp_module_array_globals_table[] = {

View File

@ -2,7 +2,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "builtin.h"
STATIC const mp_map_elem_t mp_module_collections_globals_table[] = {

View File

@ -4,7 +4,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "builtin.h"
#if MICROPY_ENABLE_FLOAT

View File

@ -2,7 +2,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "builtin.h"
// Various builtins specific to MicroPython runtime,

View File

@ -9,7 +9,6 @@
#include "obj.h"
#include "runtime0.h"
#include "runtime.h"
#include "map.h"
mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) {
if (MP_OBJ_IS_SMALL_INT(o_in)) {

View File

@ -83,9 +83,52 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_DEFINE_CONST_STATICMETHOD_OBJ(obj_name, fun_name) const mp_obj_static_class_method_t obj_name = {{&mp_type_staticmethod}, fun_name}
#define MP_DEFINE_CONST_CLASSMETHOD_OBJ(obj_name, fun_name) const mp_obj_static_class_method_t obj_name = {{&mp_type_classmethod}, fun_name}
// Need to declare this here so we are not dependent on map.h
struct _mp_map_t;
struct _mp_map_elem_t;
// Underlying map/hash table implementation (not dict object or map function)
typedef struct _mp_map_elem_t {
mp_obj_t key;
mp_obj_t value;
} mp_map_elem_t;
// TODO maybe have a truncated mp_map_t for fixed tables, since alloc=used
// put alloc last in the structure, so the truncated version does not need it
// this would save 1 ROM word for all ROM objects that have a locals_dict
// would also need a trucated dict structure
typedef struct _mp_map_t {
machine_uint_t all_keys_are_qstrs : 1;
machine_uint_t table_is_fixed_array : 1;
machine_uint_t used : (8 * sizeof(machine_uint_t) - 2);
machine_uint_t alloc;
mp_map_elem_t *table;
} mp_map_t;
typedef enum _mp_map_lookup_kind_t {
MP_MAP_LOOKUP, // 0
MP_MAP_LOOKUP_ADD_IF_NOT_FOUND, // 1
MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2
MP_MAP_LOOKUP_FIRST = 4,
} mp_map_lookup_kind_t;
void mp_map_init(mp_map_t *map, int n);
void mp_map_init_fixed_table(mp_map_t *map, int n, const mp_obj_t *table);
mp_map_t *mp_map_new(int n);
void mp_map_deinit(mp_map_t *map);
void mp_map_free(mp_map_t *map);
mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
void mp_map_clear(mp_map_t *map);
// Underlying set implementation (not set object)
typedef struct _mp_set_t {
machine_uint_t alloc;
machine_uint_t used;
mp_obj_t *table;
} mp_set_t;
void mp_set_init(mp_set_t *set, int n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
void mp_set_clear(mp_set_t *set);
// Type definitions for methods
@ -95,7 +138,7 @@ typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_t)(void);
typedef mp_obj_t (*mp_fun_var_t)(uint n, const mp_obj_t *);
typedef mp_obj_t (*mp_fun_kw_t)(uint n, const mp_obj_t *, struct _mp_map_t *);
typedef mp_obj_t (*mp_fun_kw_t)(uint n, const mp_obj_t *, mp_map_t *);
typedef enum {
PRINT_STR, PRINT_REPR
@ -384,12 +427,16 @@ machine_int_t mp_obj_tuple_hash(mp_obj_t self_in);
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, struct _mp_map_t *kwargs);
mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs);
// dict
typedef struct _mp_obj_dict_t {
mp_obj_base_t base;
mp_map_t map;
} mp_obj_dict_t;
uint mp_obj_dict_len(mp_obj_t self_in);
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
struct _mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in);
mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in);
// set
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
@ -423,9 +470,9 @@ MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj);
typedef struct _mp_obj_module_t {
mp_obj_base_t base;
qstr name;
struct _mp_map_t *globals;
mp_map_t *globals;
} mp_obj_module_t;
struct _mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in);
mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in);
// staticmethod and classmethod types; defined here so we can make const versions
// this structure is used for instances of both staticmethod and classmethod

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"
#include "binary.h"

View File

@ -8,7 +8,6 @@
#include "obj.h"
#include "parsenum.h"
#include "runtime0.h"
#include "map.h"
#if MICROPY_ENABLE_FLOAT

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"

View File

@ -9,7 +9,6 @@
#include "qstr.h"
#include "obj.h"
#include "objtuple.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"
#include "bc.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "bc.h"
#include "objgenerator.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"

View File

@ -8,7 +8,6 @@
#include "obj.h"
#include "objmodule.h"
#include "runtime.h"
#include "map.h"
#include "builtintables.h"
STATIC mp_map_t mp_loaded_modules_map; // TODO: expose as sys.modules

View File

@ -9,7 +9,6 @@
#include "obj.h"
#include "runtime.h"
#include "runtime0.h"
#include "map.h"
typedef struct _mp_obj_set_t {
mp_obj_base_t base;

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"
#include "objtuple.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"

View File

@ -12,7 +12,6 @@
#include "runtime0.h"
#include "runtime.h"
#include "emitglue.h"
#include "map.h"
#include "builtin.h"
#include "builtintables.h"
#include "bc.h"

View File

@ -3,10 +3,10 @@ void mp_deinit(void);
void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw);
struct _mp_map_t *mp_locals_get(void);
void mp_locals_set(struct _mp_map_t *m);
struct _mp_map_t *mp_globals_get(void);
void mp_globals_set(struct _mp_map_t *m);
mp_map_t *mp_locals_get(void);
void mp_locals_set(mp_map_t *m);
mp_map_t *mp_globals_get(void);
void mp_globals_set(mp_map_t *m);
mp_obj_t mp_load_name(qstr qstr);
mp_obj_t mp_load_global(qstr qstr);
@ -58,7 +58,7 @@ mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_NULL instead of r
mp_obj_t mp_make_raise_obj(mp_obj_t o);
extern mp_obj_t mp_sys_path;
struct _mp_map_t *mp_loaded_modules_get(void);
mp_map_t *mp_loaded_modules_get(void);
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
void mp_import_all(mp_obj_t module);

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime0.h"
#include "runtime.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "adc.h"
/* ADC defintions */

View File

@ -9,7 +9,6 @@
#include "qstr.h"
#include "parse.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "audio.h"

View File

@ -9,7 +9,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "nlr.h"

View File

@ -5,7 +5,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "file.h"
#include "ff.h"

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
typedef enum {
PYB_I2C_1 = 0,

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "led.h"
#include "pin.h"
#include "build/pins.h"

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "pin.h"

View File

@ -9,7 +9,6 @@
#include "obj.h"
#include "runtime.h"
#include "nlr.h"
#include "map.h"
#include "pin.h"

View File

@ -9,7 +9,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "gc.h"
#include "gccollect.h"
#include "systick.h"

View File

@ -21,7 +21,6 @@
#include "lexer.h"
#include "parse.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "cc3k/ccspi.h"

View File

@ -9,7 +9,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "sdcard.h"

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "servo.h"
// PWM

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "usart.h"
pyb_usart_t pyb_usart_global_debug = PYB_USART_NONE;

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "i2c.h"
#include "accel.h"

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "adc.h"
#include "pin.h"

View File

@ -9,7 +9,6 @@
#include "qstr.h"
#include "parse.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "dac.h"

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "nlr.h"

View File

@ -4,7 +4,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "file.h"
#include "ff.h"

View File

@ -5,7 +5,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
STATIC const char *help_text =
"Welcome to Micro Python!\n"

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "i2c.h"

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "led.h"
#include "pin.h"

View File

@ -5,7 +5,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "systick.h"
#include "rng.h"
#include "storage.h"

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "gc.h"
#include "gccollect.h"
#include "systick.h"

View File

@ -5,7 +5,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "modtime.h"
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {

View File

@ -9,7 +9,6 @@
#include "obj.h"
#include "runtime.h"
#include "nlr.h"
#include "map.h"
#include "pin.h"

View File

@ -6,7 +6,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "sdcard.h"
#include "pin.h"

View File

@ -7,7 +7,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "servo.h"

View File

@ -8,7 +8,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "usart.h"
struct _pyb_usart_obj_t {

View File

@ -9,7 +9,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "binary.h"

View File

@ -9,7 +9,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "stream.h"

View File

@ -15,7 +15,6 @@
#include "lexerunix.h"
#include "parse.h"
#include "obj.h"
#include "map.h"
#include "parsehelper.h"
#include "compile.h"
#include "runtime0.h"

View File

@ -15,7 +15,6 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "objtuple.h"
#include "objarray.h"
#include "runtime.h"