blob: addab14b7579b37fae729ca12929a2d83a92cd01 [file] [log] [blame]
Damien George28708622014-01-02 21:30:26 +00001#include <stdlib.h>
2#include <stdint.h>
3#include <string.h>
4#include <assert.h>
5
6#include "nlr.h"
7#include "misc.h"
8#include "mpconfig.h"
9#include "obj.h"
10#include "runtime.h"
11#include "map.h"
12
13typedef struct _mp_obj_module_t {
14 mp_obj_base_t base;
15 qstr name;
16 mp_map_t *globals;
17} mp_obj_module_t;
18
19void module_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
20 mp_obj_module_t *self = self_in;
21 print(env, "<module '%s' from '-unknown-file-'>", qstr_str(self->name));
22}
23
24const mp_obj_type_t module_type = {
25 { &mp_const_type },
26 "module",
27 module_print, // print
28 NULL, // call_n
29 NULL, // unary_op
30 NULL, // binary_op
31 NULL, // getiter
32 NULL, // iternext
33 {{NULL, NULL},}, // method list
34};
35
36mp_obj_t mp_obj_new_module(qstr module_name) {
37 mp_obj_module_t *o = m_new_obj(mp_obj_module_t);
38 o->base.type = &module_type;
39 o->name = module_name;
40 o->globals = mp_map_new(MP_MAP_QSTR, 0);
41 return o;
42}
43
44mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in) {
45 assert(MP_OBJ_IS_TYPE(self_in, &module_type));
46 mp_obj_module_t *self = self_in;
47 return self->globals;
48}