Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
py/objobject.c@10:33521d742af1, 2016-04-27 (annotated)
- Committer:
- Colin Hogben
- Date:
- Wed Apr 27 22:11:29 2016 +0100
- Revision:
- 10:33521d742af1
- Parent:
- 0:5868e8752d44
Update README and version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pythontech | 0:5868e8752d44 | 1 | /* |
| pythontech | 0:5868e8752d44 | 2 | * This file is part of the Micro Python project, http://micropython.org/ |
| pythontech | 0:5868e8752d44 | 3 | * |
| pythontech | 0:5868e8752d44 | 4 | * The MIT License (MIT) |
| pythontech | 0:5868e8752d44 | 5 | * |
| pythontech | 0:5868e8752d44 | 6 | * Copyright (c) 2013, 2014 Damien P. George |
| pythontech | 0:5868e8752d44 | 7 | * |
| pythontech | 0:5868e8752d44 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| pythontech | 0:5868e8752d44 | 9 | * of this software and associated documentation files (the "Software"), to deal |
| pythontech | 0:5868e8752d44 | 10 | * in the Software without restriction, including without limitation the rights |
| pythontech | 0:5868e8752d44 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| pythontech | 0:5868e8752d44 | 12 | * copies of the Software, and to permit persons to whom the Software is |
| pythontech | 0:5868e8752d44 | 13 | * furnished to do so, subject to the following conditions: |
| pythontech | 0:5868e8752d44 | 14 | * |
| pythontech | 0:5868e8752d44 | 15 | * The above copyright notice and this permission notice shall be included in |
| pythontech | 0:5868e8752d44 | 16 | * all copies or substantial portions of the Software. |
| pythontech | 0:5868e8752d44 | 17 | * |
| pythontech | 0:5868e8752d44 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| pythontech | 0:5868e8752d44 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| pythontech | 0:5868e8752d44 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| pythontech | 0:5868e8752d44 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| pythontech | 0:5868e8752d44 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| pythontech | 0:5868e8752d44 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| pythontech | 0:5868e8752d44 | 24 | * THE SOFTWARE. |
| pythontech | 0:5868e8752d44 | 25 | */ |
| pythontech | 0:5868e8752d44 | 26 | |
| pythontech | 0:5868e8752d44 | 27 | #include <stdlib.h> |
| pythontech | 0:5868e8752d44 | 28 | |
| pythontech | 0:5868e8752d44 | 29 | #include "py/objtype.h" |
| pythontech | 0:5868e8752d44 | 30 | #include "py/runtime.h" |
| pythontech | 0:5868e8752d44 | 31 | |
| pythontech | 0:5868e8752d44 | 32 | typedef struct _mp_obj_object_t { |
| pythontech | 0:5868e8752d44 | 33 | mp_obj_base_t base; |
| pythontech | 0:5868e8752d44 | 34 | } mp_obj_object_t; |
| pythontech | 0:5868e8752d44 | 35 | |
| pythontech | 0:5868e8752d44 | 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) { |
| pythontech | 0:5868e8752d44 | 37 | (void)args; |
| pythontech | 0:5868e8752d44 | 38 | mp_arg_check_num(n_args, n_kw, 0, 0, false); |
| pythontech | 0:5868e8752d44 | 39 | mp_obj_object_t *o = m_new_obj(mp_obj_object_t); |
| pythontech | 0:5868e8752d44 | 40 | o->base.type = type; |
| pythontech | 0:5868e8752d44 | 41 | return MP_OBJ_FROM_PTR(o); |
| pythontech | 0:5868e8752d44 | 42 | } |
| pythontech | 0:5868e8752d44 | 43 | |
| pythontech | 0:5868e8752d44 | 44 | #if MICROPY_CPYTHON_COMPAT |
| pythontech | 0:5868e8752d44 | 45 | STATIC mp_obj_t object___init__(mp_obj_t self) { |
| pythontech | 0:5868e8752d44 | 46 | (void)self; |
| pythontech | 0:5868e8752d44 | 47 | return mp_const_none; |
| pythontech | 0:5868e8752d44 | 48 | } |
| pythontech | 0:5868e8752d44 | 49 | STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); |
| pythontech | 0:5868e8752d44 | 50 | |
| pythontech | 0:5868e8752d44 | 51 | STATIC mp_obj_t object___new__(mp_obj_t cls) { |
| pythontech | 0:5868e8752d44 | 52 | if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) { |
| pythontech | 0:5868e8752d44 | 53 | nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, |
| pythontech | 0:5868e8752d44 | 54 | "__new__ arg must be a user-type")); |
| pythontech | 0:5868e8752d44 | 55 | } |
| pythontech | 0:5868e8752d44 | 56 | mp_obj_t o = MP_OBJ_SENTINEL; |
| pythontech | 0:5868e8752d44 | 57 | mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o); |
| pythontech | 0:5868e8752d44 | 58 | return res; |
| pythontech | 0:5868e8752d44 | 59 | } |
| pythontech | 0:5868e8752d44 | 60 | STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); |
| pythontech | 0:5868e8752d44 | 61 | STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj)); |
| pythontech | 0:5868e8752d44 | 62 | |
| pythontech | 0:5868e8752d44 | 63 | STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { |
| pythontech | 0:5868e8752d44 | 64 | #if MICROPY_CPYTHON_COMPAT |
| pythontech | 0:5868e8752d44 | 65 | { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&object___init___obj) }, |
| pythontech | 0:5868e8752d44 | 66 | #endif |
| pythontech | 0:5868e8752d44 | 67 | #if MICROPY_CPYTHON_COMPAT |
| pythontech | 0:5868e8752d44 | 68 | { MP_ROM_QSTR(MP_QSTR___new__), MP_ROM_PTR(&object___new___obj) }, |
| pythontech | 0:5868e8752d44 | 69 | #endif |
| pythontech | 0:5868e8752d44 | 70 | }; |
| pythontech | 0:5868e8752d44 | 71 | |
| pythontech | 0:5868e8752d44 | 72 | STATIC MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); |
| pythontech | 0:5868e8752d44 | 73 | #endif |
| pythontech | 0:5868e8752d44 | 74 | |
| pythontech | 0:5868e8752d44 | 75 | const mp_obj_type_t mp_type_object = { |
| pythontech | 0:5868e8752d44 | 76 | { &mp_type_type }, |
| pythontech | 0:5868e8752d44 | 77 | .name = MP_QSTR_object, |
| pythontech | 0:5868e8752d44 | 78 | .make_new = object_make_new, |
| pythontech | 0:5868e8752d44 | 79 | #if MICROPY_CPYTHON_COMPAT |
| pythontech | 0:5868e8752d44 | 80 | .locals_dict = (mp_obj_dict_t*)&object_locals_dict, |
| pythontech | 0:5868e8752d44 | 81 | #endif |
| pythontech | 0:5868e8752d44 | 82 | }; |