git @ Cat's Eye Technologies SixtyPical / 0687da8
Some headway on context.assert_in_range(). Chris Pressey 3 years ago
2 changed file(s) with 30 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
3636 pass
3737
3838
39 class RangeExceededError(StaticAnalysisError):
40 pass
41
42
3943 class ConstraintsError(StaticAnalysisError):
44 """The constraints of a routine (inputs, outputs, trashes) have been violated."""
4045 pass
4146
4247
155160 message += ' (%s)' % kwargs['message']
156161 raise exception_class(message)
157162
163 def assert_in_range(self, inside, outside):
164 # FIXME there's a bit of I'm-not-sure-the-best-way-to-do-this-ness, here...
165
166 # inside should always be meaningful
167 inside_range = self._range[inside]
168
169 # outside might not be meaningful, so default to max range if necessary
170 if outside in self._range:
171 outside_range = self._range[outside]
172 else:
173 outside_range = outside.max_range()
174 if isinstance(outside.type, TableType):
175 outside_range = (0, outside.type.size-1)
176
177 if inside_range[0] < outside_range[0] or inside_range[1] > outside_range[1]:
178 raise RangeExceededError(
179 "Possible range of {} {} exceeds acceptable range of {} {}".format(
180 inside, inside_range, outside, outside_range
181 )
182 )
183
158184 def set_touched(self, *refs):
159185 for ref in refs:
160186 self._touched.add(ref)
290316 (src.ref.name, dest.name, self.current_routine.name)
291317 )
292318 context.assert_meaningful(src, src.index)
319 context.assert_in_range(src.index, src.ref)
293320 elif isinstance(src, IndirectRef):
294321 # copying this analysis from the matching branch in `copy`, below
295322 if isinstance(src.ref.type, PointerType) and dest.type == TYPE_BYTE:
311338 else:
312339 raise TypeMismatchError((src, dest))
313340 context.assert_meaningful(dest.index)
341 context.assert_in_range(dest.index, dest.ref)
314342 context.set_written(dest.ref)
315343 elif isinstance(dest, IndirectRef):
316344 # copying this analysis from the matching branch in `copy`, below
558558 | ld x, 32
559559 | ld a, many + x
560560 | }
561 ? RangeError
561 ? RangeExceededError
562562
563563 | byte table[32] many
564564 |
571571 | ld a, 0
572572 | st a, many + x
573573 | }
574 ? RangeError
574 ? RangeExceededError
575575
576576 ### add ###
577577