paul@68 | 1 | #!/usr/bin/env python |
paul@68 | 2 | |
paul@68 | 3 | """ |
paul@68 | 4 | A really simple virtual processor employing a simple set of instructions which |
paul@68 | 5 | ignore low-level operations and merely concentrate on variable access, structure |
paul@68 | 6 | access, structure allocation and function invocations. |
paul@68 | 7 | |
paul@68 | 8 | Copyright (C) 2007, 2008 Paul Boddie <paul@boddie.org.uk> |
paul@68 | 9 | |
paul@68 | 10 | This program is free software; you can redistribute it and/or modify it under |
paul@68 | 11 | the terms of the GNU General Public License as published by the Free Software |
paul@68 | 12 | Foundation; either version 3 of the License, or (at your option) any later |
paul@68 | 13 | version. |
paul@68 | 14 | |
paul@68 | 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@68 | 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@68 | 17 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@68 | 18 | details. |
paul@68 | 19 | |
paul@68 | 20 | You should have received a copy of the GNU General Public License along with |
paul@68 | 21 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@68 | 22 | |
paul@68 | 23 | -------- |
paul@68 | 24 | |
paul@68 | 25 | The execution model of the virtual processor involves the following things: |
paul@68 | 26 | |
paul@145 | 27 | * Memory contains constants, global variable |
paul@145 | 28 | references and program code |
paul@145 | 29 | |
paul@145 | 30 | * PC (program counter) stack contains the return address associated |
paul@145 | 31 | with each function invocation |
paul@145 | 32 | |
paul@145 | 33 | * Frame stack contains invocation frames in use and in |
paul@145 | 34 | preparation plus temporary storage |
paul@145 | 35 | |
paul@145 | 36 | * Local frame pointer stack refers to the frames in the frame stack |
paul@145 | 37 | |
paul@117 | 38 | * Invocation frame pointer stack |
paul@145 | 39 | |
paul@117 | 40 | * Exception handler stack |
paul@68 | 41 | |
paul@145 | 42 | * Exception handler locals stack refers to the state of the local frame |
paul@145 | 43 | pointer stack |
paul@145 | 44 | |
paul@145 | 45 | * Exception handler PC stack refers to the state of the PC stack |
paul@68 | 46 | |
paul@145 | 47 | * Registers: current value, |
paul@145 | 48 | boolean status value, |
paul@145 | 49 | source value, |
paul@145 | 50 | current result, |
paul@145 | 51 | current exception, |
paul@145 | 52 | current callable |
paul@68 | 53 | """ |
paul@68 | 54 | |
paul@68 | 55 | class IllegalInstruction(Exception): |
paul@68 | 56 | pass |
paul@68 | 57 | |
paul@68 | 58 | class IllegalAddress(Exception): |
paul@68 | 59 | pass |
paul@68 | 60 | |
paul@68 | 61 | class EmptyPCStack(Exception): |
paul@68 | 62 | pass |
paul@68 | 63 | |
paul@92 | 64 | class EmptyFrameStack(Exception): |
paul@68 | 65 | pass |
paul@68 | 66 | |
paul@68 | 67 | class RSVPMachine: |
paul@68 | 68 | |
paul@68 | 69 | "A really simple virtual processor." |
paul@68 | 70 | |
paul@146 | 71 | def __init__(self, memory, objlist, paramlist, attr_error, type_error, pc=None, debug=0): |
paul@68 | 72 | |
paul@68 | 73 | """ |
paul@68 | 74 | Initialise the processor with a 'memory' (a list of values containing |
paul@68 | 75 | instructions and data) and the optional program counter 'pc'. |
paul@68 | 76 | """ |
paul@68 | 77 | |
paul@68 | 78 | self.memory = memory |
paul@138 | 79 | self.objlist = objlist |
paul@138 | 80 | self.paramlist = paramlist |
paul@68 | 81 | self.pc = pc or 0 |
paul@68 | 82 | self.debug = debug |
paul@117 | 83 | |
paul@117 | 84 | # Stacks. |
paul@117 | 85 | |
paul@68 | 86 | self.pc_stack = [] |
paul@68 | 87 | self.frame_stack = [] |
paul@143 | 88 | self.local_sp_stack = [0] |
paul@117 | 89 | self.invocation_sp_stack = [] |
paul@145 | 90 | self.handler_stack = [len(self.memory) - 1] # final handler is the end of the code |
paul@145 | 91 | self.handler_local_sp_stack = [] |
paul@145 | 92 | self.handler_pc_stack = [] |
paul@117 | 93 | |
paul@117 | 94 | # Registers. |
paul@117 | 95 | |
paul@119 | 96 | self.instruction = None |
paul@119 | 97 | self.operand = None |
paul@117 | 98 | self.value = None |
paul@117 | 99 | self.status = None |
paul@117 | 100 | self.source = None |
paul@132 | 101 | self.callable = None |
paul@117 | 102 | self.result = None |
paul@117 | 103 | self.exception = None |
paul@68 | 104 | |
paul@146 | 105 | # Constants. |
paul@146 | 106 | |
paul@146 | 107 | self.attr_error = attr_error |
paul@146 | 108 | self.type_error = type_error |
paul@146 | 109 | |
paul@137 | 110 | def dump(self): |
paul@138 | 111 | print "PC", self.pc, "->", self.load(self.pc) |
paul@137 | 112 | print "PC stack", self.pc_stack |
paul@137 | 113 | print "Frame stack", self.frame_stack |
paul@137 | 114 | print "Local stack pointers", self.local_sp_stack |
paul@137 | 115 | print "Invocation stack pointers", self.invocation_sp_stack |
paul@137 | 116 | print "Handler stack", self.handler_stack |
paul@145 | 117 | print "Handler frame stack", self.handler_local_sp_stack |
paul@145 | 118 | print "Handler PC stack", self.handler_pc_stack |
paul@137 | 119 | print |
paul@137 | 120 | print "Instruction", self.instruction |
paul@137 | 121 | print "Operand", self.operand |
paul@137 | 122 | print "Value", self.value |
paul@137 | 123 | print "Status", self.status |
paul@137 | 124 | print "Source", self.source |
paul@137 | 125 | print "Callable", self.callable |
paul@137 | 126 | print "Result", self.result |
paul@137 | 127 | print "Exception", self.exception |
paul@137 | 128 | |
paul@138 | 129 | def step(self): |
paul@138 | 130 | self.execute() |
paul@138 | 131 | self.dump() |
paul@138 | 132 | |
paul@68 | 133 | def load(self, address): |
paul@68 | 134 | |
paul@68 | 135 | "Return the value at the given 'address'." |
paul@68 | 136 | |
paul@68 | 137 | try: |
paul@68 | 138 | return self.memory[address] |
paul@68 | 139 | except IndexError: |
paul@68 | 140 | raise IllegalAddress, address |
paul@68 | 141 | |
paul@68 | 142 | def save(self, address, value): |
paul@68 | 143 | |
paul@68 | 144 | "Save to the given 'address' the specified 'value'." |
paul@68 | 145 | |
paul@68 | 146 | try: |
paul@68 | 147 | self.memory[address] = value |
paul@68 | 148 | except IndexError: |
paul@68 | 149 | raise IllegalAddress, address |
paul@68 | 150 | |
paul@68 | 151 | def new(self, size): |
paul@68 | 152 | |
paul@68 | 153 | """ |
paul@68 | 154 | Allocate space of the given 'size', returning the address of the space. |
paul@68 | 155 | """ |
paul@68 | 156 | |
paul@68 | 157 | addr = len(self.memory) |
paul@68 | 158 | for i in range(0, size): |
paul@68 | 159 | self.memory.append(None) |
paul@68 | 160 | return addr |
paul@68 | 161 | |
paul@68 | 162 | def push_pc(self, data): |
paul@68 | 163 | |
paul@68 | 164 | "Push 'data' onto the PC stack." |
paul@68 | 165 | |
paul@68 | 166 | self.pc_stack.append(data) |
paul@68 | 167 | |
paul@68 | 168 | def pull_pc(self): |
paul@68 | 169 | |
paul@68 | 170 | "Pull a value from the PC stack and return it." |
paul@68 | 171 | |
paul@68 | 172 | try: |
paul@68 | 173 | return self.pc_stack.pop() |
paul@68 | 174 | except IndexError: |
paul@68 | 175 | raise EmptyPCStack |
paul@68 | 176 | |
paul@90 | 177 | def run(self): |
paul@68 | 178 | |
paul@68 | 179 | "Execute code in the memory, starting from the current PC address." |
paul@68 | 180 | |
paul@68 | 181 | try: |
paul@68 | 182 | while 1: |
paul@90 | 183 | self.execute() |
paul@68 | 184 | except EmptyPCStack: |
paul@68 | 185 | pass |
paul@68 | 186 | |
paul@90 | 187 | def execute(self): |
paul@90 | 188 | |
paul@90 | 189 | "Execute code in the memory at the current PC address." |
paul@90 | 190 | |
paul@119 | 191 | self.instruction = self.load(self.pc) |
paul@118 | 192 | |
paul@118 | 193 | # Process any inputs of the instruction. |
paul@118 | 194 | |
paul@119 | 195 | self.process_inputs() |
paul@137 | 196 | |
paul@137 | 197 | # Perform the instruction itself. |
paul@137 | 198 | |
paul@137 | 199 | next_pc = self.perform(self.instruction) |
paul@118 | 200 | |
paul@119 | 201 | # Update the program counter. |
paul@118 | 202 | |
paul@119 | 203 | if next_pc is None: |
paul@119 | 204 | self.pc += 1 |
paul@119 | 205 | else: |
paul@119 | 206 | self.pc = next_pc |
paul@118 | 207 | |
paul@137 | 208 | def get_method(self, instruction): |
paul@137 | 209 | |
paul@137 | 210 | "Return the handler method for the given 'instruction'." |
paul@119 | 211 | |
paul@137 | 212 | instruction_name = instruction.__class__.__name__ |
paul@137 | 213 | if self.debug: |
paul@137 | 214 | print "%8d %s" % (self.pc, instruction_name) |
paul@119 | 215 | method = getattr(self, instruction_name, None) |
paul@90 | 216 | if method is None: |
paul@119 | 217 | raise IllegalInstruction, (self.pc, instruction_name) |
paul@118 | 218 | return method |
paul@118 | 219 | |
paul@137 | 220 | def perform(self, instruction): |
paul@137 | 221 | |
paul@137 | 222 | "Perform the 'instruction', returning the next PC value or None." |
paul@137 | 223 | |
paul@137 | 224 | self.operand = instruction.get_operand() |
paul@137 | 225 | method = self.get_method(instruction) |
paul@137 | 226 | return method() |
paul@137 | 227 | |
paul@119 | 228 | def process_inputs(self): |
paul@118 | 229 | |
paul@118 | 230 | """ |
paul@119 | 231 | Process any inputs of the current instruction. This permits any directly |
paul@118 | 232 | connected sub-instructions to produce the effects that separate |
paul@118 | 233 | instructions would otherwise have. |
paul@118 | 234 | """ |
paul@118 | 235 | |
paul@119 | 236 | for input in (self.instruction.input, self.instruction.source): |
paul@118 | 237 | if input is not None: |
paul@137 | 238 | self.perform(input) |
paul@90 | 239 | |
paul@68 | 240 | def jump(self, addr, next): |
paul@68 | 241 | |
paul@68 | 242 | """ |
paul@68 | 243 | Jump to the subroutine at (or identified by) 'addr'. If 'addr' |
paul@68 | 244 | identifies a library function then invoke the library function and set |
paul@68 | 245 | PC to 'next' afterwards; otherwise, set PC to 'addr'. |
paul@68 | 246 | """ |
paul@68 | 247 | |
paul@68 | 248 | if isinstance(addr, str): |
paul@68 | 249 | getattr(self, addr)() |
paul@119 | 250 | return next |
paul@68 | 251 | else: |
paul@138 | 252 | self.push_pc(self.pc + 1) |
paul@119 | 253 | return addr |
paul@68 | 254 | |
paul@68 | 255 | # Instructions. |
paul@68 | 256 | |
paul@98 | 257 | def LoadConst(self): |
paul@119 | 258 | self.value = None, self.operand |
paul@68 | 259 | |
paul@68 | 260 | def LoadName(self): |
paul@117 | 261 | frame = self.local_sp_stack[-1] |
paul@119 | 262 | self.value = self.frame_stack[frame + self.operand] |
paul@68 | 263 | |
paul@68 | 264 | def StoreName(self): |
paul@117 | 265 | frame = self.local_sp_stack[-1] |
paul@119 | 266 | self.frame_stack[frame + self.operand] = self.value |
paul@68 | 267 | |
paul@72 | 268 | LoadTemp = LoadName |
paul@72 | 269 | StoreTemp = StoreName |
paul@72 | 270 | |
paul@72 | 271 | def LoadAddress(self): |
paul@119 | 272 | # Preserve context (potentially null). |
paul@119 | 273 | self.value = self.load(self.operand) |
paul@72 | 274 | |
paul@117 | 275 | def LoadAddressContext(self): |
paul@119 | 276 | value = self.load(self.operand) |
paul@119 | 277 | # Replace the context with the current value. |
paul@119 | 278 | self.value = self.value[1], value[1] |
paul@72 | 279 | |
paul@72 | 280 | def StoreAddress(self): |
paul@119 | 281 | # Preserve context. |
paul@119 | 282 | self.save(self.operand, self.value) |
paul@72 | 283 | |
paul@117 | 284 | def MakeObject(self): |
paul@138 | 285 | size = self.operand |
paul@138 | 286 | context, ref = self.value |
paul@145 | 287 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@138 | 288 | addr = self.new(size) |
paul@138 | 289 | # Set the header to resemble the class. |
paul@145 | 290 | self.save(addr, (classcode, attrcode, None, None, 1)) # NOTE: __call__ method not yet provided. |
paul@119 | 291 | # Introduce null context for new object. |
paul@138 | 292 | self.value = None, addr |
paul@72 | 293 | |
paul@118 | 294 | def LoadAttr(self): |
paul@118 | 295 | context, ref = self.value |
paul@127 | 296 | # Retrieved context should already be appropriate for the instance. |
paul@127 | 297 | self.value = self.load(ref + self.operand) |
paul@118 | 298 | |
paul@118 | 299 | def StoreAttr(self): |
paul@119 | 300 | context, ref = self.value |
paul@129 | 301 | # Target should already be an instance. |
paul@119 | 302 | self.save(ref + self.operand, self.source) |
paul@119 | 303 | |
paul@119 | 304 | def LoadAttrIndex(self): |
paul@118 | 305 | context, ref = self.value |
paul@145 | 306 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@138 | 307 | element = self.objlist[classcode + self.operand] |
paul@135 | 308 | attr_index, class_attr, replace_context, offset = element |
paul@135 | 309 | if attr_index == self.operand: |
paul@127 | 310 | if class_attr: |
paul@127 | 311 | loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute |
paul@127 | 312 | if replace_context: |
paul@127 | 313 | self.value = ref, loaded_ref # classes can also replace the context if compatible |
paul@127 | 314 | return |
paul@127 | 315 | self.value = loaded_context, loaded_ref |
paul@127 | 316 | else: |
paul@127 | 317 | self.value = self.load(ref + offset) |
paul@119 | 318 | else: |
paul@146 | 319 | self.exception = self.attr_error |
paul@118 | 320 | |
paul@129 | 321 | def StoreAttrIndex(self): |
paul@129 | 322 | context, ref = self.value |
paul@145 | 323 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@138 | 324 | element = self.objlist[classcode + self.operand] |
paul@135 | 325 | attr_index, class_attr, replace_context, offset = element |
paul@135 | 326 | if attr_index == self.operand: |
paul@129 | 327 | if class_attr: |
paul@146 | 328 | self.exception = self.type_error |
paul@129 | 329 | else: |
paul@129 | 330 | self.save(ref + offset, self.source) |
paul@129 | 331 | else: |
paul@146 | 332 | self.exception = self.attr_error |
paul@118 | 333 | |
paul@127 | 334 | # NOTE: LoadAttrIndexContext is a possibility if a particular attribute can always be overridden. |
paul@127 | 335 | |
paul@98 | 336 | def MakeFrame(self): |
paul@117 | 337 | self.invocation_sp_stack.append(len(self.frame_stack)) |
paul@119 | 338 | self.frame_stack.extend([None] * self.operand) |
paul@98 | 339 | |
paul@98 | 340 | def DropFrame(self): |
paul@117 | 341 | self.local_sp_stack.pop() |
paul@117 | 342 | frame = self.invocation_sp_stack.pop() |
paul@117 | 343 | self.frame_stack = self.frame_stack[:frame] # reset stack before call |
paul@98 | 344 | |
paul@137 | 345 | def RecoverFrame(self): |
paul@137 | 346 | self.local_sp_stack.pop() |
paul@137 | 347 | |
paul@129 | 348 | def StoreFrame(self): |
paul@129 | 349 | frame = self.invocation_sp_stack[-1] # different from the current frame after MakeFrame |
paul@129 | 350 | self.frame_stack[frame + self.operand] = self.value |
paul@129 | 351 | |
paul@129 | 352 | def StoreFrameIndex(self): |
paul@129 | 353 | frame = self.invocation_sp_stack[-1] # different from the current frame after MakeFrame |
paul@145 | 354 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@138 | 355 | element = self.objlist[classcode + self.operand] |
paul@135 | 356 | attr_index, offset = element |
paul@135 | 357 | if attr_index == self.operand: |
paul@129 | 358 | self.frame_stack[frame + offset] = self.value |
paul@129 | 359 | else: |
paul@146 | 360 | self.exception = self.type_error |
paul@129 | 361 | |
paul@132 | 362 | def LoadCallable(self): |
paul@132 | 363 | context, ref = self.value |
paul@145 | 364 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@134 | 365 | self.callable = codeaddr, codedetails |
paul@132 | 366 | |
paul@132 | 367 | def StoreCallable(self): |
paul@132 | 368 | context, ref = self.value |
paul@134 | 369 | # NOTE: Should improve the representation and permit direct saving. |
paul@145 | 370 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@145 | 371 | self.save(ref, (classcode, attrcode) + self.callable + (instance,)) |
paul@132 | 372 | |
paul@132 | 373 | def LoadContext(self): |
paul@132 | 374 | context, ref = self.value |
paul@132 | 375 | self.value = None, context |
paul@132 | 376 | |
paul@132 | 377 | def CheckFrame(self): |
paul@134 | 378 | operand = self.operand |
paul@134 | 379 | frame = self.invocation_sp_stack[-1] |
paul@132 | 380 | context, ref = self.value |
paul@145 | 381 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@134 | 382 | |
paul@134 | 383 | # Support sliding of the frame to exclude any inappropriate context. |
paul@134 | 384 | |
paul@134 | 385 | if context is None: |
paul@138 | 386 | self.invocation_sp_stack[-1] += 1 |
paul@134 | 387 | operand -= 1 |
paul@134 | 388 | else: |
paul@145 | 389 | context_classcode, context_attrcode, context_codeaddr, context_codedetails, context_instance = self.load(context) |
paul@145 | 390 | if not context_instance: |
paul@138 | 391 | self.invocation_sp_stack[-1] += 1 |
paul@134 | 392 | operand -= 1 |
paul@134 | 393 | |
paul@134 | 394 | nargs, ndefaults = codedetails |
paul@134 | 395 | if not (nargs - ndefaults <= operand <= nargs): |
paul@132 | 396 | raise Exception, "CheckFrame %r" % (nargs - ndefaults, self.operand, nargs) |
paul@134 | 397 | |
paul@132 | 398 | # NOTE: Support population of defaults. |
paul@117 | 399 | |
paul@134 | 400 | def CheckSelf(self): |
paul@134 | 401 | context, ref = self.value |
paul@134 | 402 | target_context, target_ref = self.source |
paul@135 | 403 | |
paul@145 | 404 | # Check the details of the proposed context and the target's context. |
paul@135 | 405 | |
paul@145 | 406 | self._CheckInstance(ref, target_context) |
paul@124 | 407 | |
paul@132 | 408 | def JumpWithFrame(self): |
paul@138 | 409 | codeaddr, codedetails = self.callable |
paul@132 | 410 | self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame |
paul@138 | 411 | return self.jump(codeaddr, self.pc + 1) # return to the instruction after this one |
paul@98 | 412 | |
paul@132 | 413 | def ExtendFrame(self): |
paul@138 | 414 | self.frame_stack.extend([None] * self.operand) |
paul@98 | 415 | |
paul@137 | 416 | def AdjustFrame(self): |
paul@137 | 417 | if self.operand > 0: |
paul@138 | 418 | self.frame_stack.append([None] * self.operand) |
paul@137 | 419 | elif self.operand == -1: |
paul@137 | 420 | self.invocation_sp_stack[-1] -= 1 |
paul@137 | 421 | else: |
paul@137 | 422 | raise Exception, "AdjustFrame %r" % self.operand |
paul@137 | 423 | |
paul@68 | 424 | def Return(self): |
paul@138 | 425 | return self.pull_pc() |
paul@68 | 426 | |
paul@117 | 427 | def LoadResult(self): |
paul@117 | 428 | self.value = self.result |
paul@117 | 429 | |
paul@117 | 430 | def StoreResult(self): |
paul@117 | 431 | self.result = self.value |
paul@117 | 432 | |
paul@118 | 433 | def Jump(self): |
paul@119 | 434 | return self.operand |
paul@98 | 435 | |
paul@68 | 436 | def JumpIfTrue(self): |
paul@117 | 437 | if self.status: |
paul@119 | 438 | return self.operand |
paul@68 | 439 | |
paul@68 | 440 | def JumpIfFalse(self): |
paul@117 | 441 | if not self.status: |
paul@119 | 442 | return self.operand |
paul@68 | 443 | |
paul@129 | 444 | def LoadException(self): |
paul@145 | 445 | self.value = None, self.exception |
paul@129 | 446 | |
paul@129 | 447 | def StoreException(self): |
paul@145 | 448 | self.exception = self.value[1] |
paul@129 | 449 | |
paul@129 | 450 | def RaiseException(self): |
paul@145 | 451 | return self.handler_stack[-1] |
paul@129 | 452 | |
paul@129 | 453 | def PushHandler(self): |
paul@129 | 454 | self.handler_stack.append(self.operand) |
paul@145 | 455 | self.handler_local_sp_stack.append(len(self.local_sp_stack)) |
paul@145 | 456 | self.handler_pc_stack.append(len(self.pc_stack)) |
paul@129 | 457 | |
paul@129 | 458 | def PopHandler(self): |
paul@145 | 459 | # Reduce the local frame pointer stack to refer to the handler's frame. |
paul@145 | 460 | self.local_sp_stack = self.local_sp_stack[:self.handler_local_sp_stack.pop()] |
paul@145 | 461 | # Reduce the PC stack to discard all superfluous return addresses. |
paul@145 | 462 | self.pc_stack = self.pc_stack[:self.handler_pc_stack.pop()] |
paul@129 | 463 | self.handler_stack.pop() |
paul@129 | 464 | |
paul@129 | 465 | def CheckException(self): |
paul@145 | 466 | self._CheckInstance(self.exception, self.value[1]) |
paul@129 | 467 | |
paul@129 | 468 | def TestIdentity(self): |
paul@145 | 469 | self.status = self.value[1] == self.source[1] |
paul@129 | 470 | |
paul@129 | 471 | def TestIdentityAddress(self): |
paul@129 | 472 | self.status = self.value[1] == self.operand |
paul@129 | 473 | |
paul@129 | 474 | # LoadBoolean is implemented in the generated code. |
paul@129 | 475 | # StoreBoolean is implemented by testing against the True value. |
paul@68 | 476 | |
paul@132 | 477 | def InvertBoolean(self): |
paul@132 | 478 | self.status = not self.status |
paul@132 | 479 | |
paul@145 | 480 | # Common implementation details. |
paul@145 | 481 | |
paul@145 | 482 | def _CheckInstance(self, ref, cls): |
paul@145 | 483 | classcode, attrcode, codeaddr, codedetails, instance = self.load(ref) |
paul@145 | 484 | target_classcode, target_attrcode, target_codeaddr, target_codedetails, target_instance = self.load(cls) |
paul@145 | 485 | |
paul@145 | 486 | # Find the table entry for the descendant. |
paul@145 | 487 | |
paul@145 | 488 | element = self.objlist[target_classcode + attrcode] |
paul@145 | 489 | attr_index, class_attr, replace_context, offset = element |
paul@145 | 490 | if attr_index == attrcode: |
paul@145 | 491 | self.status = 1 |
paul@145 | 492 | else: |
paul@145 | 493 | self.status = 0 |
paul@145 | 494 | |
paul@68 | 495 | # vim: tabstop=4 expandtab shiftwidth=4 |