public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
rubinius / vm / builtin_class.hpp
100644 100 lines (77 sloc) 2.347 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
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
95
96
97
98
99
100
#ifndef RBX_BUILTIN_CLASS_HPP
#define RBX_BUILTIN_CLASS_HPP
 
#include "objects.hpp"
 
namespace rubinius {
  class Module : public BuiltinType {
    public:
    const static size_t fields = 5;
    const static object_type type = ModuleType;
 
    OBJECT __ivars__; // slot
    LookupTable* method_table; // slot
    SYMBOL name; // slot
    LookupTable* constants; // slot
    Module* superclass; // slot
 
    static Module* create(STATE);
    void setup(STATE);
    void setup(STATE, char* name, Module* under = NULL);
    void setup(STATE, SYMBOL name, Module* under = NULL);
    void set_const(STATE, OBJECT sym, OBJECT val);
    void set_const(STATE, char* name, OBJECT val);
    OBJECT get_const(STATE, SYMBOL sym);
    OBJECT get_const(STATE, SYMBOL sym, bool* found);
    OBJECT get_const(STATE, char* sym);
 
    void set_name(STATE, Module* under, SYMBOL name);
 
    class Info : public TypeInfo {
    public:
      BASIC_TYPEINFO(TypeInfo)
    };
  };
 
  class Class : public Module {
    public:
    const static size_t fields = 9;
    const static object_type type = ClassType;
 
    FIXNUM instance_fields; // slot
    OBJECT has_ivars; // slot
    OBJECT needs_cleanup; // slot
    FIXNUM instance_type; // slot
 
    void set_object_type(size_t type) {
      instance_type = Object::i2n(type);
    }
 
    static Class* create(STATE, Class* super);
 
    class Info : public TypeInfo {
    public:
      BASIC_TYPEINFO(TypeInfo)
    };
  };
 
  class MetaClass : public Class {
    public:
    const static size_t fields = 10;
    const static object_type type = MetaclassType;
 
    OBJECT attached_instance; // slot
 
    static MetaClass* attach(STATE, OBJECT obj, OBJECT sup = NULL);
 
    class Info : public TypeInfo {
    public:
      BASIC_TYPEINFO(TypeInfo)
    };
  };
 
  class IncludedModule : public Module {
    public:
    const static size_t field = 6;
    const static object_type type = IncModType;
 
    OBJECT module; // slot
 
    class Info : public TypeInfo {
    public:
      BASIC_TYPEINFO(TypeInfo)
    };
  };
 
  /* See t1 */
  template <>
    static bool kind_of<Module>(OBJECT obj) {
      return obj->reference_p() &&
        (obj->obj_type == Module::type ||
         obj->obj_type == Class::type ||
         obj->obj_type == MetaClass::type ||
         obj->obj_type == IncludedModule::type);
    }
 
 
};
 
#endif