summaryrefslogtreecommitdiffstatshomepage
path: root/py/objtype.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-08 18:48:12 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-08 18:48:12 +0000
commit93a9b5b64d8c26ed1df739a59e6eabcfe1c64aa7 (patch)
treea7cc10ff0f3d5b97caae733784cf41c7ec276521 /py/objtype.c
parent6c73ca1e754aa5fb822999a0b46f01e216619ec6 (diff)
downloadmicropython-93a9b5b64d8c26ed1df739a59e6eabcfe1c64aa7.tar.gz
micropython-93a9b5b64d8c26ed1df739a59e6eabcfe1c64aa7.zip
py: Proper framework for built-in 'type'.
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 8778c180ca..4a6025a70b 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -12,6 +12,32 @@ static void type_print(void (*print)(void *env, const char *fmt, ...), void *env
print(env, "<class '%s'>", self->name);
}
+// args are reverse in the array
+static mp_obj_t type_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) {
+ switch (n_args) {
+ case 1:
+ return mp_obj_get_type(args[0]);
+
+ case 3:
+ {
+ // args[2] = name
+ // args[1] = bases tuple
+ // args[0] = locals dict
+
+ mp_obj_type_t *new_type = m_new0(mp_obj_type_t, 1);
+ new_type->base.type = &mp_const_type;
+ new_type->name = qstr_str(mp_obj_get_qstr(args[2]));
+ return new_type;
+
+ //mp_obj_t new_class = mp_obj_new_class(mp_obj_get_qstr(args[2]), args[0]);
+ //return new_class;
+ }
+
+ default:
+ nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "type takes at 1 or 3 arguments"));
+ }
+}
+
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) {
@@ -26,5 +52,6 @@ const mp_obj_type_t mp_const_type = {
{ &mp_const_type },
"type",
.print = type_print,
+ .make_new = type_make_new,
.call_n = type_call_n,
};