1.1 --- a/micropython/__init__.py Sun Mar 09 02:10:12 2008 +0100
1.2 +++ b/micropython/__init__.py Sun Mar 09 02:46:57 2008 +0100
1.3 @@ -100,11 +100,6 @@
1.4
1.5 pos = len(image)
1.6
1.7 - # Position the module in the image and make a translation.
1.8 -
1.9 - module.location = pos
1.10 - trans = micropython.ast.Translation(module, objtable, paramtable)
1.11 -
1.12 # Append constants to the image.
1.13
1.14 for const in module.constants():
1.15 @@ -112,6 +107,11 @@
1.16 image.append(const)
1.17 pos += 1
1.18
1.19 + # Position the module in the image and make a translation.
1.20 +
1.21 + module.location = pos
1.22 + trans = micropython.ast.Translation(module, objtable, paramtable)
1.23 +
1.24 # Add header details.
1.25
1.26 image.append(module)
1.27 @@ -126,12 +126,11 @@
1.28 # Append classes and functions to the image.
1.29
1.30 for obj in module.all_objects:
1.31 -
1.32 - # Fix the attributes.
1.33 + if isinstance(obj, micropython.inspect.Class):
1.34
1.35 - obj.finalise_attributes()
1.36 + # Fix the attributes.
1.37
1.38 - if isinstance(obj, micropython.inspect.Class):
1.39 + obj.finalise_attributes()
1.40
1.41 # Position the class in the image.
1.42
1.43 @@ -156,6 +155,10 @@
1.44
1.45 elif isinstance(obj, micropython.inspect.Function):
1.46
1.47 + # Fix the attributes.
1.48 +
1.49 + obj.finalise_attributes()
1.50 +
1.51 # Position the function in the image.
1.52
1.53 obj.location = pos
2.1 --- a/micropython/ast.py Sun Mar 09 02:10:12 2008 +0100
2.2 +++ b/micropython/ast.py Sun Mar 09 02:46:57 2008 +0100
2.3 @@ -181,7 +181,7 @@
2.4 target_name = target.full_name()
2.5 table_entry = self.objtable.table[target_name]
2.6 pos = table_entry[attrname]
2.7 - self.replace_op(AttrInstruction(pos + target.location))
2.8 + self.replace_op(AttrInstruction(pos))
2.9
2.10 # Where the last operation involves the special 'self' name, check to
2.11 # see if the attribute is acceptably positioned.
2.12 @@ -324,7 +324,7 @@
2.13 self.new_op(LoadContext())
2.14 self.new_op(CheckContext())
2.15 self.new_op(JumpIfTrue(continue_label))
2.16 - self.new_op(LoadConst("TypeError")) # NOTE: Do this properly!
2.17 + self.new_op(LoadConst(Const("TypeError"))) # NOTE: Do this properly!
2.18 self.new_op(RaiseException())
2.19 self.set_label(continue_label)
2.20
2.21 @@ -503,7 +503,7 @@
2.22 # Only store the name when visiting this node from outside.
2.23
2.24 if self.unit is not node.unit:
2.25 - self.new_op(LoadConst(Const(node.unit)))
2.26 + self.new_op(LoadConst(node.unit))
2.27 self._visitName(node, (StoreName, StoreAttr))
2.28
2.29 # Visiting of the code occurs when get_code is invoked on this node.
3.1 --- a/micropython/inspect.py Sun Mar 09 02:10:12 2008 +0100
3.2 +++ b/micropython/inspect.py Sun Mar 09 02:46:57 2008 +0100
3.3 @@ -257,11 +257,10 @@
3.4
3.5 class Const:
3.6
3.7 - "A constant object with no parent defined as its context."
3.8 + "A constant object with no context."
3.9
3.10 def __init__(self, value):
3.11 self.value = value
3.12 - self.parent = None
3.13
3.14 # Image generation details.
3.15
3.16 @@ -656,7 +655,7 @@
3.17 self[name].position = i
3.18
3.19 j = i
3.20 - for i, attr in enumerate(self.locals()):
3.21 + for i, attr in enumerate(self.locals().values()):
3.22 attr.position = i + j
3.23
3.24 class UnresolvedName(NamespaceDict):
4.1 --- a/micropython/rsvp.py Sun Mar 09 02:10:12 2008 +0100
4.2 +++ b/micropython/rsvp.py Sun Mar 09 02:46:57 2008 +0100
4.3 @@ -34,24 +34,58 @@
4.4 else:
4.5 return "%s()" % self.__class__.__name__
4.6
4.7 +class StackRelativeInstruction(Instruction):
4.8 +
4.9 + "An instruction operating on the local value stack."
4.10 +
4.11 + def __repr__(self):
4.12 + return "%s(%r)" % (self.__class__.__name__, self.attr.position)
4.13 +
4.14 +SR = StackRelativeInstruction
4.15 +
4.16 +class AddressRelativeInstruction(Instruction):
4.17 +
4.18 + "An instruction accessing an object's attribute."
4.19 +
4.20 + def __repr__(self):
4.21 + position = self.attr.position
4.22 + if isinstance(self.attr.parent, Instance):
4.23 + location = "instance"
4.24 + result = position
4.25 + else:
4.26 + location = self.attr.parent.location
4.27 + result = location + position + 1
4.28 + return "%s(%r, %r -> %r)" % (self.__class__.__name__, location, position, result)
4.29 +
4.30 +AR = AddressRelativeInstruction
4.31 +
4.32 +class ImmediateInstruction(Instruction):
4.33 +
4.34 + "An instruction loading an address directly."
4.35 +
4.36 + def __repr__(self):
4.37 + return "%s(%r)" % (self.__class__.__name__, self.attr.location)
4.38 +
4.39 +Immediate = ImmediateInstruction
4.40 +
4.41 # Instructions operating on the value stack.
4.42
4.43 -class LoadConst(Instruction): "Load the constant from the specified location."
4.44 +class LoadConst(Immediate): "Load the constant from the specified location."
4.45 class Duplicate(Instruction): "Duplicate the top of stack."
4.46 class Pop(Instruction): "Pop the top of stack."
4.47
4.48 # Access within an invocation frame.
4.49
4.50 -class LoadName(Instruction): "Load the object from the given local attribute/variable."
4.51 -class StoreName(Instruction): "Store the object in the given local attribute/variable."
4.52 +class LoadName(SR): "Load the object from the given local attribute/variable."
4.53 +class StoreName(SR): "Store the object in the given local attribute/variable."
4.54
4.55 # Access to address-relative data.
4.56
4.57 class MakeObject(Instruction): "Make a new object."
4.58 # ... DropObject not defined: Assume garbage collection.
4.59 -class LoadAttr(Instruction): "Load the object from the given attribute."
4.60 +class LoadAttr(AR): "Load the object from the given attribute."
4.61 +class StoreAttr(AR): "Store an object in the given attribute."
4.62 class LoadAttrIndex(Instruction): "Load the object for the attribute with the given index."
4.63 -class StoreAttr(Instruction): "Store an object in the given attribute."
4.64 class StoreAttrIndex(Instruction): "Store an object in the attribute with the given index."
4.65
4.66 # Access to invocation frames in preparation.
5.1 --- a/test.py Sun Mar 09 02:10:12 2008 +0100
5.2 +++ b/test.py Sun Mar 09 02:46:57 2008 +0100
5.3 @@ -3,8 +3,8 @@
5.4 import micropython
5.5 import sys
5.6
5.7 -def show(importer):
5.8 - for i, x in enumerate(importer.get_image()):
5.9 +def show(importer, with_builtins=0):
5.10 + for i, x in enumerate(importer.get_image(with_builtins=with_builtins)):
5.11 print i, x
5.12
5.13 def attrs(obj):