Replace the value of an attribute in an instance

  • 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
  • value is the new value for this attribute

Property definitions

nitc $ VirtualMachine :: write_attribute_ph
	# Replace the value of an attribute in an instance
	# * `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
	# * `value` is the new value for this attribute
	fun write_attribute_ph(instance: Pointer, vtable: Pointer, mask: Int, id: Int, offset: Int, value: 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 *)instance)[absolute_offset + offset] = value;
		Instance_incr_ref(value);
	`}
src/vm/virtual_machine.nit:363,2--380,3