Commits

Anonymous committed 91b2b32

Finished refactoring, targetimageloading... is building under rpython. Tests not checked.

Comments (0)

Files changed (9)

spyvm/fieldtypes.py

         raise NotImplementedError("Abstract base class")
     def store(self, w_obj, n0, w_val):
         raise NotImplementedError("Abstract base class")
-    def initial_storage(self, size):
+    def size_of(self, w_obj):
+        raise NotImplementedError("Abstract base class")
+    def initial_storage(self, size, default_element):
         raise NotImplementedError("Abstract base class")
     def storage_for_list(self, collection):
         raise NotImplementedError("Abstract base class")
+    def all_vars(self, w_obj):
+        return [self.fetch(w_obj, i) for i in range(0, self.size_of(w_obj))]
 
 # This is the regular storage strategy that does not result in any
 # optimizations but can handle every case. Applicable for both
         return self.unerase(w_obj.storage)[n0]
     def store(self, w_obj, n0, w_val):
         self.unerase(w_obj.storage)[n0] = w_val
-    def initial_storage(self, size):
-        return self.erase([nil_obj] * size)
+    def size_of(self, w_obj):
+        return len(self.unerase(w_obj.storage))
+    def initial_storage(self, size, default_element):
+        return self.erase([default_element] * size)
     def storage_for_list(self, collection):
         return self.erase([x for x in collection])
 ListStorageStrategy.singleton = ListStorageStrategy()
         self.diff = change
         self.siblings = {}
     
-    def initial_storage(self, size):
-        return self.erase([w_nil] * size)
+    def initial_storage(self, size, default_element):
+        return self.erase([default_element] * size)
     
     def storage_for_list(self, collection):
         return self.erase([x for x in collection])
     
+    def size_of(self, w_obj):
+        return len(self.unerase(w_obj.storage))
+    
     def fetch(self, w_object, n0):
         w_result = self.unerase(w_object.storage)[n0]
         assert w_result is not None
         types = self.types
         changed_type = w_value.fieldtype()
         if types[n0] is not changed_type:
-            w_object.fieldtypes = self.sibling(n0, changed_type)
+            w_object.strategy = self.sibling(n0, changed_type)
         self.unerase(w_object.storage)[n0] = w_value
 
     @jit.elidable
 
 maps = {}
 
-def strategy_of_size(w_class, size):
-    if w_class.isvariable():
+def strategy_of_size(s_class, size):
+    if s_class is None or s_class.isvariable():
         return ListStorageStrategy.singleton
     else:
         return FixedSizeFieldTypes.of_size(size)
 
 def strategy_for_list(w_obj, vars):
     try:
-        if w_obj.s_class.isvariable():
+        s_class = w_obj.s_class
+        if s_class is None or w_obj.s_class.isvariable():
             return ListStorageStrategy.singleton
         else:
             size = len(vars)
         self._shadow = None # Default value
 
     def fillin(self, space, g_self):
-        from spyvm.fieldtypes import fieldtypes_of
         self.s_class = g_self.get_class().as_class_get_penumbra(space)
         self.hash = g_self.get_hash()
         self.space = space
     
     @jit.unroll_safe
     def __init__(self, space, w_class, size):
+        from spyvm.fieldtypes import strategy_of_size
         """Create new object with size = fixed + variable size."""
         W_AbstractPointersObject.__init__(self, space, w_class, size)
-        from spyvm.fieldtypes import strategy_of_size
-        self.strategy = strategy_of_size(w_class, size)
-        self.storage = self.strategy.initial_storage(size)
+        self.strategy = strategy_of_size(self.s_class, size)
+        self.storage = self.strategy.initial_storage(size, w_nil)
 
     def fillin(self, space, g_self):
+        W_AbstractPointersObject.fillin(self, space, g_self)
         from spyvm.fieldtypes import strategy_for_list
-        W_AbstractPointersObject.fillin(self, space, g_self)
         pointers = g_self.get_pointers()
         self.strategy = strategy_for_list(self, pointers)
-        self.storage = self.strategy.storage_for(pointers)
+        self.storage = self.strategy.storage_for_list(pointers)
 
+    def all_vars(self):
+        return self.strategy.all_vars(self)
+    
+    def set_all_vars(self, collection):
+        # TODO reuse storage if possible
+        self.storage = self.strategy.storage_for_list(collection)
+    
     def _fetch(self, n0):
         strategy = jit.promote(self.strategy)
         return strategy.fetch(self, n0)
 
     @jit.unroll_safe
     def clone(self, space):
-        w_result = W_PointersObject(self.space, self.getclass(space),
-                                    self.strategy.size_of(self))
-        w_result.storage = [self.fetch(space, i) for i in range(len(self.storage))]
+        length = self.strategy.size_of(self)
+        w_result = W_PointersObject(self.space, self.getclass(space), length)
+        cloned_vars = [self.fetch(space, i) for i in range(length)]
+        w_result.storage = w_result.strategy.storage_for_list(cloned_vars)
         return w_result
 
     def fieldtype(self):
         self.setword(index0, word)
 
     def getword(self, n):
-        # if n < 0:
-        #     import pdb; pdb.set_trace()
         assert self.size() > n >= 0
         if self.words is not None:
             return self.words[n]
 # class.  Note that we patch its class in the space
 # YYY there should be no global w_nil
 w_nil = instantiate(W_PointersObject)
-w_nil._vars = []

spyvm/objspace.py

         # initialize their fields to nil, we have to create it in the model
         # package, and then patch up its fields here:
         def patch_nil(w_nil):
-            from spyvm.fieldtypes import nilTyper
+            from spyvm.fieldtypes import ListStorageStrategy
             w_nil.space = self
-            w_nil.fieldtypes = nilTyper
+            w_nil.strategy = ListStorageStrategy.singleton
+            w_nil.storage = w_nil.strategy.initial_storage(0, None)
             w_nil.s_class = self.classtable['w_UndefinedObject'].as_class_get_penumbra(self)
             return w_nil
         w_nil = self.w_nil = patch_nil(model.w_nil)

spyvm/primitives.py

         print ("%s" % w_message).replace('\r', '\n')
         print ("%s" % s_frame.peek(1)).replace('\r', '\n')
         if isinstance(w_message, model.W_PointersObject):
-            print ('%s' % w_message._vars).replace('\r', '\n')
+            print ('%s' % w_message.all_vars()).replace('\r', '\n')
         # raise Exit('Probably Debugger called...')
     raise PrimitiveFailedError()
 
                 self.copy_from_w_self(i)
             except error.SenderChainManipulation, e:
                 assert e.s_context == self
-        w_self._vars = None
+        w_self.storage = w_self.strategy.initial_storage(0, None)
 
     # def detach_shadow(self):
     #     w_self = self.w_self()

spyvm/test/test_interpreter.py

         step_in_interp(s_frame)
         assert s_frame.stack() == []
         for test_index in range(8):
-            print w_frame._vars
+            print w_frame.all_vars()
             if test_index == index:
                 assert s_frame.gettemp(test_index) == space.w_true
             else:

spyvm/test/test_primitives.py

 
 class MockFrame(model.W_PointersObject):
     def __init__(self, stack):
-        self._vars = [None] * 6 + stack + [space.w_nil] * 6
+        self.set_all_vars([None] * 6 + stack + [space.w_nil] * 6)
         s_self = self.as_blockcontext_get_shadow()
         s_self.init_stack_and_temps()
         s_self.reset_stack()

spyvm/test/test_wrapper.py

 def test_simpleread():
     w_o = model.W_PointersObject(space, None, 2)
     w = wrapper.Wrapper(space, w_o)
-    w_o._vars[0] = "hello"
+    w_o.store(0, "hello")
     assert w.read(0) == "hello"
     w.write(1, "b")
     assert w.read(1) == "b"
 def test_accessor_generators():
     w_o = model.W_PointersObject(space, None, 1)
     w = wrapper.LinkWrapper(space, w_o)
-    w_o._vars[0] = "hello"
+    w_o.store(0, "hello")
     assert w.next_link() == "hello"
     w.store_next_link("boe")
     assert w.next_link() == "boe"

targetimageloadingsmalltalk.py

     w_benchmark_proc = model.W_PointersObject(
         interp.space,
         w_hpp.getclass(interp.space),
-        len(w_hpp._vars)
+        w_hpp.basic_size()
     )
 
     s_frame = context_for(interp, number, benchmark, arg)