/
builtin_class.cpp
51 lines (40 loc) · 1.36 KB
/
builtin_class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "vm.hpp"
#include "builtin_class.hpp"
#include "objectmemory.hpp"
namespace rubinius {
void Module::setup(STATE) {
SET(this, constants, LookupTable::create(state));
SET(this, method_table, MethodTable::create(state));
}
void Module::setup(STATE, char* str, Module* under) {
if(!under) under = state->globals.object;
SET(this, constants, LookupTable::create(state));
SET(this, method_table, MethodTable::create(state));
SET(this, name, state->symbol(str));
under->set_const(state, name, this);
}
void Module::set_const(STATE, OBJECT sym, OBJECT val) {
constants->store(state, sym, val);
}
void Module::set_const(STATE, char* name, OBJECT val) {
constants->store(state, state->symbol(name), val);
}
OBJECT Module::get_const(STATE, OBJECT sym) {
return constants->fetch(state, sym);
}
OBJECT Module::get_const(STATE, char* sym) {
return get_const(state, state->symbol(sym));
}
OBJECT MetaClass::attach(STATE, OBJECT obj, OBJECT sup) {
MetaClass *meta;
meta = (MetaClass*)state->om->new_object(state->globals.metaclass,
MetaClass::fields);
if(!sup) { sup = obj->klass; }
meta->IsMeta = TRUE;
SET(meta, attached_instance, obj);
meta->setup(state);
SET(meta, superclass, sup);
state->om->set_class(obj, meta);
return meta;
}
}