File tree 5 files changed +23
-1
lines changed
5 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ class Crystal::CodeGenVisitor
47
47
codegen_primitive_object_id node, target_def, call_args
48
48
when " object_crystal_type_id"
49
49
codegen_primitive_object_crystal_type_id node, target_def, call_args
50
+ when " class_crystal_instance_type_id"
51
+ codegen_primitive_class_crystal_instance_type_id node, target_def, call_args
50
52
when " symbol_to_s"
51
53
codegen_primitive_symbol_to_s node, target_def, call_args
52
54
when " class"
@@ -566,6 +568,10 @@ class Crystal::CodeGenVisitor
566
568
end
567
569
end
568
570
571
+ def codegen_primitive_class_crystal_instance_type_id (node, target_def, call_args)
572
+ type_id(context.type.instance_type)
573
+ end
574
+
569
575
def codegen_primitive_symbol_to_s (node, target_def, call_args)
570
576
load(gep @llvm_mod .globals[SYMBOL_TABLE_NAME ], int(0 ), call_args[0 ])
571
577
end
Original file line number Diff line number Diff line change @@ -2175,6 +2175,8 @@ module Crystal
2175
2175
node.type = program.uint64
2176
2176
when " object_crystal_type_id"
2177
2177
node.type = program.int32
2178
+ when " class_crystal_instance_type_id"
2179
+ node.type = program.int32
2178
2180
when " symbol_to_s"
2179
2181
node.type = program.string
2180
2182
when " class"
Original file line number Diff line number Diff line change @@ -1144,4 +1144,9 @@ class Object
1144
1144
\{% end % }
1145
1145
end
1146
1146
end
1147
+
1148
+ protected def self.set_crystal_type_id (ptr )
1149
+ ptr.as(LibC ::SizeT * ).value = LibC ::SizeT .new(crystal_instance_type_id)
1150
+ ptr
1151
+ end
1147
1152
end
Original file line number Diff line number Diff line change @@ -51,6 +51,12 @@ class Reference
51
51
end
52
52
end
53
53
54
+ class Class
55
+ @[Primitive (:class_crystal_instance_type_id )]
56
+ def crystal_instance_type_id
57
+ end
58
+ end
59
+
54
60
struct Bool
55
61
# Returns true if *self* is equal to *other*.
56
62
@[Primitive (:binary )]
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ class WeakRef(T)
9
9
end
10
10
11
11
def self.allocate
12
- GC .malloc_atomic(sizeof(self )).as(self )
12
+ ptr = GC .malloc_atomic(sizeof(self )).as(self )
13
+ # TODO: uncomment after 0.20.1
14
+ # set_crystal_type_id(ptr)
15
+ ptr
13
16
end
14
17
15
18
# Returns the referenced object or `Nil` if it has been garbage-collected.
You can’t perform that action at this time.
1 commit comments
asterite commentedon Dec 14, 2016
@BlaXpirit I finally decided to do it like this, so when overriding allocate you'll have to call
set_crystal_type_id(allocate_memory_here)
. It's just a bit more of work, but overriding allocate shouldn't be that frequently needed.