
    5 ft                   B   U d Z ddlmZ ddlmZmZ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 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 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/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mZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ ee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 )4a  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 IR level and not the AST
level---it has *no knowledge* of mypy types or expressions.
    )annotations)CallableFinalOptionalSequenceTuple)map_actuals_to_formals)ARG_POSARG_STAR	ARG_STAR2ArgKind)
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use_method_vectorcalluse_vectorcall)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RaiseStandardErrorRegisterSetMemTruncateTupleGetTupleSetUnboxUnreachableValuefloat_comparison_op_to_idfloat_op_to_idint_op_to_id)0PyListObjectPyObjectPySetObjectPyVarObject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_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)Mapper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_comparison_op_mappingint_to_int32_opint_to_int64_opssize_t_to_int_opuint8_overflow)list_build_oplist_extend_opnew_list_op)bool_opfast_isinstance_opnone_object_op)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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dd)dd/Z	 ddd)dd1Zdd2Zdd3Zdd4Zdd5Zdd6dd;Zdd>Zdd?ZddBZddCZddEZddHZddNZ	 	 dddVZ	 	 dddXZddYZdd[Z dd\Z!dOd]ddeZ"dOd]ddhZ#	 	 	 dddmZ$ddpZ%ddqZ&ddrZ'ddsZ(ddtZ)ddvZ*ddxZ+d dyZ,dd{Z-dd}Z.dOe/d~dOfddZ0ddZ1ddZ2ddZ3ddZ4dddZ5d	dZ6d
dZ7d	dZ8d	dZ9dd	dZ: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ZCddddZDddZEddZFddZG	 dddZH	 	 dddZIdddZJd	dZKddZLddZMddZNddZOddZPddZQd dńZRd!dƄZSddǄZTdd"dɄZUd#d˄ZVdd̄ZWd$d΄ZXd%dфZY	 dd&dӄZZd'dԄZ[d(dՄZ\d)dׄZ]d*dلZ^dOS (+  LowLevelIRBuildercurrent_modulestrerrorsr   mapperr{   optionsr~   returnNonec                x    || _         || _        || _        || _        g | _        g | _        d g| _        g | _        d S N)r   r   r   r   argsblockserror_handlerskeep_alives)selfr   r   r   r   s        N/var/www/equiseq/venv/lib/python3.11/site-packages/mypyc/irbuild/ll_builder.py__init__zLowLevelIRBuilder.__init__   sI     -$&	(*8<v )+    module_name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>   rG   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-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   r4   )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   r7   )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   r7   copyr  s    r   flush_keep_alivesz#LowLevelIRBuilder.flush_keep_alives  sN     	"HHYt/446677888!D	" 	"r   srcc                   |j         j        r|t          |t                    rEt	          |j                   r1|                     t          |j        dz	  t                              S |                     t          |                    S |S )Nr   rtype)
type
is_unboxed
isinstancer5   rp   r   r:   valuerv   r'   )r   r  s     r   boxzLowLevelIRBuilder.box$  sw    8 	#w'' VIch,?,? VxxCINBS T T TUUU88CHH%%%Jr   
can_borrowtarget_typerS   lineintr  c                   |j         r$|                     t          |||                    S |r| j                            |           |                     t          ||||                    S )Nborrow)r  r   rE   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  r5   rn   re   numeric_valuer]   errorr  rj   coerce_int_to_fixed_widthcoerce_fixed_width_to_intcoerce_short_int_to_fixed_widthrQ   is_native_intsize	is_signedrb   ra   rp   int_oprW   r6   
LEFT_SHIFTr   r-   rf   r.   floatint_to_floatrR   lentypesrangerD   itemsr@   rC   r   zipr  r   r$   )r   r  r  r  r   r  src_typer  shiftedr   ir*  itemtmps   `  `          r   r(  zLowLevelIRBuilder.coerce6  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#  ))re   r  rQ   r@   r&   check_tagged_short_intr   r(   BOOLr   r3  r`   r4  r,   r5   r  SLTSGEr5  r[   r6   RIGHT_SHIFTrB   r-   r$   r   ri   rh   rx   XORrZ   r   r   call_cr7   r   rF   rg   r   rr   r   )r   r  r  r  resfastslowendcheckr3  fast2fast3upper_boundcheck2lower_boundcheck3rB  ptrptr2conv_ops                       r   r/  z+LowLevelIRBuilder.coerce_int_to_fixed_width  s   #K0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[]]####%+%%5C   
r   c                    t          |          r1|                     ||t          d|          t          j        |          S J |j        |f            Nr   )ri   r5  r5   r6   rH  r  )r   r  r  r  s       r   r1  z1LowLevelIRBuilder.coerce_short_int_to_fixed_width  sO    {++ 	c;;{CK1H1H%J[]abbb-sx---ur   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      )#rh   r  r   rg   rr   r   r-   r[   r4  r5  r`   r5   r6   r6  re   r  rQ   r@   r&   r,   r   SLEr(   rE  r   r   rG  ri   r   r   rJ  r$   r   r3  rB   )r   r  r  extendedr>  rK  rL  rP  rM  rN  c1c2rX  xrB  ss                   r   r0  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"(""5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   r9   r   )
r   r  r  r  r   validinvalidoutcoercedr.  s
             r   coerce_nullablez!LowLevelIRBuilder.coerce_nullable0  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  rP   class_iris_ext_classhas_attrr2   is_borrowedr   r   r   rT   union_get_attrpy_get_attr)r   rj  rk  rl  r  r  r   s          r   get_attrzLowLevelIRBuilder.get_attrK  s    
 sx++	5!.	5 !**400	5
 dD888B ~ - '',,,88B<<&)) 	5&&sCHdKNNN##Ct444r   r  rT   c                N     d fd}                      |||          S )z0Get an attribute of an object with a union type.r  rG   r   c                4                         |           S r   )rt  )r  rk  r  rl  r   s    r   get_item_attrz7LowLevelIRBuilder.union_get_attr.<locals>.get_item_attrd  s    ==k4@@@r   r  rG   r   rG   )decompose_union_helper)r   rj  r  rk  rl  r  rw  s   `  ``` r   rr  z LowLevelIRBuilder.union_get_attr_  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.
        )load_strrJ  r   )r   rj  rk  r  keys        r   rs  zLowLevelIRBuilder.py_get_attri  s/    
 mmD!!{{=3*d;;;r   	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   rG   c                 2                                    S r   )isinstance_native)rn  r  rj  r   s   r   otherz2LowLevelIRBuilder.isinstance_helper.<locals>.otherz  s    --c8TBBBr   orc                      S r   r'  rets   r   <lambda>z5LowLevelIRBuilder.isinstance_helper.<locals>.<lambda>}      # r   r   rG   )falser  shortcircuit_helperrW   )r   rj  r}  r  r  rn  r  s   `` ` @@r   isinstance_helperz#LowLevelIRBuilder.isinstance_helpers  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   r3   rL   r;   rv   r7   )r   rj  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   rj  r  r  typs        r   
type_is_opzLowLevelIRBuilder.type_is_op  s9    ""3--xxS(LOTJJKKKr   rn  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   rG   c                 X                                                                  S r   )r  get_native_type)cr  rj  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   r9  r   rJ  r   r  r  r  r  rW   )	r   rj  rn  r  concreter  r  r  r  s	   `` `   @@r   r  z#LowLevelIRBuilder.isinstance_native  s    (11s8}}/MPQ/QQQ;;1C9M9Mh9W9W3XZ^___ 	 ::<<''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|                     t4          |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   rl  r  __setitem__)r   r   rJ  r   r   _create_dictr   is_optionalis_positionalis_namedr   r{  r&   r@   rW   r   r$   r  r(   rd  r   rE  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_regrg  skipkeep	pos_blocknamed_blocks                           r   _construct_varargsz$LowLevelIRBuilder._construct_varargs  s   P %)%)
 $&"$
$&*.!% Z	4 Z	4E4x&"&"2"2;"E"EKN[%,@$GGGG""'#'#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>>> 	N ""nn[$??"kk-+MM 	M-,,ZtLLLL((r   Nfunction
arg_values	arg_kindslist[ArgKind] | None	arg_namesSequence[str | None] | Nonec           	        t          | j        j                  r|                     |||||          }||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>u  &      #J#JDGO#J#J#J#J#J#Jr   Tr  r  )r   r   capi_version_py_vector_callallrJ  r   r  listr=  r   )	r   r  r  r  r  r  resultpos_args_tuplekw_args_dicts	            r   py_callzLowLevelIRBuilder.py_callb  s     $,344 	))(JiQZ[[F! #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(  rv   r)  argr  r   s     r   r,  z5LowLevelIRBuilder._py_vector_call.<locals>.<listcomp>  s*    ```cC1BD I I```r   T
object_ptrr   )r  setup_rarrayrv   r5   ru   num_positional_args_vectorcall_keywordsrJ  r   r\   r   r7   )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   r,  z:LowLevelIRBuilder._vectorcall_keywords.<locals>.<listcomp>  s    FFFT5Et5E5E5Er   r   )r   r:   tuplerv   r5   )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                t   t          | j        j                  r|                     ||||||          }||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  )
r   r   r  _py_vector_method_callr  r{  rJ  r   rs  r  )
r   rj  r  r  r  r  r  r  method_name_regmethods
             r   py_method_callz LowLevelIRBuilder.py_method_call  s     !!:;; 	00[*dIy F !#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   r,  z<LowLevelIRBuilder._py_vector_method_call.<locals>.<listcomp>  s7       >AC!2D99  r   Tr  r   )r  r{  r  rv   r  r  rJ  r   r5   r   r\   r   r7   )r   rj  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   r,  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>%      666c666r   c                    g | ]	}|j         
S r'  )r  r   s     r   r,  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>&  r  r   c                ,    g | ]}t          |          S r'  r|   )r)  arg_kinds     r   r,  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)  r@  r  r  r   s     r   r,  z?LowLevelIRBuilder.native_args_to_positional.<locals>.<listcomp>6  s-    (\(\(\ST$q'9Q<1)N(\(\(\r   r  r           T)rq  r   )r   num_bitmap_argsr	   r=  r  r  extendr   r   r  re   r  r5   rf   r.   r   r9   r  ri  r(  r   reversedr;  r9  error_overlapr   rV   )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_argr@  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##x%

Y&&   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	           
     N   |8t          d |D                       r|                     ||||j        ||          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>y  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   r,  z5LowLevelIRBuilder.gen_method_call.<locals>.<listcomp>  s     = = =Q = = =r   c                    g | ]}d S r   r'  r!  s     r   r,  z5LowLevelIRBuilder.gen_method_call.<locals>.<listcomp>  s     : : :! : : :r   z&arg_kinds present but arg_names is notr  r  )anyr  r  r  r  rP   rn  ro  builtin_base
has_methodmethod_decl	bound_sigr  r   r=   rp  r2   r  rT   union_method_callr
   r9  r  )r   r  r  r  rl  r  r  r  r  r  r  r   s               r   gen_method_callz!LowLevelIRBuilder.gen_method_calll  s{     S(N(NI(N(N(N%N%N &&tT:ty)U^___ 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  rG   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   rx  )rv   ry  )
r   r  r+  r  r  r,  r  r  r  r/  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   )r5   rt   r  s    r   nonezLowLevelIRBuilder.none      q/***r   c                ,    t          dt                    S )z0Load unboxed True value (type: bool_rprimitive).r   r5   rW   r  s    r   r  zLowLevelIRBuilder.true  r2  r   c                ,    t          dt                    S )z1Load unboxed False value (type: bool_rprimitive).r   r4  r  s    r   r  zLowLevelIRBuilder.false  r2  r   c                t    |                      t          t          j        t          j        d                    S )z1Load Python None value (type: object_rprimitive).r   r  )r   r8   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   r:   r`   r5   r   r  s     r   load_intzLowLevelIRBuilder.load_int  sA    (((E4I,I,I88K~>>???5>>!r   r7  c                     t          |          S )zLoad a float literal value.)r.   r9  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   r:   rz   r9  s     r   r{  zLowLevelIRBuilder.load_str  s      xxE>::;;;r   bytesc                R    |                      t          |t                              S )zLoad a bytes literal value.)r   r:   rX   r9  s     r   
load_byteszLowLevelIRBuilder.load_bytes  s    xxE+;<<===r   complexc                R    |                      t          |t                              S )zLoad a complex literal value.)r   r:   rv   r9  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(   rd  r   r?   
NAME_ERRORrF   )
r   r  rD  r   rF  r  rG  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)rF  )r   r<   rv   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   rQ  fullnames      r   r  z!LowLevelIRBuilder.get_native_type  s-    o2222++H555r   rU  c                    |                     dd          \  }}|                     t          t          ||t                              S )NrS  r   )rsplitr   r<   rv   r#   )r   rU  moduler  s       r   rT  z)LowLevelIRBuilder.load_native_type_object  s:    sA..xx
#4dFNSSTTTr   lregrregc           	     2   |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          |          r0t          |          r!|t          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          r
|dd         }|dk    rt0          |         }nt2          j        }t          |          st7          |          r|                     |||          }|}t+          |          st          |          r|                     |||||          S t          |t<                    r.|                     |||                     |||          ||          S n|t          j        v rt?          |          r|                      |||          }n5t          |          st7          |          r|                     |||          }t          j        |         }t+          |j                   r| !                    ||||          S t          |t<                    r-| !                    ||                     |||          ||          S nt+          |          r|t,          v r|                    d          r
|dd         }|dk    rt0          |         }nt2          j        }t          |t<                    r.|                     ||                     |||          |||          S t          |          r|                     |||||          S t          |          st7          |          r0|                     |||          }|                     |||||          S n|t          j        v rt?          |          r|                      |||          }n5t          |          st7          |          r|                     |||          }t          j        |         }t          |t<                    r-| !                    |                     |||          |||          S t+          |j                   r| !                    ||||          S |dv rt          j        |         }t          |          rDtE          ||          r4|                     |tF          |          }| !                    ||||          S t          |          rDtE          ||          r4|                     |tF          |          }| !                    ||||          S n||cxv r	t          v rn nt          |          rDtE          ||          r4|                     |tH          |          }|                     ||||          S t          |          rDtE          ||          r4|                     |tH          |          }|                     ||||          S tK          |          stK          |          rtt          |t<                    r/tM          tO          |(                                                    }nt          |t<                    r/tM          tO          |(                                                    }nUt?          |j                   r| )                    ||          }n*t?          |j                   r| )                    ||          }tK          |j                   rtK          |j                   ro|tT          v r#| +                    ||tT          |         |          S |                    d          r|dd         }	n|}	|	tX          v r| -                    |||	|          S t]          j/        |g           }
| 0                    |
||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)1r  r  rR   compare_tuplestranslate_eq_cmptranslate_is_opro   compare_stringsrc   compare_bytesrp   r   compare_taggedrb   r   r,   
signed_opsbool_comparison_opbool_bitwise_oprP   translate_instance_containsre   r   endswithrJ   r6   DIVra   r(  fixed_width_int_opr5   rj   r/  comparison_opr   r`   ry   rf   r.   r7  r-  r8  rH   compare_floatsrI   float_opr   getmatching_call_c)r   rY  rZ  r   r  ltyper  r  op_idbase_opcall_c_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;;;U 	=	% 0 0 	=R;T5T5T&&tT2t<<<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&& 5	G///;;s## !CRCB::(,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## !CRCB::(,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  +B/E CJue$<$< C{{4>>))$eTBBB CJue$<$< C{{4>>))$eTBBB22222222222 AJue$<$< A{{4)=tDD**4r4@@@ AJue$<$< A{{4)=tDD**4r4@@@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 *r2 6 6%%&;dD\4PP>>9B>>>vr   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   )	r5   r[   r5  r6   ANDr,   NEQr  ro  )	r   ry  r  rz  int_tagbitwise_andzeror   rO  s	            r   rD  z(LowLevelIRBuilder.check_tagged_short_int  sw    
 !3T::kk"8#w	SWXXq0$77!(=\lo"";b$??r   lhsrhsc                @   t          |j                  r=t          |j                  r)|                     ||t          |         d         |          S t          |         \  }}}}t	          t
                    }	t                      t                      t                      }}}
|                     ||          }|dv r|}n>|                     ||          }|                     t          ||t          j        |          }|                     t          ||
|t          j                             |                     |
           |                     ||||          }|                     t!          |	||                     |                     |           |                     |           |r||g}n||g}|                     |||          }|r|                     |d|          }n|}|                     t!          |	||                     |                     |           |	S )zACompare two tagged integers using given operator (value context).r   r\  not)rn   r  ro  r   r@   rW   r&   rD  r5  rU   r6   r|  r   r(   rE  r   r$   r   rJ  unary_opr   )r   r  r  r   r  op_typec_func_descnegate_resultswap_opr  short_int_block	int_blockrg  	check_lhsrO  	check_rhseqr   r  call_results                       r   rg  z LowLevelIRBuilder.compare_tagged  s     #38,, 	X1H1R1R 	X%%c30I"0Ma0PRVWWW7PQS7T4mW/***4,,
jllC//T::	EE 33C>>IKK	9eiQUVVE	6;GGHHHO,,,S'488D))***		#I&&& 	:DD:D{{;d33 	--eT::KKKT22333s###r   r  r  c                8   |dv }t          |j                  rt          |j                  s*|rt          |j                  st          |j                  rn|                     ||t          |         d         |          }|                                  |                     t          |||t          j                             dS t          |         \  }	}
}}t                      t                      }}| 	                    ||d          }|st          |j                  rD|                                  |                     t          |||t          j                             nt                      }|                     t          |||t          j                             | 
                    |           | 	                    ||d          }|                                  |                     t          |||t          j                             | 
                    |           |r||g}n||g}|                     |
||          }|r0|                     t          |||t          j                             nC|                                  |                     t          |||t          j                             | 
                    |           |                     |||	|          }|                     t          |||t          j                             dS )a~  Compare two tagged integers using given operator (conditional context).

        Assume lhs and rhs are tagged integers.

        Args:
            lhs: Left operand
            rhs: Right operand
            op: Operation, one of '==', '!=', '<', '<=', '>', '<='
            true: Branch target if comparison is true
            false: Branch target if comparison is false
        r\  r   NT)rz  )rn   r  ro  r   r  r   r(   rE  r&   rD  r   rJ  )r   r  r  r   r  r  r  is_eqrO  r  r  r  r  r  r  r  	rhs_blockr  r   r  r  s                        r   compare_tagged_conditionz*LowLevelIRBuilder.compare_tagged_condition  s    l"#CH-- 	2I#(2S2S 		.sx88	<STWT\<]<]	 &&sC1J21Nq1QSWXXE""$$$HHVE4<<===F7PQS7T4mW%/\\:<<?	//T4/HH	 
	Q+CH55 
	Q""$$$HHVIy/6;OOPPPP #IHHVIy)V[IIJJJ	***33Ct3LLI""$$$HHVIy/6;OOPPPI&&& 	:DD:D{{;d33 	=HHVD%v{;;<<<<""$$$HHVD$v{;;<<<O,,,S'488D%5566666r   c           	     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   )rJ  r   r5   rY   r   r,   r  r&   r(   rE  rz  r   r   rx   r}  r   r   )r   r  r  r   r  compare_resulterror_constantcompare_error_checkexception_check	propagatefinal_comparebranchcheck_error_resultnullr  s                  r   re  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   )rJ  r   r,   r  r}  r   r5   rY   )r   r  r  r   r  r  r  s          r   rf  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   r,  z4LowLevelIRBuilder.compare_tuples.<locals>.<listcomp>"  s    <<<
<<<r   c           	     X    g | ]&}                     t          |                    'S r'  r   rC   )r)  r@  r  r  r   s     r   r,  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)  r@  r  r  r   s     r   r,  z4LowLevelIRBuilder.compare_tuples.<locals>.<listcomp>$  r  r   r   )r  r  rR   r@   rW   r9  r:  r   r$   r  r  r&   r;  r   rx  rb   rJ  r   r(   rE  rz  r   r   )r   r  r  r   r  equalr  lengthfalse_assigntrue_assignrg  check_blocks	lhs_items	rhs_items
early_stopfinalr@  lhs_itemrhs_itemcomparer  s   ``` `                r   rb  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 @++gy$??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   instrA  c                    |                      |d|gd |          }t          |j                  s|                     t          |g|          }|dk    r,|                     |t          dt                    d|          }|S )N__contains__r`  r   r  r   )r*  rb   r  rJ  r   rj  r5   rW   )r   r  rA  r   r  rK  s         r   rk  z-LowLevelIRBuilder.translate_instance_containsD  s}    ""4$tLL!#(++ 	4++gud33C>>&&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   )r6   r|  ORrI  r   rW   )r   rY  rZ  r   r  codes         r   rj  z!LowLevelIRBuilder.bool_bitwise_opL  sg    999DD3YY8DD3YY9DD"5xxotT4FFGGGr   c                V    t           j        |         }|                     ||||          S r   )r,   rh  ro  )r   rY  rZ  r   r  ru  s         r   ri  z$LowLevelIRBuilder.bool_comparison_opW  s)    '+!!$eT:::r   c                ~    t          d|j        |          }|                     |j        ||t          j        |          S rZ  )r5   r  r5  r6   rI  )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*                    rR|dk    rd	}n|dk    rd
}n|dk    rd}nd}|r3|j                            |          r|                     ||g d |          S t3          j        |g           }|                     ||g|          }	|	sJ d|z              |	S )Nr  r   r   r   ~r   r   r   __neg____pos__
__invert__ zUnsupported unary operation: %s)r  rb   ra   r  re   r5  r5   r6   SUBr4  rI  r3  rf   r   r0   r  r  rn   r  rp   r.   rP   rn  r&  r*  r   rr  rs  )
r   r  r  r  r  r  numr  rw  r   s
             r   r  zLowLevelIRBuilder.unary_op_  s   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%% 
	K#~~"C"C% K#,11&99 K++E62tTJJJ )gr : :%%&;eWdKKBB87BBBv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  rJ  r   )r   r  r  r  keysr   r|  r  s           r   	make_dictzLowLevelIRBuilder.make_dict  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
        )rJ  r   r   r  r  s      r   new_list_op_with_lengthz)LowLevelIRBuilder.new_list_op_with_length  s     {{;$777r   c           
     `    t          t          |          t                    g}t          |          t          k    r                     t
          ||z             S                      t          |          }|s|S  fd|D             }                     t          |t          d                    }                     t          t          |                    }t          t          |                    D ]}|dk    r|}	nSt          t          |z  t                    }
                     t          t          ||
t          j                            }	                     t!          t"          |	||                                                   t%          |g                     |S )Nc                H    g | ]}                     |t                    S r'  r  )r)  rA  r  r   s     r   r,  z1LowLevelIRBuilder.new_list_op.<locals>.<listcomp>  s*    NNNtD"3T::NNNr   ob_itemr   )r5   r9  r[   !LIST_BUILDING_EXPANSION_THRESHOLDrJ  r   r   r   r3   rK   r;   rx   r;  r   r6   ADDrA   rv   r7   )r   r   r  r  result_listr   ob_item_ptrob_item_baser@  item_addressoffsets   ` `        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hh}[,	SWXXYYxx(:K N NOOs6{{## 	M 	MAAvv+ !24JDQQ#xx,lFEItTT    HHV-|T!WdKKLLLLK=))***r   c                :    |                      t          ||          S r   )rJ  r   )r   r   r  s      r   r   zLowLevelIRBuilder.new_set_op  s    {{:vt444r   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@   rO   r9  r   r%   r  r8   ru   rZ   )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)/rb   r  ra   r   r`   r5   ry   ro  r,   r}  r  re   r   r   rz   rJ  r   rs   r^   builtin_lenrx  r  rP   rn  ro  r&  r*  rW   rf   rp  r.   r/   rw   rd  r7  is_method_finalr@   rU   r&   r(   rE  r   r  
bool_valuer$   r   r   )r   r  r  r  r  
value_typenot_nonealways_truthyr  r  rN  r  	remainingas_bools                 r   r  zLowLevelIRBuilder.bool_value  s   
 ej)) 9	C->uz-J-J 9	CFF
N;; 7	C1233D''t\5EuzRRFF!%*-- 4	C1ej))DXXl5$8HIIJJFF%*n55 1	C[[!2UGUZHHFF%*o66 /	C,J;
 ;
 /	C %%eUZ88F1::D^^FD$
CCFFuz9--)	C
#0)	C 
#..z::)	C ))%RRWR\]]FF ,, "	C((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'',,,,WuguzBB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)rw   r  r  r   r(   rE  rd  r7  r  r  rP   rn  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_branchH  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        r;D ]8}t'          |t          t(          f          s| j                            |           9|j
        t          k    rQt-          |t          d|j        |          t,          j        |          }t0          |_
        |                     |           |j        |}n*|                     t5          ||j                            }|}|rWt7          |j        |          sBt;          |          r|                                 }n|                     ||||j                  }|S )zHCall function using C/native calling convention (not a Python callable).Nc                     g | ]
}|         S r'  r'  )r)  r@  rh  s     r   r,  z,LowLevelIRBuilder.call_c.<locals>.<listcomp>v  s    999awqz999r   r   r   r  )r;  minr9  	arg_typesr(  r   orderingvar_arg_typeextra_int_constantsr5   
error_kindr   r    r   r*   c_function_namereturn_typestealsrq  r  r:   r   r,   rG  r   truncated_typerB   r   r  rl   r1  )r   r  r   r  rl  r@  formal_typer  var_arg_idxrA  ry  r  extra_int_constantr  r   compr  truncaterh  s                     @r   rJ  zLowLevelIRBuilder.call_cc  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>  sC        4BFF
6;//     r   zAmbiguous:
1) {}
2) {})r9  r  r  r=  rq  priorityformatrJ  )	r   r	  r   r  rl  r  matchingr  r   s	            r   rs  z!LowLevelIRBuilder.matching_call_c  s    15 	$ 	$D4>""c$ii//  FI$PTP^F_F_     
$'
$+5
$  $#,===?Y?`?` $@ @=== }x'888#'#H 	[[4{CCFM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   r6   )r   r  r  r  r   r  s         r   r5  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	  TrI  zfloat division by zerozfloat modulo)rI   r1   rm  MODr  r.   r  rp  r/   r  r&   r   r(   rE  r   r?   ZERO_DIVISION_ERRORrF   	float_mod)
r   r  r  r   r  ru  r  errokmsgs
             r   rq  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   r1   r  r@   r_   r$   r&   r/   r.   r  r(   rE  r   is_same_float_signsrq  r4   rJ  r   )r   r  r  r  modrK  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%%% kk+c

C'8$??S!!"""dD!!!
r   c                L    |                      t          ||||                    S r   )r   r/   r   r  r  r   r  s        r   rp  z LowLevelIRBuilder.compare_floats  s#    xx)#sB==>>>r   rQ   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(  r6   rm  r  r5   r  r4  r5  inline_fixed_width_divideri   r   rh   r   rg   r   rr   check_for_zero_divisionrJ  r  inline_fixed_width_modr   r   r   )r   r  r  r  r   r  prims          r   rn  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""u;;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""u;;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&   rx  r5   r   r(   rE  r   r?   r  rF   )r   r  r  r  r  r  r!  s          r   r(  z)LowLevelIRBuilder.check_for_zero_divisionE  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 rZ  )r@   r5  r6   rm  r   r$   is_same_native_int_signsr&   r(   rE  r   MULr,   r  r5   r  r4   )r   r  r  r  r  rK  divr"  r  r  r   mulmul_eqr#  s                 r   r'  z+LowLevelIRBuilder.inline_fixed_width_divideR  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@   r5  r6   r  r   r$   r-  r&   r(   rE  r   r,   r5   r  r  r4   )r   r  r  r  r  rK  r  r"  r  r  r   r!  r#  s                r   r)  z(LowLevelIRBuilder.inline_fixed_width_mode  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 r3  )r   r,   r5   rF  r  )r   r  r4  r5  r  neg1neg2s          r   r-  z*LowLevelIRBuilder.is_same_native_int_signsw  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   r4  r5  r  r7  r8  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   ro  zLowLevelIRBuilder.comparison_op  s"    xxS#r488999r   use_pyssize_tc                4   |j         }d}t          |          st          |          st          |          ru|                     t          |t          d                    }|                     t          t          |                    }|                     t          |g                     nt          |          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 t-          |t.                    r|rJ |                     |dg t2          |          }|                     |t2          |          }t7                      t7                      }
}	|                     |t#          d          d|	|
|           |                     |
           |                     t=          t<          j        d|                     |                     tA                                 |                     |	           |S |r|                     tB          |g|          S |                     tD          |g|          S )	zGenerate len(val).

        Return short_int_rprimitive by default.
        Return c_pyssize_t if use_pyssize_t is true (unshifted).
        Nob_sizeusedr   __len__r   r   z__len__() should return >= 0)#r  rk   rq   rc   r   r3   rN   r;   r[   r7   rm   rM   rd   rJ  r   ro   r   r5   r5  ry   r6   r6  r  rP   r*  r`   r(  r&   r  r   r?   VALUE_ERRORrF   r   r   )r   ry  r  r<  r  
size_valueelem_addressr  r  r  fails              r   r  zLowLevelIRBuilder.builtin_len  s    h
c"" 	G&9#&>&> 	GBUVYBZBZ 	G88M#{I$N$NOOL'*@,"O"OPPJHHYu%%&&&&s## 	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))&'!**dBdSSS%%%HH"&24RTX   
 HH[]]######M  	<;;5udCCC;;~ud;;;r   r<  c                    t          t          |          t                    }|                     t          |g|z   |          S r   )r5   r9  r[   rJ  r   )r   r<  r  r3  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
        )rJ  r   r  s      r   new_tuple_with_lengthz'LowLevelIRBuilder.new_tuple_with_length  s     {{3fXtDDDr   r  c                <    |                      t          |g|          S r   )rJ  r   )r   r  r  s      r   r8  zLowLevelIRBuilder.int_to_float  s    {{?QC666r   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   )r<  r  rP   r   r&   r@   	enumerater9  r  rn  r  r   r(  r   r$   r   rv   )r   rj  r  rl  rI  r  
fast_items
rest_itemsrA  
exit_blockr  r@  
more_typesr   
true_blockfalse_blockrh  temptemp2s                      r   ry  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   rr  rs  )	r   rU  r  r   rl  r  r  rw  	call_c_ops	            r   r  z/LowLevelIRBuilder.translate_special_method_call	  sL    " !0 3D" = =((!H:#4dKT^ ) 
 
	 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  rP   rn  r  inherits_pythonis_augmentedr&  rd  r*  r   )
r   rY  rZ  r  r  rt  r  rn  cmp_varies_at_runtimeidentity_ref_ops
             r   rc  z"LowLevelIRBuilder.translate_eq_cmp#	  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(  rv   r   )r   rY  rZ  r  r  r   r  r  s           r   rd  z!LowLevelIRBuilder.translate_is_opE	  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)  r+  r@  s      r   r,  z2LowLevelIRBuilder._create_dict.<locals>.<listcomp>W	  s%    CCC1CCAQCCCCr   )r9  r5   r[   r  r=  rJ  r   r   )r   r  r   r  r3  rB  r<  s          r   r  zLowLevelIRBuilder._create_dictP	  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                H    | j                             || j        |           d S r   )r   r.  r   )r   r  r  s      r   r.  zLowLevelIRBuilder.error\	  s%    #t/66666r   )
r   r   r   r   r   r{   r   r~   r   r   )r   r   r   r   r   r   )r   r>   r   rG   )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  rG   r   rG   )
r  rG   r  rS   r  r  r  r   r   rG   )F)r  rG   r  rS   r  r  r   r   r  r   r   rG   )r  rG   r  rS   r  r  r   rG   )r  rG   r  r  r   rG   )rj  rG   rk  r   rl  rS   r  r  r  r   r   rG   )rj  rG   r  rT   rk  r   rl  rS   r  r  r   rG   )rj  rG   rk  r   r  r  r   rG   )rj  rG   r}  r~  r  r  r   rG   )rj  rG   r  r  r   rG   )rj  rG   r  rG   r  r  r   rG   )rj  rG   rn  r   r  r  r   rG   )
r   r  r  r  r  r   r  r   r   r  )NN)r  rG   r  r   r  r  r  r  r  r  r   rG   )r  rG   r  r   r  r  r  r  r  r  r   r  )r  r  r   rG   )rj  rG   r  r   r  r   r  r  r  r  r  r  r   rG   )rj  rG   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   rG   )r   r  r  r  r  r  r  r   r  r  r  r  r   r   )NNF)r  rG   r  r   r  r   rl  r  r  r  r  r  r  r  r  r   r   rG   )r  rG   r+  rT   r  r   r  r   r,  r  r  r  r  r  r  r  r   rG   r  )r  r  r   rG   )r  r7  r   rG   )r  r   r   rG   )r  r>  r   rG   )r  rA  r   rG   )r  rS   rD  r   r   rE  rF  r   r  r  rG  rE  r   rG   )r  r   r   rG   )rQ  r   r   rG   )rU  r   r   rG   )
rY  rG   rZ  rG   r   r   r  r  r   rG   )ry  rG   r  r  rz  r   r   rG   )
r  rG   r  rG   r   r   r  r  r   rG   )r  rG   r  rG   r   r   r  r&   r  r&   r  r  r   r   )r   )
r  rG   rA  rG   r   r   r  r  r   rG   )r  rG   r  r  r   rG   )r  rG   r  r   r  r  r   rG   )r  r  r  r  r   rG   )r  rG   r  r  r   rG   )r   r   r  r  r   rG   )r  rS   r   r  r  r   r   rG   )r   r   r  rS   r  r  r  r  r  r  r   rG   rx  )r  rG   r  r&   r  r&   r   r   r   )
r  r   r   r   r  r  rl  r  r   rG   )NF)r	  r
  r   r   r  r  rl  r  r  r   r   r  )r  rS   r  rG   r  rG   r   r  r  r  r   rG   )r  rG   r  rG   r  r  r   rG   )
r  rG   r  rG   r   r  r  r  r   rG   )r  rQ   r  rG   r  rG   r   r  r  r  r   rG   )r  rG   r  rS   r  r  r   r   )
r  rS   r  rG   r  rG   r  r  r   rG   )
r  rS   r4  rG   r5  rG   r  r  r   rG   )r4  rG   r5  rG   r  r  r   rG   )ry  rG   r  r  r<  r   r   rG   )r<  r   r  r  r   rG   )r  rG   r  r  r   rG   )rj  rG   r  rT   rl  rS   rI  rJ  r  r  r   rG   )rU  rG   r  r   r   r   rl  r  r  r  r  r   r   r  )
rY  rG   rZ  rG   r  r   r  r  r   r  )
rY  rG   rZ  rG   r  r   r  r  r   rG   )r  r   r   r   r  r  r   rG   )r  r   r  r  r   r   )___name__
__module____qualname__r   r   r   r   r   r   r  r  r	  r   r  r  r  r(  r/  r1  r0  ri  rt  rr  rs  r  r  r  r  r  r  r  r  r  r  r  r  r*  r)  r1  r  r  r7  r:  r<  r{  r@  rC  r"   rN  rP  r  rT  rx  rD  rg  r  re  rf  rb  rk  rj  ri  r  r  r  r  r   r   r  r  r  r  rJ  rs  r5  rq  r  rp  rn  r(  r'  r)  r-  r  ro  r  r  rG  r8  ry  r  rc  rd  r  r.  r'  r   r   r   r      s       + + + +' ' ' '   # # # #
" " " "# # # #
 @E 1 1 1 1 1 1, , , ,) ) ) )   " " " "    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< < < <      L L L L   2}) }) }) })H +/15c c c c cJ +/15$ $ $ $ $L	- 	- 	- 	-d d d d6' ' ' '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B B B BH
 
 
 
 
! ! ! !F47 47 47 47lc c c c6c c c c
, , , , ,\   	H 	H 	H 	H; ; ; ;E E E E3 3 3 3j   68 8 8 8   65 5 5 5 PU
 
 
 
 
 
       D? ? ? ?B= = = =@ %)I I I I I` %)     8
9 
9 
9 
9 
9< < < <:   0? ? ? ?55 55 55 55n          &   $I I I I
I I I I
: : : :0< 0< 0< 0< 0<d? ? ? ?E E E E7 7 7 7
= = = =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   )r9  r
   )r  r  r  r  s       r   r  r  `	  s@    :G  7??qLGNr   N)r  r   r  r  r   r  )__doc__
__future__r   typingr   r   r   r   r   mypy.argmapr	   
mypy.nodesr
   r   r   r   mypy.operatorsr   
mypy.typesr   r   mypyc.commonr   r   r   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/   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   rJ   mypyc.ir.rtypesrK   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   ry   rz   mypyc.irbuild.mapperr{   mypyc.irbuild.utilr}   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   r   mypyc.primitives.list_opsr   r   r   mypyc.primitives.misc_opsr   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   	DictEntryr  r   __annotations__r   r   r   r  r'  r   r   <module>r     s     # " " " " " = = = = = = = = = = = = = = . . . . . . < < < < < < < < < < < < % % % % % % ) ) ) ) ) ) ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        ; ; ; ; ; ; ; ; 4 4 4 4 4 4 4 4- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1d ( ' ' ' ' ' 0 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	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                                 Q P P P P P P P P P Q Q Q Q Q Q Q Q Q Q              0 / / / / / \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ / / / / / / ' ' ' ' ' ' $ $ $ $ $ $(5/5()	 %' ! )*ma.?!.C(D  D D D D% % %     0 ]\\ \ \ \ \!7 !7 !7 !7 !7 !7 !7 !7DD     r   