1.1 --- a/micropython/program.py Fri Jun 28 21:17:02 2013 +0200
1.2 +++ b/micropython/program.py Sat Jun 29 01:28:12 2013 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Program code and data representations.
1.6
1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -19,123 +19,6 @@
1.13 this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 -try:
1.17 - set
1.18 -except NameError:
1.19 - from sets import Set as set
1.20 -
1.21 -class Location:
1.22 -
1.23 - """
1.24 - A special representation for locations which are to be compared to program
1.25 - objects.
1.26 - """
1.27 -
1.28 - def __init__(self, location):
1.29 - self.location = location
1.30 -
1.31 - def _op(self, other, op):
1.32 - if hasattr(other, "location"):
1.33 - return op(self.location, other.location)
1.34 - else:
1.35 - raise NotImplemented
1.36 -
1.37 - def __eq__(self, other):
1.38 - return self._op(other, operator.eq)
1.39 -
1.40 - def __ne__(self, other):
1.41 - return self._op(other, operator.ne)
1.42 -
1.43 - def __lt__(self, other):
1.44 - return self._op(other, operator.lt)
1.45 -
1.46 - def __le__(self, other):
1.47 - return self._op(other, operator.le)
1.48 -
1.49 - def __gt__(self, other):
1.50 - return self._op(other, operator.gt)
1.51 -
1.52 - def __ge__(self, other):
1.53 - return self._op(other, operator.ge)
1.54 -
1.55 - def __repr__(self):
1.56 - return "Location(%r)" % self.location
1.57 -
1.58 -class Block:
1.59 -
1.60 - "A code block."
1.61 -
1.62 - def __init__(self, unit):
1.63 - self.unit = unit
1.64 - self.code = []
1.65 - self.location = None
1.66 - self.active_values = set()
1.67 -
1.68 - def __repr__(self):
1.69 - return "Block(%r, id=%r, location=%r)" % (self.unit, id(self), self.location)
1.70 -
1.71 - def set_active_values(self, values):
1.72 - self.active_values = values
1.73 -
1.74 - def get_active_values(self):
1.75 - return self.active_values
1.76 -
1.77 - def insert(self, pos, op):
1.78 - self.code.insert(pos, op)
1.79 -
1.80 - def append(self, op):
1.81 - self.code.append(op)
1.82 -
1.83 - def __len__(self):
1.84 - return len(self.code)
1.85 -
1.86 -class DataValue:
1.87 -
1.88 - "A representation of a raw program value."
1.89 -
1.90 - def __init__(self, context, ref):
1.91 - self.context = context
1.92 - self.ref = ref
1.93 -
1.94 - def __repr__(self):
1.95 - return "value: (%r, %r)" % (
1.96 - self.context, self.ref
1.97 - )
1.98 -
1.99 -class DataObject:
1.100 -
1.101 - "A representation of a raw program data object."
1.102 -
1.103 - def __init__(self, classcode, attrcode, codeaddr, name, size, funccode=None):
1.104 - self.classcode = classcode
1.105 - self.attrcode = attrcode
1.106 - self.codeaddr = codeaddr
1.107 - self.name = name
1.108 - self.size = size
1.109 - self.funccode = funccode
1.110 -
1.111 - def with_size(self, size):
1.112 - return DataObject(self.classcode, self.attrcode, self.codeaddr, self.name, size, self.funccode)
1.113 -
1.114 - def with_callable(self, codeaddr):
1.115 - return DataObject(self.classcode, self.attrcode, codeaddr, self.name, self.size, self.funccode)
1.116 -
1.117 - def __repr__(self):
1.118 - return "object: %r # %s" % (
1.119 - (self.classcode, self.attrcode, self.codeaddr, self.funccode, self.size), self.name
1.120 - )
1.121 -
1.122 -class FragmentObject:
1.123 -
1.124 - "A representation of a list fragment, used by list instances."
1.125 -
1.126 - def __init__(self, occupied_size, allocated_size):
1.127 - self.occupied_size = occupied_size
1.128 - self.allocated_size = allocated_size
1.129 -
1.130 - def __repr__(self):
1.131 - return "%r" % ((self.occupied_size, self.allocated_size),)
1.132 -
1.133 class Context:
1.134
1.135 """