X-Git-Url: http://nitlanguage.org diff --git a/src/vm.nit b/src/vm.nit index b5e5bb8..3807ab7 100644 --- a/src/vm.nit +++ b/src/vm.nit @@ -17,7 +17,7 @@ # Implementation of the Nit virtual machine module vm -intrude import interpreter::naive_interpreter +import interpreter::naive_interpreter import model_utils import perfect_hashing @@ -28,7 +28,7 @@ redef class ModelBuilder self.toolcontext.info("*** NITVM STARTING ***", 1) var interpreter = new VirtualMachine(self, mainmodule, arguments) - init_naive_interpreter(interpreter, mainmodule) + interpreter.start(mainmodule) var time1 = get_time self.toolcontext.info("*** NITVM STOPPING : {time1-time0} ***", 2) @@ -44,6 +44,16 @@ class VirtualMachine super NaiveInterpreter # Handles memory and garbage collection var memory_manager: MemoryManager = new MemoryManager + # The unique instance of the `MInit` value + var initialization_value: Instance + + init(modelbuilder: ModelBuilder, mainmodule: MModule, arguments: Array[String]) + do + super + var init_type = new MInitType(mainmodule.model) + initialization_value = new MutableInstance(init_type) + end + # Subtyping test for the virtual machine redef fun is_subtype(sub, sup: MType): Bool do @@ -96,7 +106,6 @@ class VirtualMachine super NaiveInterpreter # Sub can be discovered inside a Generic type during the subtyping test if not sub.mclass.loaded then create_class(sub.mclass) - if anchor == null then anchor = sub if sup isa MGenericType then var sub2 = sub.supertype_to(mainmodule, anchor, sup.mclass) assert sub2.mclass == sup.mclass @@ -138,21 +147,22 @@ class VirtualMachine super NaiveInterpreter assert(recv isa MutableInstance) - recv.internal_attributes = init_internal_attributes(null_instance, recv.mtype.as(MClassType).mclass.all_mattributes(mainmodule, none_visibility).length) + recv.internal_attributes = init_internal_attributes(initialization_value, recv.mtype.as(MClassType).mclass.all_mattributes(mainmodule, none_visibility).length) super end # Initialize the internal representation of an object (its attribute values) - private fun init_internal_attributes(null_instance: Instance, size: Int): Pointer + # `init_instance` is the initial value of attributes + private fun init_internal_attributes(init_instance: Instance, size: Int): Pointer import Array[Instance].length, Array[Instance].[] `{ Instance* attributes = malloc(sizeof(Instance) * size); int i; for(i=0; i