summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-20 19:20:59 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-20 19:20:59 +0000
commit7f8be591111d9fda9fb52fe1896c8c14f077a9a5 (patch)
tree759d1e186ea420b872935f6f69bc0e5f650d40c8 /py/obj.c
parenta925639247d4ec90a93262a280f7ef89ca02ccc9 (diff)
downloadmicropython-7f8be591111d9fda9fb52fe1896c8c14f077a9a5.tar.gz
micropython-7f8be591111d9fda9fb52fe1896c8c14f077a9a5.zip
py: Allow hashing of functions and tuples.
Diffstat (limited to 'py/obj.c')
-rw-r--r--py/obj.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/obj.c b/py/obj.c
index e98dbae6cf..0c91e8f6d8 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -81,9 +81,16 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
return mp_obj_str_get_hash(o_in);
} else if (MP_OBJ_IS_TYPE(o_in, &none_type)) {
return (machine_int_t)o_in;
+ } else if (MP_OBJ_IS_TYPE(o_in, &fun_native_type) || MP_OBJ_IS_TYPE(o_in, &fun_bc_type)) {
+ return (machine_int_t)o_in;
+ } else if (MP_OBJ_IS_TYPE(o_in, &tuple_type)) {
+ return mp_obj_tuple_hash(o_in);
+
+ // TODO hash class and instances
+ // TODO delegate to __hash__ method if it exists
+
} else {
- assert(0);
- return 0;
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unhashable type: '%s'", mp_obj_get_type_str(o_in)));
}
}