git @ Cat's Eye Technologies SixtyPical / 8dc4467
LocationRefs are equal if names/type are; this needed __str__ tho. Chris Pressey 3 years ago
3 changed file(s) with 16 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
8888 self._writeable.add(ref)
8989
9090 def __str__(self):
91 def locstr(loc):
92 if isinstance(loc, LocationRef):
93 return "{}:{}".format(loc.name, loc.type)
94 else:
95 return str(loc)
96
97 def locsetstr(s):
98 return '{' + ', '.join([locstr(loc) for loc in list(s)]) + '}'
99
10091 return "Context(\n _touched={},\n _meaningful={},\n _writeable={}\n)".format(
101 locsetstr(self._touched), locsetstr(self._meaningful), locsetstr(self._writeable)
92 LocationRef.format_set(self._touched), LocationRef.format_set(self._meaningful), LocationRef.format_set(self._writeable)
10293 )
10394
10495 def clone(self):
184175 )
185176
186177 def assert_affected_within(self, name, affected, limited_to):
187 # We reduce the set of LocationRefs to a set of strings (their labels).
188 # This is necessary because currently, two LocationRefs that refer to the
189 # same location are not considered euqal. (But two LocationRefs with the
190 # same label should always be the same type.)
191
192 affected = set([loc.name for loc in affected])
193 limited_to = set([loc.name for loc in limited_to])
194
195 def loc_list(label_set):
196 return ', '.join(sorted(label_set))
197
198178 overage = affected - limited_to
199179 if not overage:
200180 return
201 message = 'in %s: %s are {%s} but affects {%s} which exceeds by: {%s} ' % (
202 self.current_routine.name, name, loc_list(limited_to), loc_list(affected), loc_list(overage)
181 message = 'in %s: %s are %s but affects %s which exceeds it by: %s ' % (
182 self.current_routine.name, name,
183 LocationRef.format_set(limited_to), LocationRef.format_set(affected), LocationRef.format_set(overage)
203184 )
204185 raise IncompatibleConstraintsError(message)
205186
66
77 def __repr__(self):
88 return 'Type(%r)' % self.name
9
10 def __str__(self):
11 return self.name
912
1013 def __eq__(self, other):
1114 return isinstance(other, Type) and other.name == self.name
97100 def __repr__(self):
98101 return '%s(%r, %r)' % (self.__class__.__name__, self.type, self.name)
99102
103 def __str__(self):
104 return "{}:{}".format(self.name, self.type)
105
100106 def is_constant(self):
101107 return isinstance(self.type, RoutineType)
108
109 @classmethod
110 def format_set(cls, location_refs):
111 return '{%s}' % ', '.join([str(loc) for loc in sorted(location_refs)])
102112
103113
104114 class IndirectRef(Ref):
12331233 | {
12341234 | copy 0, lives
12351235 | }
1236 ? ForbiddenWriteError: a in main
1236 ? ForbiddenWriteError: n in main
12371237
12381238 a, z, and n are trashed, and must not be declared as outputs.
12391239
12431243 | {
12441244 | copy 0, lives
12451245 | }
1246 ? UnmeaningfulOutputError: a in main
1246 ? UnmeaningfulOutputError: n in main
12471247
12481248 Unless of course you subsequently initialize them.
12491249