1.1 --- a/rsvp.py Mon Aug 04 01:05:50 2008 +0200
1.2 +++ b/rsvp.py Wed Aug 13 19:42:59 2008 +0200
1.3 @@ -58,7 +58,7 @@
1.4
1.5 "A really simple virtual processor."
1.6
1.7 - def __init__(self, memory, pc=None, debug=0):
1.8 + def __init__(self, memory, objtable, paramtable, pc=None, debug=0):
1.9
1.10 """
1.11 Initialise the processor with a 'memory' (a list of values containing
1.12 @@ -66,6 +66,8 @@
1.13 """
1.14
1.15 self.memory = memory
1.16 + self.objtable = objtable
1.17 + self.paramtable = paramtable
1.18 self.pc = pc or 0
1.19 self.debug = debug
1.20
1.21 @@ -146,11 +148,35 @@
1.22 instruction = self.load(self.pc).__class__.__name__
1.23 if self.debug:
1.24 print "%8d %s" % (self.pc, instruction)
1.25 +
1.26 + method = self.get_method(instruction)
1.27 +
1.28 + # Process any inputs of the instruction.
1.29 +
1.30 + self.process_inputs(instruction)
1.31 + method()
1.32 +
1.33 + def get_method(self, instruction):
1.34 +
1.35 + "Return the handler method for the given 'instruction'."
1.36 +
1.37 method = getattr(self, instruction, None)
1.38 if method is None:
1.39 raise IllegalInstruction, (self.pc, instruction)
1.40 - else:
1.41 - method()
1.42 + return method
1.43 +
1.44 + def process_inputs(self, instruction):
1.45 +
1.46 + """
1.47 + Process any inputs of the 'instruction'. This permits any directly
1.48 + connected sub-instructions to produce the effects that separate
1.49 + instructions would otherwise have.
1.50 + """
1.51 +
1.52 + for input in (instruction.input, instruction.source):
1.53 + if input is not None:
1.54 + method = self.get_method(input)
1.55 + method()
1.56
1.57 def jump(self, addr, next):
1.58
1.59 @@ -190,22 +216,6 @@
1.60 LoadTemp = LoadName
1.61 StoreTemp = StoreName
1.62
1.63 - def LoadAttr(self):
1.64 - n = self.load(self.pc).get_operand()
1.65 - context, ref = self.value
1.66 - self.value = self.load(ref + n)
1.67 - self.pc += 1
1.68 -
1.69 - def StoreAttr(self):
1.70 - n = self.load(self.pc).get_operand()
1.71 - context, ref = self.value
1.72 - self.save(ref + n, self.source)
1.73 - self.pc += 1
1.74 -
1.75 - def LoadAttrIndex(self): pass
1.76 -
1.77 - def StoreAttrIndex(self): pass
1.78 -
1.79 def LoadAddress(self):
1.80 addr = self.load(self.pc).get_operand()
1.81 self.value = self.load(addr)
1.82 @@ -227,6 +237,22 @@
1.83 self.value = self.new(n)
1.84 self.pc += 1
1.85
1.86 + def LoadAttr(self):
1.87 + n = self.load(self.pc).get_operand()
1.88 + context, ref = self.value
1.89 + self.value = self.load(ref + n)
1.90 + self.pc += 1
1.91 +
1.92 + def StoreAttr(self):
1.93 + n = self.load(self.pc).get_operand()
1.94 + context, ref = self.value
1.95 + self.save(ref + n, self.source)
1.96 + self.pc += 1
1.97 +
1.98 + def LoadAttrIndex(self): pass
1.99 +
1.100 + def StoreAttrIndex(self): pass
1.101 +
1.102 def MakeFrame(self):
1.103 n = self.load(self.pc).get_operand()
1.104 self.invocation_sp_stack.append(len(self.frame_stack))
1.105 @@ -276,7 +302,9 @@
1.106 def LoadBoolean(self):
1.107 self.value = self.status
1.108
1.109 - def Jump(self): pass
1.110 + def Jump(self):
1.111 + addr = self.load(self.pc).get_operand()
1.112 + self.pc = addr
1.113
1.114 def JumpIfTrue(self):
1.115 addr = self.load(self.pc).get_operand()