Commit 5865b2c0 authored by Stefan Marr's avatar Stefan Marr

Pass class in Object constructor to avoid set afterwards

Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent 038bffe8
...@@ -378,9 +378,7 @@ class Universe(object): ...@@ -378,9 +378,7 @@ class Universe(object):
num_bytecodes, signature) num_bytecodes, signature)
def new_instance(self, instance_class): def new_instance(self, instance_class):
result = Object(self.nilObject, instance_class.get_number_of_instance_fields()) return Object(self.nilObject, instance_class.get_number_of_instance_fields(), instance_class)
result.set_class(instance_class)
return result
@staticmethod @staticmethod
def new_integer(value): def new_integer(value):
......
...@@ -8,10 +8,11 @@ class Object(AbstractObject): ...@@ -8,10 +8,11 @@ class Object(AbstractObject):
# Static field indices and number of object fields # Static field indices and number of object fields
NUMBER_OF_OBJECT_FIELDS = 0 NUMBER_OF_OBJECT_FIELDS = 0
def __init__(self, nilObject, number_of_fields = -1): def __init__(self, nilObject, number_of_fields = -1, obj_class = None):
num_fields = number_of_fields if number_of_fields != -1 else self._get_default_number_of_fields() num_fields = (number_of_fields if number_of_fields != -1
else self._get_default_number_of_fields())
self._fields = [nilObject] * num_fields self._fields = [nilObject] * num_fields
self._class = nilObject self._class = obj_class or nilObject
def get_class(self, universe): def get_class(self, universe):
return self._class return self._class
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment