auto_super_init: handle the case of constructors redefinition (instead of infinitivel...
[nit.git] / src / vm.nit
index eed0d47..754b8ec 100644 (file)
@@ -153,6 +153,7 @@ class VirtualMachine super NaiveInterpreter
                for(i=0; i<size; i++)
                        attributes[i] = null_instance;
 
+               Instance_incr_ref(null_instance);
                return attributes;
        `}
 
@@ -199,9 +200,6 @@ class VirtualMachine super NaiveInterpreter
 
                var id = mproperty.intro_mclassdef.mclass.vtable.id
                
-               # TODO : ugly hack
-               recv.attributes[mproperty] = value
-
                # Replace the old value of mproperty in recv
                write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
                                        recv.vtable.mask, id, mproperty.offset, value)
@@ -223,6 +221,7 @@ class VirtualMachine super NaiveInterpreter
                int absolute_offset = *(pointer + 1);
 
                ((Instance *)instance)[absolute_offset + offset] = value;
+               Instance_incr_ref(value);
        `}
 end
 
@@ -358,18 +357,16 @@ end
 # and informations to perform subtyping tests
 class VTable
        # The mask to perform perfect hashing
-       var mask: Int
+       var mask: Int is noinit
 
        # Unique identifier given by perfect hashing
-       var id: Int
+       var id: Int is noinit
 
        # Pointer to the c-allocated area, represents the virtual table
-       var internal_vtable: Pointer
+       var internal_vtable: Pointer is noinit
 
        # The short classname of this class
-       var classname: String
-
-       init do end
+       var classname: String is noinit
 end
 
 redef class Instance
@@ -405,8 +402,9 @@ class MemoryManager
                        total_size += 2;
                }
 
-               // Add the size of the perfect hashtable
-               total_size += mask+1;
+               // 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)
@@ -437,4 +435,4 @@ class MemoryManager
 
                return vtable;
        `}
-end
\ No newline at end of file
+end