Execute the program
(self,infile,tmpfile)
| 321 | |
| 322 | |
| 323 | def execute(self,infile,tmpfile): |
| 324 | """Execute the program""" |
| 325 | |
| 326 | self.__parser = BASICParser() |
| 327 | |
| 328 | self.__data.restore(0) # reset data pointer |
| 329 | |
| 330 | line_numbers = self.line_numbers() |
| 331 | |
| 332 | if len(line_numbers) > 0: |
| 333 | # Set up an index into the ordered list |
| 334 | # of line numbers that can be used for |
| 335 | # sequential statement execution. The index |
| 336 | # will be incremented by one, unless modified by |
| 337 | # a jump |
| 338 | index = 0 |
| 339 | self.__next_stmt = line_numbers[index] |
| 340 | |
| 341 | # Run through the program until the |
| 342 | # has line number has been reached |
| 343 | while True: |
| 344 | flowsignal = self.__execute(self.__next_stmt,infile,tmpfile) |
| 345 | self.__parser.last_flowsignal = flowsignal |
| 346 | |
| 347 | |
| 348 | if flowsignal: |
| 349 | if flowsignal.ftype == FlowSignal.SIMPLE_JUMP: |
| 350 | # GOTO or conditional branch encountered |
| 351 | try: |
| 352 | index = line_numbers.index(flowsignal.ftarget) |
| 353 | |
| 354 | except ValueError: |
| 355 | raise RuntimeError("Invalid line number supplied in GOTO or conditional branch: " |
| 356 | + str(flowsignal.ftarget)+ " in line " + str(self.__next_stmt)) |
| 357 | |
| 358 | self.__next_stmt = flowsignal.ftarget |
| 359 | |
| 360 | elif flowsignal.ftype == FlowSignal.GOSUB: |
| 361 | # Subroutine call encountered |
| 362 | # Add line number of next instruction to |
| 363 | # the return stack |
| 364 | if index + 1 < len(line_numbers): |
| 365 | self.__return_stack.append(line_numbers[index + 1]) |
| 366 | |
| 367 | else: |
| 368 | raise RuntimeError("GOSUB at end of program, nowhere to return") |
| 369 | |
| 370 | # Set the index to be the subroutine start line |
| 371 | # number |
| 372 | try: |
| 373 | index = line_numbers.index(flowsignal.ftarget) |
| 374 | |
| 375 | except ValueError: |
| 376 | raise RuntimeError("Invalid line number supplied in subroutine call: " |
| 377 | + str(flowsignal.ftarget)) |
| 378 | |
| 379 | self.__next_stmt = flowsignal.ftarget |
| 380 |
no test coverage detected