summaryrefslogtreecommitdiffstatshomepage
path: root/py/map.h
diff options
context:
space:
mode:
authorDamien <damien.p.george@gmail.com>2013-12-21 18:17:45 +0000
committerDamien <damien.p.george@gmail.com>2013-12-21 18:17:45 +0000
commitd99b05282d14ceb0163cbcd059aa37bdb415af43 (patch)
tree978135f9fe83d3c4d5b3c95f84cb104c0092936a /py/map.h
parente2880aa2fdc75298df487df7519d483acb03959c (diff)
downloadmicropython-d99b05282d14ceb0163cbcd059aa37bdb415af43.tar.gz
micropython-d99b05282d14ceb0163cbcd059aa37bdb415af43.zip
Change object representation from 1 big union to individual structs.
A big change. Micro Python objects are allocated as individual structs with the first element being a pointer to the type information (which is itself an object). This scheme follows CPython. Much more flexible, not necessarily slower, uses same heap memory, and can allocate objects statically. Also change name prefix, from py_ to mp_ (mp for Micro Python).
Diffstat (limited to 'py/map.h')
-rw-r--r--py/map.h45
1 files changed, 26 insertions, 19 deletions
diff --git a/py/map.h b/py/map.h
index 6c9df9ece0..8ee8429b52 100644
--- a/py/map.h
+++ b/py/map.h
@@ -1,30 +1,37 @@
typedef enum {
- MAP_QSTR,
- MAP_PY_OBJ,
-} py_map_kind_t;
+ MP_MAP_QSTR,
+ MP_MAP_OBJ,
+} mp_map_kind_t;
-typedef struct _py_map_elem_t {
- py_obj_t key;
- py_obj_t value;
-} py_map_elem_t;
+typedef struct _mp_map_elem_t {
+ mp_obj_t key;
+ mp_obj_t value;
+} mp_map_elem_t;
-typedef struct _py_map_t {
+typedef struct _mp_map_t {
struct {
- py_map_kind_t kind : 1;
+ mp_map_kind_t kind : 1;
machine_uint_t used : (8 * BYTES_PER_WORD - 1);
};
machine_uint_t alloc;
- py_map_elem_t *table;
-} py_map_t;
+ 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;
// these are defined in runtime.c
-py_map_t *rt_get_map_locals(void);
-void rt_set_map_locals(py_map_t *m);
+mp_map_t *rt_get_map_locals(void);
+void rt_set_map_locals(mp_map_t *m);
int get_doubling_prime_greater_or_equal_to(int x);
-void py_map_init(py_map_t *map, py_map_kind_t kind, int n);
-py_map_t *py_map_new(py_map_kind_t kind, int n);
-py_map_elem_t* py_map_lookup_helper(py_map_t *map, py_obj_t index, bool add_if_not_found);
-py_map_elem_t* py_qstr_map_lookup(py_map_t *map, qstr index, bool add_if_not_found);
-py_map_elem_t* py_map_lookup(py_obj_t o, py_obj_t index, bool add_if_not_found);
-py_obj_t py_set_lookup(py_obj_t o_in, py_obj_t index, bool add_if_not_found);
+void mp_map_init(mp_map_t *map, mp_map_kind_t kind, int n);
+mp_map_t *mp_map_new(mp_map_kind_t kind, int n);
+mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found);
+mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found);
+
+void mp_set_init(mp_set_t *set, int n);
+mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found);