U
    ñ¾|eš5  ã                   @   sf  d dl mZmZ d dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZ d dlmZ eddgƒZdZd	d
„ Zdd„ Zdd„ ZeejƒZeejƒZeeB ZeeddgƒƒZejZejZG dd„ deƒZdZdZ dZ!ej" #d¡Z$dd„ Z%dd„ Z&G dd„ deƒZ'G dd„ deƒZ(dd„ Z)G dd „ d e(ƒZ*ed!k�r8e*Z+ned!k �rHe(Z+ne,eƒ‚G d"d#„ d#ej-ƒZ.dS )$é    )Ú
namedtupleÚOrderedDictN)ÚCodeTypeÚ
ModuleType)ÚerrorsÚutilsÚ	serialize)Ú	PYVERSIONÚopcode_infoZargsizeé   c                 C   s   t | ddƒ}|rt | |ƒS | S )z°
    Objects that wraps function should provide a "__numba__" magic attribute
    that contains a name of an attribute that contains the actual python
    function object.
    Ú	__numba__N©Úgetattr)ÚobjÚattr© r   úP/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/bytecode.pyÚget_function_object   s    
r   c                 C   s   t | dt | ddƒƒS )z"Shamelessly borrowed from llpythonÚ__code__Ú	func_codeNr   )r   r   r   r   Úget_code_object   s    r   c                 C   s0   g }| D ]"}t j |¡}|d k	r| |¡ q|S ©N)ÚdisÚopmapÚgetÚappend)ÚseqÚlstÚsÚcr   r   r   Ú_as_opcodes#   s    r    ÚRETURN_VALUEÚRAISE_VARARGSc                   @   sP   e Zd ZdZdZdd„ Zedd„ ƒZedd„ ƒZd	d
„ Z	dd„ Z
edd„ ƒZdS )ÚByteCodeInstzÄ
    Attributes
    ----------
    - offset:
        byte offset of opcode
    - opcode:
        opcode integer value
    - arg:
        instruction arg
    - lineno:
        -1 means unknown
    )ÚoffsetÚnextÚopcodeÚopnameÚargÚlinenoc                 C   s.   || _ || _|| _tj| | _|| _d| _d S )Néÿÿÿÿ)r$   r%   r&   r   r'   r(   r)   ©Úselfr$   r&   r(   Ú
nextoffsetr   r   r   Ú__init__C   s    zByteCodeInst.__init__c                 C   s
   | j tkS r   )r&   ÚJUMP_OPS©r,   r   r   r   Úis_jumpK   s    zByteCodeInst.is_jumpc                 C   s
   | j tkS r   )r&   ÚTERM_OPSr0   r   r   r   Úis_terminatorO   s    zByteCodeInst.is_terminatorc                 C   sº   | j s
t‚tdkr<| jdd„ dD ƒkrL| j| jd d  S ntdkrLttƒ‚tdkrŒ| jtkrn| j| jd  S | jt	ks|t‚| jd d S n*| jtkr¢| j| j S | jt	ks°t‚| jS d S )N©é   é   c                 s   s   | ]}t j| V  qd S r   )r   r   )Ú.0Úkr   r   r   Ú	<genexpr>^   s   ÿz/ByteCodeInst.get_jump_target.<locals>.<genexpr>)ZJUMP_BACKWARDZPOP_JUMP_BACKWARD_IF_TRUEZPOP_JUMP_BACKWARD_IF_FALSEZPOP_JUMP_BACKWARD_IF_NONEZPOP_JUMP_BACKWARD_IF_NOT_NONEé   r   )r5   é
   )
r1   ÚAssertionErrorr	   r&   r$   r(   ÚNotImplementedErrorÚJREL_OPSr%   ÚJABS_OPSr0   r   r   r   Úget_jump_targetS   s"    	

ÿ

zByteCodeInst.get_jump_targetc                 C   s   d| j | j| jf S )Nz%s(arg=%s, lineno=%d))r'   r(   r)   r0   r   r   r   Ú__repr__u   s    zByteCodeInst.__repr__c                 C   s&   | j  d¡rdS | j dkrdS dS dS )zREffect of the block stack
        Returns +1 (push), 0 (none) or -1 (pop)
        ZSETUP_r:   Ú	POP_BLOCKr*   r   N)r'   Ú
startswithr0   r   r   r   Úblock_effectx   s
    
zByteCodeInst.block_effectN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r.   Úpropertyr1   r3   r@   rA   rD   r   r   r   r   r#   4   s   

"r#   r:   ÚNOPc                 c   sÀ   d}t | ƒ}d }}||k r¼| | }|t7 }|tkr˜| | |B }ttƒD ]}|| ||  d| > O }qH|t7 }|tkr¤|t||fV  |dt > }|}qnd}|t7 }d}||||fV  |}qdS )zd
    Returns a 4-int-tuple of
    (bytecode offset, opcode, argument, offset of next bytecode).
    r   é   N)ÚlenÚCODE_LENÚHAVE_ARGUMENTÚrangeÚARG_LENÚEXTENDED_ARGÚ
OPCODE_NOPÚ
NO_ARG_LEN)ÚcodeÚextended_argÚnr$   ÚiÚopr(   Újr   r   r   Ú_unpack_opargs�   s*    r[   c                 c   sJ   dt dtfV  | D ]2\}}}}|tkr.|t7 }|t |||t fV  qdS )zpPatch the bytecode stream.

    - Adds a NOP bytecode at the start to avoid jump target being at the entry.
    r   N)rS   Ú_FIXED_OFFSETr?   )Z	bc_streamr$   r&   r(   r-   r   r   r   Ú_patched_opargs±   s
    r]   c                   @   s8   e Zd Zdd„ Zdd„ Zdd„ Zdd„ ZeZd	d
„ ZdS )ÚByteCodeIterc                 C   s    || _ ttt| j jƒƒƒ| _d S r   )rU   Úiterr]   r[   Úco_code)r,   rU   r   r   r   r.   Á   s    zByteCodeIter.__init__c                 C   s   | S r   r   r0   r   r   r   Ú__iter__Å   s    zByteCodeIter.__iter__c                 C   s
   t | jƒS r   )r%   r_   r0   r   r   r   Ú_fetch_opcodeÈ   s    zByteCodeIter._fetch_opcodec                 C   s$   |   ¡ \}}}}|t||||d�fS )N)r$   r&   r(   r-   )rb   r#   r+   r   r   r   r%   Ë   s    
ÿzByteCodeIter.nextc                 C   s4   d}t |ƒD ]"}t| jƒ\}}||d| > O }q|S )Nr   rL   )rP   r%   r_   )r,   ÚsizeÚbufrX   Z_offsetÚbyter   r   r   Úread_argÒ   s
    zByteCodeIter.read_argN)	rE   rF   rG   r.   ra   rb   r%   Ú__next__rf   r   r   r   r   r^   À   s   r^   c                   @   s\   e Zd ZdZdZdd„ Zedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zedd„ ƒZdd„ ZdS )Ú	_ByteCodezF
    The decoded bytecode of a function, and related information.
    )	Úfunc_idÚco_namesÚco_varnamesÚ	co_constsÚco_cellvarsÚco_freevarsÚexception_entriesÚtableÚlabelsc                 C   s„   |j }tdd„ t |j¡D ƒƒ}| d¡ tt|ƒƒ}|  ||¡ || _	|j
| _
|j| _|j| _|j| _|j| _|| _t|ƒ| _d S )Nc                 s   s   | ]}|t  V  qd S r   )r\   )r7   Úxr   r   r   r9   å   s     z%_ByteCode.__init__.<locals>.<genexpr>r   )rU   Úsetr   Ú
findlabelsr`   Úaddr   r^   Ú_compute_linenori   rj   rk   rl   rm   rn   rp   Úsortedrq   )r,   ri   rU   rq   rp   r   r   r   r.   â   s    
z_ByteCode.__init__c                 C   s^   t  |¡D ]"\}}|t }||kr
||| _q
|j}| ¡ D ]}|jdkrR|j}q<||_q<|S )zI
        Compute the line numbers for all bytecode instructions.
        r   )r   Úfindlinestartsr\   r)   Úco_firstlinenoÚvalues)Úclsrp   rU   r$   r)   Z
adj_offsetZknownÚinstr   r   r   rv   ö   s    
z_ByteCode._compute_linenoc                 C   s   t | j ¡ ƒS r   )r_   rp   rz   r0   r   r   r   ra   	  s    z_ByteCode.__iter__c                 C   s
   | j | S r   ©rp   ©r,   r$   r   r   r   Ú__getitem__  s    z_ByteCode.__getitem__c                 C   s
   || j kS r   r}   r~   r   r   r   Ú__contains__  s    z_ByteCode.__contains__c                    s*   ‡fdd„‰ d  ‡ fdd„ˆj ¡ D ƒ¡S )Nc                    s   | d j ˆ jkrdS dS d S )Nr:   ú>ú )r$   rq   )rX   r0   r   r   Úlabel_marker  s    z$_ByteCode.dump.<locals>.label_markerÚ
c                 3   s.   | ]&}|d  j dkrdˆ |ƒf|  V  qdS )r:   ÚCACHEz
%s %10s	%sN)r'   )r7   rX   )rƒ   r   r   r9     s   þz!_ByteCode.dump.<locals>.<genexpr>)Újoinrp   Úitemsr0   r   )rƒ   r,   r   Údump  s    ÿz_ByteCode.dumpc              	   C   sÆ   i }|j }| dtj¡}t|tƒr(|j}| ¡ D ]V}|jdkr0|t	|j
ƒ }	|	|kr0z||	 }
W n tk
r|   ||	 }
Y nX |
||	< q0|D ]4}t|tƒrŒtt|ƒƒ}| |  |||j|j¡¡ qŒ|S )za
        Compute the globals used by the function with the given
        bytecode table.
        Ú__builtins__ÚLOAD_GLOBAL)Ú__globals__r   r   ÚbuiltinsÚ
isinstancer   Ú__dict__rz   r'   Ú_fix_LOAD_GLOBAL_argr(   ÚKeyErrorr   r   r^   ÚupdateÚ_compute_used_globalsrl   rj   )r{   Úfuncrp   rl   rj   ÚdÚglobsrŒ   r|   ÚnameÚvalueÚcoZsubtabler   r   r   r’     s,    



 ÿz_ByteCode._compute_used_globalsc                 C   s   |   | jj| j| j| j¡S )zv
        Get a {name: value} map of the globals used by this code
        object and any nested code objects.
        )r’   ri   r“   rp   rl   rj   r0   r   r   r   Úget_used_globals:  s     ÿz_ByteCode.get_used_globalsN)rE   rF   rG   rH   rI   r.   Úclassmethodrv   ra   r   r€   rˆ   r’   r™   r   r   r   r   rh   Ú   s   

rh   c                 C   s    t dkrt dkst‚| d? S | S )Nr4   r:   )r	   r<   )r(   r   r   r   r�   C  s    r�   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚByteCodePy311c                    s6   t ƒ  |¡ dd„ }t |j¡j}tt||ƒƒ| _d S )Nc                 S   s8   ddl m} || jt | jt | jt | j| jd�}|S )Nr   )Ú_ExceptionTableEntry)ÚstartÚendÚtargetÚdepthÚlasti)r   rœ   r�   r\   rž   rŸ   r    r¡   )Úentrœ   Úoutr   r   r   Úfixup_ehN  s      ýz(ByteCodePy311.__init__.<locals>.fixup_eh)Úsuperr.   r   ÚBytecoderU   ro   ÚtupleÚmap)r,   ri   r¤   Úentries©Ú	__class__r   r   r.   K  s    zByteCodePy311.__init__c                 C   sT   g }| j D ]0}|j|  kr&|jkr
n q
| |j|f¡ q
|rPt|ƒd }|S dS )zN
        Returns the exception entry for the given instruction offset
        r:   N)ro   r�   rž   r   r    Úmax)r,   r$   Ú
candidatesr¢   r   r   r   Úfind_exception_entry\  s    
z"ByteCodePy311.find_exception_entry)rE   rF   rG   r.   r®   Ú__classcell__r   r   rª   r   r›   J  s   r›   r4   c                   @   sB   e Zd ZdZe d¡Zedd„ ƒZdd„ Z	dd„ Z
ed	d
„ ƒZdS )ÚFunctionIdentityzò
    A function's identity and metadata.

    Note this typically represents a function whose bytecode is
    being compiled, not necessarily the top-level user function
    (the two might be distinct, e.g. in the `@generated_jit` case).
    r:   c                 C   sþ   t |ƒ}t|ƒ}t |¡}|s,t d| ¡‚z
|j}W n tk
rP   |j}Y nX | ƒ }||_	||_
| d¡d |_||_t |¡|_|jdkr–tjn|jj|_t |¡|_||_|j|_|j|_t|jƒ|_t|jƒ|_t| j ƒ}d !|j
|¡|_"||_#|S )zD
        Create the FunctionIdentity of the given function.
        z %s does not provide its bytecodeÚ.r*   Nz{}${})$r   r   r   Úpysignaturer   ÚByteCodeSupportErrorrG   ÚAttributeErrorrE   r“   Úfunc_qualnameÚsplitÚ	func_namerU   ÚinspectÚ	getmoduleÚmoduleÚ_dynamic_modnameÚmodnameÚisgeneratorfunctionÚis_generatorÚpysigÚco_filenameÚfilenamery   ÚfirstlinenorM   Ú
parametersÚ	arg_countÚlistÚ	arg_namesr%   Ú_unique_idsÚformatÚunique_nameÚ	unique_id)r{   Úpyfuncr“   rU   r¿   rµ   r,   Úuidr   r   r   Úfrom_function{  s>    
ÿ
ÿþ
zFunctionIdentity.from_functionc                 C   s   |   | j¡S )z:Copy the object and increment the unique counter.
        )rÍ   r“   r0   r   r   r   Úderive¥  s    zFunctionIdentity.derivec                 C   s   t | jd�S )ú4
        NOTE: part of ReduceMixin protocol
        )rË   )Údictr“   r0   r   r   r   Ú_reduce_statesª  s    zFunctionIdentity._reduce_statesc                 C   s
   |   |¡S )rÏ   )rÍ   )r{   rË   r   r   r   Ú_rebuild°  s    zFunctionIdentity._rebuildN)rE   rF   rG   rH   Ú	itertoolsÚcountrÇ   rš   rÍ   rÎ   rÑ   rÒ   r   r   r   r   r°   q  s   

)r°   )/Úcollectionsr   r   r   r¸   rÓ   Útypesr   r   Ú
numba.corer   r   r   Znumba.core.utilsr	   r
   r\   r   r   r    Ú	frozensetÚhasjrelr>   Úhasjabsr?   r/   r2   rR   rO   Úobjectr#   rN   rQ   rT   r'   ÚindexrS   r[   r]   r^   rh   r�   r›   ÚByteCoder=   ÚReduceMixinr°   r   r   r   r   Ú<module>   sD   	

Q$i

