1 #include "shotgun/lib/shotgun.h"
2 #include "shotgun/lib/hash.h"
3 #include "shotgun/lib/lookuptable.h"
4 #include "shotgun/lib/methtbl.h"
5 #include "shotgun/lib/string.h"
6 #include "shotgun/lib/module.h"
8 void module_setup_fields(STATE
, OBJECT module
) {
9 if(NIL_P(module_get_constants(module
))) {
10 module_set_constants(module
, lookuptable_new(state
));
12 if(NIL_P(module_get_method_table(module
))) {
13 module_set_method_table(module
, methtbl_new(state
));
17 void module_setup_name(STATE
, OBJECT module
, const char *name
, OBJECT ns
) {
20 str
= string_new(state
, name
);
21 sym
= string_to_sym(state
, str
);
22 module_set_name(module
, sym
);
23 module_const_set(state
, ns
, sym
, module
);
24 sassert(NIL_P(module_get_encloser(module
)));
25 module_set_encloser(module
, ns
);
29 void module_setup_with_namespace(STATE
, OBJECT module
, const char *name
, OBJECT ns
) {
30 module_setup_fields(state
, module
);
31 module_setup_name(state
, module
, name
, ns
);
32 module_setup_fields(state
, object_metaclass(state
, module
));
35 void module_setup(STATE
, OBJECT module
, const char *name
) {
36 module_setup_with_namespace(state
, module
, name
, BASIC_CLASS(object
));
39 void module_const_set(STATE
, OBJECT self
, OBJECT sym
, OBJECT obj
) {
42 tbl
= module_get_constants(self
);
43 lookuptable_store(state
, tbl
, sym
, obj
);
46 OBJECT
module_const_get(STATE
, OBJECT self
, OBJECT sym
) {
48 tbl
= module_get_constants(self
);
49 obj
= lookuptable_fetch(state
, tbl
, sym
);