blob: 35b44e996d8559cae723c189c3c5f96291edd212 [file] [log] [blame]
Paul Sokolovskyf54bcbf2014-05-02 17:47:01 +03001#include "mpconfig.h"
Damiend99b0522013-12-21 18:17:45 +00002#include "nlr.h"
3#include "misc.h"
Damien George55baff42014-01-21 21:40:13 +00004#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +00005#include "obj.h"
6#include "runtime.h"
7
8typedef struct _mp_obj_cell_t {
9 mp_obj_base_t base;
10 mp_obj_t obj;
11} mp_obj_cell_t;
12
13mp_obj_t mp_obj_cell_get(mp_obj_t self_in) {
14 mp_obj_cell_t *self = self_in;
15 return self->obj;
16}
17
18void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
19 mp_obj_cell_t *self = self_in;
20 self->obj = obj;
21}
22
Paul Sokolovsky418aca92014-05-03 14:10:34 +030023#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
Paul Sokolovsky2758b7d2014-04-20 13:02:00 +030024STATIC void cell_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
25 mp_obj_cell_t *o = o_in;
Paul Sokolovsky418aca92014-05-03 14:10:34 +030026 print(env, "<cell %p ", o->obj);
Paul Sokolovsky2758b7d2014-04-20 13:02:00 +030027 if (o->obj == MP_OBJ_NULL) {
28 print(env, "(nil)");
29 } else {
Paul Sokolovsky2758b7d2014-04-20 13:02:00 +030030 mp_obj_print_helper(print, env, o->obj, PRINT_REPR);
31 }
32 print(env, ">");
33}
34#endif
35
Damiend99b0522013-12-21 18:17:45 +000036const mp_obj_type_t cell_type = {
Damien Georgec5966122014-02-15 16:10:44 +000037 { &mp_type_type },
Paul Sokolovsky418aca92014-05-03 14:10:34 +030038 .name = MP_QSTR_, // cell representation is just value in < >
39#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
40 .print = cell_print,
41#endif
Damiend99b0522013-12-21 18:17:45 +000042};
43
44mp_obj_t mp_obj_new_cell(mp_obj_t obj) {
45 mp_obj_cell_t *o = m_new_obj(mp_obj_cell_t);
46 o->base.type = &cell_type;
47 o->obj = obj;
48 return o;
49}