# HG changeset patch # User Paul Boddie # Date 1218649379 -7200 # Node ID 15c15963cf292294bb78dc97149044398fafb141 # Parent 051b57229757e3afb4e77f77efa08159050c223f Added tables to the initialiser, although these will ultimately be positioned in memory. Added some more instruction implementations and moved some definitions around. diff -r 051b57229757 -r 15c15963cf29 rsvp.py --- a/rsvp.py Mon Aug 04 01:05:50 2008 +0200 +++ b/rsvp.py Wed Aug 13 19:42:59 2008 +0200 @@ -58,7 +58,7 @@ "A really simple virtual processor." - def __init__(self, memory, pc=None, debug=0): + def __init__(self, memory, objtable, paramtable, pc=None, debug=0): """ Initialise the processor with a 'memory' (a list of values containing @@ -66,6 +66,8 @@ """ self.memory = memory + self.objtable = objtable + self.paramtable = paramtable self.pc = pc or 0 self.debug = debug @@ -146,11 +148,35 @@ instruction = self.load(self.pc).__class__.__name__ if self.debug: print "%8d %s" % (self.pc, instruction) + + method = self.get_method(instruction) + + # Process any inputs of the instruction. + + self.process_inputs(instruction) + method() + + def get_method(self, instruction): + + "Return the handler method for the given 'instruction'." + method = getattr(self, instruction, None) if method is None: raise IllegalInstruction, (self.pc, instruction) - else: - method() + return method + + def process_inputs(self, instruction): + + """ + Process any inputs of the 'instruction'. This permits any directly + connected sub-instructions to produce the effects that separate + instructions would otherwise have. + """ + + for input in (instruction.input, instruction.source): + if input is not None: + method = self.get_method(input) + method() def jump(self, addr, next): @@ -190,22 +216,6 @@ LoadTemp = LoadName StoreTemp = StoreName - def LoadAttr(self): - n = self.load(self.pc).get_operand() - context, ref = self.value - self.value = self.load(ref + n) - self.pc += 1 - - def StoreAttr(self): - n = self.load(self.pc).get_operand() - context, ref = self.value - self.save(ref + n, self.source) - self.pc += 1 - - def LoadAttrIndex(self): pass - - def StoreAttrIndex(self): pass - def LoadAddress(self): addr = self.load(self.pc).get_operand() self.value = self.load(addr) @@ -227,6 +237,22 @@ self.value = self.new(n) self.pc += 1 + def LoadAttr(self): + n = self.load(self.pc).get_operand() + context, ref = self.value + self.value = self.load(ref + n) + self.pc += 1 + + def StoreAttr(self): + n = self.load(self.pc).get_operand() + context, ref = self.value + self.save(ref + n, self.source) + self.pc += 1 + + def LoadAttrIndex(self): pass + + def StoreAttrIndex(self): pass + def MakeFrame(self): n = self.load(self.pc).get_operand() self.invocation_sp_stack.append(len(self.frame_stack)) @@ -276,7 +302,9 @@ def LoadBoolean(self): self.value = self.status - def Jump(self): pass + def Jump(self): + addr = self.load(self.pc).get_operand() + self.pc = addr def JumpIfTrue(self): addr = self.load(self.pc).get_operand()