Commits

Lars Wassermann committed 8c1cadf Merge

merge with tip

Comments (0)

Files changed (4)

         SDLCursor.has_display = True
         self.has_surface = False
         self.mouse_position = [0, 0]
+        self.interrupt_key = 15 << 8 # pushing all four meta keys, of which we support three...
         self.button = 0
         self.key = 0
 

spyvm/fieldtypes.py

 from spyvm import model, shadow
 
 from rpython.rlib import objectmodel, jit, signature
+from rpython.rlib.listsort import TimSort
 
 class TypeTag():
     pass
 flt = TypeTag()
 obj = TypeTag()
 
+# may be used during debugging
+# LPI, SInt, flt, obj = 'LPI', 'SInt', 'float', 'object'
+
+class FieldSort(TimSort):
+    def lt(self, a, b):
+        return a[0] < b[0]
+
 maps = {}
 
 class VarSizedFieldTypes():
         elif parent is None:
             return self.descent([change])
         else:
-            new_fieldtype = parent.ascent([change, self.diff])
+            if n0 == self.diff[0]:
+                diff = [change]
+            else:
+                diff = [change, self.diff]
+
+            new_fieldtype = parent.ascent(diff)
+
             if not objectmodel.we_are_translated():
-                assert new_fieldtype.types == self.types[0:n0] + [changed_type] + self.types[n0+1:]
+                new_types = list(self.types)
+                new_types[n0] = changed_type
+                assert new_fieldtype.types == new_types
             siblings[change] = new_fieldtype
             return new_fieldtype
 
     def ascent(self, changes):
         parent = self.parent
         if parent is None:
-            sort(changes)
+            FieldSort(changes).sort()
             return self.descent(changes)
         else:
             change = self.diff
             return self
 
         change = changes[0]
+        if change[1] is obj:
+            return self.descent(changes[1:])
         siblings = self.siblings
         if change in siblings:
             return siblings[change].descent(changes[1:])
         else:
             new_types = list(self.types)
+            assert new_types[change[0]] == obj
             new_types[change[0]] = change[1]
             new_fieldtype = FieldTypes(new_types, self, change)
             siblings[change] = new_fieldtype
             return typer
     except AttributeError:
         return nilTyper
-
-def sort(an_array):
-    end = len(an_array) - 1
-    sort_quick_inplace(an_array, 0, end)
-
-
-def sort_quick_inplace(an_array, start, end):
-    assert start >= 0 and end < len(an_array)
-
-    def partition(an_array, start, end):
-        key = an_array[start][0]
-        i = start - 1
-        j = end + 1
-        while True:
-            i += 1
-            j -= 1
-            while not an_array[j][0] <= key:
-                j -= 1
-            while not an_array[i][0] >= key:
-                i += 1
-            if j <= i:
-                return j
-            else:
-                an_array[i], an_array[j] = an_array[j], an_array[i]
-
-    if start < end:
-        mid = partition(an_array, start, end)
-        sort_quick_inplace(an_array, start, mid)
-        sort_quick_inplace(an_array, mid + 1, end)

spyvm/primitives.py

 IDLE_FOR_MICROSECONDS = 230
 FORCE_DISPLAY_UPDATE = 231
 
-@expose_primitive(IDLE_FOR_MICROSECONDS, unwrap_spec=[object, int])
+@expose_primitive(IDLE_FOR_MICROSECONDS, unwrap_spec=[object, int], no_result=True, clean_stack=False)
 def func(interp, s_frame, w_rcvr, time_mu_s):
     import time
     time_s = time_mu_s / 1000000.0
     time.sleep(time_s)
     interp.interrupt_check_counter = 0
+    s_frame.pop()
     interp.quick_check_for_interrupt(s_frame, dec=0)
-    return w_rcvr
 
 @expose_primitive(FORCE_DISPLAY_UPDATE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):

spyvm/test/test_fieldtypes.py

 from spyvm import model, fieldtypes
 from spyvm import objspace
 
-from spyvm.fieldtypes import obj, SInt
+from spyvm.fieldtypes import obj, SInt, LPI, flt
 
 def test_simple_changes():
 	a = fieldtypes.FieldTypes.of_length(3)
 	assert len(a.siblings) == 3
 	assert len(a.sibling(0, SInt).siblings) == 2
 	assert len(a.sibling(1, SInt).siblings) == 2
-	assert len(a.sibling(2, SInt).siblings) == 1 # link to [o, i, i] not created
+	assert len(a.sibling(2, SInt).siblings) == 1 # link to [o, i, i] not created
+
+def test_multiple_changes():
+	a = fieldtypes.FieldTypes.of_length(3)
+	b = a.sibling(0, SInt)
+	for tag in [LPI, flt]:
+		assert b.sibling(0, tag).types == [tag, obj, obj]
+
+def test_obj_replacement():
+	a = fieldtypes.FieldTypes.of_length(3)
+	b = a.sibling(0, SInt).sibling(1, SInt)
+	c = a.sibling(1, SInt)
+	assert b.sibling(0, obj) is c