git @ Cat's Eye Technologies SixtyPical / c12a76e
Make assertions more robust, in hopes of hunting down bugs. Chris Pressey 7 years ago
2 changed file(s) with 16 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
175175 (location.name, self.current_routine.name)
176176 )
177177
178 def assert_affected_within(self, name, affected, limited_to):
178 def assert_affected_within(self, name, affecting_type, limiting_type):
179 assert name in ('inputs', 'outputs', 'trashes')
180 affected = getattr(affecting_type, name)
181 limited_to = getattr(limiting_type, name)
179182 overage = affected - limited_to
180183 if not overage:
181184 return
182 message = 'in %s: %s are %s but affects %s which exceeds it by: %s ' % (
185 message = 'in %s: %s for %s are %s\n\nbut %s affects %s\n\nwhich exceeds it by: %s ' % (
183186 self.current_routine.name, name,
184 LocationRef.format_set(limited_to), LocationRef.format_set(affected), LocationRef.format_set(overage)
187 limiting_type, LocationRef.format_set(limited_to),
188 affecting_type, LocationRef.format_set(affected),
189 LocationRef.format_set(overage)
185190 )
186191 raise IncompatibleConstraintsError(message)
187192
389394 if src.type == dest.type:
390395 pass
391396 elif isinstance(src.type, RoutineType) and isinstance(dest.type, VectorType):
392 self.assert_affected_within('inputs', src.type.inputs, dest.type.of_type.inputs)
393 self.assert_affected_within('outputs', src.type.outputs, dest.type.of_type.outputs)
394 self.assert_affected_within('trashes', src.type.trashes, dest.type.of_type.trashes)
397 self.assert_affected_within('inputs', src.type, dest.type.of_type)
398 self.assert_affected_within('outputs', src.type, dest.type.of_type)
399 self.assert_affected_within('trashes', src.type, dest.type.of_type)
395400 else:
396401 raise TypeMismatchError((src, dest))
397402 else:
450455 # and that this routine's trashes and output constraints are a
451456 # superset of the called routine's
452457 current_type = self.current_routine.location.type
453 self.assert_affected_within('outputs', type_.outputs, current_type.outputs)
454 self.assert_affected_within('trashes', type_.trashes, current_type.trashes)
458 self.assert_affected_within('outputs', type_, current_type)
459 self.assert_affected_within('trashes', type_, current_type)
455460
456461 self.has_encountered_goto = True
457462 elif opcode == 'trash':
2222 elif isinstance(self, VectorType):
2323 self.of_type.backpatch_constraint_labels(resolver)
2424 elif isinstance(self, RoutineType):
25 self.inputs = set([resolver(w) for w in self.inputs])
26 self.outputs = set([resolver(w) for w in self.outputs])
27 self.trashes = set([resolver(w) for w in self.trashes])
25 self.inputs = set([resolver(w) for w in self.inputs if isinstance(w, basestring)])
26 self.outputs = set([resolver(w) for w in self.outputs if isinstance(w, basestring)])
27 self.trashes = set([resolver(w) for w in self.trashes if isinstance(w, basestring)])
2828
2929
3030 TYPE_BIT = Type('bit')