1.1 --- a/micropython/__init__.py Sat Jan 24 02:41:59 2009 +0100
1.2 +++ b/micropython/__init__.py Sun Jan 25 02:56:16 2009 +0100
1.3 @@ -101,10 +101,6 @@
1.4 last_module = self.importer.modules_ordered[-1]
1.5
1.6 for module in self.importer.modules_ordered:
1.7 -
1.8 - if not with_builtins and module.name == "__builtins__":
1.9 - continue
1.10 -
1.11 pos = len(self.code)
1.12
1.13 # Position the module in the image and make a translation.
1.14 @@ -164,17 +160,29 @@
1.15 self.code += obj.default_attrs
1.16 pos += len(obj.default_attrs)
1.17
1.18 + # Omit built-in function code where requested.
1.19 +
1.20 + if not with_builtins and module.name == "__builtins__":
1.21 + pass
1.22 +
1.23 # Append the function code to the image.
1.24
1.25 - code = trans.get_code(obj)
1.26 - self.code += code
1.27 - pos += len(code)
1.28 + else:
1.29 + code = trans.get_code(obj)
1.30 + self.code += code
1.31 + pos += len(code)
1.32 +
1.33 + # Omit built-in module code where requested.
1.34 +
1.35 + if not with_builtins and module.name == "__builtins__":
1.36 + pass
1.37
1.38 # Append the module top-level code to the image.
1.39
1.40 - code = trans.get_module_code(final=(module is last_module))
1.41 - self.code += code
1.42 - pos += len(code)
1.43 + else:
1.44 + code = trans.get_module_code(final=(module is last_module))
1.45 + self.code += code
1.46 + pos += len(code)
1.47
1.48 return self.code
1.49
1.50 @@ -191,17 +199,36 @@
1.51
1.52 pos = 0
1.53 for item in self.code:
1.54 +
1.55 + # Blocks are positioned leaving space for their expansion.
1.56 +
1.57 if isinstance(item, Block):
1.58 item.location = pos
1.59 pos += len(item.code)
1.60 +
1.61 + # Other multi-location objects.
1.62 +
1.63 elif isinstance(item, (micropython.data.Class, micropython.data.Const,
1.64 micropython.data.Function, micropython.data.Module)):
1.65 +
1.66 item.location = pos
1.67 pos += 1
1.68 +
1.69 + # Code and details are associated with certain objects.
1.70 +
1.71 if isinstance(item, micropython.data.Function):
1.72 - item.code_location = pos
1.73 +
1.74 + # Set the code location only where the code has been
1.75 + # generated.
1.76 +
1.77 + if not with_builtins and item.module.name == "__builtins__":
1.78 + item.code_location = item.full_name()
1.79 + else:
1.80 + item.code_location = pos
1.81 +
1.82 elif isinstance(item, micropython.data.Const):
1.83 pos += len(self.raw_data(item))
1.84 +
1.85 else:
1.86 pos += 1
1.87
1.88 @@ -270,7 +297,10 @@
1.89 0
1.90 ))
1.91
1.92 - assert item.code_location == len(self.raw_code)
1.93 + # Check the code location only where the code has been generated.
1.94 +
1.95 + assert (not with_builtins and item.module.name == "__builtins__") or \
1.96 + item.code_location == len(self.raw_code)
1.97
1.98 elif isinstance(item, micropython.data.Module):
1.99 assert item.location == len(self.raw_code)
2.1 --- a/micropython/data.py Sat Jan 24 02:41:59 2009 +0100
2.2 +++ b/micropython/data.py Sun Jan 25 02:56:16 2009 +0100
2.3 @@ -58,10 +58,10 @@
2.4
2.5 "A mix-in providing dictionary methods."
2.6
2.7 - def __init__(self, global_namespace=None):
2.8 + def __init__(self, module=None):
2.9 self.namespace = {}
2.10 self.globals = set()
2.11 - self.global_namespace = global_namespace
2.12 + self.module = module
2.13 self.finalised = 0
2.14
2.15 def __delitem__(self, name):
2.16 @@ -98,7 +98,7 @@
2.17 """
2.18
2.19 if name in self.globals:
2.20 - self.global_namespace.set(name, value, 0)
2.21 + self.module.set(name, value, 0)
2.22 else:
2.23 attr = self._set(name, value)
2.24 attr.update(attr.value, single_assignment)
2.25 @@ -362,14 +362,14 @@
2.26
2.27 "An inspected class."
2.28
2.29 - def __init__(self, name, parent, global_namespace=None, node=None):
2.30 + def __init__(self, name, parent, module=None, node=None):
2.31
2.32 """
2.33 Initialise the class with the given 'name', 'parent' object, optional
2.34 - 'global_namespace' and optional AST 'node'.
2.35 + 'module' and optional AST 'node'.
2.36 """
2.37
2.38 - NamespaceDict.__init__(self, global_namespace)
2.39 + NamespaceDict.__init__(self, module)
2.40 self.name = name
2.41 self.parent = parent
2.42 self.astnode = node
2.43 @@ -700,17 +700,16 @@
2.44
2.45 "An inspected function."
2.46
2.47 - def __init__(self, name, parent, argnames, defaults, has_star, has_dstar, global_namespace=None, node=None):
2.48 + def __init__(self, name, parent, argnames, defaults, has_star, has_dstar, module=None, node=None):
2.49
2.50 """
2.51 Initialise the function with the given 'name', 'parent', list of
2.52 'argnames', list of 'defaults', the 'has_star' flag (indicating the
2.53 presence of a * parameter), the 'has_dstar' flag (indicating the
2.54 - presence of a ** parameter), optional 'global_namespace', and optional
2.55 - AST 'node'.
2.56 + presence of a ** parameter), optional 'module', and optional AST 'node'.
2.57 """
2.58
2.59 - NamespaceDict.__init__(self, global_namespace)
2.60 + NamespaceDict.__init__(self, module)
2.61 self.name = name
2.62 self.parent = parent
2.63 self.argnames = argnames
2.64 @@ -878,7 +877,7 @@
2.65 "Make a function from a method."
2.66
2.67 function = Function(self.name, self.parent, self.argnames[1:], self.defaults,
2.68 - self.has_star, self.has_dstar, self.global_namespace, self.astnode)
2.69 + self.has_star, self.has_dstar, self.module, self.astnode)
2.70 function.default_attrs = self.default_attrs
2.71 return function
2.72
2.73 @@ -886,8 +885,8 @@
2.74
2.75 "A module, class or function which was mentioned but could not be imported."
2.76
2.77 - def __init__(self, name, parent_name, global_namespace=None):
2.78 - NamespaceDict.__init__(self, global_namespace)
2.79 + def __init__(self, name, parent_name, module=None):
2.80 + NamespaceDict.__init__(self, module)
2.81 self.name = name
2.82 self.parent_name = parent_name
2.83 self.parent = None
3.1 --- a/micropython/rsvp.py Sat Jan 24 02:41:59 2009 +0100
3.2 +++ b/micropython/rsvp.py Sun Jan 25 02:56:16 2009 +0100
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 RSVP instruction classes.
3.6
3.7 -Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -19,13 +19,15 @@
3.13 this program. If not, see <http://www.gnu.org/licenses/>.
3.14 """
3.15
3.16 -from micropython.data import Attr
3.17 +from micropython.data import Attr, Const
3.18
3.19 def name(attr):
3.20 if isinstance(attr, Attr):
3.21 return attr.name or "<unnamed>"
3.22 + elif isinstance(attr, Const):
3.23 + return attr
3.24 else:
3.25 - return attr or "<unnamed>"
3.26 + return attr.full_name() or "<unnamed>"
3.27
3.28 class Instruction:
3.29
4.1 --- a/rsvp.py Sat Jan 24 02:41:59 2009 +0100
4.2 +++ b/rsvp.py Sun Jan 25 02:56:16 2009 +0100
4.3 @@ -5,7 +5,7 @@
4.4 ignore low-level operations and merely concentrate on variable access, structure
4.5 access, structure allocation and function invocations.
4.6
4.7 -Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -56,7 +56,12 @@
4.13 pass
4.14
4.15 class IllegalAddress(Exception):
4.16 - pass
4.17 + def __init__(self, address):
4.18 + self.address = address
4.19 + def __repr__(self):
4.20 + return "IllegalAddress(%r)" % self.address
4.21 + def __str__(self):
4.22 + return repr(self)
4.23
4.24 class EmptyPCStack(Exception):
4.25 pass
4.26 @@ -161,7 +166,9 @@
4.27 try:
4.28 return self.memory[address]
4.29 except IndexError:
4.30 - raise IllegalAddress, address
4.31 + raise IllegalAddress(address)
4.32 + except TypeError:
4.33 + raise IllegalAddress(address)
4.34
4.35 def save(self, address, value):
4.36
4.37 @@ -170,7 +177,9 @@
4.38 try:
4.39 self.memory[address] = value
4.40 except IndexError:
4.41 - raise IllegalAddress, address
4.42 + raise IllegalAddress(address)
4.43 + except TypeError:
4.44 + raise IllegalAddress(address)
4.45
4.46 def new(self, size):
4.47