def rebuild_line_dict(): """ Preparse to build line number dictionary. """ state.basic_state.line_numbers, offsets = {}, [] state.basic_state.bytecode.seek(0) scanline, scanpos, last = 0, 0, 0 while True: state.basic_state.bytecode.read(1) # pass \x00 scanline = util.parse_line_number(state.basic_state.bytecode) if scanline == -1: scanline = 65536 # if parse_line_number returns -1, it leaves the stream pointer here: 00 _00_ 00 1A break state.basic_state.line_numbers[scanline] = scanpos last = scanpos util.skip_to(state.basic_state.bytecode, tk.end_line) scanpos = state.basic_state.bytecode.tell() offsets.append(scanpos) state.basic_state.line_numbers[65536] = scanpos # rebuild offsets state.basic_state.bytecode.seek(0) last = 0 for pos in offsets: state.basic_state.bytecode.read(1) state.basic_state.bytecode.write( str(vartypes.value_to_uint(program_memory_start + pos))) state.basic_state.bytecode.read(pos - last - 3) last = pos # ensure program is properly sealed - last offset must be 00 00. keep, but ignore, anything after. state.basic_state.bytecode.write('\0\0\0')
def rebuild_line_dict(): """ Preparse to build line number dictionary. """ state.basic_state.line_numbers, offsets = {}, [] state.basic_state.bytecode.seek(0) scanline, scanpos, last = 0, 0, 0 while True: state.basic_state.bytecode.read(1) # pass \x00 scanline = util.parse_line_number(state.basic_state.bytecode) if scanline == -1: scanline = 65536 # if parse_line_number returns -1, it leaves the stream pointer here: 00 _00_ 00 1A break state.basic_state.line_numbers[scanline] = scanpos last = scanpos util.skip_to(state.basic_state.bytecode, tk.end_line) scanpos = state.basic_state.bytecode.tell() offsets.append(scanpos) state.basic_state.line_numbers[65536] = scanpos # rebuild offsets state.basic_state.bytecode.seek(0) last = 0 for pos in offsets: state.basic_state.bytecode.read(1) state.basic_state.bytecode.write(str(vartypes.integer_to_bytes(vartypes.int_to_integer_unsigned(program_memory_start + pos)))) state.basic_state.bytecode.read(pos - last - 3) last = pos # ensure program is properly sealed - last offset must be 00 00. keep, but ignore, anything after. state.basic_state.bytecode.write('\0\0\0')
def resume(jumpnum): """ Execute jump for a RESUME instruction. """ start_statement, runmode = state.basic_state.error_resume state.basic_state.errn = 0 state.basic_state.error_handle_mode = False state.basic_state.error_resume = None state.basic_state.events.suspend_all = False if jumpnum == 0: # RESUME or RESUME 0 set_pointer(runmode, start_statement) elif jumpnum == -1: # RESUME NEXT set_pointer(runmode, start_statement) util.skip_to(get_codestream(), tk.end_statement, break_on_first_char=False) else: # RESUME n jump(jumpnum)
def read_entry(): """ READ a unit of DATA. """ current = state.basic_state.bytecode.tell() state.basic_state.bytecode.seek(state.basic_state.data_pos) if util.peek(state.basic_state.bytecode) in tk.end_statement: # initialise - find first DATA util.skip_to(state.basic_state.bytecode, ('\x84', )) # DATA if state.basic_state.bytecode.read(1) not in ('\x84', ','): raise error.RunError(error.OUT_OF_DATA) vals, word, literal = '', '', False while True: # read next char; omit leading whitespace if not literal and vals == '': c = util.skip_white(state.basic_state.bytecode) else: c = util.peek(state.basic_state.bytecode) # parse char if c == '' or (not literal and c == ',') or ( c in tk.end_line or (not literal and c in tk.end_statement)): break elif c == '"': state.basic_state.bytecode.read(1) literal = not literal if not literal: util.require(state.basic_state.bytecode, tk.end_statement + (',', )) else: state.basic_state.bytecode.read(1) if literal: vals += c else: word += c # omit trailing whitespace if c not in tk.whitespace: vals += word word = '' state.basic_state.data_pos = state.basic_state.bytecode.tell() state.basic_state.bytecode.seek(current) return vals
def read_entry(): """ READ a unit of DATA. """ current = state.basic_state.bytecode.tell() state.basic_state.bytecode.seek(state.basic_state.data_pos) if util.peek(state.basic_state.bytecode) in util.end_statement: # initialise - find first DATA util.skip_to(state.basic_state.bytecode, ('\x84',)) # DATA if state.basic_state.bytecode.read(1) not in ('\x84', ','): # out of DATA raise error.RunError(4) vals, word, literal = '', '', False while True: # read next char; omit leading whitespace if not literal and vals == '': c = util.skip_white(state.basic_state.bytecode) else: c = util.peek(state.basic_state.bytecode) # parse char if c == '' or (not literal and c == ',') or (c in util.end_line or (not literal and c in util.end_statement)): break elif c == '"': state.basic_state.bytecode.read(1) literal = not literal if not literal: util.require(state.basic_state.bytecode, util.end_statement+(',',)) else: state.basic_state.bytecode.read(1) if literal: vals += c else: word += c # omit trailing whitespace if c not in util.whitespace: vals += word word = '' state.basic_state.data_pos = state.basic_state.bytecode.tell() state.basic_state.bytecode.seek(current) return vals