def chain(action, g, jumpnum, delete_lines): """ Chain load the program from g and hand over execution. """ if delete_lines: # delete lines from existing code before merge (without MERGE, this is pointless) delete(*delete_lines) action(g) # don't close files! # RUN flow.jump(jumpnum, err=error.IFC)
def trap_error(self, e): """ Handle a BASIC error through trapping. """ if e.pos is None: if state.basic_state.run_mode: e.pos = state.basic_state.bytecode.tell()-1 else: e.pos = -1 state.basic_state.errn = e.err state.basic_state.errp = e.pos # don't jump if we're already busy handling an error if state.basic_state.on_error is not None and state.basic_state.on_error != 0 and not state.basic_state.error_handle_mode: state.basic_state.error_resume = state.basic_state.current_statement, state.basic_state.run_mode flow.jump(state.basic_state.on_error) state.basic_state.error_handle_mode = True state.basic_state.events.suspend_all = True else: raise e
def start(cmd='', run=False, quit=False): """ Start the interpreter. """ if cmd: store_line(cmd) if run: # run command before program if cmd: run_once() # position the pointer at start of program and enter execute mode flow.jump(None) state.basic_state.execute_mode = True state.console_state.screen.cursor.reset_visibility() # read-eval-print loop until quit or exception while True: run_once() if quit and state.console_state.keyb.buf.is_empty(): break
def trap_error(e): """ Handle a BASIC error through trapping. """ if e.pos is None: if state.basic_state.run_mode: e.pos = state.basic_state.bytecode.tell()-1 else: e.pos = -1 state.basic_state.errn = e.err state.basic_state.errp = e.pos # don't jump if we're already busy handling an error if state.basic_state.on_error is not None and state.basic_state.on_error != 0 and not state.basic_state.error_handle_mode: state.basic_state.error_resume = state.basic_state.current_statement, state.basic_state.run_mode flow.jump(state.basic_state.on_error) state.basic_state.error_handle_mode = True state.basic_state.events.suspend_all = True else: raise e
def run(self, command, run, quit, wait): """ Interactive interpreter session. """ if command: self.store_line(command) self.loop() if run: # position the pointer at start of program and enter execute mode flow.jump(None) state.basic_state.parse_mode = True state.console_state.screen.cursor.reset_visibility() try: try: while True: self.loop() if quit and state.console_state.keyb.buf.is_empty(): break except error.Exit: # pause before exit if requested if wait: signals.video_queue.put(signals.Event(signals.VIDEO_SET_CAPTION, 'Press a key to close window')) signals.video_queue.put(signals.Event(signals.VIDEO_SHOW_CURSOR, False)) state.console_state.keyb.pause = True # this performs a blocking keystroke read if in pause state events.check_events() finally: # close interfaces signals.video_queue.put(signals.Event(signals.VIDEO_QUIT)) signals.message_queue.put(signals.Event(signals.AUDIO_QUIT)) # persist unplayed tones in sound queue state.console_state.tone_queue_store = [ signals.save_queue(q) for q in signals.tone_queue] state.save() # close files if we opened any devices.close_files() devices.close_devices() except error.Reset: # delete state if resetting state.delete()