
    X-Ph                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlmZmZmZmZmZmZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZ ddZddZd dZ d!dZ!dS )"zGenerate a class that represents a nested function.

The class defines __call__ for calling the function and allows access to
non-local variables defined in outer scopes.
    )annotations)ENV_ATTR_NAME	SELF_NAME)ClassIR)FuncDeclFuncIRFuncSignature
RuntimeArg)
BasicBlockCallRegisterReturnSetAttrValue)	RInstanceobject_rprimitive)	IRBuilder)FuncInfoImplicitClass)method_new_opbuilderr   returnNonec                   | j                                          dx}}d}|| j        v r#|dz   t          |          z   }|dz  }|| j        v #| j                            |           t          || j        d          }| j         j        rd|_        | j	        d         j
        r,t          | j	        d         j                  |j        t          <   |g|_        t!          |          | j         _        | j                            |           |                     |          }|                     || j         j        j                  | j         j        _        dS )	a  Generate an (incomplete) callable class representing a function.

    This can be a nested function or a function within a non-extension
    class.  Also set up the 'self' variable for that class.

    This takes the most recently visited function and returns a
    ClassIR to represent that function. Each callable class contains
    an environment attribute which points to another ClassIR
    representing the environment class where some of its variables can
    be accessed.

    Note that some methods, such as '__call__', are not yet
    created here. Use additional functions, such as
    add_call_to_callable_class(), to add them.

    Return a newly constructed ClassIR representing the callable
    class for the nested function.
    _objr   _   T)is_generatedN)fn_infonamespaced_namecallable_class_namesstraddr   module_name	is_nestedhas_dictfn_infoscontains_nestedr   	env_class
attributesr   mror   callable_classclassesappendadd_self_to_envreadfitemlineself_reg)r   name	base_namecountcallable_class_irself_targets         \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/irbuild/callable_class.pysetup_callable_classr;      s]   : "/99;;AAAAD9E
'.
.
.3U+
 '.
.
.  $$T***
  g&9MMM   *%)" + `6?@PQS@T@^6_6_$]3./%23D%E%EGO"O,--- ))*;<<K.5ll;H]Hb.c.cGO"+++    argslist[Register]blockslist[BasicBlock]sigr	   r    r   r   c                   t          |j                  |j        z
  }t          t	          t
          t                    f|j        d|         z   |j                  }t          d|j	        j
        j        | j        |          }t          ||||j        j        |j        j                  }||j	        j
        j        d<   ||j	        j
        j        d<   |S )a  Generate a '__call__' method for a callable class representing a nested function.

    This takes the blocks and signature associated with a function
    definition and uses those to build the '__call__' method of a
    given callable class, used to represent that function.
    N__call__)traceback_name)lenr=   num_bitmap_argsr	   r
   r   r   ret_typer   r-   irr5   r%   r   r2   r3   methodsmethod_decls)r   r=   r?   rA   r    nargscall_fn_decl
call_fn_irs           r:   add_call_to_callable_classrN   Q   s     MMC//E
	I0	1	13chvv6FF C J(>(A(FH[]`aaLdFGM$6w}GY  J 5?G%j19EG*:6r<   c                z   |j         j        }|                     |j        j        dt
          |t
                    5  |                     dt
                    }|                     dt
                     t                      t                      }}|                     | 	                    |          | 
                                d|          }|                     |||           |                     |           |                     t          |                                                      |                     |           |                     t          |                     t"          |                                 | 	                    |          g|                               ddd           dS # 1 swxY w Y   dS )z3Generate the '__get__' method for a callable class.__get__)	self_typeinstanceownerisN)r2   r3   enter_methodr-   rH   r   add_argumentr   translate_is_opr1   none_objectadd_bool_branchactivate_blockr$   r   selfcall_cr   )r   r    r3   rR   instance_blockclass_block
comparisons          r:   add_get_to_callable_classr`   l   s   =D			!# 
 
 
 
 
 ''
4EFFW&7888
 '1llJLL,,LL""G$7$7$9$94
 

 	
KHHH{+++F7<<>>**+++~...7>>-',,..',,xBXBX1Y[_``aa	
 	
 	
/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   E(F00F47F4r   c                   |j         }|                     t          |j        j        j        g |j                            }d}| j        j        r| j        j	        j
        }n6| j        j        r| j        j        j
        }n| j        j        r| j        j
        }|r/|                     t          |t          ||j                             |S )a,  Create an instance of a callable class for a function.

    Calls to the function will actually call this instance.

    Note that fn_info refers to the function being assigned, whereas
    builder.fn_info refers to the function encapsulating the function
    being turned into a callable class.
    N)r2   r$   r   r-   rH   ctorr3   r    is_generatorgenerator_classcurr_env_regr&   r)   r   r   )r   r    r2   func_regre   s        r:   instantiate_callable_classrg      s     ME{{4 6 9 >EJOOPPH L# 46C		" 45B		( 43 PGHm\5:NNOOOOr<   N)r   r   r   r   )r   r   r=   r>   r?   r@   rA   r	   r    r   r   r   )r   r   r    r   r   r   )r   r   r    r   r   r   )"__doc__
__future__r   mypyc.commonr   r   mypyc.ir.class_irr   mypyc.ir.func_irr   r   r	   r
   mypyc.ir.opsr   r   r   r   r   r   mypyc.ir.rtypesr   r   mypyc.irbuild.builderr   mypyc.irbuild.contextr   r   mypyc.primitives.misc_opsr   r;   rN   r`   rg    r<   r:   <module>rs      sT    # " " " " " 1 1 1 1 1 1 1 1 % % % % % % H H H H H H H H H H H H K K K K K K K K K K K K K K K K 8 8 8 8 8 8 8 8 + + + + + + 9 9 9 9 9 9 9 9 3 3 3 3 3 3;d ;d ;d ;d|   6
 
 
 
>" " " " " "r<   