
    mi                        U d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZmZ ddlmZ erddlmZ eeeeeef         ZeeeeefZ de!d	<   ddZ"ddZ#dS )ad  Constant folding of IR values.

For example, 3 + 5 can be constant folded into 8.

This is mostly like mypy.constant_fold, but we can bind some additional
NameExpr and MemberExpr references here, since we have more knowledge
about which definitions can be trusted -- we constant fold only references
to other compiled modules in the same compilation unit.
    )annotations)TYPE_CHECKINGFinalUnion)constant_fold_binary_opconstant_fold_unary_op)	BytesExprComplexExpr
Expression	FloatExprIntExpr
MemberExprNameExprOpExprStrExpr	UnaryExprVar)bytes_from_str)	IRBuilderr   CONST_TYPESbuilderr   exprr   returnConstantValue | Nonec                   t          |t                    r|j        S t          |t                    r|j        S t          |t                    r|j        S t          |t
                    rt          |j                  S t          |t                    r|j        S t          |t                    rC|j	        }t          |t                    r%|j        r|j        }t          |t                    r|S nt          |t                    rC|                     |          }|+|\  }}}|j        r|j        }t          |t                    r|S nt          |t                     rEt#          | |j                  }t#          | |j                  }	||	t)          |j        ||	          S nVt          |t,                    rAt#          | |j                  }
|
*t          |
t0                    st3          |j        |
          S dS )zeReturn the constant value of an expression for supported operations.

    Return None otherwise.
    N)
isinstancer   valuer   r   r	   r   r
   r   noder   is_finalfinal_valuer   r   get_final_refr   constant_fold_exprleftright constant_fold_binary_op_extendedopr   r   bytesr   )r   r   r   r    finalfn	final_varnativer#   r$   r   s              s/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/mypyc/irbuild/constant_fold.pyr"   r"   '   s   
 $   z$	"" z$   z$	"" *dj)))$$$ :z	D(	#	# :ydC   	#T] 	#*K+55 #""	D*	%	% :%%d++$)!B	6! ''3kK99 '&&	D&	!	! :!'4955"7DJ77 13DGT5III	D)	$	$ :"7DI66Zu%=%=)$'59994    r&   strr#   ConstantValuer$   c                   t          |t                    s&t          |t                    st          | ||          S | dk    r/t          |t                    rt          |t                    r||z   S | dk    r/t          |t                    rt          |t                    r||z  S | dk    r/t          |t                    rt          |t                    r||z  S dS )zLike mypy's constant_fold_binary_op(), but includes bytes support.

    mypy cannot use constant folded bytes easily so it's simpler to only support them in mypyc.
    +*N)r   r'   r   int)r&   r#   r$   s      r,   r%   r%   P   s     dE"" 8:eU+C+C 8&r4777	SyyZe,,yE51I1Iye|	sz$..:eS3I3Ie|	sz$,,E51I1Ie|4r-   N)r   r   r   r   r   r   )r&   r.   r#   r/   r$   r/   r   r   )$__doc__
__future__r   typingr   r   r   mypy.constant_foldr   r   
mypy.nodesr	   r
   r   r   r   r   r   r   r   r   r   mypyc.irbuild.utilr   mypyc.irbuild.builderr   r3   floatcomplexr.   r'   r/   r   __annotations__r"   r%    r-   r,   <module>r?      st     # " " " " " . . . . . . . . . . N N N N N N N N                          . - - - - - 0////// c5'3565'36 6 6 6 6& & & &R     r-   