git @ Cat's Eye Technologies SixtyPical / 0fff8e4
Begin to implement vector tables, stuck at a type equality problem. Chris Pressey 3 years ago
3 changed file(s) with 50 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
363363 elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
364364 if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
365365 pass
366 else:
367 raise TypeMismatchError((src, dest))
366 elif isinstance(src.type, VectorType) and isinstance(dest.ref.type, TableType) and dest.ref.type.of_type == src.type:
367 # TODO ideally we'd check if the vectors in the table are compatible, rather than equal, to the src
368 pass
369 else:
370 raise TypeMismatchError("""\n\n%r\n\n%r\n\n%r\n\n%r\n\n%r\n\n%r""" % (src, src.type, dest, dest.ref.type, dest.ref.type.of_type, (src.type == dest.ref.type.of_type)))
368371
369372 elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
370373 if TableType.is_a_table_type(src.ref.type, TYPE_WORD) and dest.type == TYPE_WORD:
374 pass
375 elif isinstance(dest.type, VectorType) and isinstance(src.ref.type, TableType) and src.ref.type.of_type == dest.type:
376 # TODO ideally we'd check if the vectors in the table are compatible, rather than equal, to the src
371377 pass
372378 else:
373379 raise TypeMismatchError((src, dest))
3131 self.trashes = trashes or set()
3232
3333 def __repr__(self):
34 return 'RoutineType(%r, inputs=%r, outputs=%r, trashes=%r)' % (
35 self.name, self.inputs, self.outputs, self.trashes
34 return '%s(%r, inputs=%r, outputs=%r, trashes=%r)' % (
35 self.__class__.__name__, self.name, self.inputs, self.outputs, self.trashes
3636 )
3737
3838 def __eq__(self, other):
6464 self.of_type = of_type
6565 self.size = size
6666 self.name = '{} table[{}]'.format(self.of_type.name, self.size)
67
68 def __repr__(self):
69 return '%s(%r, %r)' % (
70 self.__class__.__name__, self.of_type, self.size
71 )
6772
6873 @classmethod
6974 def is_a_table_type(cls_, x, of_type):
122127 t.inputs = set([resolver(w) for w in t.inputs])
123128 t.outputs = set([resolver(w) for w in t.outputs])
124129 t.trashes = set([resolver(w) for w in t.trashes])
130 if isinstance(self.type, TableType) and isinstance(self.type.of_type, ExecutableType):
131 t = self.type.of_type
132 t.inputs = set([resolver(w) for w in t.inputs])
133 t.outputs = set([resolver(w) for w in t.outputs])
134 t.trashes = set([resolver(w) for w in t.trashes])
125135
126136 @classmethod
127137 def format_set(cls, location_refs):
18991899 | ld a, x
19001900 | }
19011901 = ok
1902
1903 ### vector table ###
1904
1905 Copying to and from a vector table.
1906
1907 | vector
1908 | outputs x
1909 | trashes a, z, n
1910 | one
1911 | vector
1912 | outputs x
1913 | trashes a, z, n
1914 | table[256] many
1915 |
1916 | routine bar outputs x trashes a, z, n {
1917 | ld x, 200
1918 | }
1919 |
1920 | routine main
1921 | inputs one, many
1922 | outputs one, many
1923 | trashes a, x, n, z
1924 | {
1925 | ld x, 0
1926 | copy bar, one
1927 | copy one, many + x
1928 | //copy many + x, one
1929 | //call one
1930 | }
1931 = ok