1.1 --- a/micropython/rsvp.py Sat Apr 26 18:35:18 2008 +0200
1.2 +++ b/micropython/rsvp.py Sun Apr 27 03:11:12 2008 +0200
1.3 @@ -25,6 +25,9 @@
1.4
1.5 "A generic instruction."
1.6
1.7 + stack_usage = 0
1.8 + stack_temp_usage = 0
1.9 +
1.10 def __init__(self, attr=None):
1.11 self.attr = attr
1.12
1.13 @@ -85,48 +88,86 @@
1.14
1.15 Immediate = ImmediateInstruction
1.16
1.17 +# Mix-in classes for stack effects.
1.18 +
1.19 +class StackAdd:
1.20 +
1.21 + """
1.22 + Indicate that the stack must grow to accommodate the result of this
1.23 + instruction.
1.24 + """
1.25 +
1.26 + stack_usage = 1
1.27 +
1.28 +class StackRemove:
1.29 +
1.30 + "Indicate that the stack must shrink as an effect of this instruction."
1.31 +
1.32 + stack_usage = -1
1.33 +
1.34 +class StackRemove2:
1.35 +
1.36 + "Indicate that the stack must shrink as an effect of this instruction."
1.37 +
1.38 + stack_usage = -2
1.39 +
1.40 +class TempAdd:
1.41 +
1.42 + "Indicate that one more temporary storage location is now required."
1.43 +
1.44 + stack_temp_usage = 1
1.45 +
1.46 +class TempRemove:
1.47 +
1.48 + "Indicate that one fewer temporary storage location is now required."
1.49 +
1.50 + stack_temp_usage = -1
1.51 +
1.52 # Instructions operating on the value stack.
1.53
1.54 -class LoadConst(Address): "Load the constant from the specified location."
1.55 -class Duplicate(Instruction): "Duplicate the top of stack."
1.56 -class Pop(Instruction): "Pop the top of stack."
1.57 +class LoadConst(StackAdd, Address): "Load the constant from the specified location."
1.58 +class Duplicate(StackAdd, Instruction): "Duplicate the top of the stack."
1.59 +class Pop(StackRemove, Immediate): "Pop entries from the top of the stack."
1.60
1.61 # Access within an invocation frame.
1.62
1.63 -class LoadName(SR): "Load the object from the given local attribute/variable."
1.64 -class StoreName(SR): "Store the object in the given local attribute/variable."
1.65 -class LoadTemp(SR): "Load the object from the given temporary location."
1.66 -class StoreTemp(SR): "Store the object in the given temporary location."
1.67 +class LoadName(StackAdd, SR): "Load the object from the given local attribute/variable."
1.68 +class StoreName(StackRemove, SR): "Store the object in the given local attribute/variable."
1.69 +class LoadTemp(TempAdd, SR): "Load the object from the given temporary location."
1.70 +class StoreTemp(SR): "Store the object in the given temporary location."
1.71
1.72 # Access to address-relative data.
1.73
1.74 -class MakeObject(Instruction): "Make a new object."
1.75 -# ... DropObject not defined: Assume garbage collection.
1.76 -class LoadAttr(AR): "Load the object from the given attribute."
1.77 -class StoreAttr(AR): "Store an object in the given attribute."
1.78 -class LoadAttrIndex(Immediate): "Load the object for the attribute with the given index."
1.79 -class StoreAttrIndex(Immediate): "Store an object in the attribute with the given index."
1.80 +class MakeObject(StackAdd, Instruction): "Make a new object."
1.81 +# ... DropObject not defined: Assume garbage collection.
1.82 +class LoadAttr(AR): "Load the object from the given attribute."
1.83 +class StoreAttr(StackRemove2, AR): "Store an object in the given attribute."
1.84 +class LoadAttrIndex(Immediate): "Load the object for the attribute with the given index."
1.85 +class StoreAttrIndex(StackRemove2, Immediate): "Store an object in the attribute with the given index."
1.86 +class LoadAddress(StackAdd, AR): "Load the object from the given fixed attribute address."
1.87 +class StoreAddress(StackRemove, AR): "Store an object in the given fixed attribute address."
1.88
1.89 # Access to invocation frames in preparation.
1.90
1.91 -class MakeFrame(Instruction): "Make a new invocation frame."
1.92 -class ReserveFrame(Immediate): "Reserve the given number of entries for the invocation frame."
1.93 -class DropFrame(Instruction): "Drop an invocation frame."
1.94 -class StoreFrame(Instruction): "Store an argument at the given frame location."
1.95 -class StoreFrameIndex(Immediate): "Store an argument for the parameter with the given index."
1.96 -class CheckFrame(Instruction): "Check the invocation frame for the target."
1.97 -class JumpWithFrame(Instruction): "Jump, adopting the invocation frame."
1.98 +class MakeFrame(Instruction): "Make a new invocation frame."
1.99 +class ReserveFrame(Immediate): "Reserve the given number of entries for the invocation frame."
1.100 +class DropFrame(Instruction): "Drop an invocation frame."
1.101 +class StoreFrame(StackRemove, Instruction): "Store an argument at the given frame location."
1.102 +class StoreFrameIndex(StackRemove, Immediate): "Store an argument for the parameter with the given index."
1.103 +class CheckFrame(Instruction): "Check the invocation frame for the target."
1.104 +class JumpWithFrame(Instruction): "Jump, adopting the invocation frame."
1.105
1.106 # Invocation-related instructions.
1.107
1.108 -class Jump(Instruction): "Jump unconditionally."
1.109 -class JumpIfFalse(Instruction): "Jump if the last evaluation gave a false result."
1.110 -class JumpIfTrue(Instruction): "Jump if the last evaluation gave a true result."
1.111 -class LoadCallable(Instruction): "Load the target of an invocation."
1.112 -class LoadContext(Instruction): "Load the context of an invocation."
1.113 -class CheckContext(Instruction): "Check the context of an invocation against the target, potentially discarding the context."
1.114 -class RaiseException(Instruction): "Raise an exception."
1.115 -class Return(Instruction): "Return a value from a subprogram."
1.116 -class CheckException(Instruction): "Check the raised exception against another."
1.117 +class Jump(Instruction): "Jump unconditionally."
1.118 +class JumpIfFalse(Instruction): "Jump if the last evaluation gave a false result."
1.119 +class JumpIfTrue(Instruction): "Jump if the last evaluation gave a true result."
1.120 +class LoadCallable(Instruction): "Load the target of an invocation."
1.121 +class LoadContext(Instruction): "Load the context of an invocation."
1.122 +class CheckContext(Instruction): """Check the context of an invocation against the target,
1.123 + potentially discarding the context."""
1.124 +class RaiseException(Instruction): "Raise an exception."
1.125 +class Return(Instruction): "Return a value from a subprogram."
1.126 +class CheckException(Instruction): "Check the raised exception against another."
1.127
1.128 # vim: tabstop=4 expandtab shiftwidth=4