blob: 310478734f158a4028153e3161ac930316cd77bc [file] [log] [blame]
Damiend99b0522013-12-21 18:17:45 +00001#include <stdlib.h>
2#include <stdint.h>
3
4#include "nlr.h"
5#include "misc.h"
6#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +00007#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +00008#include "obj.h"
Damien George4e8dc8c2014-01-27 23:15:32 +00009#include "runtime0.h"
Damiend99b0522013-12-21 18:17:45 +000010
11typedef struct _mp_obj_none_t {
12 mp_obj_base_t base;
13} mp_obj_none_t;
14
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020015STATIC void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
Damiend99b0522013-12-21 18:17:45 +000016 print(env, "None");
17}
18
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020019STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
Damien George4e8dc8c2014-01-27 23:15:32 +000020 switch (op) {
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +020021 case RT_UNARY_OP_BOOL: return mp_const_false;
Damien George4e8dc8c2014-01-27 23:15:32 +000022 default: return MP_OBJ_NULL; // op not supported for None
23 }
24}
25
Damiend99b0522013-12-21 18:17:45 +000026const mp_obj_type_t none_type = {
27 { &mp_const_type },
28 "NoneType",
Paul Sokolovsky860ffb02014-01-05 22:34:09 +020029 .print = none_print,
Damien George4e8dc8c2014-01-27 23:15:32 +000030 .unary_op = none_unary_op,
Damiend99b0522013-12-21 18:17:45 +000031};
32
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020033STATIC const mp_obj_none_t none_obj = {{&none_type}};
Damiend99b0522013-12-21 18:17:45 +000034const mp_obj_t mp_const_none = (mp_obj_t)&none_obj;
35
36// the stop-iteration object just needs to be something unique
37// it's not the StopIteration exception
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020038STATIC const mp_obj_none_t stop_it_obj = {{&none_type}};
Damiend99b0522013-12-21 18:17:45 +000039const mp_obj_t mp_const_stop_iteration = (mp_obj_t)&stop_it_obj;