Return the attribute value in instance with a sequence of perfect_hashing

  • instance is the attributes array of the receiver
  • vtable is the pointer to the virtual table of the class (of the receiver)
  • mask is the perfect hashing mask of the class
  • id is the identifier of the class
  • offset is the relative offset of this attribute

Property definitions

nitc $ VirtualMachine :: read_attribute_ph
	# Return the attribute value in `instance` with a sequence of perfect_hashing
	# * `instance` is the attributes array of the receiver
	# * `vtable` is the pointer to the virtual table of the class (of the receiver)
	# * `mask` is the perfect hashing mask of the class
	# * `id` is the identifier of the class
	# * `offset` is the relative offset of this attribute
	fun read_attribute_ph(instance: Pointer, vtable: Pointer, mask: Int, id: Int, offset: Int): Instance `{
		// Perfect hashing position
		int hv = mask & id;
		long unsigned int *pointer = (long unsigned int*)(((long int *)vtable)[-hv]);

		// pointer+1 is the position where the delta of the class is
		int absolute_offset = *(pointer + 1);

		Instance res = ((Instance *)instance)[absolute_offset + offset];

		return res;
	`}
src/vm/virtual_machine.nit:313,2--330,3