File tree 9 files changed +115
-10
lines changed
9 files changed +115
-10
lines changed Original file line number Diff line number Diff line change
1
+ #include " alloc.hpp"
2
+
3
+ #include " builtin/trie.hpp"
4
+
5
+ namespace rubinius {
6
+ uintptr_t Trie::fields_offset;
7
+
8
+ void Trie::bootstrap (STATE) {
9
+ Trie* trie = ALLOCA (Trie);
10
+ fields_offset = (uintptr_t )&(trie->field ) - (uintptr_t )trie;
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef RBX_BUILTIN_TRIE_HPP
2
+ #define RBX_BUILTIN_TRIE_HPP
3
+
4
+ #include " memory.hpp"
5
+
6
+ #include " builtin/object.hpp"
7
+
8
+ namespace rubinius {
9
+ class Trie : public DataHeader {
10
+ public:
11
+ const static object_type type = TrieType;
12
+ static uintptr_t fields_offset;
13
+
14
+ attr_field (full_size, native_int);
15
+ attr_field (bitmap, native_int);
16
+
17
+ Object* field[0 ];
18
+
19
+ public:
20
+ native_int num_fields () const {
21
+ return (full_size () - fields_offset) / sizeof (Object*);
22
+ }
23
+
24
+ static void bootstrap (STATE);
25
+
26
+ class Info : public TypeInfo {
27
+ public:
28
+ Info (object_type type)
29
+ : TypeInfo(type)
30
+ {
31
+ allow_user_allocate = false ;
32
+ }
33
+
34
+ virtual void mark (Object* obj, memory::ObjectMark& mark) {}
35
+ virtual void auto_mark (Object* obj, memory::ObjectMark& mark) {}
36
+ virtual void show (STATE, Object* self, int level) {}
37
+ virtual void show_simple (STATE, Object* self, int level) {}
38
+ virtual size_t object_size (const ObjectHeader* object) { return sizeof (Trie); }
39
+ };
40
+ };
41
+ }
42
+ #endif
Original file line number Diff line number Diff line change @@ -808,7 +808,8 @@ def initialize
808
808
"Float" => :Float ,
809
809
"Bignum" => :Bignum ,
810
810
"Hash" => :Hash ,
811
- "Channel" => :Channel
811
+ "Channel" => :Channel ,
812
+ "DataHeader" => :DataHeader ,
812
813
}
813
814
814
815
end
@@ -840,7 +841,9 @@ def parse_stream(f)
840
841
841
842
while l = f . gets
842
843
next unless m = class_pattern . match ( l )
843
- if m [ 2 ] != "Object" and m [ 2 ] != "ObjectHeader"
844
+ if m [ 2 ] == "DataHeader"
845
+ cpp = CPPClass . new ( m [ 1 ] )
846
+ elsif m [ 2 ] != "Object" and m [ 2 ] != "ObjectHeader"
844
847
# We've found a class definition that doesn't extend Object.
845
848
# If we recognize the superclass, make a new CPPClass instance
846
849
# for this class definition.
Original file line number Diff line number Diff line change 48
48
#include " builtin/thread.hpp"
49
49
#include " builtin/time.hpp"
50
50
#include " builtin/stat.hpp"
51
+ #include " builtin/trie.hpp"
51
52
#include " builtin/tuple.hpp"
52
53
#include " builtin/autoload.hpp"
53
54
#include " builtin/proc.hpp"
@@ -266,6 +267,7 @@ namespace rubinius {
266
267
JIT::bootstrap (state);
267
268
CodeDB::bootstrap (state);
268
269
Diagnostics::bootstrap (state);
270
+ Trie::bootstrap (state);
269
271
}
270
272
271
273
// @todo document all the sections of bootstrap_ontology
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ namespace rubinius {
26
26
nw.flags64 );
27
27
}
28
28
29
+ size_t DataHeader::slow_size_in_bytes (VM* vm) const {
30
+ return vm->memory ()->type_info [type_id ()]->object_size (this );
31
+ }
32
+
29
33
bool ObjectHeader::set_inflated_header (STATE, uint32_t ih_index, HeaderWord orig) {
30
34
31
35
if (orig.f .meaning == eAuxWordInflated) return false ;
Original file line number Diff line number Diff line change @@ -280,6 +280,42 @@ Object* const cUndef = reinterpret_cast<Object*>(0x22L);
280
280
private:
281
281
};
282
282
283
+ class DataHeader {
284
+ HeaderWord header;
285
+ void * __body__[0 ];
286
+
287
+ public:
288
+
289
+ ObjectFlags flags () const {
290
+ return header.f ;
291
+ }
292
+
293
+ object_type type_id () const {
294
+ return flags ().obj_type ;
295
+ }
296
+
297
+ /* It's the slow case, should be called only if there's no cached
298
+ * instance size. */
299
+ size_t slow_size_in_bytes (VM* vm) const ;
300
+
301
+ size_t size_in_bytes (VM* vm) const {
302
+ size_t size = TypeInfo::instance_sizes[type_id ()];
303
+ if (size != 0 ) {
304
+ return size;
305
+ } else {
306
+ return slow_size_in_bytes (vm);
307
+ }
308
+ }
309
+
310
+ size_t body_in_bytes (VM* state) const {
311
+ return size_in_bytes (state) - sizeof (DataHeader);
312
+ }
313
+
314
+ void ** pointer_to_body () {
315
+ return __body__;
316
+ }
317
+ };
318
+
283
319
class ObjectHeader {
284
320
private:
285
321
HeaderWord header;
Original file line number Diff line number Diff line change @@ -48,12 +48,6 @@ namespace rubinius {
48
48
auto_mark (obj, mark);
49
49
}
50
50
51
- size_t TypeInfo::object_size (const ObjectHeader* obj) {
52
- abort ();
53
- // Must be implemented, if goes here
54
- return 0 ;
55
- }
56
-
57
51
void TypeInfo::class_info (STATE, const Object* self, bool newline) {
58
52
std::cout << const_cast <Object*>(self)->to_s (state, true )->c_str (state);
59
53
if (newline) std::cout << std::endl;
Original file line number Diff line number Diff line change 1
1
#ifndef RBX_VM_TYPE_INFO_HPP
2
2
#define RBX_VM_TYPE_INFO_HPP
3
3
4
+ #include < stdlib.h>
4
5
#include < map>
5
6
#include < stdexcept>
6
7
#include < vector>
@@ -15,6 +16,7 @@ namespace rubinius {
15
16
class Class ;
16
17
class Object ;
17
18
class Memory ;
19
+ class DataHeader ;
18
20
class ObjectHeader ;
19
21
20
22
namespace memory {
@@ -94,9 +96,18 @@ namespace rubinius {
94
96
virtual void populate_slot_locations () { }
95
97
96
98
/* *
97
- * Slow case, should be called only if instance_size is zero
99
+ * Objects whose size is static generate a entry in the types data
100
+ * structure for that size, which is accessed directly via the data
101
+ * structure instead of via a method call. Objects whose size is defined
102
+ * at runtime must implement this method.
98
103
*/
99
- virtual size_t object_size (const ObjectHeader * obj);
104
+ virtual size_t object_size (const ObjectHeader* obj) {
105
+ ::abort ();
106
+ }
107
+
108
+ virtual size_t object_size (const DataHeader* obj) {
109
+ ::abort ();
110
+ }
100
111
101
112
/* *
102
113
* Currently prints the same output as show_simple. Is specialized by
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ field_extract_headers = %w[
120
120
machine/builtin/jit.hpp
121
121
machine/builtin/code_db.hpp
122
122
machine/builtin/diagnostics.hpp
123
+ machine/builtin/trie.hpp
123
124
]
124
125
125
126
transcoders_src_dir = File . expand_path "../../vendor/oniguruma/enc/trans" , __FILE__
You can’t perform that action at this time.
0 commit comments