1.1 --- a/micropython/rsvp.py Sun Mar 09 02:10:12 2008 +0100
1.2 +++ b/micropython/rsvp.py Sun Mar 09 02:46:57 2008 +0100
1.3 @@ -34,24 +34,58 @@
1.4 else:
1.5 return "%s()" % self.__class__.__name__
1.6
1.7 +class StackRelativeInstruction(Instruction):
1.8 +
1.9 + "An instruction operating on the local value stack."
1.10 +
1.11 + def __repr__(self):
1.12 + return "%s(%r)" % (self.__class__.__name__, self.attr.position)
1.13 +
1.14 +SR = StackRelativeInstruction
1.15 +
1.16 +class AddressRelativeInstruction(Instruction):
1.17 +
1.18 + "An instruction accessing an object's attribute."
1.19 +
1.20 + def __repr__(self):
1.21 + position = self.attr.position
1.22 + if isinstance(self.attr.parent, Instance):
1.23 + location = "instance"
1.24 + result = position
1.25 + else:
1.26 + location = self.attr.parent.location
1.27 + result = location + position + 1
1.28 + return "%s(%r, %r -> %r)" % (self.__class__.__name__, location, position, result)
1.29 +
1.30 +AR = AddressRelativeInstruction
1.31 +
1.32 +class ImmediateInstruction(Instruction):
1.33 +
1.34 + "An instruction loading an address directly."
1.35 +
1.36 + def __repr__(self):
1.37 + return "%s(%r)" % (self.__class__.__name__, self.attr.location)
1.38 +
1.39 +Immediate = ImmediateInstruction
1.40 +
1.41 # Instructions operating on the value stack.
1.42
1.43 -class LoadConst(Instruction): "Load the constant from the specified location."
1.44 +class LoadConst(Immediate): "Load the constant from the specified location."
1.45 class Duplicate(Instruction): "Duplicate the top of stack."
1.46 class Pop(Instruction): "Pop the top of stack."
1.47
1.48 # Access within an invocation frame.
1.49
1.50 -class LoadName(Instruction): "Load the object from the given local attribute/variable."
1.51 -class StoreName(Instruction): "Store the object in the given local attribute/variable."
1.52 +class LoadName(SR): "Load the object from the given local attribute/variable."
1.53 +class StoreName(SR): "Store the object in the given local attribute/variable."
1.54
1.55 # Access to address-relative data.
1.56
1.57 class MakeObject(Instruction): "Make a new object."
1.58 # ... DropObject not defined: Assume garbage collection.
1.59 -class LoadAttr(Instruction): "Load the object from the given attribute."
1.60 +class LoadAttr(AR): "Load the object from the given attribute."
1.61 +class StoreAttr(AR): "Store an object in the given attribute."
1.62 class LoadAttrIndex(Instruction): "Load the object for the attribute with the given index."
1.63 -class StoreAttr(Instruction): "Store an object in the given attribute."
1.64 class StoreAttrIndex(Instruction): "Store an object in the attribute with the given index."
1.65
1.66 # Access to invocation frames in preparation.