forked from rubinius/rubinius
/
staticscope.cpp
75 lines (58 loc) · 2.17 KB
/
staticscope.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
#include "vm.hpp"
#include "prelude.hpp"
#include "builtin/class.hpp"
#include "builtin/staticscope.hpp"
#include "builtin/system.hpp"
#include "builtin/symbol.hpp"
#include "builtin/lookuptable.hpp"
#include "builtin/compactlookuptable.hpp"
#include "call_frame.hpp"
#include <sstream>
namespace rubinius {
void StaticScope::init(STATE) {
GO(staticscope).set(state->new_class("StaticScope", G(object), G(rubinius)));
G(staticscope)->set_object_type(state, StaticScopeType);
G(staticscope)->name(state, state->symbol("Rubinius::StaticScope"));
}
void StaticScope::bootstrap_methods(STATE) {
System::attach_primitive(state,
G(staticscope), false,
state->symbol("const_set"),
state->symbol("static_scope_const_set"));
}
StaticScope* StaticScope::create(STATE) {
return state->new_object<StaticScope>(G(staticscope));
}
Module* StaticScope::for_method_definition() {
if(current_module_->nil_p()) {
return module_;
}
return current_module_;
}
StaticScope* StaticScope::of_sender(STATE, CallFrame* calling_environment) {
if(calling_environment->previous) {
return calling_environment->previous->static_scope();
}
return nil<StaticScope>();
}
Object* StaticScope::const_set(STATE, Object* name, Object* value) {
module_->set_const(state, name, value);
return value;
}
Object* StaticScope::cvar_get(STATE, Symbol* name) {
if(!name->is_cvar_p(state)->true_p()) return Primitives::failure();
return module_->cvar_get(state, name);
}
Object* StaticScope::cvar_defined(STATE, Symbol* name) {
if(!name->is_cvar_p(state)->true_p()) return Primitives::failure();
return module_->cvar_defined(state, name);
}
Object* StaticScope::cvar_set(STATE, Symbol* name, Object* value) {
if(!name->is_cvar_p(state)->true_p()) return Primitives::failure();
return module_->cvar_set(state, name, value);
}
Object* StaticScope::cvar_get_or_set(STATE, Symbol* name, Object* value) {
if(!name->is_cvar_p(state)->true_p()) return Primitives::failure();
return module_->cvar_get_or_set(state, name, value);
}
}