Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <stdint.h> |
| 3 | #include <assert.h> |
| 4 | |
| 5 | #include "nlr.h" |
| 6 | #include "misc.h" |
| 7 | #include "mpconfig.h" |
| 8 | #include "obj.h" |
| 9 | #include "runtime.h" |
| 10 | |
| 11 | typedef struct _mp_obj_cell_t { |
| 12 | mp_obj_base_t base; |
| 13 | mp_obj_t obj; |
| 14 | } mp_obj_cell_t; |
| 15 | |
| 16 | mp_obj_t mp_obj_cell_get(mp_obj_t self_in) { |
| 17 | mp_obj_cell_t *self = self_in; |
| 18 | return self->obj; |
| 19 | } |
| 20 | |
| 21 | void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) { |
| 22 | mp_obj_cell_t *self = self_in; |
| 23 | self->obj = obj; |
| 24 | } |
| 25 | |
| 26 | const mp_obj_type_t cell_type = { |
| 27 | { &mp_const_type }, |
| 28 | "cell", |
| 29 | NULL, // print |
| 30 | NULL, // call_n |
| 31 | NULL, // unary_op |
| 32 | NULL, // binary_op |
| 33 | NULL, // getiter |
| 34 | NULL, // iternext |
| 35 | {{NULL, NULL},}, // method list |
| 36 | }; |
| 37 | |
| 38 | mp_obj_t mp_obj_new_cell(mp_obj_t obj) { |
| 39 | mp_obj_cell_t *o = m_new_obj(mp_obj_cell_t); |
| 40 | o->base.type = &cell_type; |
| 41 | o->obj = obj; |
| 42 | return o; |
| 43 | } |