
    X-Ph\                   F   U d Z ddlmZ ddlmZ ddlmZ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 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 ddl 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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZS ddlTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ eeeP         ePf         Zd Zd!ed"z  d!z
  z  Zd#ed$<   h d%Zd#ed&<   h d'Zd#ed(<    G d) d*          Zd3d1Zd2S )4zeA "low-level" IR builder class.

See the docstring of class LowLevelIRBuilder for more information.

    )annotations)Sequence)CallableFinalOptional)map_actuals_to_formals)ARG_POSARG_STAR	ARG_STAR2ArgKind)
op_methodsunary_op_methods)AnyType	TypeOfAny)BITMAP_BITSFAST_ISINSTANCE_MAX_SUBCLASSESMAX_LITERAL_SHORT_INTMAX_SHORT_INTMIN_LITERAL_SHORT_INTMIN_SHORT_INTPLATFORM_SIZE)Errors)ClassIRall_concrete_classes)FuncDeclFuncSignature)-	ERR_FALSE	ERR_NEVERNAMESPACE_MODULENAMESPACE_STATICNAMESPACE_TYPEAssignAssignMulti
BasicBlockBoxBranchCallCallCCastComparisonOpExtendFloatFloatComparisonOpFloatNegFloatOpGetAttrGetElementPtrGotoIntegerIntOp	KeepAliveLoadAddressLoadErrorValueLoadLiteralLoadMem
LoadStatic
MethodCallOpPrimitiveDescriptionPrimitiveOpRaiseStandardErrorRegisterTruncateTupleGetTupleSetUnboxUnreachableValuefloat_comparison_op_to_idfloat_op_to_idint_op_to_id)/PyObjectPySetObjectRArray	RInstance
RPrimitiveRTupleRTypeRUnionbit_rprimitivebitmap_rprimitivebool_rprimitivebytes_rprimitivec_int_rprimitivec_pointer_rprimitivec_pyssize_t_rprimitivec_size_t_rprimitivecheck_native_int_rangedict_rprimitivefloat_rprimitiveint_rprimitiveis_bit_rprimitiveis_bool_rprimitiveis_bytes_rprimitiveis_dict_rprimitiveis_fixed_width_rtypeis_float_rprimitiveis_frozenset_rprimitiveis_int16_rprimitiveis_int32_rprimitiveis_int64_rprimitiveis_int_rprimitiveis_list_rprimitiveis_none_rprimitiveis_set_rprimitiveis_short_int_rprimitiveis_str_rprimitive	is_taggedis_tuple_rprimitiveis_uint8_rprimitivelist_rprimitivenone_rprimitiveobject_pointer_rprimitiveobject_rprimitiveoptional_value_typepointer_rprimitiveshort_int_rprimitivestr_rprimitiveconcrete_arg_kind)CompilerOptions)bytes_compare)dict_build_opdict_new_opdict_ssize_t_size_opdict_update_in_display_op)err_occurred_opkeep_propagating_op)copysign_opint_to_float_op)generic_len_opgeneric_ssize_t_len_op
py_call_oppy_call_with_kwargs_oppy_getattr_oppy_method_call_oppy_vectorcall_method_oppy_vectorcall_op)int16_divide_opint16_mod_opint16_overflowint32_divide_opint32_mod_opint32_overflowint64_divide_opint64_mod_opint64_to_int_opint_to_int32_opint_to_int64_opssize_t_to_int_opuint8_overflow)list_build_oplist_extend_op
list_itemsnew_list_op)bool_opbuf_init_itemdebug_print_opfast_isinstance_opnone_object_opnot_implemented_opvar_object_size)ERR_NEG_INTCFunctionDescription
binary_opsmethod_call_ops	unary_ops)
new_set_op)str_check_if_truestr_ssize_t_size_opunicode_compare)list_tuple_opnew_tuple_opnew_tuple_with_length_op)is_runtime_subtype)is_same_type)
is_subtype
         r   PY_VECTORCALL_ARGUMENTS_OFFSET>   %=*=+=-=<<>>//=<<=>>=*%&+-^|&=//^=|=FIXED_WIDTH_INT_BINARY_OPS>   <=r   <>r   r   !=r   ==>=r   r   BOOL_BINARY_OPSc                     e Zd ZdZddZddZddZddZddZddZ	ddddZ
dd Zdd!Zdd#Zdd$Zdd'Zdd)Zdd*dd0Z	 ddd*dd2Zdd3Zdd4Zdd5Zdd6Zdd7dd<Zdd?Zdd@ZddCZddDZddFZddIZddOZ	 	 dddWZ	 	 dddYZ ddZZ!dd\Z"dd]Z#dPd^ddfZ$dPd^ddiZ%	 	 	 dd dnZ&ddqZ'ddrZ(ddsZ)ddtZ*dduZ+ddwZ,ddyZ-ddzZ.dd|Z/dd~Z0dPe1ddPfddZ2d	dZ3d
dZ4ddZ5ddZ6ddZ7dddZ8ddZ9ddZ:dddZ;ddZ<ddZ=ddZ>ddZ?ddZ@ddZAddZBddZCddZDddddZEddZFddZGddZH	 dddZI	 	 dddZJ	 dddZK	 	 dd dZLdd!dZMddZNd"dZOd#dZPd$dÄZQd%dĄZRd&dńZSd&dƄZTd'dɄZUd(dʄZVd#d˄ZWdd)d̈́ZXd*dτZYddЄZZd+d҄Z[d,dՄZ\	 dd-dׄZ]d.d؄Z^d/dلZ_d0dۄZ`d1d݄ZadPS (2  LowLevelIRBuilderax  A "low-level" IR builder class.

    LowLevelIRBuilder provides core abstractions we use for constructing
    IR as well as a number of higher-level ones (accessing attributes,
    calling functions and methods, and coercing between types, for
    example).

    The core principle of the low-level IR builder is that all of its
    facilities operate solely on the mypyc IR level and not the mypy AST
    level---it has *no knowledge* of mypy types or expressions.

    The mypyc.irbuilder.builder.IRBuilder class wraps an instance of this
    class and provides additional functionality to transform mypy AST nodes
    to IR.
    errorsErrors | Noneoptionsr{   returnNonec                \    || _         || _        g | _        g | _        d g| _        g | _        d S N)r   r   argsblockserror_handlerskeep_alives)selfr   r   s      X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/irbuild/ll_builder.py__init__zLowLevelIRBuilder.__init__   s8    $&	(*8<v )+    module_namestrmodule_pathc                "    || _         || _        dS )z,Set the name and path of the current module.N)r   r   )r   r   r   s      r   
set_modulezLowLevelIRBuilder.set_module   s    &&r   opr<   rF   c                    | j         d         j        r
J d            | j         d         j                            |           |S )z
Add an op.zCan't add to finished block)r   
terminatedopsappend)r   r   s     r   addzLowLevelIRBuilder.add  sB    ;r?-LL/LLLLB""2&&&	r   targetr$   c                r    | j         d         j        s$|                     t          |                     dS dS )zAdd goto to a basic block.r   N)r   r   r   r2   )r   r   s     r   gotozLowLevelIRBuilder.goto  s;    {2) 	#HHT&\\"""""	# 	#r   blockc                    | j         r| j         d         j        sJ | j        d         |_        | j                             |           dS )z>Add a basic block and make it the active one (target of adds).r   N)r   r   r   error_handlerr   r   r   s     r   activate_blockz LowLevelIRBuilder.activate_block  sM    ; 	.;r?----"1"55!!!!!r   c                Z    |                      |           |                     |           dS )z.Add goto a block and make it the active block.N)r   r   r   s     r   goto_and_activatez#LowLevelIRBuilder.goto_and_activate  s.    		%E"""""r   Fstealvalueslist[Value]r   boolc               N    |                      t          ||                     d S )Nr   )r   r5   )r   r   r   s      r   
keep_alivezLowLevelIRBuilder.keep_alive  s'    6///00000r   handlerBasicBlock | Nonec                :    | j                             |           d S r   )r   r   )r   r  s     r   push_error_handlerz$LowLevelIRBuilder.push_error_handler  s    ""7+++++r   c                4    | j                                         S r   )r   popr   s    r   pop_error_handlerz#LowLevelIRBuilder.pop_error_handler   s    "&&(((r   r@   c                    | j         d         S )zWReturn reference to the 'self' argument.

        This only works in a method.
        r   )r   r  s    r   r   zLowLevelIRBuilder.self#  s    
 y|r   c                    | j         rB|                     t          | j                                                              g | _         d S d S r   )r   r   r5   copyr  s    r   flush_keep_alivesz#LowLevelIRBuilder.flush_keep_alives*  sN     	"HHYt/446677888!D	" 	"r   toprintstr | Valuec                    t          |t                    r|                     |          }|                     t          |gd           d S )Nr   )
isinstancer   load_strprimitive_opr   )r   r  s     r   debug_printzLowLevelIRBuilder.debug_print/  sE    gs## 	-mmG,,G.7)R88888r   srcc                   |j         j        r|t          |t                    rEt	          |j                   r1|                     t          |j        dz	  t                              S |                     t          |                    S |S )Nr   rtype)
type
is_unboxedr  r3   rn   r   r8   valuert   r%   )r   r  s     r   boxzLowLevelIRBuilder.box6  sw    8 	#w'' VIch,?,? VxxCINBS T T TUUU88CHH%%%Jr   
can_borrowtarget_typerP   lineintr  c                   |j         r$|                     t          |||                    S |r| j                            |           |                     t          ||||                    S )Nborrow)r  r   rD   r   r   r)   )r   r  r  r   r  s        r   unbox_or_castzLowLevelIRBuilder.unbox_or_cast>  sp     ! 	M88E#{D99::: - '',,,88Dk4
KKKLLLr   forcec          	     Z
    |j         }|j        r|j        s                     |          S |j        r|j        rt          ||          spt	          |t
                    rwt          |          rht          |          rY|                                }t          ||          s 
                    d| d| d           t          |j        dz	  |          S t          |          r&t          |          r                     ||          S t          |          r%t          |          r                     |          S t          |          r&t          |          r                     ||          S t	          |t                     rEt	          |t                     r0|j        r)|j        r"|j        |j        k    r|j        |j        k    r|S t)          |          st+          |          rnt-          |          r_                     t0          |t          dt0                    t2          j                  }                     t9          ||d                    S t)          |          st+          |          r4t          |          r%                     t9          ||d                    S t	          |t
                    rct;          |          rTt-          |          r$t=          t?          |j        dz                      S t=          t?          |j                            S t-          |          r%t;          |          r                      |          S t	          |tB                    r t	          |tB                    r
tE          |j#                  tE          |j#                  k    rg }	tI          tE          |j#                            D ]y}
d}t	          |tJ                    r$|j&        |
         }t	          |tN                    s|}|%tQ          ||
          }                     |           |	)                    |           z                     tK           fd	tU          |	|j#                  D                                 S                      |          } +                    ||          S |j        s|j        stY          ||          s +                    |||
          S |r4tO          |          }                     t[          ||                     |S |S )a  Generate a coercion/cast from one type to other (only if needed).

        For example, int -> object boxes the source int; int -> int emits nothing;
        object -> int unboxes the object. All conversions preserve object value.

        If force is true, always generate an op (even if it is just an assignment) so
        that the result will have exactly target_type as the type.

        Returns the register with the converted value (may be same as src).
        zValue z is out of range for ""r   Fsigned   Nc                D    g | ]\  }}                     ||          S  )coerce).0vtr   r   s      r   
<listcomp>z,LowLevelIRBuilder.coerce.<locals>.<listcomp>  s-    \\\TQQ400\\\r   r  ).r  r  r  r   r  r3   rl   rb   numeric_valuerZ   errorr  rh   coerce_int_to_fixed_widthcoerce_fixed_width_to_intcoerce_short_int_to_fixed_widthrN   is_native_intsize	is_signedr_   r^   rn   int_oprT   r4   
LEFT_SHIFTr   r+   rc   r,   floatint_to_floatrO   lentypesrangerC   itemsr@   rB   r   zipr%  r   r"   )r   r  r  r   r&  r  src_typer  shiftedr   ir0  itemtmps   `  `          r   r.  zLowLevelIRBuilder.coerceH  s_   & 8 	!{'= 	!88C==  G	>K$: G	>DVkE
 E
 G	> 3((@+H55@ )55@
 ))++-k5AA [JJSSS[SSSUYZZZsyA~{;;;"8,, 71Ek1R1R 755c;MMM%h// 54Ek4R4R 555c4@@@(22 37KK7X7X 3;;CdSSS8Z001{J771 *1  -	1
 M[%555&+*??? 
$X.. '2CH2M2M 'S\T T ' ++#S'!_*E*EuGW  xxwE J J JKKK"8,, 0A(0K0K &{33  xxsK F F FGGGC)) .A+.N.N X&& 8 syA~!6!6777U39--...8$$ )<[)I)I ((d3338V,,{F33 ''3{/@+A+AAA s8>2233 
% 
%AA!#x00 %"y|)$99 % $Ay$S!,,MM!$$$$xx\\\\\SIZ=[=[\\\^b    ((3--C%%c;===# 	(> 	zkH
 H
 	 %%c;%TTT 	;''CHHVC%%&&&J
r   c           	     
   t          |          s
J |            t          |t                    sJ t          |          }t	                      t	                      t	                      }}}|                     ||          }|                     t          |||t          j                             | 	                    |           |j
        }	|	t          j
        k     rt	                      t	                      }}
d|	dz  dz
  z  }|j        s|dz  }|                     t          |t          ||j                  t          j                            }|                     t          ||
|t          j                             | 	                    |
           |j        r| }nd}|                     t          |t          ||j                  t          j                            }|                     t          |||t          j                             | 	                    |           |                     t&          |t          dt&                    t(          j        |          }|                     t-          ||                    }ni|	t          j
        k    r&|                     t/          ||d                    }n|}|                     ||t          d|          t(          j        |          }|                     t1          ||                     |                     |           | 	                    |           t5          |          s!t7          |          r|	t          j
        k    r|                     t8          |t          dt8                    t(          j        |          }t          t<                    }|                     t1          ||                     t5          |          rt>          }nt@          }| !                    ||g|          }|                     t1          ||                     |                     tE          |g                     |                     |           nt7          |          r>| !                    tF          g |           |                     tI                                 ntK          |          r>| !                    tL          g |           |                     tI                                 nWtO          |          r>| !                    tP          g |           |                     tI                                 n
J |            | 	                    |           |S )Nr   r   r+  r   Tr)  ))rb   r  rN   r@   r$   check_tagged_short_intr   r&   BOOLr   r9  r]   r:  r*   r3   r  SLTSGEr;  rX   r4   RIGHT_SHIFTrA   r+   r"   r   rg   rf   rv   XORrW   r   r   call_cr5   r   rE   re   r   rp   r   )r   r  r  r   resfastslowendcheckr9  fast2fast3upper_boundcheck2lower_boundcheck3rH  ptrptr2conv_ops                       r   r5  z+LowLevelIRBuilder.coerce_int_to_fixed_width  s   #K00==+===+z22222{##$,,
jllCd++C66tT6;77888D!!!.%%%%<<5Eq1-K( !q XXl3SX0N0NP\P`aabbFHHVFE4==>>>&&&$  *lXXl3SX0N0NP\P`aabbFHHVFE4==>>>&&&++&122! C ((8C5566CCn)))hhvc;tDDDEE++k3;0G0GIZ\`aaCS!!"""		#D!!!{++ 	&,,	&159L1L1L ++"C4F)G)GTX C 011DHHVD#&&'''";// *))++gvt44CHHVC%%&&&HHYu%%&&&IIcNNNN -- 	&KKD111HH[]]#### -- 		&KKD111HH[]]#### -- 	&KKD111HH[]]####%+%%%C   
r   c                    t          |          st          dk    r@t          |          r1|                     ||t	          d|          t
          j        |          S J |j        |t          f            )N   r   )rg   r   rf   r;  r3   r4   rN  r  )r   r  r  r   s       r   r7  z1LowLevelIRBuilder.coerce_short_int_to_fixed_width  sk    {++ 	cQ#6{#C#C;;{CK1H1H%J[]abbb<sxm<<<<r   c           	     z   t          |j                  rt          dk    s(t          |j                  st	          |j                  ro|                     t          |t          |j        j                            }| 	                    t          |t          dt                    t          j        |          S t          |j                  sJ t          |j        t                     sJ |j        }t#          t                    }t%                      t%                      t%                      t%                      f\  }}}}	|                     t'          |t          t(          |          t&          j                            }
|                     t-          |
||t,          j                             |                     |           |                     t'          |t          t2          |          t&          j                            }|                     t-          |||t,          j                             |                     |           t7          |          rt8          }n.t          |          rt          dk    sJ t:          }n
J |            |                     ||g|          }|                     t?          ||                     |                      |	           |                     |           t          j!        |j!        k     r)|                     tE          |t                              }n|}| 	                    t          |t          d|j                  t          j        |          }|                     t?          ||                     |                      |	           |                     |	           |S )Nr   r)  r   r`  )#rf   r  r   re   rp   r   r+   rX   r:  r;  r]   r3   r4   r<  rb   r  rN   r@   r$   r*   r   SLEr&   rK  r   r   rM  rg   r   r   rP  r"   r   r9  rA   )r   r  r   extendedrD  rQ  rR  rV  rS  rT  c1c2r^  xrH  ss                   r   r6  z+LowLevelIRBuilder.coerce_fixed_width_to_int  s
    **	/</A/A"38,, 0B"38,, 0B
 xxs,B38K] ^ ^ ^__H;;122    $CH-----#(J/////8~&&!+z||Z\\:<<!WeT3XXl3x(H(H,JZ[[\\D$44555D!!!XXl3x(H(H,JZ[[\\E455666D!!!x(( 	#%GG ** 	# A%%%%'GG"("""KK#--Q   		#E"""..((8C)?@@AACCCKKWQ-A-A5CSUYZZQ   		#C   
r   c                   |j         j        |j        k    r:|j        rt          |j         |          s|j        st          |j         |          r|S t	          |          }t                      t                      t                      }}}|                     t          |||t          j                             | 	                    |           | 
                    |||          }|                     t          |||                     |                     |           | 	                    |           |                     t          |                    }	|                     t          ||	|                     |                     |           |S )z2Generate a coercion from a potentially null value.)r  r  r   r   r@   r$   r   r&   IS_ERRORr   r.  r"   r   r7   r   )
r   r  r  r   r   validinvalidoutcoercedr4  s
             r   coerce_nullablez!LowLevelIRBuilder.coerce_nullableD  s\   8+"888# 9(:38[(Q(Q 9* 9/9#(K/P/P 9 J+&&(llJLL*,,wWeV_==>>>E"""++c;55..///		#G$$$4455t,,---s###r   r#  objattrresult_typer$  c                  t          |j        t                    ry|j        j        j        rh|j        j                            |          rIt          ||||          }|j        r| j        	                    |           | 
                    |          S t          |j        t                    r|                     ||j        |||          S |                     |||          S )z.Get a native or Python attribute of an object.r#  )r  r  rM   class_iris_ext_classhas_attrr0   is_borrowedr   r   r   rQ   union_get_attrpy_get_attr)r   ro  rp  rq  r   r$  r   s          r   get_attrzLowLevelIRBuilder.get_attr_  s    
 sx++	5!.	5 !**400	5
 dD888B ~ - '',,,88B<<&)) 	5&&sCHdKNNN##Ct444r   r  rQ   c                N     d fd}                      |||          S )z0Get an attribute of an object with a union type.r  rF   r   c                4                         |           S r   )ry  )r  rp  r   rq  r   s    r   get_item_attrz7LowLevelIRBuilder.union_get_attr.<locals>.get_item_attrx  s    ==k4@@@r   r  rF   r   rF   )decompose_union_helper)r   ro  r  rp  rq  r   r|  s   `  ``` r   rw  z LowLevelIRBuilder.union_get_attrs  s[    
	A 	A 	A 	A 	A 	A 	A 	A 	A **3{MSWXXXr   c                h    |                      |          }|                     t          ||g|          S )zuGet a Python attribute (slow).

        Prefer get_attr() which generates optimized code for native classes.
        )r  r  r   )r   ro  rp  r   keys        r   rx  zLowLevelIRBuilder.py_get_attr}  s1    
 mmD!!  c
DAAAr   	class_irslist[ClassIR]c                     |s                                  S                      |d                   |dd         D ],d	 fd}                     dt          fd|          -S )
zHFast path for isinstance() that checks against a list of native classes.r   r   Nr   rF   c                 2                                    S r   )isinstance_native)rs  r   ro  r   s   r   otherz2LowLevelIRBuilder.isinstance_helper.<locals>.other  s    --c8TBBBr   orc                      S r   r-  rets   r   <lambda>z5LowLevelIRBuilder.isinstance_helper.<locals>.<lambda>      # r   r   rF   )falser  shortcircuit_helperrT   )r   ro  r  r   r  rs  r  s   `` ` @@r   isinstance_helperz#LowLevelIRBuilder.isinstance_helper  s     	 ::<<$$S)A,==!!"" 	\ 	\HC C C C C C C C C **4++++uVZ[[CC
r   c                    |                      t          |t          d|                    }|                      t          t          |                    }|                      t          |g                     |S )Nob_type)r   r1   rJ   r9   rt   r5   )r   ro  r   ob_type_addressr  s        r   get_type_of_objz!LowLevelIRBuilder.get_type_of_obj  s^    ((=h	4#P#PQQ((7#4oFFGGC5!!"""r   type_objc                    |                      ||          }|                     t          ||t          j        |                    S r   )r  r   r*   EQ)r   ro  r  r   typs        r   
type_is_opzLowLevelIRBuilder.type_is_op  s9    ""3--xxS(LOTJJKKKr   rs  r   c                    t          |          }|t          |          t          dz   k    r1                     t                               |          g          S |s                                 S                      |d                   }                     |          |dd         D ],d	 fd}                     dt          fd|          -S )
zFast isinstance() check for a native class.

        If there are three or fewer concrete (non-trait) classes among the class
        and all its children, use even faster type comparison checks `type(obj)
        is typ`.
        Nr   r   r   rF   c                 X                                                                  S r   )r  get_native_type)cr   ro  r   s   r   r  z2LowLevelIRBuilder.isinstance_native.<locals>.other  s'    sD,@,@,C,CTJJJr   r  c                      S r   r-  r  s   r   r  z5LowLevelIRBuilder.isinstance_native.<locals>.<lambda>  r  r   r  )
r   r?  r   r  r   r  r  r  r  rT   )	r   ro  rs  r   concreter  r  r  r  s	   `` `   @@r   r  z#LowLevelIRBuilder.isinstance_native  s#    (11s8}}/MPQ/QQQ$$"S$*>*>x*H*H$I4    	 ::<<''44ooc8T22!"" 	\ 	\AK K K K K K K K K **4++++uVZ[[CC
r   r   +Sequence[tuple[Value, ArgKind, str | None]]has_star	has_star2!tuple[Value | None, Value | None]c          	        d}d}g }g }g }	d}
|D ]\  }}}|t           k    r7||                     ||          }|                     t          ||g|           I|t          k    r9||                     ||	|          }|                     t          ||g|           |                                }|	                                o|}|
                                p|                                o|o|}|r5|r||                     ||          }|r||                     ||	|          }|r||                    |           5|rG|E|J |                     |          }|                    |           |	                    |           ~|
}t                      }|r|rL|
sJt          t                    }|                     t#          ||                                 |                     |rt                      n|}t                      }|                     t'          |||t&          j                             |                     |           |rP|rN|
rLt                      t                      }}|                     t'          |
||t&          j                             n%t                      x}}|                     |           |rI|                     |           |sJ |                     |d|gd|           |                     |           |rg|r|
rc|                     |           |J |                     |          }|sJ |                     |d||gd|           |                     |           |rj|rh|rf||usJ |                     |           |                     t#          ||                                 |                     |                     |           |                     |           |}
|s|r|sJ |s|	r|sJ |r6||                     ||          }n|                     t6          |g|          }|r||                     ||	|          }||fS )a  Construct *args and **kwargs from a collection of arguments

        This is pretty complicated, and almost all of the complication here stems from
        one of two things (but mostly the second):
          * The handling of ARG_STAR/ARG_STAR2. We want to create as much of the args/kwargs
            values in one go as we can, so we collect values until our hand is forced, and
            then we emit creation of the list/tuple, and expand it from there if needed.

          * Support potentially nullable argument values. This has very narrow applicability,
            as this will never be done by our compiled Python code, but is critically used
            by gen_glue_method when generating glue methods to mediate between the function
            signature of a parent class and its subclasses.

            For named-only arguments, this is quite simple: if it is
            null, don't put it in the dict.

            For positional-or-named arguments, things are much more complicated.
              * First, anything that was passed as a positional arg
                must be forwarded along as a positional arg. It *must
                not* be converted to a named arg. This is because mypy
                does not enforce that positional-or-named arguments
                have the same name in subclasses, and it is not
                uncommon for code to have different names in
                subclasses (a bunch of mypy's visitors do this, for
                example!). This is arguably a bug in both mypy and code doing
                this, and they ought to be using positional-only arguments, but
                positional-only arguments are new and ugly.

              * On the flip side, we're willing to accept the
                infelicity of sometimes turning an argument that was
                passed by keyword into a positional argument. It's wrong,
                but it's very marginal, and avoiding it would require passing
                a bitmask of which arguments were named with every function call,
                or something similar.
                (See some discussion of this in testComplicatedArgs)

            Thus, our strategy for positional-or-named arguments is to
            always pass them as positional, except in the one
            situation where we can not, and where we can be absolutely
            sure they were passed by name: when an *earlier*
            positional argument was missing its value.

            This means that if we have a method `f(self, x: int=..., y: object=...)`:
              * x and y present:      args=(x, y), kwargs={}
              * x present, y missing: args=(x,),   kwargs={}
              * x missing, y present: args=(),     kwargs={'y': y}

            To implement this, when we have multiple optional
            positional arguments, we maintain a flag in a register
            that tracks whether an argument has been missing, and for
            each such optional argument (except the first), we check
            the flag to determine whether to append the argument to
            the *args list or add it to the **kwargs dict. What a
            mess!

            This is what really makes everything here such a tangle;
            otherwise the *args and **kwargs code could be separated.

        The arguments has_star and has_star2 indicate whether the target function
        takes an ARG_STAR and ARG_STAR2 argument, respectively.
        (These will always be true when making a pycall, and be based
        on the actual target signature for a native call.)
        Nr   r   rq  r   __setitem__)r
   r   r  r   r   _create_dictrP  r   is_optionalis_positionalis_namedr   r  r$   r@   rT   r   r"   r  r&   ri  r   rK  r   translate_special_method_calltrue	new_tupler   )r   r   r   r  r  star_resultstar2_resultstar_values
star2_keysstar2_valuesseen_empty_regr  kindnamenullable	maybe_posmaybe_namedr  new_seen_empty_regrl  skipkeep	pos_blocknamed_blocks                           r   _construct_varargsz$LowLevelIRBuilder._construct_varargs  s$   P %)%)
 $&"$
$&*.!% Z	4 Z	4E4x&"&"2"2;"E"EK!!.;2FMMMM""'#'#4#4Zt#T#TL5e7LSWXXXX++-- ..00=X	"mmoo\$2B2B2D2D2[2[R[
  Y  J[%8&*&6&6{D&I&I" Y|';'+'8'8\SW'X'X  !4&&u--- <#7+++----C%%c*** ''... &4" ll . ! Q Q-5o-F-F*(:DJJLL$!O!OPPP+4=:<<<#D%<<DHHVE4vGGHHH''---
  ) ) )-7\\:<<{IHHVNKFKXXYYYY.8ll:IIIi((( #''	222&&&&66#XwDt 7    IIcNNN #	 #^ #''444+++----C''''66$mc5\tZ^ 7    IIcNNN #	 #.@ #s????''---HHV$6		TJJKKKIIcNNN##C(((!3;;;8;;; >L>Y>>> 	T ""nn[$??"//}dSS 	M-,,ZtLLLL((r   Nfunction
arg_values	arg_kindslist[ArgKind] | None	arg_namesSequence[str | None] | Nonec           	     t   |                      |||||          }||S |t          d |D                       r |                     t          |g|z   |          S |J |                     t          t          |||                    |dd          \  }}|r|sJ |                     t          |||g|          S )zCall a Python function (non-native and slow).

        Use py_call_op or py_call_with_kwargs_op for Python function call.
        Nc              3  ,   K   | ]}|t           k    V  d S r   r	   r/  r  s     r   	<genexpr>z,LowLevelIRBuilder.py_call.<locals>.<genexpr>  &      #J#JDGO#J#J#J#J#J#Jr   Tr  r  )_py_vector_callallrP  r   r  listrC  r   )	r   r  r  r   r  r  resultpos_args_tuplekw_args_dicts	            r   py_callzLowLevelIRBuilder.py_callx  s     %%h
D)YWWM #J#J	#J#J#J J J;;zH:
+BDIII $$$'+'>'>ZI6677X\ (? (
 (
$ .,...{{1Hnl3[]abbbr   Value | Nonec           	         |t          d |D                       r|r- fd|D             }                     t          |d          }nt          dt                    }t          ||          }                     |          }	                     t          ||t          |t                    |	g          }
|r" 
                    t          |                     |
S dS )zCall function using the vectorcall API if possible.

        Return the return value if successful. Return None if a non-vectorcall
        API should be used instead.
        Nc              3  j   K   | ].}|                                  o|                                 V  /d S r   is_starr  r  s     r   r  z4LowLevelIRBuilder._py_vector_call.<locals>.<genexpr>  R       $
 $
>B9t'7'7'9'9#9$
 $
 $
 $
 $
 $
r   c                H    g | ]}                     |t                    S r-  r.  rt   r/  argr   r   s     r   r2  z5LowLevelIRBuilder._py_vector_call.<locals>.<listcomp>  s*    ```cC1BD I I```r   T
object_ptrr   )r  setup_rarrayrt   r3   rs   num_positional_args_vectorcall_keywordsrP  r   rY   r   r5   )r   r  r  r   r  r  coerced_argsarg_ptrnum_poskeywordsr  s   `  `       r   r  z!LowLevelIRBuilder._py_vector_call  s     $
 $
FO$
 $
 $
 !
 !
  @`````U_```++,=|X\+]]!!%>??)*i@@G00;;HKK 7GG5H$I$I8T E
  2 <00111Ltr   c                    |rCd |D             }|r5|                      t          t          |          t                              S t	          dt                    S )zReturn a reference to a tuple literal with keyword argument names.

        Return null pointer if there are no keyword arguments.
        c                    g | ]}||S r   r-  )r/  r  s     r   r2  z:LowLevelIRBuilder._vectorcall_keywords.<locals>.<listcomp>  s    FFFT5Et5E5E5Er   r   )r   r8   tuplert   r3   )r   r  kw_lists      r   r  z&LowLevelIRBuilder._vectorcall_keywords  s]    
  	PFF	FFFG PxxE'NN<M N NOOOq+,,,r   method_namec                B   |                      ||||||          }||S |t          d |D                       r6|                     |          }|                     t          ||g|z   |          S |                     |||          }	|                     |	||||          S )z+Call a Python method (non-native and slow).Nc              3  ,   K   | ]}|t           k    V  d S r   r  r  s     r   r  z3LowLevelIRBuilder.py_method_call.<locals>.<genexpr>  r  r   r  r  )_py_vector_method_callr  r  rP  r   rx  r  )
r   ro  r  r  r   r  r  r  method_name_regmethods
             r   py_method_callz LowLevelIRBuilder.py_method_call  s     ,,j$	9
 
 M#J#J	#J#J#J J J"mmK88O;;032H:2UW[\\\ %%c;==F<<
DIYb<cccr   c           	         |t          d |D                       r̉                     |          } fd|g|z   D             }                     t          |d          }	t	          ||          }
                     |          }                     t          ||	t          |
dz   t          z  t                    |g          }                     t          |                     |S dS )zCall method using the vectorcall API if possible.

        Return the return value if successful. Return None if a non-vectorcall
        API should be used instead.
        Nc              3  j   K   | ].}|                                  o|                                 V  /d S r   r  r  s     r   r  z;LowLevelIRBuilder._py_vector_method_call.<locals>.<genexpr>  r  r   c                H    g | ]}                     |t                    S r-  r  r  s     r   r2  z<LowLevelIRBuilder._py_vector_method_call.<locals>.<listcomp>  s7       >AC!2D99  r   Tr  r   )r  r  r  rt   r  r  rP  r   r3   r   rY   r   r5   )r   ro  r  r  r   r  r  r  r  r  r  r  r  s   `   `        r   r  z(LowLevelIRBuilder._py_vector_method_call  s%     $
 $
FO$
 $
 $
 !
 !
 #mmK88O    FIUZEW  L ''(9<TX'YYG)*i@@G00;;HKK'#Wq[,JJL_``	 	 	E HHY|,,---Ltr   bitmap_argsdeclr   Sequence[Value]list[ArgKind]Sequence[str | None]r  list[Register] | Nonec                   |                      ||||j        ||          }|                     t          |||                    S )a  Call a native function.

        If bitmap_args is given, they override the values of (some) of the bitmap
        arguments used to track the presence of values for certain arguments. By
        default, the values of the bitmap arguments are inferred from args.
        r  )native_args_to_positionalsigr   r'   )r   r  r   r  r  r   r  s          r   callzLowLevelIRBuilder.call	  sM    " --)Y$K . 
 
 xxT4..///r   r  r   c               F   |j         }|j        }|r|d|          }d |D             }	d |D             }
d D             }t          ||	|
d           }dx}}g }t          ||          D ]e\  }}|j                                        r#|                    fd|D                        |p|j        t          k    }|p|j        t          k    }f| 	                    ||||          \  }}g }t          ||          D ]*\  }}|j        t          k    r|sJ |}n|j        t          k    r|sJ |}n|sxt          |j                  rt          d	|j                  }nt          |j                  rt          d
          }n|                     t!          |j        d                    }ng|d	                  }|d	                                                  r|                     ||j        |          }n|                     ||j        |          }|                    |           ,t+          t-          |                    D ]}|r/|t/          |          k     r|                    ||                    3d	}d	}t          ||          D ]g\  }}|j                                        rI|j        j        r=|t2          z  |cxk    r|dz   t2          z  k     rn n|r|d|t2          dz
  z  z  z  }|dz  }h|                    t          |t4                               |S )a  Prepare arguments for a native call.

        Given args/kinds/names and a target signature for a native call, map
        keyword arguments to their appropriate place in the argument list,
        fill in error values for unspecified default arguments,
        package arguments that will go into *args/**kwargs into a tuple/dict,
        and coerce arguments to the appropriate type.
        Nc                    g | ]	}|j         
S r-  )r  r/  r  s     r   r2  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>7      666c666r   c                    g | ]	}|j         
S r-  )r  r  s     r   r2  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>8  r  r   c                ,    g | ]}t          |          S r-  ry   )r/  arg_kinds     r   r2  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>:  s!    PPP(+H55PPPr   c                4    t          t          j                  S r   )r   r   special_form)ns    r   r  z=LowLevelIRBuilder.native_args_to_positional.<locals>.<lambda>@  s    gi455 r   Fc                >    g | ]}|         |         |         fS r-  r-  )r/  rF  r  r  r   s     r   r2  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>H  s-    (\(\(\ST$q'9Q<1)N(\(\(\r   r  r           T)rv  r   )r   num_bitmap_argsr   rC  r  r  extendr
   r   r  rb   r  r3   rc   r,   r   r7   r  rn  r.  r   reversedrA  r?  error_overlapr   rS   )r   r   r  r  r  r   r  sig_argsr
  sig_arg_kindssig_arg_namesconcrete_kindsformal_to_actualr  r  star_arg_entrieslstr  star_arg	star2_argoutput_args
output_argbase_argrF  bitmapr  s    ```                      r   r  z+LowLevelIRBuilder.native_args_to_positional  s   & 8 	%!}H66X66666X666PPiPPP155
 
  %$9,h77 	; 	;HCx!! ^ ''(\(\(\(\(\(\X[(\(\(\]]]738x#7H!:SX%:II"55dX 6 
 
) $&,h77 	+ 	+HCx8##%

Y&&    &

 G'11 V!(CH!5!5JJ(22 V!&sJJ!%.t*T*T*T!U!UJJA<SV$0022 G!%!5!5h$!O!OJJ!%Xsx!F!FJz****%((## 	C 	CA q3{#3#333"";q>222FA 0(;;  S8'')) ch.D ;!CCCCq1u.CCCCCC C"aAq,A&BBFFAwv/@AABBBBr   baser  RType | Nonelist[str | None] | Nonec	           
     D   |3t          d |D                       r|                     ||||||          S t          |j        t                    r?|j        j        j        r-|j        j        j        s|j        j                            |          r|j        j        	                    |          }	|%|
J d            d |D             }d |D             }n|
J d            |	j
        sJ |                     ||||	j
        |          }|                     t          ||||                    S |j        j                            |          r>|                     t          |||                    }
|                     |
||||          S n;t          |j        t"                    r!|                     ||j        ||||||          S |r|t&          gt)          |          z  k    r|                     ||||||          }|r|S |                     ||||||          S )	z/Generate either a native or Python method call.Nc              3  >   K   | ]}|                                 V  d S r   )r  r  s     r   r  z4LowLevelIRBuilder.gen_method_call.<locals>.<genexpr>  s*      (N(ND(N(N(N(N(N(Nr   z&arg_kinds not present but arg_names isc                    g | ]	}t           
S r-  r  r/  _s     r   r2  z5LowLevelIRBuilder.gen_method_call.<locals>.<listcomp>  s     = = =Q = = =r   c                    g | ]}d S r   r-  r$  s     r   r2  z5LowLevelIRBuilder.gen_method_call.<locals>.<listcomp>  s     : : :! : : :r   z&arg_kinds present but arg_names is notr  r  )anyr  r  r  rM   rs  rt  builtin_base
has_methodmethod_decl	bound_sigr  r   r;   ru  r0   r  rQ   union_method_callr	   r?  r  )r   r  r  r  rq  r   r  r  r  r  r  r   s               r   gen_method_callz!LowLevelIRBuilder.gen_method_call~  sz     S(N(NI(N(N(N%N%N &&tT:tYPYZZZ ty),,		"/	 I&3	
 y!,,T22 y)55d;;$$,,.V,,, = =* = = =I : :z : : :II$002Z000 ~%%%!;;	9dnd 
 xx
4z4 H HIII#,,T22 88GD$$=$=>>||j$)y $    	6** 	))diz;iQZ  
  	I'S__)DDD77dJTj 8  F   ""4z4IVVVr   obj_typereturn_rtypec	                l     pt           d fd}	                     |||	          S )z8Generate a method call with a union type for the object.r  rF   r   c           	     :                         |           S r   )r-  )r  r  r  r  r   r  r/  r   s    r   call_union_itemz<LowLevelIRBuilder.union_method_call.<locals>.call_union_item  s*    ''tZtY	  r   r}  )rt   r~  )
r   r  r.  r  r  r/  r   r  r  r2  s
   `  `````` r   r,  z#LowLevelIRBuilder.union_method_call  sq     $8'8	 	 	 	 	 	 	 	 	 	 	 	
 **4<Z^___r   c                ,    t          dt                    S )z0Load unboxed None value (type: none_rprimitive).r   )r3   rr   r  s    r   nonezLowLevelIRBuilder.none      q/***r   c                ,    t          dt                    S )z0Load unboxed True value (type: bool_rprimitive).r   r3   rT   r  s    r   r  zLowLevelIRBuilder.true  r5  r   c                ,    t          dt                    S )z1Load unboxed False value (type: bool_rprimitive).r   r7  r  s    r   r  zLowLevelIRBuilder.false  r5  r   c                t    |                      t          t          j        t          j        d                    S )z1Load Python None value (type: object_rprimitive).r   r  )r   r6   r   r  r  r  s    r   none_objectzLowLevelIRBuilder.none_object  s*    xxN$79KRTUUUVVVr   r  c                    |t           k    s|t          k     r(|                     t          |t                              S t          |          S )z-Load a tagged (Python) integer literal value.)r   r   r   r8   r]   r3   r   r  s     r   load_intzLowLevelIRBuilder.load_int  sA    (((E4I,I,I88K~>>???5>>!r   r=  c                     t          |          S )zLoad a float literal value.)r,   r<  s     r   
load_floatzLowLevelIRBuilder.load_float  s    U||r   c                R    |                      t          |t                              S )zLoad a str literal value.

        This is useful for more than just str literals; for example, method calls
        also require a PyObject * form for the name of the method.
        )r   r8   rx   r<  s     r   r  zLowLevelIRBuilder.load_str  s      xxE>::;;;r   bytesc                R    |                      t          |t                              S )zLoad a bytes literal value.)r   r8   rU   r<  s     r   
load_byteszLowLevelIRBuilder.load_bytes  s    xxE+;<<===r   complexc                R    |                      t          |t                              S )zLoad a complex literal value.)r   r8   rt   r<  s     r   load_complexzLowLevelIRBuilder.load_complex  s    xxE+<==>>>r   r   r  
identifier
str | None	namespace	error_msgc           	        |d| d}t                      t                      }}|                     t          |||||                    }	|                     t          |	||t          j        d                     |                     |           |                     t          t          j        ||                     |                     t                                 |                     |           |	S )Nzname "z" is not definedr  Trare)	r$   r   r:   r&   ri  r   r?   
NAME_ERRORrE   )
r   r  rG  r   rI  r   rJ  ok_blockerror_blockr  s
             r   load_static_checkedz%LowLevelIRBuilder.load_static_checked  s     ====I *jll+C[)RVWWWXX{HfoDQQQRRRK(((#$6$A9dSSTTTH%%%r   c                `    |                      t          t          |t                              S )N)rI  )r   r:   rt   r   )r   r  s     r   load_modulezLowLevelIRBuilder.load_module  s%    xx
#4dFVWWWXXXr   clsc                N    |j          d|j         }|                     |          S )zLoad native type object..)r   r  load_native_type_object)r   rT  fullnames      r   r  z!LowLevelIRBuilder.get_native_type  s-    o2222++H555r   rX  c                    |                     dd          \  }}|                     t          t          ||t                              S )NrV  r   )rsplitr   r:   rt   r!   )r   rX  moduler  s       r   rW  z)LowLevelIRBuilder.load_native_type_object  s:    sA..xx
#4dFNSSTTTr   lregrregc           	        |j         }|j         }t          |t                    r1t          |t                    r|dv r|                     ||||          S |dv r|                     ||||          }||S |dv r|                     ||||          S t          |          r+t          |          r|dv r|                     ||||          S t          |          r+t          |          r|dv r| 	                    ||||          S t          |          r\t          |          rM|t          v rD|t          j        v r|                     ||||          S |                     |||d         |          S t          |t                     r|dv r|                     ||||          S t%          |          r|t&          v r|                    d          }|dk    rt*          |         }nt,          j        }t          |          st1          |          r|                     |||          }|}t%          |          st5          |          r|                     |||||          S t          |t8                    r.|                     |||                     |||          ||          S n|t          j        v rt;          |          r|                     |||          }n5t          |          st1          |          r|                     |||          }t          j        |         }t%          |j                   r|                     ||||          S t          |t8                    r-|                     ||                     |||          ||          S nt%          |          r|t&          v r|                    d          }|dk    rt*          |         }nt,          j        }t          |t8                    r.|                     ||                     |||          |||          S t5          |          r|                     |||||          S t          |          st1          |          r0|                     |||          }|                     |||||          S n|t          j        v rt;          |          r|                     |||          }n5t          |          st1          |          r|                     |||          }t          j        |         }t          |t8                    r-|                     |                     |||          |||          S t%          |j                   r|                     ||||          S tA          |          stA          |          rtt          |t8                    r/tC          tE          |#                                                    }nt          |t8                    r/tC          tE          |#                                                    }nUt;          |j                   r| $                    ||          }n*t;          |j                   r| $                    ||          }tA          |j                   rtA          |j                   ro|tJ          v r#| &                    ||tJ          |         |          S |'                    d          r|dd         }	n|}	|	tP          v r| )                    |||	|          S | *                    ||||          }
|
r|
S tW          j,        |g           }| -                    |||g|          }|sJ d	|z              |S )
zPerform a binary operation.

        Generate specialized operations based on operand types, with a fallback
        to generic operations.
        )r   r   N)isis notr   )innot in=r   r   z Unsupported binary operation: %s).r  r  rO   compare_tuplestranslate_eq_cmptranslate_is_oprm   compare_stringsr`   compare_bytesr_   r   r*   
signed_opsbool_comparison_opbool_bitwise_oprM   translate_instance_containsrb   r   removesuffixrI   r4   DIVr^   r.  rn   fixed_width_int_opr3   rh   r5  comparison_oprc   r,   r=  r3  r>  rG   compare_floatsendswithrH   float_op	dunder_opr   getmatching_primitive_op)r   r\  r]  r   r   ltyper  r  op_idbase_oprt  primitive_ops_candidatesr   s                r   	binary_opzLowLevelIRBuilder.binary_op  s    		 eV$$ 	=E6)B)B 	=r\GYGY&&tT2t<<< ))$b$??E  !!!''dB=== U## 	>(9%(@(@ 	>R<EWEW''dB===u%% 	<*=e*D*D 	<|I[I[%%dD"d;;;e$$ 	E);E)B)B 	Er_G\G\\,,,..tT2tDDD++D$1tDDDeY'' 	JB2B,B,B33D$DIII&& 3	G///__S))::(,EE!IE%e,, "0A%0H0H ";;tUD99D!E'.. S)E2B2B S225$eTRRRdG,, 22tT[[ud%C%CUD   |...$U++ :99$tLLDD'.. :2CE2J2J :;;tUD99D$/3'	22 G--dD%FFFdG,, a--dDKKeT4R4RTY[_```!%(( 	G///__S))::(,EE!IEdG,, 22t{{4==tUD   U## S225$eTRRR%e,, S0A%0H0H S;;tUD99D225$eTRRRS |...$U++ :99$tLLDD'.. :2CE2J2J :;;tUD99D$/3dG,, a--dkk$t.L.LdTY[_```'	22 G--dD%FFFu%% 	D)<U)C)C 	D$(( 5U4#5#5#7#78899D'** 5U4#5#5#7#78899"49-- 5((t44"49-- 5((t44"49-- D2Edi2P2P D222..tT;TUW;XZ^___;;s## ! "gGG Gn,,==tWdCCCNN4r488	 	#->"b#9#9 ++,DtTlTXYY>>9B>>>>r   c                   |j         }t          |t                    sdS |rt          j        |          nt          j        |          }|dS |j                            |          sdS |j                            |          }|st          |j
        j                  dk    rdS |rIt          |j
        j                  dk    s*t          |j         |j
        j        d         j                   sdS |r&t          t          j         |j
        j                  rdS |r|gng }|                     ||||j
        j        |          S )aZ  
        Dispatch a dunder method if applicable.
        For example for `a + b` it will use `a.__add__(b)` which can lead to higher performance
        due to the fact that the method could be already compiled and optimized instead of going
        all the way through `PyNumber_Add(a, b)` python api (making a jump into the python DL).
        Nr   r+  )r  r  rM   r   ru  r   rs  r)  r*  r?  r  r   r   r   ret_typer-  )	r   r\  r]  r   r   rw  r  r  r   s	            r   rt  zLowLevelIRBuilder.dunder_op  sC    	%++ 	4,0NjnR(((6F6J26N6N4~((55 	4~))+66 	DHM**a//4 	S''1,,Jty$(-XYJZJ_4`4`,4 	J168IJJ 	 4%vv2##D+tTX=NPTUUUr   valnegatedc                   t          dt          |          }|                     t          ||t          j        |          }t          dt          |          }|rt
          j        nt
          j        }|                     ||||          }|S )zuCheck if a tagged integer is a short integer.

        Return the result of the check (value of type 'bit').
        r   r   )	r3   rX   r;  r4   ANDr*   NEQr  rp  )	r   r~  r   r  int_tagbitwise_andzeror   rU  s	            r   rJ  z(LowLevelIRBuilder.check_tagged_short_int  sw    
 !3T::kk"8#w	SWXXq0$77!(=\lo"";b$??r   lhsrhsc           	     J   |                      t          ||g|          }t          dt          |          }|                     t          ||t
          j        |                    }t                      t                      t                      }
}	}t          |||
t          j	                  }d|_
        |                     |           |                     |           |                      t          g |          }t          dt          |          }|                     t          ||t
          j        |                    }t          ||	|
t          j	                  }d|_
        |                     |           |                     |	           |                      t          g |           |                     |
           |                     |
           |dk    rt
          j        nt
          j        }|                     t          |t          dt                    ||                    S )zCompare two stringsr   Fr   r   )rP  r   r3   rV   r   r*   r  r$   r&   rK  r  r   r   rv   r  r   r   )r   r  r  r   r   compare_resulterror_constantcompare_error_checkexception_check	propagatefinal_comparebranchcheck_error_resultnullop_types                  r   rg  z!LowLevelIRBuilder.compare_strings  s   _sCj$GG %5t<<"hh$OO
 
 5?LL*,,PZP\P\M+_mV[YYO,,,![["dCCq,d33"hh+T<3CTJJ
 
 +Yv{SSI&&&'T222		-   M***%'4ZZ,//\5Exx^WQ@P5Q5QSZ\`aabbbr   c           	         |                      t          ||g|          }|dk    rt          j        nt          j        }|                     t          |t          dt                    ||                    S )Nr   r   )rP  r|   r*   r  r  r   r3   rV   )r   r  r  r   r   r  r  s          r   rh  zLowLevelIRBuilder.compare_bytes  s^    ]S#JEE%'4ZZ,//\5Exx^WQ@P5Q5QSZ\`aabbbr   c                    t          j        t                    rt          j        t                    sJ |dk    rdnd}t          t                    }t          j        j                  dk    rkt          j        j                  dk    rN                     t          ||r 	                                n 
                                                     |S t          j        j                  }t                      t                      t                      }
}	}d t          |          D             } fdt          |          D             } fdt          |          D             }|r||	}}n|	|}}t          t          j        j                            D ]}|dk    r                     ||                    ||         }||         }                     |||          }t          |j                  s                     t"          |g          }|t          j        j                  dz
  k     r&t%          ||||dz            t$          j                  }nt%          |||t$          j                  }||_                             |                                |                                t          | 
                                                                          |
                                |	                                t          | 	                                                                          |
           |S )	zCompare two tuples item by itemr   TFr   c                *    g | ]}t                      S r-  )r$   r$  s     r   r2  z4LowLevelIRBuilder.compare_tuples.<locals>.<listcomp>  s    <<<
<<<r   c           	     X    g | ]&}                     t          |                    'S r-  r   rB   )r/  rF  r  r   r   s     r   r2  z4LowLevelIRBuilder.compare_tuples.<locals>.<listcomp>  1    MMM!TXXhsAt4455MMMr   c           	     X    g | ]&}                     t          |                    'S r-  r  )r/  rF  r   r  r   s     r   r2  z4LowLevelIRBuilder.compare_tuples.<locals>.<listcomp>  r  r   r   )r  r  rO   r@   rT   r?  r@  r   r"   r  r  r$   rA  r   r{  r_   r  r   r&   rK  r  r   r   )r   r  r  r   r   equalr  lengthfalse_assigntrue_assignrl  check_blocks	lhs_items	rhs_items
early_stopfinalrF  lhs_itemrhs_itemcomparer  s   ``` `                r   rd  z LowLevelIRBuilder.compare_tuples  s    #(F++L
38V0L0LLLLd

/**sx~!##CHN(;(;q(@(@HHVF5$JDIIKKKdjjllDQQRRRMSX^$$)3z||Z\\3k<<eFmm<<<MMMMMMuV}}MMM	MMMMMMuV}}MMM	 	: ,kJJ +\Js38>**++ 	 	AAvv##LO444 |H |HnnXxTBBG &gl33 F++GgYEE3sx~&&***\!a%5H&+VVUFKHH"FNHHVL)))

d33444		#K(((		T22333s###r   instrG  c                    |                      |d|gd |          }t          |j                  s|                     t          |g|          }|dk    r,|                     |t          dt                    d|          }|S )N__contains__rb  r   r  r   )r-  r_   r  r  r   rk  r3   rT   )r   r  rG  r   r   rQ  s         r   rl  z-LowLevelIRBuilder.translate_instance_contains  s    ""4$tLL!#(++ 	:##GcUD99C>>&&sGA_,M,M,MsTXYYC
r   c           	         |dk    rt           j        }n0|dk    rt           j        }n|dk    rt           j        }n
J |            |                     t          t
          ||||                    S )Nr   r   r   )r4   r  ORrO  r   rT   )r   r\  r]  r   r   codes         r   rk  z!LowLevelIRBuilder.bool_bitwise_op  sh    999DD3YY8DD3YY9DD"xxotT4FFGGGr   c                V    t           j        |         }|                     ||||          S r   )r*   ri  rp  )r   r\  r]  r   r   rx  s         r   rj  z$LowLevelIRBuilder.bool_comparison_op!  s)    '+!!$eT:::r   c                ~    t          d|j        |          }|                     |j        ||t          j        |          S Nr   )r3   r  r;  r4   rO  )r   r  r   masks       r   	unary_notzLowLevelIRBuilder.unary_not%  s3    q%*d++{{5:udEItDDDr   expr_opc                   |j         }t          |          st          |          r$|dk    r|                     ||          S |dk    r|S t	          |          r|dk    r1|                     |t          d|          |t          j        |          S |dk    ry|j	        r1|                     ||t          d|          t          j
        |          S d|j        dz  z  dz
  }|                     ||t          ||          t          j
        |          S |dk    r|S t          |          r1|dk    r#|                     t          ||                    S |dk    r|S t          |t                    r2|j        }t#          |          r|dz  }t          | ||j                  S t'          |          r|dk    r|S t          |t(                    rt)          |j         |j                  S t          |t*                    r|                     |d ||          }||S t/          j        |g           }|                     ||g|          }	|	sJ d	|z              |	S )
Nnotr   r   r   ~r   r   r   zUnsupported unary operation: %s)r  r_   r^   r  rb   r;  r3   r4   SUBr:  rO  r9  rc   r   r.   r  r  rl   r   rn   r,   rM   rt  r   ru  rv  )
r   r  r  r   r  r  numr  rz  r   s
             r   unary_opzLowLevelIRBuilder.unary_op)  sg   jc"" 	&7&<&< 	%~~eT222#~~$$ 	#~~{{33	4PPPC= X;;sE72s3C3CUYPTUUU #(Q,/14D;;sE743E3EuyRVWWWCs## 	#~~xx 5 5666CeW%% 	2+C&s++ 	C4ej111S>> 	gnnLeU## 	3%+uz222c9%% 	^^E4$??F!#,="#=#= ++,DugtTTBB87BBBBr   key_value_pairsSequence[DictEntry]c                \   d }g }g }|D ]\  }}|J|+|                     |           |                     |           4|                     |d||gd |           Q||                     |||          }|                     t          ||g|           ||                     |||          }|S )Nr  r  r  )r   r  r  rP  r   )r   r  r   r  keysr   r  r  s           r   	make_dictzLowLevelIRBuilder.make_dictW  s    # ) 	S 	SJC>KK$$$MM%(((22MC<TPT 3    
 >!..tVTBBF5TRRRR>&&tVT::Fr   r  c                <    |                      t          |g|          S )a  This function returns an uninitialized list.

        If the length is non-zero, the caller must initialize the list, before
        it can be made visible to user code -- otherwise the list object is broken.
        You might need further initialization with `new_list_set_item_op` op.

        Args:
            length: desired length of the new list. The rtype should be
                    c_pyssize_t_rprimitive
            line: line number
        )rP  r   r   r  r   s      r   new_list_op_with_lengthz)LowLevelIRBuilder.new_list_op_with_lengthr  s     {{;$777r   c           	     f    t          t          |          t                    g}t          |          t          k    r                     t
          ||z             S                      t          |          }|s|S  fd|D             }                     t          |gt                              }t          t          |                    D ]:}                     t          |t          |t                    ||         g           ;                     t          |g                     |S )Nc                H    g | ]}                     |t                    S r-  r  )r/  rG  r   r   s     r   r2  z1LowLevelIRBuilder.new_list_op.<locals>.<listcomp>  s*    NNNtD"3T::NNNr   )r3   r?  rX   !LIST_BUILDING_EXPANSION_THRESHOLDrP  r   r   r   r>   r   rA  r  r   r5   )r   r   r   r  result_listr   ob_item_baserF  s   ` `     r   r   zLowLevelIRBuilder.new_list_op  s*   &s6{{4JDQQRv;;;;;;;}fvotDDD kk+vt<< 	NNNNNvNNNxx[M:t L LMMs6{{## 	 	Aga9O.P.PRVWXRYZ\`    	K=))***r   c                :    |                      t          ||          S r   )r  r   )r   r   r   s      r   r   zLowLevelIRBuilder.new_set_op  s      VT:::r   r  	item_typer  c                  t          t          |t          |                              }|                     t	          |t          |                               |                     t          |rt          nt          |                    S )z;Declare and initialize a new RArray, returning its address.)	r@   rL   r?  r   r#   r  r6   rs   rW   )r   r  r   r  arrays        r   r  zLowLevelIRBuilder.setup_rarray  ss     	3v;;7788UDLL11222xxZY11EY[`aa
 
 	
r   	expr_typeleftCallable[[], Value]rightc                   t          |          }t                      t                      t                      }	}}|dk    r||fn||f\  }
} |            }|                     ||
|           |                     |           |                     |||          }|                     t          ||                     |                     |	           |                     |            |            }|                     |||          }|                     t          ||                     |                     |	           |                     |	           |S )Nand)r@   r$   add_bool_branchr   r.  r   r"   r   )r   r   r  r  r  r   r   	left_body
right_body
next_block	true_body
false_body
left_valueleft_coercedright_valueright_coerceds                   r   r  z%LowLevelIRBuilder.shortcircuit_helper  sC    )$$,6LL*,,
z:	 <>;;Y 7 7YXbLc	:TVV
ZJ???I&&&{{:y$??--...		*J'''eggKDAA..///		*J'''r   c           	        t          |j                  st          |j                  r|}nCt          |j        t                    r>t          dt                    }|                     ||t          j	        |j
                  }nt          |j                  rEt          d|j                  }|                     t          ||t          j	                            }nt          |j        t                    r$|                     t           |g|j
                  }nTt          |j        t"                    st          |j        t$                    rI|                     ||j
                  }t          d          }|                     ||d|j
                  }nt+          |j        t,                    rU|j        j        j        rD|j        j                            d          r%|                     |dg t6          |j
                  }nht9          |j                  r6|                     |t=          d          t>          j	        |j
                  }ntA          |j                  }|| !                    || "                                d|j
                  }d}t+          |t,                    r6|j                            d          s|j        #                    d          rd}|r|}ntI          tJ                    }tM                      tM                      tM                      }
}	}tO          |||	tN          j(                  }|                     |           | )                    |           | *                    |||j
                  }| +                    |          }|                     tY          ||                     | -                    |
           | )                    |	           |                     tY          |t          dtJ                                         | -                    |
           | )                    |
           n"| .                    t^          |g|j
                  }|S )	z_Return bool(value).

        The result type can be bit_rprimitive or bool_rprimitive.
        r   r   __bool__r  Nr`  FT)0r_   r  r^   r   r]   r3   rw   rp  r*   r  r   rb   r   r   rx   rP  r   rq   r[   builtin_lenr{  r  rM   rs  rt  r)  r-  rT   rc   rq  r,   r-   ru   rf  r:  is_method_finalr@   rR   r$   r&   rK  r   r%  
bool_valuer"   r   r  r   )r   r  r  r  r  
value_typenot_nonealways_truthyr  r  rT  r  	remainingas_bools                 r   r  zLowLevelIRBuilder.bool_value  s   
 ej)) 9	I->uz-J-J 9	IFF
N;; 7	I1233D''t\5EuzRRFF!%*-- 4	I1ej))DXXl5$8HIIJJFF%*n55 1	I[[!2UGUZHHFF%*o66 /	I,J;
 ;
 /	I %%eUZ88F1::D^^FD$
CCFFuz9--)	I
#0)	I 
#..z::)	I ))%RRWR\]]FF ,, "	I((c

<M<QSXS]^^FF,UZ88J%//t7G7G7I7I8UZU_`` %j)44 -%.99"  -$-==jII- )-  -%FF &n55F'1||Z\\:<<%D#HdE6;GGFHHV$$$''--- !% 2 25*ej Q QI"ooi88GHHVFG44555IIcNNN''...HHVFGA~,F,FGGHHHIIcNNN'',,,,**7UGUZHHr   r  r  c                   t          |j                  }|F|                     |          }|                     t	          |||t          j                             d S |                     ||                                 d|j                  }t	          |||t          j                  }|                     |           d}t          |t                    r6|j                            d          s|j                            d          rd}|sbt                      |_        |                     |j                   |                     |||j                  }	|                     |	||           d S d S )Nr`  Fr  T)ru   r  r  r   r&   rK  rf  r:  r   r  rM   rs  r)  r  r$   r  r   r%  r  )
r   r  r  r  opt_value_typer  is_noner  r  r  s
             r   r  z!LowLevelIRBuilder.add_bool_branch  sc   ,UZ88!//JHHVJeV[AABBBBB **5$2B2B2D2DhPUPZ[[GGT5&+>>FHHV!M.)44 )%.99  )$-==jII) %)M  =(ll##FK000 !..unejQQ	$$Ye<<<<<= =r   descr   c                   g t          t          t          |          t          |j                                      D ]C}|j        |         }||         }|                     |||          }                    |           D|j        |j        J fd|j        D             d}|j        t          |j                  }t          t          |j                  t          |                    D ];}||         }|                     ||j        |          }                    |           <|j        D ]-}	|	\  }
}t          |
||          }                    |           .|j
        }|t          k    rt          }|                     t          |j        |j        |j        |j        ||||j        	  	                  }|j        r;D ]8}t)          |t          t*          f          s| j                            |           9|j
        t          k    rQt/          |t          d|j        |          t.          j        |          }t2          |_
        |                     |           |j        |}n*|                     t7          ||j                            }|}|rWt9          |j        |          sBt=          |          r|                                 }n|                     ||||j                  }|S )zHCall function using C/native calling convention (not a Python callable).Nc                     g | ]
}|         S r-  r-  )r/  rF  rm  s     r   r2  z,LowLevelIRBuilder.call_c.<locals>.<listcomp>3  s    999awqz999r   r   is_purer   r  ) rA  minr?  	arg_typesr.  r   orderingvar_arg_typeextra_int_constantsr3   
error_kindr   r   r   r(   c_function_namereturn_typestealsrv  r  r  r8   r   r*   rM  r   truncated_typerA   r   r  rj   r4  )r   r  r   r   rq  rF  formal_typer  var_arg_idxrG  r~  r  extra_int_constantr  r   compr  truncaterm  s                     @r   rP  zLowLevelIRBuilder.call_c   s    s3t99c$.&9&9::;; 	  	 A.+Kq'C++c;55CNN3=$$,,,99994=999G(dn--K3t~..D		:: $ $1gkk#t'8$??s####, 	/ 	/DHC!(c4!8!8NN-...._
$$"J$  
 
 

 
  	1  1 1!#'=>> 1$++C000?k))43CT(J(JLL\^bccD'DOHHTNNN&FFxx1D E EFFHF 	]1&+{KK 	]!+.. ] V[$4K[\\r   
candidateslist[CFunctionDescription]c                   d }|D ]}t          |j                  t          |          k    r(t          d t          ||j                  D                       rN|j        r|rE|rA|j        |j        k    sJ d                    ||                      |j        |j        k    r|}|}|r|                     ||||          }|S d S )Nc              3  F   K   | ]\  }}t          |j        |          V  d S r   r   r  r/  actualformals      r   r  z4LowLevelIRBuilder.matching_call_c.<locals>.<genexpr>x  sC        4BFF
6;//     r   Ambiguous:
1) {}
2) {})r?  r  r  rC  rv  priorityformatrP  )	r   r  r   r   rq  r  matchingr  r   s	            r   matching_call_cz!LowLevelIRBuilder.matching_call_cl  s    15 	$ 	$D4>""c$ii//  FI$PTP^F_F_     
$'
$+5
$  $#,===?Y?`?` $@ @=== }x'888#'#H 	[[4{CCFMtr   r=   c                   |j         rvt          |j        |j        |j        |j        |j        |j         |j        |j        |j	        |j
        |j        |j        |j                  }|                     ||||          S g }t          t!          t#          |          t#          |j                                      D ]G}|j        |         }||         }	|J |                     |	||          }	|                    |	           H|j
        J |j        J |j        rJ |                     t+          |||                    }
|j	        r;|D ]8}	t-          |	t.          t0          f          s| j                            |	           9|j        t4          k    rQt7          |
t/          d|j        |          t6          j        |          }t:          |_        |                     |           |j        J |
}|rWt=          |j        |          sBtA          |          r| !                                }n|                     ||||j	                  }|S )zAdd a primitive op.r  )rq  Nr  r   r  )"r  r   r  r  r  r  r  r  r  rv  r  r  r  r  rP  rA  r  r?  r.  r   r   r>   r  r3   r8   r   r   r*   rM  r   r   r  rj   r4  )r   r  r   r   rq  c_descrm  rF  r  r  r   r  r  s                r   r  zLowLevelIRBuilder.primitive_op  sa     	L *	 !#$ (  F ;;vtT{;KKK
 s3t99c$.&9&9::;; 	  	 A.+Kq'C***++c;55CNN3}$$$ (((+++++gt$???@@ 	1  1 1!#'=>> 1$++C000?k))43CT(J(JLL\^bccD'DOHHTNNN"*** 	]1&+{KK 	]!+.. ] V[$4K[\\r   list[PrimitiveDescription]c                   d }|D ]}t          |j                  t          |          k    r(t          d t          ||j                  D                       rN|j        r|rE|rA|j        |j        k    sJ d                    ||                      |j        |j        k    r|}|}|r|                     ||||          S d S )Nc              3  F   K   | ]\  }}t          |j        |          V  d S r   r  r  s      r   r  z:LowLevelIRBuilder.matching_primitive_op.<locals>.<genexpr>  sH         #FF 6;//     r   r  )r   rq  )r?  r  r  rC  rv  r  r  r  )r   r  r   r   rq  r  r  r  s           r   rv  z'LowLevelIRBuilder.matching_primitive_op  s    15 	$ 	$D4>""c$ii//   '*$&?&?     $ '	$ ,6	$
  $#,===?Y?`?` $@ @=== }x'888#'#H 	Y$$Xt$K$XXXtr   r  c           	     N    |                      t          |||||                    S )a  Generate a native integer binary op.

        Use native/C semantics, which sometimes differ from Python
        semantics.

        Args:
            type: Either int64_rprimitive or int32_rprimitive
            op: IntOp.* constant (e.g. IntOp.ADD)
        )r   r4   )r   r  r  r  r   r   s         r   r;  zLowLevelIRBuilder.int_op  s&     xxdCb$77888r   c           	     @   t           |         }|t          j        t          j        fv r+t	          |t
                    r|j        dk    s
|                     |t          d          t          j	        |          }t                      t                      }}|                     t          |||t          j        d                     |                     |           |t          j        k    rd}	nd}	|                     t          t          j        |	|                     |                     t#                                 |                     |           |t          j        k    r|                     |||          S |                     t          ||||                    S )a  Generate a native float binary arithmetic operation.

        This follows Python semantics (e.g. raise exception on division by zero).
        Add a FloatOp directly if you want low-level semantics.

        Args:
            op: Binary operator (e.g. '+' or '*')
        r  TrL  zfloat division by zerozfloat modulo)rH   r/   rn  MODr  r,   r  rq  r-   r  r$   r   r&   rK  r   r?   ZERO_DIVISION_ERRORrE   	float_mod)
r   r  r  r   r   rx  r  errokmsgs
             r   rs  zLowLevelIRBuilder.float_op  sZ    r"W['+...sE** (syC/?/?''U3ZZ9J9MtTT$,,
R3FKdCCCDDD##C(((GK''2CC(C+,>,RTWY]^^___'''##B'''GK>>#sD11188GCeT::;;;r   c                   |                      t          ||t          j        |                    }t          t                    }|                      t          ||                     t                      t                      t                      t                      f\  }}}}	|                      t          |t          d          t          j	        |                    }
|                      t          |
||t          j                             |                     |           |                     |||          }|                      t          ||	|t          j                             |                     |           |                     ||d|          }|                      t          ||                     |                      t          |	                     |                     |           |                     t"          t          d          |g|          }|                      t          ||                     |                      t          |	                     |                     |	           |S )z/Perform x % y on floats using Python semantics.r  r   )r   r/   r  r@   r\   r"   r$   r-   r,   r  r&   rK  r   is_same_float_signsrs  r2   r  r   )r   r  r  r   modrQ  trickyadjustcopysigndoneis_zero
same_signsadjs                r   r  zLowLevelIRBuilder.float_mod  s   hhwsCd;;<<'((S!!""")3z||Z\\S]S_S_)_&$((,S%**>O>RTXYYZZ66;??@@@F###--c3==

D&&+>>???F###mmCc400S!!"""dH%%% eCjj#->EES!!"""dD!!!
r   c                L    |                      t          ||||                    S r   )r   r-   r   r  r  r   r   s        r   rq  z LowLevelIRBuilder.compare_floats*  s#    xx)#sB==>>>r   rN   c                   |                      |||          }|                      |||          }|t          j        k    rt          |t                    rK|j        dvrB|j        s#|                     |||t          j        |          S |                     ||||          S t          |          rt          }nwt          |          rt          }n`t          |          rt          }nIt          |          r0|                     |||           |                     |||||          S J |            |                     |||g|          S |t          j        k    rt          |t                    rK|j        dvrB|j        s#|                     |||t          j        |          S |                     ||||          S t          |          rt(          }nwt          |          rt*          }n`t          |          rt,          }nIt          |          r0|                     |||           |                     |||||          S J |            |                     |||g|          S |                     |||||          S )a  Generate a binary op using Python fixed-width integer semantics.

        These may differ in overflow/rounding behavior from native/C ops.

        Args:
            type: Either int64_rprimitive or int32_rprimitive
            op: IntOp.* constant (e.g. IntOp.ADD)
        )r   r   )r.  r4   rn  r  r3   r  r:  r;  inline_fixed_width_dividerg   r   rf   r   re   r   rp   check_for_zero_divisionrP  r  inline_fixed_width_modr   r   r   )r   r  r  r  r   r   prims          r   ro  z$LowLevelIRBuilder.fixed_width_int_op-  s    kk#tT**kk#tT**??#w'' PCIW,D,D~ P;;tS#uy$GGG  99$S$OOO"4(( 
#&$T** #&$T** #&$T** #,,S$==={{4c2t<<<"d""";;tc3Z666??#w'' MCIW,D,D~ M;;tS#uy$GGG  66tS#tLLL"4(( 
##$T** ##$T** ##$T** #,,S$==={{4c2t<<<"d""";;tc3Z666{{4c2t444r   c                   t                      t                      }}|                     |t          d|          d|          }|                     t	          |||t          j                             |                     |           |                     t          t          j        d|                     |                     t                                 |                     |           d S )Nr   r   z"integer division or modulo by zero)
r$   r{  r3   r   r&   rK  r   r?   r  rE   )r   r  r  r   r  r  r  s          r   r"  z)LowLevelIRBuilder.check_for_zero_divisiond  s    ,,
R..ga&6&6dCCb&+66777C   "68\^b 	
 	
 	

 	Br   c                   t          |          }|                     |||t          j        |          }|                     t          ||                     |                     ||||          }t                      t                      t                      }
}	}|                     t          ||
|t          j	                             | 
                    |           |                     |||t          j        |          }|                     t          ||t          j        |                    }|                     t          ||
|	t          j	                             | 
                    |	           |                     ||t          d|          t          j        |          }|                     t          ||                     |                     t!          |
                     | 
                    |
           |S r  )r@   r;  r4   rn  r   r"   is_same_native_int_signsr$   r&   rK  r   MULr*   r  r3   r  r2   )r   r  r  r  r   rQ  divr  r  r  r  mulmul_eqr  s                 r   r!  z+LowLevelIRBuilder.inline_fixed_width_divideq  s   tnnkk$S%)T::S!!"""224c4HH
)||Z\\:<<
D&&+>>???F###kk$S%)T::,sC$GGHHffk::;;;F###kk$WQ%5%5uy$GGS!!"""dD!!!
r   c           	        t          |          }|                     |||t          j        |          }|                     t          ||                     |                     ||||          }t                      t                      t                      }
}	}|                     t          ||
|t          j	                             | 
                    |           |                     t          |t          d|          t          j        |                    }|                     t          ||
|	t          j	                             | 
                    |	           |                     |||t          j        |          }|                     t          ||                     |                     t          |
                     | 
                    |
           |S Nr   )r@   r;  r4   r  r   r"   r'  r$   r&   rK  r   r*   r3   r  ADDr2   )r   r  r  r  r   rQ  r  r  r  r  r  r  r  s                r   r#  z(LowLevelIRBuilder.inline_fixed_width_mod  sv   tnnkk$S%)T::S!!"""224c4HH
)||Z\\:<<
D&&+>>???F###((<WQ-=-=|PTUUVVvv{;;<<<F###kk$S%)T::S!!"""dD!!!
r   abc           	     T   |                      t          |t          d|          t          j        |                    }|                      t          |t          d|          t          j        |                    }|                      t          ||t          j        |                    S r-  )r   r*   r3   rL  r  )r   r  r/  r0  r   neg1neg2s          r   r'  z*LowLevelIRBuilder.is_same_native_int_signs  s|    xxQ4(8(8,:JDQQRRxxQ4(8(8,:JDQQRRxxT4$GGHHHr   c                P   |                      t          |t          d          t          j        |                    }|                      t          |t          d          t          j        |                    }|                      t	          ||t          j        |                    S )Nr  )r   r-   r,   LTr*   r  )r   r/  r0  r   r2  r3  s         r   r  z%LowLevelIRBuilder.is_same_float_signs  sx    xx)!U3ZZ9J9MtTTUUxx)!U3ZZ9J9MtTTUUxxT4$GGHHHr   c                L    |                      t          ||||                    S r   )r   r*   r  s        r   rp  zLowLevelIRBuilder.comparison_op  s"    xxS#r488999r   use_pyssize_tc                   |j         }d}t          |          st          |          st          |          r|                     t
          |g|          }nt          |          st          |          ru|                     t          |t          d                    }|                     t          t          |                    }|                     t          |g                     nYt          |          r|                     t           |g|          }n,t#          |          r|                     t$          |g|          }|B|r|S t'          dt          |          }|                     t*          ||t,          j        |          S t1          |t2                    r|rJ |                     |dg t6          |          }|                     |t6          |          }t;                      t;                      }
}	|                     |t'          d          d|          }|                     ||	|
           |                      |
           |                     tC          tB          j"        d|                     |                     tG                                 |                      |	           |S |r|                     tH          |g|          S |                     tJ          |g|          S )zGenerate len(val).

        Return short_int_rprimitive by default.
        Return c_pyssize_t if use_pyssize_t is true (unshifted).
        Nusedr   __len__r   r   z__len__() should return >= 0)&r  ri   ro   r`   r  r   rk   rd   r   r1   rK   r9   rX   r5   ra   rP  r   rm   r   r3   r;  rw   r4   r<  r  rM   r-  r]   r.  r$   r{  r  r   r?   VALUE_ERRORrE   r   r   )r   r~  r   r7  r  
size_valueelem_addressoffsetr  r  failconds               r   r  zLowLevelIRBuilder.builtin_len  s    h
c"" 		G&9#&>&> 		GBUVYBZBZ 		G**?SE4HHJJs## 	G'>s'C'C 	G88M#{F$K$KLLL'*@,"O"OPPJHHYu%%&&&&$$ 	G%9C5$GGJJs## 	G%83%FFJ! "!!Q 6==F;;3ZIY[_```c9%% 	$$$$))#y"ndSSF[[>>F!||Z\\B>>&'!**dDAAD  r4000%%%HH"&24RTX   
 HH[]]######M  	<;;5udCCC;;~ud;;;r   rB  c                    t          t          |          t                    }|                     t          |g|z   |          S r   )r3   r?  rX   rP  r   )r   rB  r   r9  s       r   r  zLowLevelIRBuilder.new_tuple  s4    c%jj*@AA{{<$%>>>r   c                <    |                      t          |g|          S )a  This function returns an uninitialized tuple.

        If the length is non-zero, the caller must initialize the tuple, before
        it can be made visible to user code -- otherwise the tuple object is broken.
        You might need further initialization with `new_tuple_set_item_op` op.

        Args:
            length: desired length of the new tuple. The rtype should be
                    c_pyssize_t_rprimitive
            line: line number
        )rP  r   r  s      r   new_tuple_with_lengthz'LowLevelIRBuilder.new_tuple_with_length  s     {{3fXtDDDr   r
  c                <    |                      t          |g|          S r   )r  r   )r   r
  r   s      r   r>  zLowLevelIRBuilder.int_to_float  s      1#t<<<r   process_itemCallable[[Value], Value]c                4   g }g }|j         D ]B}t          |t                    r|                    |           -|                    |           Ct	                      }	t          |          }
t          |          D ]\  }}|t          |          dz
  k     p|}|rd|                     ||j	        |          }t	                      t	                      }}| 
                    |||           |                     |           |                     |||          } ||          }|                     |||          }|                     t          |
|                     |                     |	           |r|                     |           |rx|                     |t           |d          } ||          }|                     |||          }|                     t          |
|                     |                     |	           |                     |	           |
S )al  Generate isinstance() + specialized operations for union items.

        Say, for Union[A, B] generate ops resembling this (pseudocode):

            if isinstance(obj, A):
                result = <result of process_item(cast(A, obj)>
            else:
                result = <result of process_item(cast(B, obj)>

        Args:
            obj: value with a union type
            rtype: the union type
            result_type: result of the operation
            process_item: callback to generate op for a single union item (arg is coerced
                to union item type)
            line: line number
        r   T)r&  )rB  r  rM   r   r$   r@   	enumerater?  r  rs  r  r   r.  r   r"   r   rt   )r   ro  r  rq  rE  r   
fast_items
rest_itemsrG  
exit_blockr  rF  
more_typesr   
true_blockfalse_blockrm  temptemp2s                      r   r~  z(LowLevelIRBuilder.decompose_union_helper  s   6 

K 	( 	(D$	** (!!$'''' !!$''''\\
+&& ,, 	1 	1GAtS__q00>JJ 0++CEE*4,,
K
$$R[AAA##J///kk#tT22G<((DKKk488EHHVFE**+++IIj!!! 1##K000 	" kk#'8$dkKKG<((DKKk488EHHVFE**+++IIj!!!J'''r   base_regc                l    t          j        |g           }|                     ||g|z   |||          }|S )ar  Translate a method call which is handled nongenerically.

        These are special in the sense that we have code generated specifically for them.
        They tend to be method calls which have equivalents in C that are more direct
        than calling with the PyObject api.

        Return None if no translation found; otherwise return the target register.
        r  )r   ru  rv  )	r   rQ  r  r   rq  r   r  rz  r  s	            r   r  z/LowLevelIRBuilder.translate_special_method_call*	  sL    " $3#6tR#@#@ 11$xj4&7{Wa 2 
 
 r   c                   |j         }|j         }t          |t                    r||k    sdS |j        }|                    d           p#|                    d           p|j        p|j        }|rdS |                    d          s"|dk    rdnd}	|                     |||	|          S | 	                    |t          |         |g||          S )zeAdd a equality comparison operation.

        Args:
            expr_op: either '==' or '!='
        N__eq____ne__r   r_  r`  )r  r  rM   rs  r  inherits_pythonis_augmentedr)  rf  r-  r   )
r   r\  r]  r  r   rw  r  rs  cmp_varies_at_runtimeidentity_ref_ops
             r   re  z"LowLevelIRBuilder.translate_eq_cmpA	  s     		5),, 	%4>
 ((222 %++H555%'% $	 	 ! 	 4""8,, 	K&-oodd8O''dOTJJJ##D*W*=vudSSSr   c                    |dk    rt           j        nt           j        }|                     |t          |          }|                     |t          |          }|                     t          ||||                    S )zCreate equality comparison operation between object identities

        Args:
            expr_op: either 'is' or 'is not'
        r_  )r*   r  r  r.  rt   r   )r   r\  r]  r  r   r   r  r  s           r   rf  z!LowLevelIRBuilder.translate_is_opc	  sf     !(4\__\5Ekk$ 1488kk$ 1488xxS#r488999r   r  c                   t          |          }|dk    r\t          |t                    }d t          t	          ||                    D             }|                     t          |g|z   |          S |                     t          g |          S )z9Create a dictionary(possibly empty) using keys and valuesr   c                    g | ]	}|D ]}|
S r-  r-  )r/  r1  rF  s      r   r2  z2LowLevelIRBuilder._create_dict.<locals>.<listcomp>u	  s%    CCC1CCAQCCCCr   )r?  r3   rX   r  rC  rP  r}   r~   )r   r  r   r   r9  r<  rB  s          r   r  zLowLevelIRBuilder._create_dictn	  s     4yy!88 '.D E EJCCSv%6%6 7 7CCCE;;}zlU.BDIII;;{B555r   r  c                j    | j         
J d            | j                             || j        |           d S )Nz-cannot generate errors in this compiler phase)r   r4  r   )r   r  r   s      r   r4  zLowLevelIRBuilder.errorz	  s<    {&&(W&&&#t/66666r   )r   r   r   r{   r   r   )r   r   r   r   r   r   )r   r<   r   rF   )r   r$   r   r   )r   r$   r   r   )r   r   r   r   r   r   )r  r  r   r   )r   r  )r   r@   )r   r   )r  r  r   r   )r  rF   r   rF   )
r  rF   r  rP   r   r!  r  r   r   rF   )F)r  rF   r  rP   r   r!  r&  r   r  r   r   rF   )r  rF   r  rP   r   r!  r   rF   )r  rF   r   r!  r   rF   )ro  rF   rp  r   rq  rP   r   r!  r$  r   r   rF   )ro  rF   r  rQ   rp  r   rq  rP   r   r!  r   rF   )ro  rF   rp  r   r   r!  r   rF   )ro  rF   r  r  r   r!  r   rF   )ro  rF   r   r!  r   rF   )ro  rF   r  rF   r   r!  r   rF   )ro  rF   rs  r   r   r!  r   rF   )
r   r  r   r!  r  r   r  r   r   r  )NN)r  rF   r  r   r   r!  r  r  r  r  r   rF   )r  rF   r  r   r   r!  r  r  r  r  r   r  )r  r  r   rF   )ro  rF   r  r   r  r   r   r!  r  r  r  r  r   rF   )ro  rF   r  r   r  r   r   r!  r  r  r  r  r   r  )r  r   r   r  r  r  r  r  r   r!  r  r  r   rF   )r   r  r  r  r  r  r  r   r   r!  r  r  r   r   )NNF)r  rF   r  r   r  r   rq  r  r   r!  r  r  r  r   r  r   r   rF   )r  rF   r.  rQ   r  r   r  r   r/  r  r   r!  r  r  r  r   r   rF   r  )r  r!  r   rF   )r  r=  r   rF   )r  r   r   rF   )r  rA  r   rF   )r  rD  r   rF   )r  rP   rG  r   r   rH  rI  r   r   r!  rJ  rH  r   rF   )r  r   r   rF   )rT  r   r   rF   )rX  r   r   rF   )
r\  rF   r]  rF   r   r   r   r!  r   rF   )
r\  rF   r]  r  r   r   r   r!  r   r  )r~  rF   r   r!  r  r   r   rF   )
r  rF   r  rF   r   r   r   r!  r   rF   )r   )
r  rF   rG  rF   r   r   r   r!  r   rF   )r  rF   r   r!  r   rF   )r  rF   r  r   r   r!  r   rF   )r  r  r   r!  r   rF   )r  rF   r   r!  r   rF   )r   r   r   r!  r   rF   )r  rP   r   r  r  r   r   rF   )r   r   r  rP   r  r  r  r  r   r!  r   rF   r}  )r  rF   r  r$   r  r$   r   r   r   )
r  r   r   r   r   r!  rq  r  r   rF   )NF)r  r  r   r   r   r!  rq  r  r  r   r   r  )
r  r=   r   r   r   r!  rq  r  r   rF   )r  r	  r   r   r   r!  rq  r  r  r   r   r  )r  rP   r  rF   r  rF   r   r!  r   r!  r   rF   )r  rF   r  rF   r   r!  r   rF   )
r  rF   r  rF   r   r!  r   r!  r   rF   )r  rN   r  rF   r  rF   r   r!  r   r!  r   rF   )r  rF   r  rP   r   r!  r   r   )
r  rP   r  rF   r  rF   r   r!  r   rF   )
r  rP   r/  rF   r0  rF   r   r!  r   rF   )r/  rF   r0  rF   r   r!  r   rF   )r~  rF   r   r!  r7  r   r   rF   )rB  r   r   r!  r   rF   )r
  rF   r   r!  r   rF   )ro  rF   r  rQ   rq  rP   rE  rF  r   r!  r   rF   )rQ  rF   r  r   r   r   rq  r  r   r!  r  r   r   r  )
r\  rF   r]  rF   r  r   r   r!  r   r  )
r\  rF   r]  rF   r  r   r   r!  r   rF   )r  r   r   r   r   r!  r   rF   )r  r   r   r!  r   r   )b__name__
__module____qualname____doc__r   r   r   r   r   r   r  r  r	  r   r  r  r  r%  r.  r5  r7  r6  rn  ry  rw  rx  r  r  r  r  r  r  r  r  r  r  r   r  r-  r,  r4  r  r  r:  r=  r?  r  rC  rF  r    rQ  rS  r  rW  r{  rt  rJ  rg  rh  rd  rl  rk  rj  r  r  r  r  r   r   r  r  r  r  rP  r  r  rv  r;  rs  r  rq  ro  r"  r!  r#  r'  r  rp  r  r  rC  r>  r~  r  re  rf  r  r4  r-  r   r   r   r      s         	+ 	+ 	+ 	+' ' ' '   # # # #
" " " "# # # #
 @E 1 1 1 1 1 1, , , ,) ) ) )   " " " "
9 9 9 9    PUM M M M M M g !g g g g g gRR R R Rh= = = =5 5 5 5n   8 W\5 5 5 5 5 5(Y Y Y YB B B B      L L L L   6}) }) }) })H +/15c c c c cF +/15$ $ $ $ $L	- 	- 	- 	-d d d d2' ' ' 'b .20 0 0 0 0 0< .2] ] ] ] ] ]L +/-1 9W 9W 9W 9W 9Wv` ` ` `2+ + + ++ + + ++ + + +W W W W" " " "   < < < <> > > >? ? ? ? #') $    (Y Y Y Y6 6 6 6
U U U Ur r r rhV V V VB
 
 
 
 
c c c c6c c c c
, , , , ,\   	H 	H 	H 	H; ; ; ;E E E E, , , ,\   68 8 8 8   *; ; ; ; PU
 
 
 
 
 
       D? ? ? ?B= = = =@ %)J J J J Jb %)     B %)B B B B BR %)     :
9 
9 
9 
9 
9< < < <:   0? ? ? ?55 55 55 55n          &   $I I I I
I I I I
: : : :/< /< /< /< /<b? ? ? ?E E E E= = = =
= = = =L !    . T  T  T  TD	: 	: 	: 	:
6 
6 
6 
67 7 7 7 7 7r   r   r  r   r  r  r   r!  c                V    |t          |           S d}|D ]}|t          k    r|dz  }|S )Nr   r   )r?  r	   )r  r  r  r  s       r   r  r  	  s@    :G  7??qLGNr   N)r  r   r  r  r   r!  )ra  
__future__r   collections.abcr   typingr   r   r   mypy.argmapr   
mypy.nodesr	   r
   r   r   mypy.operatorsr   r   
mypy.typesr   r   mypyc.commonr   r   r   r   r   r   r   mypyc.errorsr   mypyc.ir.class_irr   r   mypyc.ir.func_irr   r   mypyc.ir.opsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   mypyc.ir.rtypesrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   mypyc.irbuild.utilrz   mypyc.optionsr{   mypyc.primitives.bytes_opsr|   mypyc.primitives.dict_opsr}   r~   r   r   mypyc.primitives.exc_opsr   r   mypyc.primitives.float_opsr   r   mypyc.primitives.generic_opsr   r   r   r   r   r   r   r   mypyc.primitives.int_opsr   r   r   r   r   r   r   r   r   r   r   r   r   mypyc.primitives.list_opsr   r   r   r   mypyc.primitives.misc_opsr   r   r   r   r   r   r   mypyc.primitives.registryr   r   r   r   r   mypyc.primitives.set_opsr   mypyc.primitives.str_opsr   r   r   mypyc.primitives.tuple_opsr   r   r   mypyc.rt_subtyper   mypyc.sametyper   mypyc.subtyper   r  	DictEntryr  r   __annotations__r   r   r   r  r-  r   r   <module>r     s     # " " " " " $ $ $ $ $ $ , , , , , , , , , , . . . . . . < < < < < < < < < < < < 7 7 7 7 7 7 7 7 ) ) ) ) ) ) ) )                         ; ; ; ; ; ; ; ; 4 4 4 4 4 4 4 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .^0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0b 1 0 0 0 0 0 ) ) ) ) ) ) 4 4 4 4 4 4            J I I I I I I I C C C C C C C C	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                              ] \ \ \ \ \ \ \ \ \ \ \                               0 / / / / / \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ / / / / / / ' ' ' ' ' ' $ $ $ $ $ $(5/5()	 %' ! )*ma.?!.C(D  D D D D% % %     0 ]\\ \ \ \ \]"7 ]"7 ]"7 ]"7 ]"7 ]"7 ]"7 ]"7@E     r   