comparison pytouhou/vm/eclrunner.py @ 376:69ec72b990a4

Support more than one version of a vm.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 06 Aug 2012 23:10:09 +0200
parents 704bea2e4360
children eef492100f4c
comparison
equal deleted inserted replaced
375:8f2f3053906a 376:69ec72b990a4
24 24
25 25
26 class ECLMainRunner(object): 26 class ECLMainRunner(object):
27 __metaclass__ = MetaRegistry 27 __metaclass__ = MetaRegistry
28 __slots__ = ('_main', '_subs', '_game', 'frame', 28 __slots__ = ('_main', '_subs', '_game', 'frame',
29 'instruction_pointer', 29 'instruction_pointer', 'boss_wait', 'handlers')
30 'boss_wait')
31 30
32 def __init__(self, main, subs, game): 31 def __init__(self, main, subs, game):
33 self._main = main 32 self._main = main
34 self._subs = subs 33 self._subs = subs
35 self._game = game 34 self._game = game
35 self.handlers = self._handlers[6]
36 self.frame = 0 36 self.frame = 0
37 self.boss_wait = False 37 self.boss_wait = False
38 38
39 self.instruction_pointer = 0 39 self.instruction_pointer = 0
40 40
55 else: 55 else:
56 self.instruction_pointer += 1 56 self.instruction_pointer += 1
57 57
58 if frame == self.frame: 58 if frame == self.frame:
59 try: 59 try:
60 callback = self._handlers[instr_type] 60 callback = self.handlers[instr_type]
61 except KeyError: 61 except KeyError:
62 logger.warn('unhandled main opcode %d (args: %r)', instr_type, args) 62 logger.warn('unhandled main opcode %d (args: %r)', instr_type, args)
63 else: 63 else:
64 callback(self, sub, instr_type, *args) 64 callback(self, sub, instr_type, *args)
65 65
119 119
120 120
121 121
122 class ECLRunner(object): 122 class ECLRunner(object):
123 __metaclass__ = MetaRegistry 123 __metaclass__ = MetaRegistry
124 __slots__ = ('_subs', '_enemy', '_game', '_pop_enemy', 'variables', 'sub', 'frame', 124 __slots__ = ('_subs', '_enemy', '_game', '_pop_enemy', 'variables', 'sub',
125 'instruction_pointer', 'comparison_reg', 'stack', 125 'frame', 'instruction_pointer', 'comparison_reg', 'stack',
126 'running') 126 'running', 'handlers')
127 127
128 def __init__(self, subs, sub, enemy, game, pop_enemy): 128 def __init__(self, subs, sub, enemy, game, pop_enemy):
129 # Things not supposed to change 129 # Things not supposed to change
130 self._subs = subs 130 self._subs = subs
131 self._enemy = enemy 131 self._enemy = enemy
132 self._game = game 132 self._game = game
133 self._pop_enemy = pop_enemy 133 self._pop_enemy = pop_enemy
134 self.handlers = self._handlers[6]
134 135
135 self.running = True 136 self.running = True
136 137
137 # Things supposed to change (and be put in the stack) 138 # Things supposed to change (and be put in the stack)
138 self.variables = [0, 0, 0, 0, 139 self.variables = [0, 0, 0, 0,
170 if not rank_mask & (0x100 << self._game.rank): 171 if not rank_mask & (0x100 << self._game.rank):
171 continue 172 continue
172 173
173 if frame == self.frame: 174 if frame == self.frame:
174 try: 175 try:
175 callback = self._handlers[instr_type] 176 callback = self.handlers[instr_type]
176 except KeyError: 177 except KeyError:
177 logger.warn('[%d %r - %04d] unhandled opcode %d (args: %r)', 178 logger.warn('[%d %r - %04d] unhandled opcode %d (args: %r)',
178 id(self), [self.sub] + [e[0] for e in self.stack], 179 id(self), [self.sub] + [e[0] for e in self.stack],
179 self.frame, instr_type, args) 180 self.frame, instr_type, args)
180 else: 181 else: