Convert Python types to proper Python type hierarchy.

Now much more inline with how CPython does types.
This commit is contained in:
Damien George
2014-01-04 20:21:15 +00:00
parent e9906ac3d7
commit 71c5181a8d
36 changed files with 285 additions and 173 deletions

View File

@@ -5,7 +5,9 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "mpqstr.h"
#include "obj.h"
#include "runtime.h"
#include "map.h"
typedef struct _mp_obj_set_t {
@@ -29,10 +31,34 @@ void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
print(env, "}");
}
static const mp_obj_type_t set_type = {
static mp_obj_t set_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) {
switch (n_args) {
case 0:
// return a new, empty set
return mp_obj_new_set(0, NULL);
case 1:
{
// 1 argument, an iterable from which we make a new set
mp_obj_t set = mp_obj_new_set(0, NULL);
mp_obj_t iterable = rt_getiter(args[0]);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
mp_obj_set_store(set, item);
}
return set;
}
default:
nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "set takes at most 1 argument, %d given", (void*)(machine_int_t)n_args));
}
}
const mp_obj_type_t set_type = {
{ &mp_const_type },
"set",
set_print, // print
set_make_new, // make_new
NULL, // call_n
NULL, // unary_op
NULL, // binary_op