
    X-Ph                        d 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
mZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZmZmZ dd	lmZmZ dd
l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@mAZAmBZB ddlCmDZD ddlEmFZFmGZGmHZHmIZI ddlJmKZKmLZL ddlMmNZN ddlOmPZPmQZQmRZR ddlSmTZT ddlUmVZV ddlWmXZX ddlYmZZZm[Z[ ddZ\dd!Z]dd$Z^dd(Z_	 ddd3Z`dd6Zadd7Zb	 ddd@ZcddBZdddEZeddFZfddHZgddIZhd8dJddRZi G dS dTe          ZjddYZkdd[Zldd]Zmdd_ZnddaZoddfZpddjZqddlZrddoZsddsZtddvZuddwZvddxZwddzZxdd|Zydd}ZzddZ{ddZ|ddZ}d)S )a  Transform mypy AST functions to IR (and related things).

Normal functions are translated into a list of basic blocks
containing various IR ops (defined in mypyc.ir.ops).

This also deals with generators, async functions and nested
functions. All of these are transformed into callable classes. These
have a custom __call__ method that implements the call, and state, such
as an environment containing non-local variables, is stored in the
instance of the callable class.
    )annotations)defaultdict)Sequence)
NamedTuple)
ArgKindClassDef	DecoratorFuncBaseFuncDefFuncItem
LambdaExprOverloadedFuncDefTypeInfoVar)CallableTypeTypeUnboundTypeget_proper_type)LAMBDA_NAMEPROPSET_PREFIX	SELF_NAME)ClassIRNonExtClassInfo)FUNC_CLASSMETHODFUNC_NORMALFUNC_STATICMETHODFuncDeclFuncIRFuncSignature
RuntimeArg)
BasicBlockGetAttrIntegerLoadAddressLoadLiteralRegisterReturnSetAttrUnboxUnreachableValue)	RInstancebool_rprimitivedict_rprimitiveint_rprimitiveobject_rprimitive)	IRBuildercalculate_arg_defaultsgen_arg_defaults)add_call_to_callable_classadd_get_to_callable_classinstantiate_callable_classsetup_callable_class)FuncInfo)add_vars_to_envfinalize_env_classload_env_registerssetup_env_class)gen_generator_funcgen_generator_func_body)AssignmentTarget)dict_get_method_with_nonedict_new_opdict_set_item_op)py_setattr_op)register_function)builtin_names)is_same_method_signatureis_same_typebuilderr1   fdefr   returnNonec                2   | j                             || j        j                  }t	          | ||j        |          \  }}|r*|                     t          | |          ||j                   t          | |           | 
                    ||j                   d S N)mapperfdef_to_sigoptionsstrict_dunders_typinggen_func_itemnameassignget_func_targetlinemaybe_insert_into_registry_dictadd_function)rH   rI   sigfunc_irfunc_regs        V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/irbuild/function.pytransform_func_defr]   X   s    
.
$
$T7?+P
Q
QC%gtTYDDGX  Lw55xKKK#GT222$),,,,,    or   c                L    |j         sJ |                     |j                    d S rM   )implaccept)rH   r_   s     r\   transform_overloaded_func_defrc   d   s'    6MMMNN16r^   decr	   c                   | j                             |j        | j        j                  }t          | |j        |j        j        |          \  }}d }|rKt          | |j        |          }|                     t          | |j                  ||j        j
                   nd|j        | j        v rV|j        j                            d          d         }|                     ||j
                  }t          | |j        |          }|S|                     t           |                                 |                     |j        j                  |g|j
                   t'          | |j                   | j                            |           d S )N.)rN   rO   funcrP   rQ   rR   rS   load_decorated_funcrT   rU   rV   fdefs_to_decoratorsfullnamesplitload_global_strprimitive_oprB   load_globals_dictload_strrW   	functionsappend)rH   rd   rY   rZ   r[   decorated_funcrS   	orig_funcs           r\   transform_decoratorru   j   sc   
.
$
$SXw/T
U
UC%gsxLLGX#'N K,WchIIw99>38=YYYY 
W0	0	0x &&s++B/ ++D#(;;	,Wch	JJ!&&(('*:*:38=*I*I>Z	
 	
 	
 $GSX666W%%%%%r^   exprr   r+   c           	     J   t          | j        |                   }t          |t                    sJ g }t	          |j        |j                  D ]W\  }}||j        _        |	                    t          |j        j        |                     |          |j                             X|                     |j                  }t          ||          }t            | j         }| xj        dz  c_        t%          | |||          \  }	}
|
J | j        	                    |	           |
S )N   )r   types
isinstancer   zip	arguments	arg_typesvariabletyperr   r    rS   type_to_rtypekindret_typer   r   lambda_counterrR   rq   )rH   rv   typruntime_argsargarg_typer   fsigfnamerZ   r[   s              r\   transform_lambda_exprr      s*   
'--
.
.Cc<(((((LT^S];; 
 
X$s|('*?*?*I*I38TT	
 	
 	
 	
 $$S\22Hx00D4G244Ea%gtUDAAGXW%%%Or^   Nfitemr   rS   strrY   r   cdefClassDef | Nonetuple[FuncIR, Value | None]c                D    d}| j         v pt          |t                    }| j                                        v }| j        v }| j        v d}	t           |          }
d}r& j        j	        j
                 }|j         }	j        }rt          |          }n|}t          |||t                     ||||	|
	  	        }|j        }                     |j                   |s|rt'                      |s|	rt)                      |r,t+            fd          \  }}t-           ||           nt/                     \  }}rI j                            |           t          |t4                    sJ t7           ||j        |          S ||fS )a  Generate and return the FuncIR for a given FuncDef.

    If the given FuncItem is a nested function, then we generate a
    callable class representing the function and use that instead of
    the actual function. if the given FuncItem contains a nested
    function, then we generate an environment class so that inner
    nested functions can access the environment of the given FuncDef.

    Consider the following nested function:

        def a() -> None:
            def b() -> None:
                def c() -> None:
                    return None
                return None
            return None

    The classes generated would look something like the following.

                has pointer to        +-------+
        +-------------------------->  | a_env |
        |                             +-------+
        |                                 ^
        |                                 | has pointer to
    +-------+     associated with     +-------+
    | b_obj |   ------------------->  | b_env |
    +-------+                         +-------+
                                          ^
                                          |
    +-------+         has pointer to      |
    | c_obj |   --------------------------+
    +-------+
    NF)	r   rS   
class_name	namespace	is_nestedcontains_nestedis_decorated
in_non_extadd_nested_funcs_to_env)r   c           	     .    t          | ||          S rM   )gen_func_ir)argsblocksfn_inforH   r   is_singledispatchrY   s      r\   <lambda>zgen_func_item.<locals>.<lambda>   s!    +vsGT;L+ + r^   )nested_fitemsrz   r   encapsulating_funcskeysrj   singledispatch_implshas_nested_func_self_referencerN   
type_to_irinfois_ext_classrS   singledispatch_main_func_namer8   gen_func_nsis_generatorenterr   r<   r7   r=   r>   gen_func_bodyrq   rr   r   gen_dispatch_func_ir)rH   r   rS   rY   r   r[   r   r   r   r   r   r   ir	func_namer   r   rZ   r   s   `  ``            @r\   rR   rR      s#   V "H
 ..O*UJ2O2OIw:??AAAOG77L!==J<WeLLJ ^&ty1(
Y
 1$77			g&&'! 7
 
 
G 'LMM'CLM111  !, !    &J &W%%% Q.      
 
 	 #x@@@@)'3>OPP M  )))%)))))#GUGL$LLLHr^   r   boolc           	        t          |            t          |            | j        j        rt	          |            t          |            |                     | j        j        j                   | 	                                 | j
        d         }|                                 \  }}}}}	t          | ||||	||          \  }
}t          | |	||           |
|fS )Nrg   )r;   r3   r   r   r:   r9   rb   r   bodymaybe_add_implicit_return	symtablesleaver   r2   )rH   rY   r   r   symtabler   _r   r   r   rZ   r[   s               r\   r   r     s     wW& $7###GNN7?(-...%%'''  $H)0&D!VXw#GT63O`aaGX 7GXx@@@Hr^   c                     t          d  j                            |t                                D                       rdS t           fd j                            |g           D                       S )zDoes a nested function contain a self-reference in its body?

    If a nested function only has references in the surrounding function,
    we don't need to add it to the environment.
    c              3  @   K   | ]}t          |t                    V  d S rM   )rz   r
   ).0syms     r\   	<genexpr>z1has_nested_func_self_reference.<locals>.<genexpr>3  s,      
Y
Y:c8$$
Y
Y
Y
Y
Y
Yr^   Tc              3  8   K   | ]}t          |          V  d S rM   )r   )r   nestedrH   s     r\   r   z1has_nested_func_self_reference.<locals>.<genexpr>5  sA         	'w77     r^   )anyfree_variablesgetsetr   )rH   r   s   ` r\   r   r   -  s     
Y
Y0F0J0J5RURWRW0X0X
Y
Y
YYY t    155eR@@     r^   Fr   list[Register]r   list[BasicBlock]r   r8   is_singledispatch_main_funcc           	        d}|j         s|j        r4t          | ||||          }t          | |           t	          | |          }nt          |j        t                    sJ | j        j	        |j                 }	|j
        s|rb|dn|j        }
t          |j        |
| j        ||	j        |	j        |	j                  }	t#          |	|||j        j        |j        j                  }n(t#          |	|||j        j        |j        j                  }||fS )a  Generate the FuncIR for a function.

    This takes the basic blocks and function info of a particular
    function and returns the IR. If the function is nested,
    also returns the register containing the instance of the
    corresponding callable class.
    N)traceback_name)r   r   r4   r5   r6   rz   r   r   rN   func_to_declr   rS   r   module_namer   is_prop_getteris_prop_setterr   rV   )rH   r   r   rY   r   r   r   r[   rZ   	func_declr   s              r\   r   r   ;  s5     "H G. ,WdFCQQ!'7333-gw??'-11111N/>	 	#> 	!%49J #(( I 4);GML^  GG 4);GML^  G Xr^   r   c           	        |j         }| j        j        |j                 }| j                            || j        j                  }t          | ||||          \  }}| j        	                    |           t          | |          r|j                            d          \  }}}|                     |j                  }	|                     |	||j                  }
t!          | ||
          }|                     t$          |	|                     |          |g|j                   |j        r||j        vsJ |d f|j        |<   n0|| j        v r'||j        v sJ |j        |         \  }}||f|j        |<   ||j        |j        j         <   |j        dd          D ]}||j        v r|dk    rzt7          |j        |         j        |j        |         j                  sJt;          | |j        |         j        ||||          }||j        ||f<   | j        	                    |           |j        rCt;          | |j        ||||d          }||j        ||f<   | j        	                    |           d S d S )Nrf   rx   __init__T	do_py_ops) rS   rN   r   r   rO   rP   rQ   rR   rq   rr   r   rk   
rpartitionload_native_type_objectpy_get_attrrV   ri   rn   rC   rp   is_property
propertiesprop_settersmethodsdeclmromethod_declsrF   rY   gen_glueglue_methodsallow_interpreted_subclasses)rH   r   rI   rS   class_irrY   rZ   r[   r   r   rt   rs   	getter_irbasefs                  r\   handle_ext_methodr   h  s   9D~(3H
.
$
$T7?+P
Q
QC%gtT3EEGXW%%%GT"" 
]--c22
1d --dm<<''T49==	 -WdIFF 	C!1!1$!7!7H$)	
 	
 	
  
9 8.....%,dOD!!	%	%	%x******40	1%.$8D!*1HW\&' QRR  ( (D%%%
"",%d+/1B41H1L  # $"3D"9"=wRVX\]]A23H!4,/$$Q''' , $Wgk7HhX\]]]23x./  #####$ $r^   non_extr   c                (   |j         }| j                            || j        j                  }t          | ||||          \  }}|J | j                            |           t          | |          r|}t          | ||          }|j
        r9|                     d|j                  }	|                     |	|g|j                  }n| j        j        |         j        t           k    r9|                     d|j                  }
|                     |
|g|j                  }nX| j        j        |         j        t"          k    r8|                     d|j                  }|                     ||g|j                  }|                     ||||j                   d S )Nzbuiltins.propertyzbuiltins.classmethodzbuiltins.staticmethod)rS   rN   rO   rP   rQ   rR   rq   rr   r   ri   r   load_module_attr_by_fullnamerV   py_callr   r   r   r   add_to_non_ext_dict)rH   r   r   rI   rS   rY   rZ   r[   rt   propcls_meth	stat_meths               r\   handle_non_ext_methodr     s    9D
.
$
$T7?+P
Q
QC%gtT3EEGXW%%%GT"" A	&wi@@  
E334GSS??4(TY??		$T	*	/3C	C	C778NPTPYZZ??8hZCC		$T	*	/3D	D	D889PRVR[\\	??9xj$)DDxCCCCCr^   c                J    d                     d | j        D                       S )zJGenerate a namespace for a nested function using its outer function names.r   c              3  p   K   | ]1}|j         r(|j         d k    |j         |j        sdn	d|j        z   z   V  2dS )z<module> r   N)rS   r   )r   r   s     r\   r   zgen_func_ns.<locals>.<genexpr>  s`        9 j00 		tIRRC$/4IJ0000 r^   )joinfn_infos)rH   s    r\   r   r     s7    88  $     r^   orig_func_regc                   t          | |          s|S | j        |         }|}t          |          D ]P}|                    | j                  }t          |t                    sJ |                     ||g|j                  }Q|S )zApply decorators to a function.

    Given a decorated FuncDef and an instance of the callable class
    representing that FuncDef, apply the corresponding decorator
    functions on that decorated FuncDef and return the decorated
    function.
    )	r   rj   reversedrb   visitorrz   r+   r   rV   )rH   rI   r   
decoratorsr[   d	decorators          r\   ri   ri     s     &&  ,T2JHj!! I IHHW_--	)U+++++??9xj(-HHOr^   c                    || j         v S rM   )rj   rH   rI   s     r\   r   r     s    7...r^   r   base_sigtargetr   clsr   r   r   c          	     x    |j         rt          | |||||j        |          S t          | |||||j        |          S )ay  Generate glue methods that mediate between different method types in subclasses.

    Works on both properties and methods. See gen_glue_methods below
    for more details.

    If do_py_ops is True, then the glue methods should use generic
    C API operations instead of direct calls, to enable generating
    "shadow" glue methods that work with interpreted subclasses.
    )r   gen_glue_propertyrV   gen_glue_method)rH   r   r   r   r   rI   r   s          r\   r   r     sJ    &  [ (FCtyR[\\\w&#tTYPYZZZr^   c                  .    e Zd ZU ded<   ded<   ded<   dS )ArgInfozlist[Value]r   zlist[str | None]	arg_nameszlist[ArgKind]	arg_kindsN)__name__
__module____qualname____annotations__ r^   r\   r   r     s6         r^   r   rt_argsSequence[RuntimeArg]rV   intc                     d |D             } fd|D             }d |D             }d |D             }t          |||          S )Nc                D    g | ]}t          |j                  |j        fS r  )r   rS   r   r   r   s     r\   
<listcomp>zget_args.<locals>.<listcomp>  s'    >>>s#ch--*>>>r^   c           	     n    g | ]1\  }}                                         ||d                     2S )T)is_arg)readadd_local_reg)r   varr   rH   rV   s      r\   r  zget_args.<locals>.<listcomp>  sP       C 	W**3T*BBDII  r^   c                    g | ]D}|j                                         s |j                                         r|j        s|j        nd ES rM   )r   is_namedis_optionalpos_onlyrS   r  s     r\   r  zget_args.<locals>.<listcomp>  s\        H%%''bCH,@,@,B,Bb3<b^b  r^   c                    g | ]	}|j         
S r  )r   r  s     r\   r  zget_args.<locals>.<listcomp>  s    ---c---r^   )r   )rH   r  rV   	fake_varsr   r  r  s   ` `    r\   get_argsr    s    >>g>>>I    "  D   I .-W---I4I...r^   	do_pycallc                   t          | ||j        j        |           |                                  |j        | j        d<   t          |j                  }|j        j        t          k    r0t          |j        d         j        t          |                    |d<   t          | ||          }|j        |j        |j        }}
}	d}|j        rW|	d|j                  }	|
d|j                  }
|d|j                  }t          | j        j        |j         d                   }t%          d |
D                       r*t%          d |j        j        j        D                       rd}|ry|j        j        t&          k    r| j                            |          }d}n
|	d         }d}| j                            ||j        |	|d         ||
|d         ||d                   }n%| j                            |j        |	|
|||          }|                     ||j        |          }|                     t3          |                     |                                 \  }}}}}|j        r|d|j                  }t7          t9          |j        d	z   |j        z   d
z   |j        | j        t=          ||          |j        j                  ||          S )aU  Generate glue methods that mediate between different method types in subclasses.

    For example, if we have:

    class A:
        def f(builder: IRBuilder, x: int) -> object: ...

    then it is totally permissible to have a subclass

    class B(A):
        def f(builder: IRBuilder, x: object) -> int: ...

    since '(object) -> int' is a subtype of '(int) -> object' by the usual
    contra/co-variant function subtyping rules.

    The trickiness here is that int and object have different
    runtime representations in mypyc, so A.f and B.f have
    different signatures at the native C level. To deal with this,
    we need to generate glue methods that mediate between the
    different versions by coercing the arguments and return
    values.

    If do_pycall is True, then make the call using the C API
    instead of a native call.
    rg   r   Nc              3  >   K   | ]}|                                 V  d S rM   )is_star)r   r   s     r\   r   z"gen_glue_method.<locals>.<genexpr>R  s*      
0
0d4<<>>
0
0
0
0
0
0r^   c              3  J   K   | ]}|j                                          V  d S rM   )r   r  r  s     r\   r   z"gen_glue_method.<locals>.<genexpr>R  sD       9 9#&CH9 9 9 9 9 9r^   Trx   )bitmap_args___glue)check_native_overrider   rY   r   r   	ret_typeslistr   r   r   r    rS   r,   r  r  r  num_bitmap_argsrH   r   r   get_native_typepy_method_callcallcoerceaddr'   r   r   r   r   r   )rH   r   r   r   r   rV   r  r  arg_infor   r  r  r   firststretvalarg_regsr   r   r   s                       r\   r   r     s   D '8V[_dCCCMMOOO$-Gb8=!!G{;&&a 0 5y~~FF
$//H!)0BHDVY)DK N/x///09!9 99:	9!9 99:	7?/1I0I0K0KLMM 
0
0i
0
0
000 S 9 9*0+/*>9 9 9 6 6  	 
;000O33C88EBBGEB//6;RSS	4233233
 
 %%Ky)T{ & 
 
 ^^FH$5t<<FKKv'.}}$Ha1 75X5556K$*W4H'8,,K	
 	
 	
 
 
r^   sub_sigc           	        t          |                                |                                          D ]\  }}|j        j        r7|j        s0|j        r)|j        r"|                     dd|j         dz   |           |j        j        s|j        j        rDt          |j        |j                  s*|                     dd|j         d|j         dz   |           dS )zReport an error if an override changes signature in unsupported ways.

    Glue methods can work around many signature changes but not all of them.
    zAn argument with type "z6" cannot be given a default value in a method overridezIncompatible argument type z" (base class has type "z")N)r{   	real_argsr   error_overlapoptionalr&  errorrG   )rH   r   r1  rV   base_argsub_args         r\   r#  r#  y  s    !!3!3!5!5w7H7H7J7JKK  '=& 		$ )9 h>V  ,_(-___`  
 =& 	',*D 	w|<<  1Q',QQQQQR   r^   do_pygetattrc                   |                                   t          t          t          |                    }|                     |          }|                     ||          }	|j        | j        d<   |r|                     |	|j	        |          }
n)| 
                    t          |	|j	        |                    }
|                     |
|j        |          }| 
                    t          |                     |                                 \  }}}}}t          t!          |j	        dz   |j	        z   dz   |j	        | j        t%          |g|                    ||          S )a  Generate glue methods for properties that mediate between different subclass types.

    Similarly to methods, properties of derived types can be covariantly subtyped. Thus,
    properties also require glue. However, this only requires the return type to change.
    Further, instead of a method call, an attribute get is performed.

    If do_pygetattr is True, then get the attribute using the Python C
    API instead of a native call.
    rg   r!  r"  )r   r    r   r,   add_self_to_envr  r   r$  r   rS   r+  r"   r*  r'   r   r   r   r   r   )rH   rY   r   r   r   rV   r:  rt_argself_targetr   r/  retboxr   r   r   return_types                   r\   r   r     s;   $ MMOOO	9S>>22F))#..K
,,{D
)
)CLGb >$$S&+t<<WS&+t<<==^^FCL$77FKKv&-mmoo#D!V[!K$*W4H6(K00		
 	
 		 	 	r^   r?   c                    |j         r|                     |j                   S | j        j        s| j        j        r|                     |          S |                     |t                    S )zGiven a FuncDef, return the target for the instance of its callable class.

    If the function was not already defined somewhere, then define it
    and add it to the current environment.
    )original_deflookupr   r   r   r  r0   r   s     r\   rU   rU     sf      1~~d/000# $w'N $~~d###  '8999r^   r   r   unbounded_typeType | Nonec                .   t          |t                    r|j        n|j                            d|j                   || j        j        v r.| j        j        |         }| j                            |          }n|j        t          v r:t          |j                 \  }}| 
                    t          |||                    }nt          fd| j        D             dt                    x}r|                     |          }	|k    r+                    | d                              d          ng D ]}
|                     |	|
|          }	| j                            |	|j        t(          |d          }n|                     |j        |          }|S )Nrf   c              3  X   K   | ]$}|k    s                     | d            |V  %dS )rf   N)
startswith)r   iload_attr_paths     r\   r   zload_type.<locals>.<genexpr>  sJ      aaq~':':n>W>W[\X_X_X_>`>`':':':':':aar^   r   )defaultkeyF)borrow)rz   r   rS   rk   removesuffixrN   r   rH   r'  rE   r+  r$   maximportslenload_moduleremoveprefixrl   r   get_attrr0   rm   )rH   r   rD  rV   r   	class_objbuiltin_addr_typesrcr   loaded_moduleattrrJ  s              @r\   	load_typerZ    s     *.+FFXCLl>sx>>""  gn'''>,S1O33H==				&	&!.s|!<3KK,=sD I IJJ		aaaaGOaaa   
 <  ++K88
 ,, '';(9(9(9::@@EEE	K 	KD
 $//tTJJMMO,,38%6U - 
 
		 ++CHd;;	r^   r   rk   
str | Nonec                    |rb|                     | j                  sH|                    d          d         }|                     |          }|                     |||          }n|                     ||          }|S )Nrf   r   )rH  current_modulersplitrR  r   rm   )rH   r   rk   rV   modulerX  rh   s          r\   	load_funcr`    s     8++G,BCC 8 %%a(++F33""=)TBB&&y$77Kr^   !main_singledispatch_function_namec                r   |j         }| j        j        |         }t          | |j        j        |          }|                                 }| j                            |j        d         |          }| j        	                    |dt          |          }t                      t                      t                      }}
}	|                     t          ||g|          }|                     ||                                 d|          }t!          t"                    }|                     ||
|	           |                     |
           |                     |||           |                     |           |                     |	           |                     d|          }t/          | ||          }|                     |||g|          }|                     t2          |||g|           |                     |||           |                     |           |                     |           t5          | ||||           d S )Nr   dispatch_cachezis notzfunctools._find_impl)rV   rN   r   r  rY   r   selfrH   get_type_of_objrT  r.   r!   rn   r@   translate_is_opnone_objectr&   r0   add_bool_branchactivate_blockrT   gotor   load_singledispatch_registryr   rB   gen_calls_to_correct_impl)rH   ra  r   rV   current_func_declr,  dispatch_func_objr   rc  call_find_impl	use_cache	call_func
get_resultis_not_noneimpl_to_use	find_implregistryuncached_impls                     r\   )generate_singledispatch_dispatch_functionrx    s    :D3E:!2!6!;TBBH..x}Q/?FFH_--+_d N ,6<<z||yIN%%&?.RZA[]abbJ))*g6I6I6K6KXW[\\K,--KKNCCC9%%%NN;
D111LL>***445KTRRI+G5FMMHOOI(/CTJJM)NHm+TVZ[[[NN;t444LL9%%%g{HeTJJJJJr^   rt  r,  c                     j         j        |         d fd}t          d         \  }}                     t	          ||                    } j                            ||          }	t                      t                      }}
                     |	|
|            	                    |
                                t          |t                              }t           |          }|                                D ]\  }}t                      t                      }}                     |          }                     ||d          }                     |||            	                    |            ||            	                    |                                t!                                  	                    |                                |j        j        j                  }                     |j        j                  }                     t1          |                     d S )	NrI   r   rJ   rK   c                   j         j        |          }j                            |j        j        j                  }                    |j        j	                  }
                    t          |                     d S rM   )rN   r   rH   r)  r   r  r  r*  rY   r   r+  r'   )rI   r   ret_valcoercedr,  rH   rm  rV   s       r\   gen_native_func_call_and_returnzBgen_calls_to_correct_impl.<locals>.gen_native_func_call_and_return>  sx    N/5	/&&x}h&8(:Ld
 
 ..*;*?*H$OOF7OO$$$$$r^   zbuiltins.intz==)rI   r   rJ   rK   )rN   r   rE   r+  r$   rH   
type_is_opr!   rh  ri  r)   r/   get_native_impl_idsitemsload_int	binary_opr*   r   r   r  r  r*  rY   r   r'   )rH   rt  r,  r   rV   r}  r   rW  int_type_objis_intnative_callnon_native_call	passed_id
native_idsra   rI  	call_impl	next_impl
current_idcondr{  r|  rm  s   ` ` `                 @r\   rl  rl  9  s4     3E:% % % % % % % % % ^,HC;;{3T::;;L_''\4HHF#-<<KFKAAA;'''E+~tDDEEI$We44J##%% * *a)||Z\\9	%%a((
  JdCCi;;; 	y)))''---y)))) KK?+++ooX]D(*<h>P G nnW&7&;&DdKKGKKw     r^   main_func_namedispatch_nametuple[FuncIR, Value]c                   |                      t          ||                     t          |            t          | j        j        j        j        d<   t          | j        j        j        j        d<   d| j        j        j        _        d| j        j        j        _	        t          |            t          | ||           |                                 \  }}}}}t          | ||||          }	| j                            |	           t!          | |           t#          | |           t%          | |          }
t'          | ||	j        |          }||
fS )zCreate a dispatch function (a function that checks the first argument type and dispatches
    to the correct implementation)
    rv  rc  T)r   r8   r7   r.   r   callable_classr   
attributeshas_dictneeds_getseters+generate_singledispatch_callable_class_ctorrx  r   r4   rq   rr   r5   %add_register_method_to_callable_classr6   &generate_dispatch_glue_native_functionr   )rH   r   r  r  rY   r   r   r   r   dispatch_callable_classr[   dispatch_func_irs               r\   r   r   i  s:    MM(5-00111!!!?NGO"%0<ETGO"%01AB15GO"%.8<GO"%5/888-g~uMMM")--//D!VQ8$PSU\]]4555gw///)'7;;;)'7;;H=/4m  X%%r^   callable_class_declr   c                   |j         }|                                  |                     ||          }| j        j        |         }t          | |j        j        |          }|g|j        z   }t          j	        g|j
        z   }	|j        }
|
                    dd           | j                            |||	|
|          }|                     t!          |                     |                                 \  }}}}}t%          |||          S )Nr   rd  )rV   r   rm   rN   r   r  rY   r   r   ARG_POSr  r  insertrH   r)  r+  r'   r   r   )rH   r   r  r  rV   r  r   r,  r   r  r  r{  r0  r   r   r   s                   r\   r  r    s     :DMMOOO,,]DAAN>&u-D55Hhm+D!H$66I"IQo""#6iTXYYGKKw   &-mmoo#HaG$&)))r^   c           
     n   d}| j         j        j        }|                     |dt                    5  |                     t          g |          }|                     t          | 	                                d||                     |                     t          g |          }| 
                    d          }|                     t          | 	                                ||g|           |                     t          t          dt          |          |                     ddd           dS # 1 swxY w Y   dS )zGCreate an __init__ that sets registry and dispatch_cache to empty dictsrg   r   rv  rc  rx   N)r   r  r   enter_methodr-   call_crA   r+  r(   rd  rp   rn   rC   r'   r#   )rH   rV   r   
empty_dict
cache_dictdispatch_cache_strs         r\   r  r    s]   D-0H			h
O	D	D E E^^KT::
GGLLNNJ
DIIJJJ^^KT::
$--.>??]W\\^^=OQ[,\^bcccF71ot<<dCCDDDE E E E E E E E E E E E E E E E E Es   C-D**D.1D.c                   d}|                      |j        j        dt                    5  |                     dt                    }|                     dt          t
          j                  }|                     t          | 	                                ||g|          }| 
                    t          ||                     d d d            d S # 1 swxY w Y   d S )Nrg   registerr   rh   )r  r  r   r0   add_argumentr   ARG_OPTr  rD   rd  r+  r'   )rH   r   rV   cls_argfunc_argr{  s         r\   r  r    s    D			g47EV	W	W + +&&u.?@@''0A7?SS..!2W\\^^Wh4WY]^^F7D))***	+ + + + + + + + + + + + + + + + + +s   BCCCrn  c                F    | j                             |dt          |          S )Nrv  )rH   rT  r.   )rH   rn  rV   s      r\   rk  rk    s     ?##$5z?TXYYYr^   	orig_namec                    d|  dS )N%__mypyc_singledispatch_main_function_r!  r  )r  s    r\   r   r     s    @9@@@@r^   c                   |j         }|| j        v }t          t                    }| j                                        D ].\  }}|D ]&\  }}||k    r||                             |           '/|s|sd S |rt          |j                  }	t          | |	|j	        |          }
| 
                    d|          }| j                            ||
fg|          }|                     |j        |          }|                     t          ||                     d          |g|           |                                D ]\  }}t#          | |          }||vrt          | |j        |j	        |          }n2||         }t%          |t&                    }|                     |          }t          | |j        |j	        |          }t+          | ||          }|D ]3}t-          | |d |          }|                     t.          |||g|           4| j                            |dt2          |          }|                     |dg d |           	d S )Nzbuiltins.objectrv  rc  clear)rV   r   r   r%  r  rr   r   rS   r`  rk   r   rH   	make_dictrm   rn   rC   rp   r  r%   r0   r+  rk  rZ  rB   rT  r.   gen_method_call)rH   r   rV   r   to_register	main_funcimplsdispatch_typera   r  main_func_objloaded_object_typeregistry_dictrn  singledispatch_funcry   r  	to_insertr  load_literalrv  r   loaded_typerc  s                           r\   rW   rW     s   :D"'7+G"G8CD8I8IK#8>>@@ = =	5#( 	= 	=M4}}I&--m<<<	=  : " 

6uzBB!'>5>4PP$AABSUYZZ114F3V2WY]^^#33EJEE-w/?/?
/K/K][]a	
 	
 	
 '2&7&7&9&9 I I"U )2EFF

""!'5:u~tLLII#E*J&z3DEELL11I%(-/B/KT
 
 09JDQQ 	] 	]C#GS$==K  !1Hk93UW[\\\\ 11/$
 
 	T4HHHH+I Ir^   r  dict[FuncDef, int]c                T      j         |         } fdt          |          D             S )zgReturn a dict of registered implementation to native implementation ID for all
    implementations
    c                B    i | ]\  }\  }}t          |          ||S r  )r   )r   rI  r   ra   rH   s       r\   
<dictcomp>z'get_native_impl_ids.<locals>.<dictcomp>  s3    ^^^;C,wX\B]B]^D!^^^r^   )r   	enumerate)rH   r  r  s   `  r\   r  r    s5     ()<=E^^^^)E*:*:^^^^r^   r   is_traitc                   |j         }|                     |           |                     d|j        j        d         j                  }|sJ| j                            |||j        j        d          }| 	                    t          |                     n!| 	                    t                                 |                                 \  }}}	}
}t          |||	          S )zGenerate an implicit trivial property getter for an attribute.

    These are used if an attribute can also be accessed as a property.
    rd  r   rg   )rS   r   r  rY   r   r   rH   rT  r   r+  r'   r*   r   r   )rH   r   r   r  rS   self_regvaluer   r   r   r   r   s               r\   gen_property_getter_irr    s     >DMM$##FIM,>q,A,FGGH #((49OQSTTF5MM""""KMM""")0&D!VXw)T6***r^   c                b   |j         }|                     |           |                     d|j        j        d         j                  }|                     d|j        j        d         j                  }|                    t                    sJ |t          t                    d         }|s%| 	                    t          |||d                     | 	                    t          |                                                      |                                 \  }}	}
}}t          |||
          S )zGenerate an implicit trivial property setter for an attribute.

    These are used if an attribute can also be accessed as a property.
    rd  r   r  rx   Nrg   )rS   r   r  rY   r   r   rH  r   rQ  r+  r(   r'   noner   r   )rH   r   r   r  rS   r  	value_reg	attr_namer   r   r   r   r   s                r\   gen_property_setter_irr    s    >DMM$##FIM,>q,A,FGGH$$Wim.@.C.HIII??>*****S((**+I AGHiB??@@@KKw||~~&&''')0&D!VXw)T6***r^   )rH   r1   rI   r   rJ   rK   )rH   r1   r_   r   rJ   rK   )rH   r1   rd   r	   rJ   rK   )rH   r1   rv   r   rJ   r+   rM   )rH   r1   r   r   rS   r   rY   r   r   r   rJ   r   )
rH   r1   rY   r   r   r   r   r   rJ   r   )rH   r1   r   r   rJ   r   )F)rH   r1   r   r   r   r   rY   r   r   r8   r   r   r   r   rJ   r   )rH   r1   r   r   rI   r   rJ   rK   )
rH   r1   r   r   r   r   rI   r   rJ   rK   )rH   r1   rJ   r   )rH   r1   rI   r   r   r+   rJ   r+   )rH   r1   rI   r   rJ   r   )rH   r1   r   r   r   r   r   r   r   r   rI   r   r   r   rJ   r   )rH   r1   r  r	  rV   r
  rJ   r   )rH   r1   r   r   r   r   r   r   r   r   rV   r
  r  r   rJ   r   )
rH   r1   r   r   r1  r   rV   r
  rJ   rK   )rH   r1   rY   r   r   r   r   r   r   r   rV   r
  r:  r   rJ   r   )rH   r1   rI   r   rJ   r?   )
rH   r1   r   r   rD  rE  rV   r
  rJ   r+   )
rH   r1   r   r   rk   r[  rV   r
  rJ   r+   )rH   r1   ra  r   r   r   rJ   rK   )rH   r1   rt  r+   r,  r   r   r   rV   r
  rJ   rK   )rH   r1   r   r   r  r   r  r   rY   r   rJ   r  )
rH   r1   r   r   r  r   r  r   rJ   r   )rH   r1   rJ   rK   )rH   r1   r   r8   rJ   rK   )rH   r1   rn  r+   rV   r
  rJ   r+   )r  r   rJ   r   )rH   r1   r   r   rJ   rK   )rH   r1   r  r   rJ   r  )
rH   r1   r   r   r   r   r  r   rJ   r   )~__doc__
__future__r   collectionsr   collections.abcr   typingr   
mypy.nodesr   r   r	   r
   r   r   r   r   r   r   
mypy.typesr   r   r   r   mypyc.commonr   r   r   mypyc.ir.class_irr   r   mypyc.ir.func_irr   r   r   r   r   r   r    mypyc.ir.opsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   mypyc.ir.rtypesr,   r-   r.   r/   r0   mypyc.irbuild.builderr1   r2   r3   mypyc.irbuild.callable_classr4   r5   r6   r7   mypyc.irbuild.contextr8   mypyc.irbuild.env_classr9   r:   r;   r<   mypyc.irbuild.generatorr=   r>   mypyc.irbuild.targetsr?   mypyc.primitives.dict_opsr@   rA   rB   mypyc.primitives.generic_opsrC   mypyc.primitives.misc_opsrD   mypyc.primitives.registryrE   mypyc.sametyperF   rG   r]   rc   ru   r   rR   r   r   r   r   r   r   ri   r   r   r   r  r   r#  r   rU   rZ  r`  rx  rl  r   r  r  r  rk  r   rW   r  r  r  r  r^   r\   <module>r     s  
 
 # " " " " " # # # # # # $ $ $ $ $ $                              H G G G G G G G G G G G ? ? ? ? ? ? ? ? ? ? 6 6 6 6 6 6 6 6                                                        V U U U U U U U U U            + * * * * *            P O O O O O O O 2 2 2 2 2 2 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 6 6 6 6 6 6 7 7 7 7 7 7 3 3 3 3 3 3 A A A A A A A A
	- 	- 	- 	-   & & & &>   > !n n n n nb   2   * ).* * * * *Z@$ @$ @$ @$FD D D D>      ,/ / / / [ [ [ [ [ [2    j   / / / /[ [ [ [|   :) ) ) )X: : : :*, , , ,^     K  K  K  KF-! -! -! -!`& & & &8* * * *&E E E E+ + + +Z Z Z ZA A A A.I .I .I .Ib_ _ _ _+ + + +&+ + + + + +r^   