2013-12-21 13:17:45 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "nlr.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mpconfig.h"
|
2014-01-21 16:40:13 -05:00
|
|
|
#include "qstr.h"
|
2013-12-21 13:17:45 -05:00
|
|
|
#include "obj.h"
|
2014-01-27 18:15:32 -05:00
|
|
|
#include "runtime0.h"
|
2013-12-21 13:17:45 -05:00
|
|
|
|
|
|
|
typedef struct _mp_obj_none_t {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
} mp_obj_none_t;
|
|
|
|
|
2014-02-12 11:15:40 -05:00
|
|
|
STATIC void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
|
2013-12-21 13:17:45 -05:00
|
|
|
print(env, "None");
|
|
|
|
}
|
|
|
|
|
2014-02-12 11:15:40 -05:00
|
|
|
STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
|
2014-01-27 18:15:32 -05:00
|
|
|
switch (op) {
|
2014-01-29 21:37:19 -05:00
|
|
|
case RT_UNARY_OP_BOOL: return mp_const_false;
|
2014-01-27 18:15:32 -05:00
|
|
|
default: return MP_OBJ_NULL; // op not supported for None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 13:17:45 -05:00
|
|
|
const mp_obj_type_t none_type = {
|
|
|
|
{ &mp_const_type },
|
2014-02-15 06:34:50 -05:00
|
|
|
.name = MP_QSTR_NoneType,
|
2014-01-05 15:34:09 -05:00
|
|
|
.print = none_print,
|
2014-01-27 18:15:32 -05:00
|
|
|
.unary_op = none_unary_op,
|
2013-12-21 13:17:45 -05:00
|
|
|
};
|
|
|
|
|
2014-02-12 11:15:40 -05:00
|
|
|
STATIC const mp_obj_none_t none_obj = {{&none_type}};
|
2013-12-21 13:17:45 -05:00
|
|
|
const mp_obj_t mp_const_none = (mp_obj_t)&none_obj;
|
|
|
|
|
|
|
|
// the stop-iteration object just needs to be something unique
|
|
|
|
// it's not the StopIteration exception
|
2014-02-12 11:15:40 -05:00
|
|
|
STATIC const mp_obj_none_t stop_it_obj = {{&none_type}};
|
2013-12-21 13:17:45 -05:00
|
|
|
const mp_obj_t mp_const_stop_iteration = (mp_obj_t)&stop_it_obj;
|