-
Notifications
You must be signed in to change notification settings - Fork 608
/
symbol.cpp
94 lines (75 loc) · 2.37 KB
/
symbol.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
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "builtin/array.hpp"
#include "builtin/class.hpp"
#include "builtin/encoding.hpp"
#include "builtin/exception.hpp"
#include "builtin/fixnum.hpp"
#include "builtin/string.hpp"
#include "builtin/symbol.hpp"
#include "builtin/tuple.hpp"
#include "object_utils.hpp"
#include "objectmemory.hpp"
#include "ontology.hpp"
#include <sstream>
#define StartSize 16
#define Increments 32
namespace rubinius {
void Symbol::init(STATE) {
GO(symbol).set(ontology::new_class(state, "Symbol"));
G(symbol)->set_object_type(state, Symbol::type);
}
native_int Symbol::index() const {
return STRIP_SYMBOL_TAG(this);
}
Integer* Symbol::index(STATE) {
return Fixnum::from(this->index());
}
Symbol* Symbol::from_index(STATE, size_t index) {
return (Symbol*)APPLY_SYMBOL_TAG(index);
}
String* Symbol::to_str(STATE) {
String* str = state->shared().symbols.lookup_string(state, this);
if(!str) {
std::ostringstream msg;
msg << "Invalid symbol 0x" << std::hex << reinterpret_cast<uintptr_t>(this);
Exception::range_error(state, msg.str().c_str());
}
return str;
}
std::string& Symbol::cpp_str(STATE) {
return state->shared().symbols.lookup_cppstring(this);
}
std::string Symbol::debug_str(SharedState& shared) {
return shared.symbols.lookup_debug_string(this);
}
std::string Symbol::debug_str(STATE) {
return debug_str(state->shared());
}
Array* Symbol::all_symbols(STATE) {
return state->shared().symbols.all_as_array(state);
}
Object* Symbol::is_ivar_p(STATE) {
return RBOOL(state->shared().symbols.kind(state, this) == SymbolTable::IVar);
}
Object* Symbol::is_cvar_p(STATE) {
return RBOOL(state->shared().symbols.kind(state, this) == SymbolTable::CVar);
}
Object* Symbol::is_constant_p(STATE) {
return RBOOL(state->shared().symbols.kind(state, this) == SymbolTable::Constant);
}
Encoding* Symbol::encoding(STATE) {
// TODO
return Encoding::usascii_encoding(state);
}
Encoding* Symbol::encoding(STATE, Encoding* enc) {
// TODO
return enc;
}
void Symbol::Info::show(STATE, Object* self, int level) {
Symbol* sym = try_as<Symbol>(self);
std::cout << ":" << sym->debug_str(state) << std::endl;
}
void Symbol::Info::show_simple(STATE, Object* self, int level) {
show(state, self, level);
}
void Symbol::Info::mark(Object* t, ObjectMark& mark) { }
}