dual_tape/assembler.py
def assembler(file: str) -> Tuple[int, Dict[int, int], Dict[int, int]]:
    """
    info: Takes a program and converts it into machine code.
    :param file: str
    :return: Tuple[Dict[int, int], Dict[int, int]]
    """
    instructions, data = {}, {}
    name_space = {}
    at = 0
    for parts, _ in _read_file(file):
        if parts and not parts[0].startswith("#"):
            if parts[0].startswith("@"):
                name = parts[0][1:]
                if name in name_space:
                    raise AssemblerError.name_collection(name)
                name_space[name] = at
            at += 1
    at = 0
    for line_number, line_data in enumerate(_read_file(file)):
        parts, line = line_data
        if parts and not parts[0].startswith("#"):
            if parts[0].startswith("@"):
                del parts[0]
            try:
                if len(parts[0]) != 1 or ord(parts[0]) not in INSTRUCTIONS:
                    raise AssemblerError.bad_line(line, line_number + 1)
                instructions[at] = ord(parts.pop(0))
                if parts and not parts[0].startswith("#"):
                    try:
                        data[at] = int(parts[0])
                        del parts[0]
                    except ValueError:
                        if parts[0].startswith("@"):
                            name = parts.pop(0)[1:]
                            if name not in name_space:
                                raise AssemblerError.missing_name(name)
                            data[at] = name_space[name]
                        elif parts[0].startswith("c") and len(parts[0]) == 2:
                            data[at] = ord(parts.pop(0)[1])
                        else:
                            raise AssemblerError.bad_line(line, line_number + 1)
                    if parts and not parts[0].startswith("#"):
                        raise AssemblerError.bad_line(line, line_number + 1)
            except IndexError:
                raise AssemblerError.bad_line(line, line_number + 1)
            at += 1
    entry_point = name_space.get("")
    if entry_point is None:
        raise AssemblerError.missing_entry_point()
    return entry_point, instructions, data

    info: Takes a program and converts it into machine code.
    :param file: str
    :return: Tuple[Dict[int, int], Dict[int, int]]
    
Takes a program and converts it into machine code.
Takes a program and converts it into machine code .
def assembler(file: str) -> Tuple[int, Dict[int, int], Dict[int, int]]:
    instructions, data = {}, {}
    name_space = {}
    at = 0
    for parts, _ in _read_file(file):
        if parts and not parts[0].startswith("#"):
            if parts[0].startswith("@"):
                name = parts[0][1:]
                if name in name_space:
                    raise AssemblerError.name_collection(name)
                name_space[name] = at
            at += 1
    at = 0
    for line_number, line_data in enumerate(_read_file(file)):
        parts, line = line_data
        if parts and not parts[0].startswith("#"):
            if parts[0].startswith("@"):
                del parts[0]
            try:
                if len(parts[0]) != 1 or ord(parts[0]) not in INSTRUCTIONS:
                    raise AssemblerError.bad_line(line, line_number + 1)
                instructions[at] = ord(parts.pop(0))
                if parts and not parts[0].startswith("#"):
                    try:
                        data[at] = int(parts[0])
                        del parts[0]
                    except ValueError:
                        if parts[0].startswith("@"):
                            name = parts.pop(0)[1:]
                            if name not in name_space:
                                raise AssemblerError.missing_name(name)
                            data[at] = name_space[name]
                        elif parts[0].startswith("c") and len(parts[0]) == 2:
                            data[at] = ord(parts.pop(0)[1])
                        else:
                            raise AssemblerError.bad_line(line, line_number + 1)
                    if parts and not parts[0].startswith("#"):
                        raise AssemblerError.bad_line(line, line_number + 1)
            except IndexError:
                raise AssemblerError.bad_line(line, line_number + 1)
            at += 1
    entry_point = name_space.get("")
    if entry_point is None:
        raise AssemblerError.missing_entry_point()
    return entry_point, instructions, data
def assembler ( file : str ) -> Tuple [ int , Dict [ int , int ] , Dict [ int , int ] ] : instructions , data = { } , { } name_space = { } at = 0 for parts , _ in _read_file ( file ) : if parts and not parts [ 0 ] . startswith ( "#" ) : if parts [ 0 ] . startswith ( "@" ) : name = parts [ 0 ] [ 1 : ] if name in name_space : raise AssemblerError . name_collection ( name ) name_space [ name ] = at at += 1 at = 0 for line_number , line_data in enumerate ( _read_file ( file ) ) : parts , line = line_data if parts and not parts [ 0 ] . startswith ( "#" ) : if parts [ 0 ] . startswith ( "@" ) : del parts [ 0 ] try : if len ( parts [ 0 ] ) != 1 or ord ( parts [ 0 ] ) not in INSTRUCTIONS : raise AssemblerError . bad_line ( line , line_number + 1 ) instructions [ at ] = ord ( parts . pop ( 0 ) ) if parts and not parts [ 0 ] . startswith ( "#" ) : try : data [ at ] = int ( parts [ 0 ] ) del parts [ 0 ] except ValueError : if parts [ 0 ] . startswith ( "@" ) : name = parts . pop ( 0 ) [ 1 : ] if name not in name_space : raise AssemblerError . missing_name ( name ) data [ at ] = name_space [ name ] elif parts [ 0 ] . startswith ( "c" ) and len ( parts [ 0 ] ) == 2 : data [ at ] = ord ( parts . pop ( 0 ) [ 1 ] ) else : raise AssemblerError . bad_line ( line , line_number + 1 ) if parts and not parts [ 0 ] . startswith ( "#" ) : raise AssemblerError . bad_line ( line , line_number + 1 ) except IndexError : raise AssemblerError . bad_line ( line , line_number + 1 ) at += 1 entry_point = name_space . get ( "" ) if entry_point is None : raise AssemblerError . missing_entry_point ( ) return entry_point , instructions , data
info: Takes a program and converts it into machine code.
info : Takes a program and converts it into machine code .
"""
    info: Takes a program and converts it into machine code.
    :param file: str
    :return: Tuple[Dict[int, int], Dict[int, int]]
    """
None
file
str
None