def test_to_bits_string(self): for want, input_ in [ ('0b0', 0b0), ('0b1', 0b1), ('0b10', 0b10), ('0b1010', 0b1010), ('0b1_0000', 0b1_0000), ('0b10_0000', 0b10_0000), ('0b1010_0101', 0b1010_0101), ('0b1_1010_0101', 0b1_1010_0101), ]: self.assertEqual(want, bit_helpers.to_bits_string(input_))
def main(argv): if len(argv) > 1: raise app.UsageError('Too many command-line arguments.') init_xls.init_xls(sys.argv) stmt_index = 0 last_result = None while True: prompt = f'dslx[{stmt_index}]> ' if sys.stdin.isatty() else '' try: # TODO(leary): Update this to support multi-line input. line = input(prompt) except EOFError: if sys.stdin.isatty(): print('\r', end='') break # Some helper 'magic' commands for printing out values in different ways. if line == '%int': if last_result is None: print('No last result for magic command.') continue assert isinstance(last_result, value_mod.Value), last_result print(last_result.get_bit_value_int64()) continue if line == '%bin': if last_result is None: print('No last result for magic command.') assert isinstance(last_result, value_mod.Value), last_result assert last_result is not None print( bit_helpers.to_bits_string(last_result.get_bit_value_uint64())) continue result = handle_line(line, stmt_index) if result is None: continue last_result = result stmt_index += 1