Commits

Lars Wassermann committed ce39ff5

fixed another bug in fieldtypes
added tests for all the bugs found

Comments (0)

Files changed (2)

spyvm/fieldtypes.py

 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]
             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:])

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