diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-05 22:27:11 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-05 22:27:11 +0000 |
commit | d52a0318ce266e1d9ce0d877f64a8fe097cef080 (patch) | |
tree | 9c57f2bd169754c56679b25dd41c003a046c1137 /py/objtype.c | |
parent | 49fb6e53b35f991d79caadbb6320a39452944b4d (diff) | |
parent | 12e2656472bf53e467c066eda6f3e177a97210ca (diff) | |
download | micropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.tar.gz micropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.zip |
Merge remote-tracking branch 'upstream/master' into list_remove
Diffstat (limited to 'py/objtype.c')
-rw-r--r-- | py/objtype.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/py/objtype.c b/py/objtype.c index 83ae48d2d1..aeeaebb95d 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -4,17 +4,30 @@ #include "nlr.h" #include "misc.h" #include "mpconfig.h" +#include "mpqstr.h" #include "obj.h" -void type_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { - print(env, "<a type>"); +static void type_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { + mp_obj_type_t *self = self_in; + print(env, "<class '%s'>", self->name); +} + +static mp_obj_t type_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { + mp_obj_type_t *self = self_in; + if (self->make_new != NULL) { + // TODO we need to init the object if it's an instance of a type + return self->make_new(self, n_args, args); + } else { + nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "cannot create '%s' instances", self->name)); + } } const mp_obj_type_t mp_const_type = { { &mp_const_type }, - "<a type>", + "type", type_print, // print - NULL, // call_n + NULL, // make_new + type_call_n, // call_n NULL, // unary_op NULL, // binary_op NULL, // getiter |