blob: 165c8e5a43e92a079570bc6644063260493190dc [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Damiend99b0522013-12-21 18:17:45 +000027#include <stdlib.h>
Damiend99b0522013-12-21 18:17:45 +000028
Paul Sokolovskyf54bcbf2014-05-02 17:47:01 +030029#include "mpconfig.h"
Damiend99b0522013-12-21 18:17:45 +000030#include "nlr.h"
31#include "misc.h"
Damien George55baff42014-01-21 21:40:13 +000032#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +000033#include "obj.h"
Damien George4e8dc8c2014-01-27 23:15:32 +000034#include "runtime0.h"
Damiend99b0522013-12-21 18:17:45 +000035
36typedef struct _mp_obj_none_t {
37 mp_obj_base_t base;
38} mp_obj_none_t;
39
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020040STATIC 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 +000041 print(env, "None");
42}
43
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020044STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
Damien George4e8dc8c2014-01-27 23:15:32 +000045 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +010046 case MP_UNARY_OP_BOOL: return mp_const_false;
Damien George6ac5dce2014-05-21 19:42:43 +010047 default: return MP_OBJ_NULL; // op not supported
Damien George4e8dc8c2014-01-27 23:15:32 +000048 }
49}
50
Damien George07ddab52014-03-29 13:15:08 +000051const mp_obj_type_t mp_type_NoneType = {
Damien Georgec5966122014-02-15 16:10:44 +000052 { &mp_type_type },
Damien Georgea71c83a2014-02-15 11:34:50 +000053 .name = MP_QSTR_NoneType,
Paul Sokolovsky860ffb02014-01-05 22:34:09 +020054 .print = none_print,
Damien George4e8dc8c2014-01-27 23:15:32 +000055 .unary_op = none_unary_op,
Damiend99b0522013-12-21 18:17:45 +000056};
57
Damien George07ddab52014-03-29 13:15:08 +000058const mp_obj_none_t mp_const_none_obj = {{&mp_type_NoneType}};