o
    hj                     @  s   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ dddZddddZedkrNee dS )a  Command-line entry point: `mbc build script.mb -o script.hex`.

Wires the pipeline together. `build` will raise NotImplementedError today
(parser and codegen are unfinished) -- that's expected; this exists so the
plumbing and error reporting are in place as each stage gets built out.
    )annotationsN)Path   )__version__)generate_bytecode)write_intel_hex)tokenize)parse)expand_macrossource_pathr   output_pathreturnNonec                 C  s6   |   }tt|}t|}t|}|t| d S N)	read_textr
   r   r	   r   
write_textr   )r   r   sourcetokensprogrambytecode r   J/sessions/nice-awesome-ritchie/mnt/compiler/src/microbasic_compiler/cli.pybuild   s
   r   argvlist[str] | Noneintc              
   C  s"  t jddd}|jdddt d |jdd	d
}|jddd}|jdtdd |jddtdd || }|jdkr|j	pC|j
d}zt|j
| W n9 tyi } ztd| tjd W Y d }~dS d }~w ty } ztd| tjd W Y d }~dS d }~ww td|  dS dS )NmbczRoboteq MicroBasic compiler)progdescriptionz	--versionversionz	%(prog)s )actionr   commandT)destrequiredr   z!Compile a .mb script to Intel HEX)helpr   zPath to .mb source file)typer$   z-oz--outputz,Output .hex path (default: alongside source)z.hexzerror: )filer   zwrote r   )argparseArgumentParseradd_argumentr   add_subparsers
add_parserr   
parse_argsr!   outputr   with_suffixr   NotImplementedErrorprintsysstderr	Exception)r   parsersubbuild_pargsr   excr   r   r   main   s.   

r9   __main__)r   r   r   r   r   r   r   )r   r   r   r   )__doc__
__future__r   r'   r1   pathlibr    r   codegenr   hexfiler   lexerr   r4   r	   preprocessorr
   r   r9   __name__
SystemExitr   r   r   r   <module>   s     

