Пример #1
0
 def auto_step(self):
     """ Generate an AUTO line number and wait for input. """
     numstr = str(state.basic_state.auto_linenum)
     console.write(numstr)
     if state.basic_state.auto_linenum in state.basic_state.line_numbers:
         console.write('*')
         line = bytearray(console.wait_screenline(from_start=True))
         if line[:len(numstr)+1] == numstr+'*':
             line[len(numstr)] = ' '
     else:
         console.write(' ')
         line = bytearray(console.wait_screenline(from_start=True))
     # run or store it; don't clear lines or raise undefined line number
     state.basic_state.direct_line = tokenise.tokenise_line(line)
     c = util.peek(state.basic_state.direct_line)
     if c == '\0':
         # check for lines starting with numbers (6553 6) and empty lines
         empty, scanline = program.check_number_start(state.basic_state.direct_line)
         if not empty:
             program.store_line(state.basic_state.direct_line)
             reset.clear()
         state.basic_state.auto_linenum = scanline + state.basic_state.auto_increment
     elif c != '':
         # it is a command, go and execute
         state.basic_state.parse_mode = True
Пример #2
0
def auto_step():
    """ Generate an AUTO line number and wait for input. """
    numstr = str(state.basic_state.auto_linenum)
    console.write(numstr)
    if state.basic_state.auto_linenum in state.basic_state.line_numbers:
        console.write('*')
        line = bytearray(console.wait_screenline(from_start=True))
        if line[:len(numstr)+1] == numstr+'*':
            line[len(numstr)] = ' '
    else:
        console.write(' ')
        line = bytearray(console.wait_screenline(from_start=True))
    # run or store it; don't clear lines or raise undefined line number
    state.basic_state.direct_line = tokenise.tokenise_line(line)
    c = util.peek(state.basic_state.direct_line)
    if c == '\0':
        # check for lines starting with numbers (6553 6) and empty lines
        empty, scanline = program.check_number_start(state.basic_state.direct_line)
        if not empty:
            program.store_line(state.basic_state.direct_line)
            reset.clear()
        state.basic_state.auto_linenum = scanline + state.basic_state.auto_increment
    elif c != '':
        # it is a command, go and execute
        state.basic_state.execute_mode = True
Пример #3
0
def run_once():
    """ Read-eval-print loop: run once. """
    try:
        while True:
            state.basic_state.last_mode = state.basic_state.execute_mode, state.basic_state.auto_mode
            if state.basic_state.execute_mode:
                try:
                    # may raise Break
                    backend.check_events()
                    handle_basic_events()
                    if not statements.parse_statement():
                        state.basic_state.execute_mode = False
                except error.Break as e:
                    handle_break(e)
            elif state.basic_state.auto_mode:
                try:
                    # auto step, checks events
                    auto_step()
                except error.Break:
                    state.basic_state.auto_mode = False    
            else:    
                show_prompt()
                try:
                    # input loop, checks events
                    line = console.wait_screenline(from_start=True, alt_replace=True) 
                    state.basic_state.prompt = not store_line(line)
                except error.Break:
                    state.basic_state.prompt = False
                    continue
            # change loop modes
            if switch_mode():
                break
    except error.RunError as e:
        handle_error(e) 
        state.basic_state.prompt = True
Пример #4
0
 def loop(self):
     """ Run read-eval-print loop until control returns to user after a command. """
     try:
         while True:
             self.last_mode = state.basic_state.parse_mode, state.basic_state.auto_mode
             if state.basic_state.parse_mode:
                 try:
                     # may raise Break
                     events.check_events()
                     self.handle_basic_events()
                     # returns True if more statements to parse
                     if not statements.parse_statement():
                         state.basic_state.parse_mode = False
                 except error.RunError as e:
                     self.trap_error(e)
                 except error.Break as e:
                     # ctrl-break stops foreground and background sound
                     state.console_state.sound.stop_all_sound()
                     self.handle_break(e)
             elif state.basic_state.auto_mode:
                 try:
                     # auto step, checks events
                     self.auto_step()
                 except error.Break:
                     # ctrl+break, ctrl-c both stop background sound
                     state.console_state.sound.stop_all_sound()
                     state.basic_state.auto_mode = False
             else:
                 self.show_prompt()
                 try:
                     # input loop, checks events
                     line = console.wait_screenline(from_start=True)
                     self.prompt = not self.store_line(line)
                 except error.Break:
                     state.console_state.sound.stop_all_sound()
                     self.prompt = False
                     continue
             # change loop modes
             if self.switch_mode():
                 break
     except error.RunError as e:
         self.handle_error(e)
         self.prompt = True
     except error.Exit:
         raise
     except error.Reset:
         raise
     except Exception as e:
         if debug.debug_mode:
             raise
         debug.bluescreen(e)
Пример #5
0
def run_once():
    """ Read-eval-print loop: run once. """
    try:
        while True:
            state.basic_state.last_mode = state.basic_state.execute_mode, state.basic_state.auto_mode
            if state.basic_state.execute_mode:
                try:
                    # may raise Break
                    backend.check_events()
                    handle_basic_events()
                    # returns True if more statements to parse
                    if not statements.parse_statement():
                        state.basic_state.execute_mode = False
                except error.RunError as e:
                    trap_error(e)
                except error.Break as e:
                    # ctrl-break stops foreground and background sound
                    state.console_state.sound.stop_all_sound()
                    handle_break(e)
            elif state.basic_state.auto_mode:
                try:
                    # auto step, checks events
                    auto_step()
                except error.Break:
                    # ctrl+break, ctrl-c both stop background sound
                    state.console_state.sound.stop_all_sound()
                    state.basic_state.auto_mode = False
            else:
                show_prompt()
                try:
                    # input loop, checks events
                    line = console.wait_screenline(from_start=True)
                    state.basic_state.prompt = not store_line(line)
                except error.Break:
                    state.console_state.sound.stop_all_sound()
                    state.basic_state.prompt = False
                    continue
            # change loop modes
            if switch_mode():
                break
    except error.RunError as e:
        handle_error(e)
        state.basic_state.prompt = True
    except error.Exit:
        raise
    except Exception as e:
        if debug.debug_mode:
            raise
        bluescreen(e)
Пример #6
0
def input_console(prompt, readvar, newline):
    """ Read a list of variables for INPUT. """
    # readvar is a list of (name, indices) tuples
    # we return a list of (name, indices, values) tuples
    while True:
        console.write(prompt)
        line = console.wait_screenline(write_endl=newline)
        inputstream = InputTextFile(line)
        # read the values and group them and the separators
        values, seps = zip(*[inputstream.read_var(v) for v in readvar])
        # last separator not empty: there were too many values or commas
        # if there are Nones: there were too few or empty values
        if (seps[-1] or None in values):
            # good old Redo!
            console.write_line('?Redo from start')
        else:
            return [r + [v] for r, v in zip(readvar, values)]
Пример #7
0
def input_console(prompt, readvar, newline):
    """ Read a list of variables for INPUT. """
    # readvar is a list of (name, indices) tuples
    # we return a list of (name, indices, values) tuples
    while True:
        console.write(prompt)
        line = console.wait_screenline(write_endl=newline)
        inputstream = InputTextFile(line)
        # read the values and group them and the separators
        values, seps = zip(*[inputstream.read_var(v) for v in readvar])
        # last separator not empty: there were too many values or commas
        # if there are Nones: there were too few or empty values
        if (seps[-1] or None in values):
            # good old Redo!
            console.write_line('?Redo from start')
        else:
            return [ r + [v] for r, v in zip(readvar, values) ]
Пример #8
0
def input_console(prompt, readvar, newline):
    """ Read a list of variables for INPUT. """
    # readvar is a list of (name, indices) tuples
    # we return a list of (name, indices, values) tuples
    while True:
        console.write(prompt)
        line = console.wait_screenline(write_endl=newline)
        inputstream = InputTextFile(line)
        # read the values and group them and the separators
        values, seps = zip(*[inputstream.read_var(v) for v in readvar])
        # last separator not empty: there were too many values or commas
        # earlier separators empty: there were too few values
        # empty values will be converted to zero by str_to_value_keep
        # Nene means a conversion error occurred
        if (seps[-1] or '' in seps[:-1] or None in values):
            # good old Redo!
            console.write_line('?Redo from start')
        else:
            return [r + [v] for r, v in zip(readvar, values)]
Пример #9
0
def input_console(prompt, readvar, newline):
    """ Read a list of variables for INPUT. """
    # readvar is a list of (name, indices) tuples
    # we return a list of (name, indices, values) tuples
    while True:
        console.write(prompt)
        line = console.wait_screenline(write_endl=newline)
        inputstream = InputTextFile(line)
        # read the values and group them and the separators
        values, seps = zip(*[inputstream.read_var(v) for v in readvar])
        # last separator not empty: there were too many values or commas
        # earlier separators empty: there were too few values
        # empty values will be converted to zero by string_to_number
        # None means a conversion error occurred
        if (seps[-1] or '' in seps[:-1] or None in values):
            # good old Redo!
            console.write_line('?Redo from start')
        else:
            return [r + [v] for r, v in zip(readvar, values)]