Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objobject.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython 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 
27 #include <stdlib.h>
28 
29 #include "py/objtype.h"
30 #include "py/runtime.h"
31 
32 typedef struct _mp_obj_object_t {
35 
36 STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
37  (void)args;
38  mp_arg_check_num(n_args, n_kw, 0, 0, false);
40  o->base.type = type;
41  return MP_OBJ_FROM_PTR(o);
42 }
43 
44 #if MICROPY_CPYTHON_COMPAT
45 STATIC mp_obj_t object___init__(mp_obj_t self) {
46  (void)self;
47  return mp_const_none;
48 }
49 STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
50 
51 STATIC mp_obj_t object___new__(mp_obj_t cls) {
53  mp_raise_TypeError("__new__ arg must be a user-type");
54  }
56  mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);
57  return res;
58 }
59 STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__);
60 STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj));
61 
62 STATIC const mp_rom_map_elem_t object_locals_dict_table[] = {
63  #if MICROPY_CPYTHON_COMPAT
64  { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&object___init___obj) },
65  #endif
66  #if MICROPY_CPYTHON_COMPAT
67  { MP_ROM_QSTR(MP_QSTR___new__), MP_ROM_PTR(&object___new___obj) },
68  #endif
69 };
70 
71 STATIC MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table);
72 #endif
73 
75  { &mp_type_type },
76  .name = MP_QSTR_object,
77  .make_new = object_make_new,
78  #if MICROPY_CPYTHON_COMPAT
79  .locals_dict = (mp_obj_dict_t*)&object_locals_dict,
80  #endif
81 };
mp_obj_base_t base
Definition: objobject.c:33
#define mp_const_none
Definition: obj.h:614
#define MP_DEFINE_CONST_DICT(dict_name, table_name)
Definition: obj.h:317
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
#define MP_OBJ_SENTINEL
Definition: obj.h:75
#define MP_ROM_QSTR(q)
Definition: obj.h:241
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
Definition: argcheck.c:32
#define MP_ROM_PTR(p)
Definition: obj.h:242
#define STATIC
Definition: mpconfig.h:1178
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name)
Definition: obj.h:285
args
Definition: i18n.py:175
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
qstr name
Definition: obj.h:478
#define MP_DEFINE_CONST_STATICMETHOD_OBJ(obj_name, fun_name)
Definition: obj.h:336
uint64_t mp_obj_t
Definition: obj.h:39
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objtype.c:247
STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objobject.c:36
#define mp_obj_is_instance_type(type)
Definition: objtype.h:47
NORETURN void mp_raise_TypeError(const char *msg)
Definition: runtime.c:1460
const mp_obj_type_t mp_type_object
Definition: objobject.c:74
#define m_new_obj(type)
Definition: misc.h:60
struct _mp_obj_object_t mp_obj_object_t