
    J/Ph!                         d dl mZmZ d dl Zd dlmZmZmZ  G d de          Z	 G d de          Z
 G d d	e          ZdS )
    )Constant	IRBuilderN)typesconfigcgutilsc                   $    e Zd ZdZd Zd Zd ZdS )_ArgManagerzA
    A utility class to handle argument unboxing and cleanup
    c                 h    || _         || _        || _        || _        d| _        g | _        || _        d S )Nr   )contextbuilderapienv_manager	arg_countcleanupsnextblk)selfr   r   r   r   endblknargss          V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/callwrapper.py__init__z_ArgManager.__init__   s8    &    c                 b     j                             |          t          j         j        j                  5   j                             j                   ddd           n# 1 swxY w Y    fd} j        	                    |            j        
                    d j        z            } j                            |          5   |              j                             j                   ddd           n# 1 swxY w Y   | _         xj        dz  c_        j        S )ak  
        Unbox argument and emit code that handles any error during unboxing.
        Args are cleaned up in reverse order of the parameter list, and
        cleanup begins as soon as unboxing of any argument fails. E.g. failure
        on arg2 will result in control flow going through:

            arg2.err -> arg1.err -> arg0.err -> arg.end (returns)
        Nc                      j                              j        j                    j                                          j        j        r-j        j                            j	         j                   d S d S N)
r   reflect_native_valuevaluer   cleanupr   
enable_nrtnrtdecrefr   )nativer   tys   r   cleanup_argz(_ArgManager.add_arg.<locals>.cleanup_arg&   s    H))"flD<LMMM ~)   
 |& H ''b&,GGGGGH Hr   z	arg%d.err   )r   to_native_valuer   if_unlikelyr   is_errorbranchr   r   appendappend_basic_blockr   
goto_blockr   )r   objr"   r#   
cleanupblkr!   s   ` `  @r   add_argz_ArgManager.add_arg   s    ))"c22  v?? 	. 	.L---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.	H 	H 	H 	H 	H 	H 	H 	[))) \44$.(* *
\$$Z00 	. 	.KMMML---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 "!|s#    A**A.1A.*DDDc                 .    | j         D ]} |             dS )zR
        Emit the cleanup code after returning from the wrapped function.
        N)r   )r   dtors     r   emit_cleanupz_ArgManager.emit_cleanupB   s,     M 	 	DDFFFF	 	r   N)__name__
__module____qualname____doc__r   r.   r1    r   r   r	   r	      sL           , , ,\    r   r	   c                       e Zd ZdZd Zd ZdS )_GilManagerzY
    A utility class to handle releasing the GIL and then re-acquiring it
    again.
    c                 b    || _         || _        || _        |                                | _        d S r   )r   r   argmansave_threadthread_state)r   r   r   r:   s       r   r   z_GilManager.__init__P   s/    OO--r   c                 v    | j                             | j                   | j                                         d S r   )r   restore_threadr<   r:   r1   )r   s    r   r1   z_GilManager.emit_cleanupV   s5     1222  """""r   N)r2   r3   r4   r5   r   r1   r6   r   r   r8   r8   J   s<         
. . .# # # # #r   r8   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )PyCallWrapperc                 Z    || _         || _        || _        || _        || _        || _        d S r   )r   modulefuncfndescenvrelease_gil)r   r   rB   rC   rD   rE   call_helperrF   s           r   r   zPyCallWrapper.__init__\   s3    	&r   c                    | j         j        }| j                            t          j                  }t          j                            ||||g          }t          j        	                    | j
        ||          }t          |                    d                    }|j        \  }}}d|_        d|_        d|_        | j                            |          }	|                     |	||||           ||	fS )N)nameentry
py_closurepy_argspy_kws)rD   llvm_cpython_wrapper_namer   get_argument_typer   pyobjectllvmliteirFunctionTypeFunctionrB   r   r*   argsrI   get_python_apibuild_wrapper)
r   wrapnamepyobjwraptywrapperr   closurerU   kwsr   s
             r   buildzPyCallWrapper.builde   s    ;8 ..u~>>))%%1FGG+&&t{F&JJG66w??@@ %\s#	l))'223$<<<|r   c                 (   t          | j        j                  }fdt          |          D             } j        || j        j        ||g|R  }|                    d|t          |j        d                     }	t          j
        ||	          5  |                                                               d d d            n# 1 swxY w Y   |                    d          }
|                    |
          5  |                                                               d d d            n# 1 swxY w Y   |                     |          }t!          | j        |||
|          }g }t%          || j        j                  D ]s\  }}t'          |t(          j                  r|                    d            5|                    |                    |          |          }|                    |           t| j        rt5          ||          }| j        j                            || j        | j        j        | j        j        |d          \  }}|                     |d           |                                  |                     |d           |!                    |j"        d	          5  |!                    |j#                  5  $                                 d d d            n# 1 swxY w Y   | %                                }&                    |||          }|                    |           d d d            n# 1 swxY w Y   | j        j        '                    ||           |                                                               d S )
Nc                 8    g | ]}                                 S r6   )
alloca_obj).0_r   s     r   
<listcomp>z/PyCallWrapper.build_wrapper.<locals>.<listcomp>   s#    777Q  777r   z==zarg.end)noinline)attrsz# callwrapper: emit_cleanupz# callwrapper: emit_cleanup endT)likely)(lenrD   argtypesrangeunpack_tuplequalnameicmp_unsignedr   typer   r&   retget_null_objectr*   r+   get_envr	   r   zip
isinstancer   Omittedr)   r.   loadrF   r8   	call_convcall_functionrC   restypedebug_printr1   if_thenis_okis_nonereturn_none_simplified_return_typefrom_native_returnraise_error)r   r   r   r\   rU   r]   r   objsparseokpredr   r   cleanup_manager	innerargsr,   r"   valstatusretvalrettys    `                  r   rW   zPyCallWrapper.build_wrapper~   sy   DK())7777%,,777"#"4)=#(%8268 8 8 $$W\4((* *  $// 	/ 	/KK++--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ ++I66'' 	/ 	/KK++--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ ll300%dlGS&165B B 	4!566 	& 	&GC"em,, &  &&&&%--gll3.?.?DD  %%%% 	I)'3HHO /==TY 3T[5I] > , , 	"?@@@$$&&&"CDDD __V\$_77 	 	00 " "!!!" " " " " " " " " " " " " " " 0022E((DDCKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	**7C@@@C''))*****s[   (CCC9(D--D14D1,L?K(L?(K,	,L?/K,	0AL??MMc                 `   | j                             | j                  }| j                             |j        |          }|                    |          }| j                             ||          }|                    |d| j        j                   |	                    | j
        ||          }|S )zpGet the Environment object which is declared as a global
        in the module of the wrapped function.
        T)return_pyobject	debug_msg)r   get_env_namerD   declare_env_globalrB   ru   get_env_bodyemit_environment_sentryenv_nameget_env_managerrE   )r   r   r   envnamegvptrenvptrenv_bodyr   s           r   rq   zPyCallWrapper.get_env   s     ,++DK88//HHe$$<,,Wf==##FD.2k.B 	$ 	D 	D 	D))$(HfEEr   c                 `    | j         j        }t          |t          j                  r|j        S |S )z
        The NPM callconv has already converted simplified optional types.
        We can simply use the value type from it.
        )rD   rx   rs   r   Optionalrn   )r   rx   s     r   r~   z%PyCallWrapper._simplified_return_type   s/    
 +%gu~.. 	<Nr   c                 ~    t           j        r0| j                            |d                    |                     d S d S )NzDEBUGJIT: {0})r   	DEBUG_JITr   ry   format)r   r   msgs      r   ry   zPyCallWrapper.debug_print   sF     	KL$$Wo.D.DS.I.IJJJJJ	K 	Kr   N)	r2   r3   r4   r   r^   rW   rq   r~   ry   r6   r   r   r@   r@   [   sw        ' ' '  2E+ E+ E+N  
 
 
K K K K Kr   r@   )llvmlite.irr   r   rQ   
numba.corer   r   r   objectr	   r8   r@   r6   r   r   <module>r      s    + + + + + + + +     - - - - - - - - - -@ @ @ @ @& @ @ @F# # # # #& # # #"GK GK GK GK GKF GK GK GK GK GKr   