forked from rubinius/rubinius
/
variable_scope.cpp
81 lines (64 loc) · 2.22 KB
/
variable_scope.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "vm.hpp"
#include "objectmemory.hpp"
#include "call_frame.hpp"
#include "gc/gc.hpp"
#include "builtin/object.hpp"
#include "builtin/variable_scope.hpp"
#include "builtin/class.hpp"
#include "builtin/system.hpp"
#include "builtin/tuple.hpp"
namespace rubinius {
void VariableScope::init(STATE) {
GO(variable_scope).set(state->new_class("VariableScope", G(object), G(rubinius)));
G(variable_scope)->set_object_type(state, VariableScopeType);
G(variable_scope)->name(state, state->symbol("Rubinius::VariableScope"));
}
void VariableScope::bootstrap_methods(STATE) {
System::attach_primitive(state,
G(variable_scope), false,
state->symbol("method_visibility"),
state->symbol("variable_scope_method_visibility"));
}
VariableScope* VariableScope::of_sender(STATE, CallFrame* call_frame) {
CallFrame* dest = static_cast<CallFrame*>(call_frame->previous);
return dest->promote_scope(state);
}
VariableScope* VariableScope::current(STATE, CallFrame* call_frame) {
return call_frame->promote_scope(state);
}
Tuple* VariableScope::locals(STATE) {
Tuple* tup = Tuple::create(state, number_of_locals_);
for(int i = 0; i < number_of_locals_; i++) {
tup->put(state, i, get_local(state, i));
}
return tup;
}
// bootstrap method, replaced with an attr_accessor in kernel.
Object* VariableScope::method_visibility(STATE) {
return Qnil;
}
void VariableScope::Info::mark(Object* obj, ObjectMark& mark) {
auto_mark(obj, mark);
VariableScope* vs = as<VariableScope>(obj);
vs->fixup();
if(!vs->isolated()) {
Object** ary = vs->stack_locals();
size_t locals = vs->number_of_locals();
for(size_t i = 0; i < locals; i++) {
Object* tmp = mark.call(ary[i]);
if(tmp) { ary[i] = tmp; }
}
}
}
void VariableScope::Info::visit(Object* obj, ObjectVisitor& visit) {
auto_visit(obj, visit);
VariableScope* vs = as<VariableScope>(obj);
if(!vs->isolated()) {
Object** ary = vs->stack_locals();
size_t locals = vs->number_of_locals();
for(size_t i = 0; i < locals; i++) {
visit.call(ary[i]);
}
}
}
}