# Construct virtual tables with a bi-dimensional layout
private fun intern_init_vtable(ids: Array[Int], nb_methods: Array[Int], deltas: Array[Int], mask: Int): Pointer
import Array[Int].length, Array[Int].[] `{
// Allocate and fill current virtual table
int i;
int total_size = 0; // total size of this virtual table
int nb_classes = Array_of_Int_length(nb_methods);
for(i = 0; i<nb_classes; i++) {
/* - One for each method of this class
* - One for the delta (offset of this group of attributes in objects)
* - One for the id
*/
total_size += Array_of_Int__index(nb_methods, i);
total_size += 2;
}
// Add the size of the perfect hashtable (mask +1)
// Add one because we start to fill the vtable at position 1 (0 is the init position)
total_size += mask+2;
long unsigned int* vtable = malloc(sizeof(long unsigned int)*total_size);
// Initialisation to the first position of the virtual table (ie : Object)
long unsigned int *init = vtable + mask + 2;
for(i=0; i<total_size; i++)
vtable[i] = (long unsigned int)init;
// Set the virtual table to its position 0
// ie: after the hashtable
vtable = vtable + mask + 1;
int current_size = 1;
for(i = 0; i < nb_classes; i++) {
/*
vtable[hv] contains a pointer to the group of introduced methods
For each superclasse we have in virtual table :
(id | delta | introduced methods)
*/
int hv = mask & Array_of_Int__index(ids, i);
vtable[current_size] = Array_of_Int__index(ids, i);
vtable[current_size + 1] = Array_of_Int__index(deltas, i);
vtable[-hv] = (long unsigned int)&(vtable[current_size]);
current_size += 2;
current_size += Array_of_Int__index(nb_methods, i);
}
return vtable;
`}
src/vm/virtual_machine.nit:938,2--987,3