comparison pytouhou/vm/eclrunner.py @ 364:b07e2f71f240

Empty ECL stack when calling a callback.
author Thibaut Girka <thib@sitedethib.com>
date Mon, 09 Jul 2012 22:13:52 +0200
parents 3be4c1078095
children 238d06c6603e
comparison
equal deleted inserted replaced
363:cb1460b9b6cf 364:b07e2f71f240
140 self.switch_to_sub(sub) 140 self.switch_to_sub(sub)
141 141
142 self.stack = [] 142 self.stack = []
143 143
144 144
145 def switch_to_sub(self, sub): 145 def switch_to_sub(self, sub, preserve_stack=False):
146 if not preserve_stack:
147 self.stack = []
146 self.running = True 148 self.running = True
147 self.frame = 0 149 self.frame = 0
148 self.sub = sub 150 self.sub = sub
149 self.instruction_pointer = 0 151 self.instruction_pointer = 0
150 152
405 def call(self, sub, param1, param2): 407 def call(self, sub, param1, param2):
406 self.stack.append((self.sub, self.frame, self.instruction_pointer, 408 self.stack.append((self.sub, self.frame, self.instruction_pointer,
407 list(self.variables), self.comparison_reg)) 409 list(self.variables), self.comparison_reg))
408 self.variables[0] = param1 410 self.variables[0] = param1
409 self.variables[4] = param2 411 self.variables[4] = param2
410 self.switch_to_sub(sub) 412 self.switch_to_sub(sub, preserve_stack=True)
411 413
412 414
413 @instruction(36) 415 @instruction(36)
414 def ret(self): 416 def ret(self):
415 self.sub, self.frame, self.instruction_pointer, self.variables, self.comparison_reg = self.stack.pop() 417 self.sub, self.frame, self.instruction_pointer, self.variables, self.comparison_reg = self.stack.pop()