1.1 --- a/rsvp.py Sat Jun 28 20:46:45 2008 +0200
1.2 +++ b/rsvp.py Mon Jun 30 00:32:54 2008 +0200
1.3 @@ -101,15 +101,15 @@
1.4 self.memory.append(None)
1.5 return addr
1.6
1.7 - def push(self, data):
1.8 + def stack_save(self, n, data):
1.9
1.10 - "Push 'data' onto the value stack."
1.11 + "Save to location 'n' on the value stack the given 'data'."
1.12
1.13 self.value_stack.append(data)
1.14
1.15 - def pull(self):
1.16 + def stack_load(self, n):
1.17
1.18 - "Pull a value from the value stack and return it."
1.19 + "Load a value from the value stack at location 'n'."
1.20
1.21 return self.value_stack.pop()
1.22
1.23 @@ -191,57 +191,22 @@
1.24
1.25 # Instructions.
1.26
1.27 - def Pop(self):
1.28 - self.pull()
1.29 - self.pc += 1
1.30 -
1.31 - def MakeFrame(self):
1.32 - top = len(self.value_stack)
1.33 - self.add_frame(top)
1.34 - self.pc += 1
1.35 -
1.36 - def ReserveFrame(self):
1.37 - n = self.load(self.pc).get_operand()
1.38 - while n > 0:
1.39 - self.push(None)
1.40 - n -= 1
1.41 - self.pc += 1
1.42 -
1.43 - def DropFrame(self):
1.44 - result = self.pull()
1.45 - frame = self.pull_frame()
1.46 - self.value_stack = self.value_stack[:frame] # reset stack before call
1.47 - self.push(result)
1.48 - self.pc += 1
1.49 -
1.50 - def JumpWithFrame(self):
1.51 - attr = self.pull()
1.52 - self.frame_sp += 1 # adopt the added frame
1.53 - target_location = attr[0]
1.54 - target = self.load(target_location)
1.55 - self.jump(target.code_location, self.pc + 1) # return to the instruction after this one
1.56 -
1.57 - def LoadContext(self):
1.58 + def LoadConst(self):
1.59
1.60 """
1.61 - LoadContext
1.62 - Load context from top of stack: get the context from the value on the
1.63 - top of the stack, pushing it onto the stack.
1.64 + LoadConst addr
1.65 + Load the reference to memory: get the address addr, push the value onto
1.66 + the stack as a value without context.
1.67 +
1.68 + This is useful for loading constants.
1.69 + NOTE: This assumes that constants are encoded with context.
1.70 """
1.71
1.72 - attr = self.value_stack[-1]
1.73 - self.push((attr[1], None))
1.74 - self.pc += 1
1.75 -
1.76 - def CheckContext(self):
1.77 -
1.78 - """
1.79 - CheckContext
1.80 - Check the context: check the context on the top of the stack
1.81 - """
1.82 -
1.83 - attr = self.value_stack[-1]
1.84 - # NOTE: To be written.
1.85 + op = self.load(self.pc)
1.86 + addr = op.get_operand()
1.87 + value = (addr, None)
1.88 + for result in op.results:
1.89 + self.stack_save(result.level, value)
1.90 self.pc += 1
1.91
1.92 def LoadName(self):
1.93 @@ -273,22 +238,6 @@
1.94 LoadTemp = LoadName
1.95 StoreTemp = StoreName
1.96
1.97 - def LoadConst(self):
1.98 -
1.99 - """
1.100 - LoadConst addr
1.101 - Load the reference to memory: get the address addr, push the value onto
1.102 - the stack as a value without context.
1.103 -
1.104 - This is useful for loading constants.
1.105 - NOTE: This assumes that constants are encoded with context.
1.106 - """
1.107 -
1.108 - addr = self.load(self.pc).get_operand()
1.109 - value = (addr, None)
1.110 - self.push(value)
1.111 - self.pc += 1
1.112 -
1.113 def LoadAttr(self):
1.114
1.115 """
1.116 @@ -319,6 +268,10 @@
1.117 self.save(ref + n, value)
1.118 self.pc += 1
1.119
1.120 + def LoadAttrIndex(self): pass
1.121 +
1.122 + def StoreAttrIndex(self): pass
1.123 +
1.124 def LoadAddress(self):
1.125
1.126 """
1.127 @@ -346,6 +299,58 @@
1.128 self.save(addr, value)
1.129 self.pc += 1
1.130
1.131 + def MakeFrame(self):
1.132 + n = self.load(self.pc).get_operand()
1.133 + top = len(self.value_stack)
1.134 + self.add_frame(top)
1.135 + while n > 0:
1.136 + self.push(None)
1.137 + n -= 1
1.138 + self.pc += 1
1.139 +
1.140 + def DropFrame(self):
1.141 + result = self.pull()
1.142 + frame = self.pull_frame()
1.143 + self.value_stack = self.value_stack[:frame] # reset stack before call
1.144 + self.push(result)
1.145 + self.pc += 1
1.146 +
1.147 + def LoadCallable(self): pass
1.148 +
1.149 + def LoadContext(self):
1.150 +
1.151 + """
1.152 + LoadContext
1.153 + Load context from top of stack: get the context from the value on the
1.154 + top of the stack, pushing it onto the stack.
1.155 + """
1.156 +
1.157 + attr = self.value_stack[-1]
1.158 + self.push((attr[1], None))
1.159 + self.pc += 1
1.160 +
1.161 + def CheckFrame(self): pass
1.162 +
1.163 + def CheckSelf(self): pass
1.164 +
1.165 + def CheckContext(self):
1.166 +
1.167 + """
1.168 + CheckContext
1.169 + Check the context: check the context on the top of the stack
1.170 + """
1.171 +
1.172 + attr = self.value_stack[-1]
1.173 + # NOTE: To be written.
1.174 + self.pc += 1
1.175 +
1.176 + def JumpWithFrame(self):
1.177 + attr = self.pull()
1.178 + self.frame_sp += 1 # adopt the added frame
1.179 + target_location = attr[0]
1.180 + target = self.load(target_location)
1.181 + self.jump(target.code_location, self.pc + 1) # return to the instruction after this one
1.182 +
1.183 def Return(self):
1.184
1.185 """
1.186 @@ -356,6 +361,10 @@
1.187
1.188 self.pc = self.pull_pc()
1.189
1.190 + def LoadResult(self): pass
1.191 +
1.192 + def Jump(self): pass
1.193 +
1.194 def JumpIfTrue(self):
1.195
1.196 """