# Allocates a VTable for this class and gives it an id
# * `vm` The currently executed VirtualMachine
# * `explicit` Indicate if this class was directly instantiated (i.e. not indirectly loaded)
private fun make_vt(vm: VirtualMachine, explicit: Bool)
do
# `ordering` contains the order of superclasses for virtual tables
ordering = superclasses_ordering(vm)
ordering.remove(self)
var ids = new Array[Int]
var nb_methods = new Array[Int]
var nb_attributes = new Array[Int]
# Absolute offset of attribute from the beginning of the attributes table
var offset_attributes = 0
# Absolute offset of method from the beginning of the methods table,
# is initialize to 3 because the first position is empty in the virtual table
# and the second and third are respectively class id and delta
var offset_methods = 3
var parent
var prefix_index = ordering.index_of(prefix.as(not null))
for i in [0..ordering.length[ do
parent = ordering[i]
# Get the number of introduced methods and attributes for this class
var methods = parent.intro_mmethods.length
var attributes = parent.intro_mattributes.length
# Updates `mmethods` and `mattributes`
mmethods.add_all(parent.intro_mmethods)
mattributes.add_all(parent.intro_mattributes)
ids.push(parent.vtable.)
nb_methods.push(methods)
nb_attributes.push(attributes)
# If the class is in the suffix part of the order
if i > prefix_index then
moved_class_attributes(vm, ordering[i], offset_attributes)
moved_class_methods(vm, ordering[i], offset_methods)
end
offset_attributes += attributes
offset_methods += methods
offset_methods += 2 # Because each block starts with an id and the delta
end
# Update the positions of the class
update_positions(offset_attributes, offset_methods)
ordering.add(self)
# Compute the identifier with Perfect Hashing
compute_identifier(vm, ids, offset_methods)
# Update caches and offsets of methods and attributes for this class
# If the loading was explicit, the virtual table will be allocated and filled
set_offsets(vm, explicit)
if not explicit then
# Just init the C-pointer to NULL to avoid errors
vtable. = vm.memory_manager.null_ptr
end
end
src/vm/virtual_machine.nit:456,2--521,4