1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-12-23 21:33:05 +00:00

LocationRefs are equal if names/type are; this needed __str__ tho.

This commit is contained in:
Chris Pressey 2017-12-12 12:45:47 +00:00
parent de6c96fef8
commit 8dc44673fa
3 changed files with 16 additions and 25 deletions

View File

@ -89,17 +89,8 @@ class Context(object):
self._writeable.add(ref)
def __str__(self):
def locstr(loc):
if isinstance(loc, LocationRef):
return "{}:{}".format(loc.name, loc.type)
else:
return str(loc)
def locsetstr(s):
return '{' + ', '.join([locstr(loc) for loc in list(s)]) + '}'
return "Context(\n _touched={},\n _meaningful={},\n _writeable={}\n)".format(
locsetstr(self._touched), locsetstr(self._meaningful), locsetstr(self._writeable)
LocationRef.format_set(self._touched), LocationRef.format_set(self._meaningful), LocationRef.format_set(self._writeable)
)
def clone(self):
@ -185,22 +176,12 @@ class Analyzer(object):
)
def assert_affected_within(self, name, affected, limited_to):
# We reduce the set of LocationRefs to a set of strings (their labels).
# This is necessary because currently, two LocationRefs that refer to the
# same location are not considered euqal. (But two LocationRefs with the
# same label should always be the same type.)
affected = set([loc.name for loc in affected])
limited_to = set([loc.name for loc in limited_to])
def loc_list(label_set):
return ', '.join(sorted(label_set))
overage = affected - limited_to
if not overage:
return
message = 'in %s: %s are {%s} but affects {%s} which exceeds by: {%s} ' % (
self.current_routine.name, name, loc_list(limited_to), loc_list(affected), loc_list(overage)
message = 'in %s: %s are %s but affects %s which exceeds it by: %s ' % (
self.current_routine.name, name,
LocationRef.format_set(limited_to), LocationRef.format_set(affected), LocationRef.format_set(overage)
)
raise IncompatibleConstraintsError(message)

View File

@ -8,6 +8,9 @@ class Type(object):
def __repr__(self):
return 'Type(%r)' % self.name
def __str__(self):
return self.name
def __eq__(self, other):
return isinstance(other, Type) and other.name == self.name
@ -98,9 +101,16 @@ class LocationRef(Ref):
def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.type, self.name)
def __str__(self):
return "{}:{}".format(self.name, self.type)
def is_constant(self):
return isinstance(self.type, RoutineType)
@classmethod
def format_set(cls, location_refs):
return '{%s}' % ', '.join([str(loc) for loc in sorted(location_refs)])
class IndirectRef(Ref):
def __init__(self, ref):

View File

@ -1234,7 +1234,7 @@ a, z, and n are trashed, and must be declared as such
| {
| copy 0, lives
| }
? ForbiddenWriteError: a in main
? ForbiddenWriteError: n in main
a, z, and n are trashed, and must not be declared as outputs.
@ -1244,7 +1244,7 @@ a, z, and n are trashed, and must not be declared as outputs.
| {
| copy 0, lives
| }
? UnmeaningfulOutputError: a in main
? UnmeaningfulOutputError: n in main
Unless of course you subsequently initialize them.