1.1 --- a/micropython/__init__.py Sun Mar 11 01:49:53 2012 +0100
1.2 +++ b/micropython/__init__.py Mon Mar 26 23:24:38 2012 +0200
1.3 @@ -5,7 +5,7 @@
1.4 from the simplify package but has had various details related to that package
1.5 removed.
1.6
1.7 -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 @@ -44,6 +44,7 @@
1.13 import micropython.opt
1.14 import micropython.inspect
1.15 import micropython.table
1.16 +import bisect
1.17 import os
1.18
1.19 try:
1.20 @@ -316,7 +317,7 @@
1.21
1.22 for name, descendant in obj.all_descendants().items():
1.23 if descendant in all_objects:
1.24 - attributes[name] = descendant
1.25 + attributes["#" + name] = descendant
1.26
1.27 t.add(full_name, attributes)
1.28
1.29 @@ -362,6 +363,16 @@
1.30
1.31 return self.paramtable
1.32
1.33 + def object_at(self, pos):
1.34 +
1.35 + "Return the object whose code can be found at 'pos'."
1.36 +
1.37 + i = bisect.bisect_left(self.code, Location(pos))
1.38 + if i > 0:
1.39 + return self.code[i-1]
1.40 + else:
1.41 + return None
1.42 +
1.43 class Importer:
1.44
1.45 "An import machine, searching for and loading modules."
2.1 --- a/micropython/code.py Sun Mar 11 01:49:53 2012 +0100
2.2 +++ b/micropython/code.py Mon Mar 26 23:24:38 2012 +0200
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Generate low-level code.
2.6
2.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -87,7 +87,7 @@
2.13
2.14 "Return a new code block."
2.15
2.16 - return Block()
2.17 + return Block(self.unit)
2.18
2.19 def get_block(self):
2.20
3.1 --- a/micropython/common.py Sun Mar 11 01:49:53 2012 +0100
3.2 +++ b/micropython/common.py Mon Mar 26 23:24:38 2012 +0200
3.3 @@ -462,6 +462,43 @@
3.4 def __repr__(self):
3.5 return "AtLeast(%r)" % self.count
3.6
3.7 +class Location:
3.8 +
3.9 + """
3.10 + A special representation for locations which are to be compared to program
3.11 + objects.
3.12 + """
3.13 +
3.14 + def __init__(self, location):
3.15 + self.location = location
3.16 +
3.17 + def _op(self, other, op):
3.18 + if hasattr(other, "location"):
3.19 + return op(self.location, other.location)
3.20 + else:
3.21 + raise NotImplemented
3.22 +
3.23 + def __eq__(self, other):
3.24 + return self._op(other, operator.eq)
3.25 +
3.26 + def __ne__(self, other):
3.27 + return self._op(other, operator.ne)
3.28 +
3.29 + def __lt__(self, other):
3.30 + return self._op(other, operator.lt)
3.31 +
3.32 + def __le__(self, other):
3.33 + return self._op(other, operator.le)
3.34 +
3.35 + def __gt__(self, other):
3.36 + return self._op(other, operator.gt)
3.37 +
3.38 + def __ge__(self, other):
3.39 + return self._op(other, operator.ge)
3.40 +
3.41 + def __repr__(self):
3.42 + return "Location(%r)" % self.location
3.43 +
3.44 # Useful data.
3.45
3.46 operator_functions = {
4.1 --- a/micropython/program.py Sun Mar 11 01:49:53 2012 +0100
4.2 +++ b/micropython/program.py Mon Mar 26 23:24:38 2012 +0200
4.3 @@ -23,13 +23,14 @@
4.4
4.5 "A code block."
4.6
4.7 - def __init__(self):
4.8 + def __init__(self, unit):
4.9 + self.unit = unit
4.10 self.code = []
4.11 self.location = None
4.12 self.active_values = set()
4.13
4.14 def __repr__(self):
4.15 - return "Block(%r, location=%r)" % (id(self), self.location)
4.16 + return "Block(%r, id=%r, location=%r)" % (self.unit, id(self), self.location)
4.17
4.18 def set_active_values(self, values):
4.19 self.active_values = values
5.1 --- a/micropython/rsvp.py Sun Mar 11 01:49:53 2012 +0100
5.2 +++ b/micropython/rsvp.py Mon Mar 26 23:24:38 2012 +0200
5.3 @@ -197,7 +197,7 @@
5.4 if type_name in ("__builtins__.tuple", "__builtins__.list"):
5.5 return [len(value)] + list(value)
5.6 elif type_name == "__builtins__._accessor":
5.7 - return [value, objtable.get_index(value)]
5.8 + return [value, objtable.get_index("#" + value)]
5.9 else:
5.10 return [value]
5.11
5.12 @@ -244,7 +244,7 @@
5.13 return [
5.14 DataObject(
5.15 objtable.as_list().get_code("__builtins__.function"),
5.16 - objtable.get_index("__builtins__.function"), # is instance
5.17 + objtable.get_index("#__builtins__.function"), # is instance
5.18 item.code_location,
5.19 "__builtins__.function",
5.20 len(item.defaults) + 1, # size (not accurate for lambda functions before instantiation)