py: Support instance __call__ method.
diff --git a/py/objtype.c b/py/objtype.c
index 3d22b8e..75d53b8 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -338,6 +338,16 @@
     }
 }
 
+STATIC mp_obj_t class_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {
+    mp_obj_class_t *self = self_in;
+    mp_obj_t member = mp_obj_class_lookup(self->base.type, MP_QSTR___call__);
+    if (member == MP_OBJ_NULL) {
+        return member;
+    }
+    mp_obj_t meth = mp_obj_new_bound_meth(member, self);
+    return mp_call_function_n_kw(meth, n_args, n_kw, args);
+}
+
 /******************************************************************************/
 // type object
 //  - the struct is mp_obj_type_t and is defined in obj.h so const types can be made
@@ -474,6 +484,7 @@
     o->load_attr = class_load_attr;
     o->store_attr = class_store_attr;
     o->subscr = class_subscr;
+    o->call = class_call;
     o->bases_tuple = bases_tuple;
     o->locals_dict = locals_dict;
     return o;
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index e970f58..784bf59 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -31,6 +31,7 @@
 Q(__str__)
 Q(__getattr__)
 Q(__del__)
+Q(__call__)
 
 Q(micropython)
 Q(byte_code)
diff --git a/py/runtime.c b/py/runtime.c
index 30db01c..b56740a 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -481,10 +481,13 @@
 
     // do the call
     if (type->call != NULL) {
-        return type->call(fun_in, n_args, n_kw, args);
-    } else {
-        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));
+        mp_obj_t res = type->call(fun_in, n_args, n_kw, args);
+        if (res != NULL) {
+            return res;
+        }
     }
+
+    nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));
 }
 
 // args contains: fun  self/NULL  arg(0)  ...  arg(n_args-2)  arg(n_args-1)  kw_key(0)  kw_val(0)  ... kw_key(n_kw-1)  kw_val(n_kw-1)