1.1 --- a/rsvp.py Sat Oct 10 01:52:27 2009 +0200
1.2 +++ b/rsvp.py Sat Oct 10 03:09:29 2009 +0200
1.3 @@ -52,7 +52,7 @@
1.4 current callable
1.5 """
1.6
1.7 -from micropython.program import ReplaceableContext, PlaceholderContext, FragmentObject
1.8 +from micropython.program import DataValue, ReplaceableContext, PlaceholderContext, FragmentObject
1.9 from rsvplib import Library
1.10
1.11 class IllegalInstruction(Exception):
1.12 @@ -281,10 +281,10 @@
1.13 # NOTE: Assumptions about headers and content made.
1.14
1.15 attr_location = module.location + 1 + attr.position
1.16 - context, ref = self.load(attr_location)
1.17 + value = self.load(attr_location)
1.18
1.19 - if ref is not None:
1.20 - content = self.load(ref + 1)
1.21 + if value is not None:
1.22 + content = self.load(value.ref + 1)
1.23 print label, expected, content
1.24 success = success and (int(expected) == content)
1.25 else:
1.26 @@ -380,13 +380,13 @@
1.27 # Instructions.
1.28
1.29 def LoadConst(self):
1.30 - self.value = self.operand, self.operand
1.31 + self.value = DataValue(self.operand, self.operand)
1.32
1.33 def LoadClass(self):
1.34 - self.value = PlaceholderContext, self.operand
1.35 + self.value = DataValue(PlaceholderContext, self.operand)
1.36
1.37 def LoadFunction(self):
1.38 - self.value = ReplaceableContext, self.operand
1.39 + self.value = DataValue(ReplaceableContext, self.operand)
1.40
1.41 def LoadName(self):
1.42 frame = self.local_sp_stack[-1]
1.43 @@ -407,14 +407,14 @@
1.44 self.value = self.load(self.operand)
1.45
1.46 def LoadAddressContext(self):
1.47 - context, ref = self.load(self.operand)
1.48 - inst_context, inst_ref = self.value
1.49 - self.value = inst_ref, ref
1.50 + value = self.load(self.operand)
1.51 + inst_value = self.value
1.52 + self.value = DataValue(inst_value.ref, value.ref)
1.53
1.54 def LoadAddressContextCond(self):
1.55 - context, ref = self.load(self.operand)
1.56 - inst_context, inst_ref = self.value
1.57 - self.value = self._LoadAddressContextCond(context, ref, inst_ref)
1.58 + value = self.load(self.operand)
1.59 + inst_value = self.value
1.60 + self.value = self._LoadAddressContextCond(value.context, value.ref, inst_value.ref)
1.61
1.62 def StoreAddress(self):
1.63 # Preserve context.
1.64 @@ -422,43 +422,43 @@
1.65
1.66 def StoreAddressContext(self):
1.67 # Overwrite context if null.
1.68 - context_context, context_ref = self.value
1.69 - source_context, source_ref = self.source
1.70 - if source_context is ReplaceableContext:
1.71 - context = context_ref
1.72 + context_value = self.value
1.73 + source_value = self.source
1.74 + if source_value.context is ReplaceableContext:
1.75 + context = context_value.ref
1.76 else:
1.77 - context = source_context
1.78 - self.save(self.operand, (context, source_ref))
1.79 + context = source_value.context
1.80 + self.save(self.operand, DataValue(context, source_value.ref))
1.81
1.82 def MakeInstance(self):
1.83 size = self.operand
1.84 - context, ref = self.value
1.85 + value = self.value
1.86 # NOTE: Referencing the instance template.
1.87 - addr = self._MakeObject(size, ref - 1)
1.88 + addr = self._MakeObject(size, value.ref - 1)
1.89 # Introduce object as context for the new object.
1.90 - self.value = addr, addr
1.91 + self.value = DataValue(addr, addr)
1.92
1.93 def MakeFragment(self):
1.94 size = self.operand
1.95 addr = self._MakeFragment(size)
1.96 # NOTE: Context is not relevant for fragments.
1.97 - self.value = None, addr
1.98 + self.value = DataValue(None, addr)
1.99
1.100 def LoadAttr(self):
1.101 - context, ref = self.value
1.102 + value = self.value
1.103 # Retrieved context should already be appropriate for the instance.
1.104 # NOTE: Adding 1 to skip any header.
1.105 - self.value = self.load(ref + self.operand + 1)
1.106 + self.value = self.load(value.ref + self.operand + 1)
1.107
1.108 def StoreAttr(self):
1.109 - context, ref = self.value
1.110 + value = self.value
1.111 # Target should already be an instance.
1.112 # NOTE: Adding 1 to skip any header.
1.113 - self.save(ref + self.operand + 1, self.source)
1.114 + self.save(value.ref + self.operand + 1, self.source)
1.115
1.116 def LoadAttrIndex(self):
1.117 - context, ref = self.value
1.118 - data = self.load(ref)
1.119 + value = self.value
1.120 + data = self.load(value.ref)
1.121 element = self.objlist[data.classcode + self.operand]
1.122
1.123 if element is not None:
1.124 @@ -467,7 +467,7 @@
1.125 if static_attr:
1.126 self.value = self.load(offset) # offset is address of class/module attribute
1.127 else:
1.128 - self.value = self.load(ref + offset)
1.129 + self.value = self.load(value.ref + offset)
1.130 return
1.131
1.132 self.exception = self._MakeObject(2, self.attr_error_instance)
1.133 @@ -476,29 +476,29 @@
1.134 # LoadAttrIndexContext not defined.
1.135
1.136 def LoadAttrIndexContextCond(self):
1.137 - inst_context, inst_ref = self.value
1.138 - data = self.load(inst_ref)
1.139 + inst_value = self.value
1.140 + data = self.load(inst_value.ref)
1.141 element = self.objlist[data.classcode + self.operand]
1.142
1.143 if element is not None:
1.144 attr_index, static_attr, offset = element
1.145 if attr_index == self.operand:
1.146 if static_attr:
1.147 - loaded_context, loaded_ref = self.load(offset) # offset is address of class/module attribute
1.148 + loaded_value = self.load(offset) # offset is address of class/module attribute
1.149 if data.attrcode is None: # absent attrcode == class/module
1.150 - self.value = loaded_context, loaded_ref
1.151 + self.value = loaded_value
1.152 else:
1.153 - self.value = self._LoadAddressContextCond(loaded_context, loaded_ref, inst_ref)
1.154 + self.value = self._LoadAddressContextCond(loaded_value.context, loaded_value.ref, inst_value.ref)
1.155 else:
1.156 - self.value = self.load(inst_ref + offset)
1.157 + self.value = self.load(inst_value.ref + offset)
1.158 return
1.159
1.160 self.exception = self._MakeObject(2, self.attr_error_instance)
1.161 return self.RaiseException()
1.162
1.163 def StoreAttrIndex(self):
1.164 - context, ref = self.value
1.165 - data = self.load(ref)
1.166 + value = self.value
1.167 + data = self.load(value.ref)
1.168 element = self.objlist[data.classcode + self.operand]
1.169
1.170 if element is not None:
1.171 @@ -508,7 +508,7 @@
1.172 self.exception = self._MakeObject(2, self.type_error_instance)
1.173 return self.RaiseException()
1.174 else:
1.175 - self.save(ref + offset, self.source)
1.176 + self.save(value.ref + offset, self.source)
1.177 return
1.178
1.179 self.exception = self._MakeObject(2, self.attr_error_instance)
1.180 @@ -530,9 +530,9 @@
1.181 self.frame_stack[frame + self.operand] = self.value
1.182
1.183 def StoreFrameIndex(self):
1.184 - context, ref = self.value
1.185 + value = self.value
1.186 frame = self.invocation_sp_stack[-1] # different from the current frame after MakeFrame
1.187 - data = self.load(ref)
1.188 + data = self.load(value.ref)
1.189 element = self.paramlist[data.funccode + self.operand]
1.190
1.191 if element is not None:
1.192 @@ -546,32 +546,32 @@
1.193 return self.RaiseException()
1.194
1.195 def LoadCallable(self):
1.196 - context, ref = self.value
1.197 - data = self.load(ref)
1.198 + value = self.value
1.199 + data = self.load(value.ref)
1.200 self.callable = data.codeaddr
1.201
1.202 def StoreCallable(self):
1.203 - context, ref = self.value
1.204 + value = self.value
1.205 # NOTE: Should improve the representation and permit direct saving.
1.206 - data = self.load(ref)
1.207 - self.save(ref, data.with_callable(self.callable))
1.208 + data = self.load(value.ref)
1.209 + self.save(value.ref, data.with_callable(self.callable))
1.210
1.211 def LoadContext(self):
1.212 - context, ref = self.value
1.213 + value = self.value
1.214 # NOTE: Omission of the context of the context would make things like
1.215 # NOTE: self() inside methods impossible.
1.216 - self.value = context, context
1.217 + self.value = DataValue(value.context, value.context)
1.218
1.219 def CheckContext(self):
1.220 - self.status = self.value[1] is not ReplaceableContext
1.221 + self.status = self.value.ref is not ReplaceableContext
1.222
1.223 def CheckClass(self):
1.224 - context, ref = self.value
1.225 - if ref in (ReplaceableContext, PlaceholderContext):
1.226 + value = self.value
1.227 + if value.ref in (ReplaceableContext, PlaceholderContext):
1.228 self.status = 0
1.229 return
1.230
1.231 - data = self.load(ref)
1.232 + data = self.load(value.ref)
1.233
1.234 # Classes are not themselves usable as the self argument.
1.235 # NOTE: This may change at some point.
1.236 @@ -609,7 +609,7 @@
1.237 self.frame_stack.extend([None]) # ExtendFrame(1)
1.238
1.239 def FillDefaults(self):
1.240 - context, ref = self.value
1.241 + value = self.value
1.242 (nargs, ndefaults) = self.operand
1.243
1.244 # The frame is actually installed as the locals.
1.245 @@ -625,7 +625,7 @@
1.246 pos = nlocals
1.247
1.248 while pos < nargs:
1.249 - self.frame_stack[frame + pos] = self.load(ref + default + 1) # skip header
1.250 + self.frame_stack[frame + pos] = self.load(value.ref + default + 1) # skip header
1.251 default += 1
1.252 pos += 1
1.253
1.254 @@ -649,15 +649,15 @@
1.255 extra += 1
1.256 pos += 1
1.257
1.258 - self.value = ref, ref
1.259 + self.value = DataValue(ref, ref)
1.260
1.261 def CheckSelf(self):
1.262 - context, ref = self.value
1.263 - context_context, context_ref = self.source
1.264 + value = self.value
1.265 + context_value = self.source
1.266
1.267 # Check the details of the proposed context and the target's context.
1.268
1.269 - self.status = self._CheckInstance(ref, context_ref)
1.270 + self.status = self._CheckInstance(value.ref, context_value.ref)
1.271
1.272 def JumpInFrame(self):
1.273 codeaddr = self.callable
1.274 @@ -700,10 +700,10 @@
1.275 return self.operand
1.276
1.277 def LoadException(self):
1.278 - self.value = self.exception, self.exception
1.279 + self.value = DataValue(self.exception, self.exception)
1.280
1.281 def StoreException(self):
1.282 - self.exception = self.value[1]
1.283 + self.exception = self.value.ref
1.284
1.285 def ClearException(self):
1.286 self.exception = None
1.287 @@ -729,13 +729,13 @@
1.288 self.handler_stack.pop()
1.289
1.290 def CheckException(self):
1.291 - self.status = self.exception is not None and self._CheckInstance(self.exception, self.value[1])
1.292 + self.status = self.exception is not None and self._CheckInstance(self.exception, self.value.ref)
1.293
1.294 def TestIdentity(self):
1.295 - self.status = self.value[1] == self.source[1]
1.296 + self.status = self.value.ref == self.source.ref
1.297
1.298 def TestIdentityAddress(self):
1.299 - self.status = self.value[1] == self.operand
1.300 + self.status = self.value.ref == self.operand
1.301
1.302 # LoadBoolean is implemented in the generated code.
1.303 # StoreBoolean is implemented by testing against the True value.
1.304 @@ -787,9 +787,9 @@
1.305 # This provides the context overriding for methods.
1.306 if context is ReplaceableContext or context is not PlaceholderContext and self._CheckInstance(inst_ref, context):
1.307 # Replace the context with the instance.
1.308 - return inst_ref, ref
1.309 + return DataValue(inst_ref, ref)
1.310 else:
1.311 - return context, ref
1.312 + return DataValue(context, ref)
1.313
1.314 # Convenience functions.
1.315