
    qi;                     0    d dl Z d dlmZmZ  G d d      Zy)    N)AnyOptionalc                   l    e Zd ZdZdededdfdZdedefdZddZde	e
   fd	Zdefd
Zde	e
   fdZy)_PyInstDecoderzH
    Decodes Python bytecode instructions to extract variable names
    code_objectlastireturnNc                     || _         t        t        j                  |            | _        | j                  |      | _        y )N)r   listdisget_instructionsinstructions_find_instruction_indexoffset)selfr   r   s      d/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/functorch/dim/_py_inst_decoder.py__init__z_PyInstDecoder.__init__
   s4    & !5!5k!BC2259    c                 l    d}t        | j                        D ]  \  }}|j                  |k  r|} |S  |S )z<Find instruction index corresponding to lasti (byte offset).r   )	enumerater   r   )r   r   best_idxiinstrs        r   r   z&_PyInstDecoder._find_instruction_index   sG     !$"3"34 	HAu||u$	
 r   c                 .    | xj                   dz  c_         y)z Advance to the next instruction.   N)r   r   s    r   nextz_PyInstDecoder.next   s    qr   c                     | j                   t        | j                        k  r#| j                  | j                      j                  S y)z/Get the opcode name of the current instruction.N)r   lenr   opnamer   s    r   opcodez_PyInstDecoder.opcode   s7    ;;T..//$$T[[1888r   c                     | j                   t        | j                        k  r'| j                  | j                      j                  xs dS y)z,Get the argument of the current instruction.r   )r   r   r   argr   s    r   opargz_PyInstDecoder.oparg%   s<    ;;T..//$$T[[155::r   c                 `   | j                         }|syd}|dv r| j                  j                  }nQ|dk(  r| j                  j                  }n5|dk(  r/| j                  j                  }|s| j                  j
                  }ny| j                         }|rd|cxk  rt        |      k  r||   S  yy)zA
        Extract variable name from current instruction.
        N)
STORE_NAMESTORE_GLOBAL
STORE_FASTSTORE_DEREFr   )r!   r   co_namesco_varnamesco_cellvarsco_freevarsr$   r   )r   r    namesr#   s       r   namez_PyInstDecoder.name+   s     33$$--E|#$$00E}$$$00E((44jjlQ#*E
*: + r   )r	   N)__name__
__module____qualname____doc__r   intr   r   r   r   strr!   r$   r/    r   r   r   r      se    :C : : :

S 
S 
 s hsm r   r   )r   typingr   r   r   r6   r   r   <module>r8      s    
  > >r   