1.1 --- a/micropython/rsvp.py Thu Sep 01 00:35:47 2011 +0200
1.2 +++ b/micropython/rsvp.py Mon Sep 05 00:16:33 2011 +0200
1.3 @@ -297,14 +297,18 @@
1.4
1.5 "A generic instruction."
1.6
1.7 + default_working = "working"
1.8 + default_target = "working"
1.9 + default_source = None
1.10 +
1.11 # NOTE: Ultimately, instructions apart from Transfer will use specific
1.12 # NOTE: registers such as "working_value" and "working_context".
1.13
1.14 - def __init__(self, attr=None, working="working", target="working", source=None):
1.15 + def __init__(self, attr=None, working=None, target=None, source=None):
1.16 self.attr = attr
1.17 - self.working = working
1.18 - self.target = target
1.19 - self.source = source
1.20 + self.working = working or self.default_working
1.21 + self.target = target or self.default_target
1.22 + self.source = source or self.default_source
1.23
1.24 def get_details(self):
1.25 return self.__class__, self.attr, self.working, self.target, self.source
1.26 @@ -333,13 +337,13 @@
1.27 return repr(operand)
1.28
1.29 def format_working(self):
1.30 - return self.working != "working" and (", working=%r" % self.working) or ""
1.31 + return self.working != self.default_working and (", working=%r" % self.working) or ""
1.32
1.33 def format_source(self):
1.34 - return self.source is not None and (", source=%r" % self.source) or ""
1.35 + return self.source != self.default_source and (", source=%r" % self.source) or ""
1.36
1.37 def format_target(self):
1.38 - return self.target != "working" and (", target=%r" % self.target) or ""
1.39 + return self.target != self.default_target and (", target=%r" % self.target) or ""
1.40
1.41 def get_operand(self):
1.42 return None
1.43 @@ -463,6 +467,7 @@
1.44 class StoreName(FR):
1.45 "Store the source value into the given local attribute/variable."
1.46 cost = 2
1.47 + default_target = None
1.48
1.49 class LoadTemp(Immediate):
1.50 "Load the current value from the given temporary location."
1.51 @@ -471,6 +476,7 @@
1.52 class StoreTemp(Immediate):
1.53 "Store the current value into the given temporary location."
1.54 cost = 2
1.55 + default_target = None
1.56
1.57 # Access to static data.
1.58
1.59 @@ -481,6 +487,8 @@
1.60 class StoreAddress(Address):
1.61 "Store the source value into the given fixed attribute address."
1.62 cost = 1
1.63 + default_working = None
1.64 + default_target = None
1.65
1.66 class LoadAddressContext(Address):
1.67 "Load the current value from the given fixed attribute address, using the current value as context."
1.68 @@ -489,6 +497,7 @@
1.69 class StoreAddressContext(Address):
1.70 "Store the current value into the given fixed attribute address, using the current value as context."
1.71 cost = 2
1.72 + default_target = None
1.73
1.74 class LoadAddressContextCond(Address):
1.75 """
1.76 @@ -514,6 +523,7 @@
1.77 class StoreAttr(AR):
1.78 "Store the source value into the given attribute of the object referenced by the current value."
1.79 cost = 2
1.80 + default_target = None
1.81
1.82 class LoadAttrIndex(Immediate):
1.83 "Load into the current value the attribute of the current value with the given index."
1.84 @@ -522,6 +532,7 @@
1.85 class StoreAttrIndex(Immediate):
1.86 "Store the source value into the attribute of the current value with the given index."
1.87 cost = 6
1.88 + default_target = None
1.89
1.90 class LoadAttrIndexContextCond(Immediate):
1.91 """
1.92 @@ -539,28 +550,34 @@
1.93 class StoreCallable(Instruction):
1.94 "Store the source value into the object referenced by the current value."
1.95 cost = 3
1.96 + default_target = None
1.97
1.98 # Access to invocation frames in preparation.
1.99
1.100 class MakeFrame(Immediate):
1.101 "Make a new invocation frame."
1.102 cost = 2
1.103 + default_target = None
1.104
1.105 class AdjustFrame(Immediate):
1.106 "Adjust the current invocation frame for corrected invocations."
1.107 cost = 2
1.108 + default_target = None
1.109
1.110 class DropFrame(Instruction):
1.111 "Drop an invocation frame."
1.112 cost = 2
1.113 + default_target = None
1.114
1.115 class StoreFrame(Immediate):
1.116 "Store the current value as an argument for the parameter with the given position."
1.117 cost = 2
1.118 + default_target = None
1.119
1.120 class StoreFrameIndex(Immediate):
1.121 "Store the source value as an argument of the current value for the parameter with the given index."
1.122 cost = 6
1.123 + default_target = None
1.124
1.125 # Context-related tests.
1.126
1.127 @@ -592,10 +609,12 @@
1.128 class FillDefaults(Immediate):
1.129 "Fill frame positions with defaults, if appropriate."
1.130 cost = 8 # variable
1.131 + default_target = None
1.132
1.133 class ExtendFrame(Immediate):
1.134 "Extend the current frame for temporary storage use."
1.135 cost = 1
1.136 + default_target = None
1.137
1.138 class CopyExtra(Immediate):
1.139 "Copy extra arguments into a separate sequence, starting from the given position."
1.140 @@ -606,46 +625,56 @@
1.141 class JumpInFrame(Instruction):
1.142 "Jump, using the current locals, to the current callable."
1.143 cost = 2
1.144 + default_target = None
1.145
1.146 class JumpWithFrame(Instruction):
1.147 "Jump, adopting the invocation frame, to the current callable."
1.148 cost = 3
1.149 + default_target = None
1.150
1.151 class JumpWithFrameDirect(Target):
1.152 "Jump to the specified address, adopting the invocation frame."
1.153 cost = 3
1.154 + default_target = None
1.155
1.156 class Return(Instruction):
1.157 "Return from a subprogram."
1.158 cost = 2
1.159 + default_target = None
1.160
1.161 # Branch-related instructions.
1.162
1.163 class Jump(Address):
1.164 "Jump unconditionally."
1.165 cost = 1
1.166 + default_target = None
1.167
1.168 class JumpIfFalse(Address):
1.169 "Jump if the last evaluation gave a false result."
1.170 cost = 2
1.171 + default_target = None
1.172
1.173 class JumpIfTrue(Address):
1.174 "Jump if the last evaluation gave a true result."
1.175 cost = 2
1.176 + default_target = None
1.177
1.178 # Exception-related instructions, using a special exception "register".
1.179
1.180 class RaiseException(Instruction):
1.181 "Raise an exception, jumping to the active handler."
1.182 cost = 2
1.183 + default_target = None
1.184
1.185 class PushHandler(Address):
1.186 "Push an exception handler onto the handler stack."
1.187 cost = 3
1.188 + default_target = None
1.189
1.190 class PopHandler(Immediate):
1.191 "Pop exception handlers from the handler stack."
1.192 cost = 3
1.193 + default_target = None
1.194
1.195 class CheckException(Instruction):
1.196 "Check the raised exception against another."
1.197 @@ -671,16 +700,15 @@
1.198
1.199 # Instructions which can affect the current value. (LoadAttrIndexContext not defined.)
1.200
1.201 -current_value_instructions = (
1.202 - Transfer,
1.203 - LoadConst, LoadClass, LoadFunction,
1.204 - LoadName, LoadTemp,
1.205 - LoadAddress, LoadAddressContext, LoadAddressContextCond,
1.206 - LoadAttr, LoadAttrIndex, LoadAttrIndexContextCond,
1.207 - LoadCallable,
1.208 - MakeInstance, MakeFragment,
1.209 - CopyExtra,
1.210 - CheckClass, CheckContext, CheckException, CheckInstance, CheckFrame, CheckExtra
1.211 - )
1.212 +def affects_register(instruction, register):
1.213 +
1.214 + """
1.215 + Returns whether 'instruction' affects the given 'register', either directly
1.216 + or as a consequence of its execution.
1.217 + """
1.218 +
1.219 + return instruction.target == register or isinstance(instruction, (
1.220 + JumpWithFrame, JumpWithFrameDirect, JumpIfTrue, JumpIfFalse, Jump
1.221 + ))
1.222
1.223 # vim: tabstop=4 expandtab shiftwidth=4