public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
rubinius / vm / builtin_symbol.hpp
100644 63 lines (48 sloc) 1.409 kb
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
#ifndef RBX_BUILTIN_SYMBOL_HPP
#define RBX_BUILTIN_SYMBOL_HPP
 
namespace rubinius {
 
  class String;
  class Hash;
  class Tuple;
 
  class Symbol : public BuiltinType {
  public:
    const static size_t fields = 0;
    const static object_type type = SymbolType;
 
    native_int index() {
      return DATA_STRIP_TAG(this);
    }
 
    static Symbol* from_index(STATE, size_t index) {
      return (Symbol*)DATA_APPLY_TAG(index, DATA_TAG_SYMBOL);
    }
 
    String* to_str(STATE);
 
    class Info : public TypeInfo {
    public:
      Info(object_type type) : TypeInfo(type) { }
    };
  };
 
  /* See t1 */
  template <>
    static bool kind_of<Symbol>(OBJECT obj) {
      return obj->symbol_p();
    }
 
  typedef Symbol* SYMBOL;
 
  class SymbolTable : public BuiltinType {
  public:
    const static size_t fields = 3;
    const static object_type type = SymbolTableType;
 
    OBJECT __ivars__; // slot
    Tuple* symbols; // slot
    Hash* strings; // slot
 
    static SymbolTable* create(STATE);
    SYMBOL lookup(STATE, const char* str, size_t size = 0);
    SYMBOL lookup(STATE, String* str);
    String* find_string(STATE, Symbol* sym);
 
    class Info : public TypeInfo {
    public:
      Info(object_type type) : TypeInfo(type) { }
      virtual void set_field(STATE, OBJECT target, size_t index, OBJECT val);
      virtual OBJECT get_field(STATE, OBJECT target, size_t index);
    };
  };
}
 
#endif