Execute a method dispatch with perfect hashing and return the appropriate MMethodDef

  • vtable Pointer to the internal virtual table of the class
  • mask Perfect hashing mask of the receiver class
  • id Identifier of the class which introduce the method
  • offset Relative offset of the method from the beginning of the block

Property definitions

nitc $ VirtualMachine :: method_dispatch_ph
	# Execute a method dispatch with perfect hashing and return the appropriate `MMethodDef`
	# * `vtable` Pointer to the internal virtual table of the class
	# * `mask` Perfect hashing mask of the receiver class
	# * `id` Identifier of the class which introduce the method
	# * `offset` Relative offset of the method from the beginning of the block
	fun method_dispatch_ph(vtable: Pointer, mask: Int, id: Int, offset: Int): MMethodDef `{
		// Perfect hashing position
		int hv = mask & id;
		long unsigned int *pointer = (long unsigned int*)(((long int *)vtable)[-hv]);

		// pointer+2 is the position where methods are
		// Add the offset of property and get the method implementation
		MMethodDef propdef = (MMethodDef)*(pointer + 2 + offset);

		return propdef;
	`}
src/vm/virtual_machine.nit:258,2--273,3