
    Ǆg                     x    d dl mZ d dlmZmZ  G d de      Z G d de      Zd ZdZ	d	Z
d
ZdZ G d de      Zy)    )deque)typescgutilsc                   0    e Zd ZdZd Zd ZddZd Zd Zy)	
DataPackerz
    A helper to pack a number of typed arguments into a data structure.
    Omitted arguments (i.e. values with the type `Omitted`) are automatically
    skipped.
    c                    || _         || _        |D cg c]  }|j                  |       c}| _        g | _        g | _        t        |      D ]q  \  }}t        |t        j                        r!| j                  j                  |       | j
                  j                  | j                  |   j                                s y c c}w N)_dmm	_fe_typeslookup_models	_pack_map	_be_types	enumerate
isinstancer   Omittedappendget_data_type)selfdmmfe_typestyis        c/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/numba/core/datamodel/packer.py__init__zDataPacker.__init__   s    	!19:2

2:x( 	GEArb%--0%%a(%%dll1o&C&C&EF	G	 ;s   Cc                     | j                   D cg c]$  }| j                  |   j                  |||         & }}t        j                  ||      S c c}w )zE
        Return the given values packed as a data structure.
        )r   r   as_datar   make_anonymous_struct)r   buildervaluesr   elemss        r   r   zDataPacker.as_data   sV    
 ..* a((&)< * *,,We<<*s   )ANc                    g }t        | j                        D ]d  \  }}t        j                  ||d|      }| j                  |   j                  ||      }|!|j                  | j                  |   |f       `|||<   f |S Nr   )r   r   r   gep_inboundsr   load_from_data_pointerr   r   )	r   r   ptrformal_listresr   i_formalelem_ptrvals	            r   _do_loadzDataPacker._do_load#   s    $T^^4 	,KAx++GS!Q?H,,x(??RC"

DNN84c:;(+H%	, 
    c                 &    | j                  ||      S )zK
        Load the packed values and return a (type, value) tuples.
        r,   )r   r   r&   s      r   loadzDataPacker.load.   s     }}Wc**r-   c                 *    | j                  |||       y)z
        Load the packed values into a sequence indexed by formal
        argument number (skipping any Omitted position).
        Nr/   )r   r   r&   r'   s       r   	load_intozDataPacker.load_into4   s    
 	gsK0r-   r	   )	__name__
__module____qualname____doc__r   r   r,   r0   r2    r-   r   r   r      s!    
G=	+1r-   r   c                   @    e Zd ZdZd Zd Zd Zd Zd	dZe	d        Z
y)
	ArgPackera  
    Compute the position for each high-level typed argument.
    It flattens every composite argument into primitive types.
    It maintains a position map for unflattening the arguments.

    Since struct (esp. nested struct) have specific ABI requirements (e.g.
    alignment, pointer address-space, ...) in different architecture (e.g.
    OpenCL, CUDA), flattening composite argument types simplifes the call
    setup from the Python side.  Functions are receiving simple primitive
    types and there are only a handful of these.
    c                 \   || _         || _        t        |      | _        g | _        g }|D ]W  }| j                   j                  |      }| j                  j                  |       |j                  |j                                Y t        |      | _	        t        t        |            | _        y r	   )r
   _fe_argslen_nargs_dm_argsr   r   get_argument_type_Unflattener_unflattenerlist_flatten_be_args)r   r   fe_argsargtysr   dms         r   r   zArgPacker.__init__I   s    	'l 	2B!!"%BMM  $MM"..01	2 )0Xf-.r-   c                 &   t        |      | j                  k7  r#t        d| j                  t        |      fz        |syt        | j                  |      D cg c]  \  }}|j                  ||       }}}t        t        |            }|S c c}}w )z$Flatten all argument values
        z+invalid number of args: expected %d, got %dr7   )r<   r=   	TypeErrorzipr>   as_argumenttuplerC   )r   r   r    rG   r+   argss         r   as_argumentszArgPacker.as_argumentsW   s     v;$++%I#{{CK89 : :   #4==&9B w,   Xd^$s   Bc                     | j                   j                  |      }t        | j                  |      D cg c]  \  }}|j	                  ||       }}}|S c c}}w )z&Unflatten all argument values
        )rA   	unflattenrJ   r>   from_argument)r   r   rM   valtreerG   r+   r    s          r   from_argumentszArgPacker.from_argumentsh   s_     ##--d3!$T]]G!<b# ""7C0   	s   Ac                     | j                   j                  |      }t        ||      D ]  \  }}| j                  ||        y)z9Assign names for each flattened argument values.
        N)rA   rP   rJ   _assign_names)r   rM   namesrR   avalanames         r   assign_nameszArgPacker.assign_namess   sD     ##--d3w. 	,KD%tU+	,r-   c                    t        |t        t        f      r,t        |      D ]  \  }}| j	                  ||||fz           y dj                  t        t        |            }||g}dj                  t        t        |            |_
        y )N)depth.)r   rL   rB   r   rU   joinmapstrfilterboolname)r   val_or_nestedrb   r[   posrW   postfixpartss           r   rU   zArgPacker._assign_names{   s|    meT]3&}5 E	T""4UcV^"DE hhs3/G7OE!$&u*=!>Mr-   c                 :    t        d | j                  D              S )z\Return a list of LLVM types that are results of flattening
        composite types.
        c              3   ,   K   | ]  }|d k7  s	|  yw)r7   Nr7   ).0r   s     r   	<genexpr>z+ArgPacker.argument_types.<locals>.<genexpr>   s     <B28R<s   
)rL   rD   )r   s    r   argument_typeszArgPacker.argument_types   s    
 <$--<<<r-   N)r7   )r3   r4   r5   r6   r   rN   rS   rY   rU   propertyrk   r7   r-   r   r9   r9   <   s4    
/"	,? = =r-   r9   c                     fd |       S )z3
    Flatten nested iterable of (tuple, list).
    c              3   t   K   | D ].  }t        |t        t        f      r |      D ]  }|  +| 0 y wr	   )r   rL   rB   )iterabler   jrecs      r   rq   z_flatten.<locals>.rec   sC      	A!eT]+Q AG 	s   58r7   )ro   rq   s    @r   rC   rC      s     x=r-               c                   "    e Zd ZdZd Zd Zd Zy)r@   z
    An object used to unflatten nested sequences after a given pattern
    (an arbitrarily nested sequence).
    The pattern shows the nested sequence shape desired when unflattening;
    the values it contains are irrelevant.
    c                 0    | j                  |      | _        y r	   )_build_unflatten_code_code)r   patterns     r   r   z_Unflattener.__init__   s    //8
r-   c                 *    g fd |       S )zzBuild the unflatten opcode sequence for the given *iterable* structure
        (an iterable of nested sequences).
        c                    | D ]  }t        |t        t        f      rWt        |      dkD  r3j	                  t
                |       j	                  t               Zj	                  t               pj	                  t                y r#   )	r   rL   rB   r<   r   
_PUSH_LIST_POP_APPEND_EMPTY_TUPLE_APPEND_NEXT_VALUE)ro   r   coderq   s     r   rq   z/_Unflattener._build_unflatten_code.<locals>.rec   sd     	4a%/1vzJ/AD)$78KK 23	4r-   r7   )r   ro   r   rq   s     @@r   rx   z"_Unflattener._build_unflatten_code   s     
	4 	Hr-   c                    t        |      }g }|}g }| j                  D ]  }|t        u r(|j                  |       |j                  g        |d   }3|t        u r |j                  |j                                [|t        u r|j                  d       u|t        u s~|j                         } |rJ |       |rJ |       |S )z*Rebuild a nested tuple structure.
        r7   )	r   ry   r}   r   r   popleftr   r~   pop)r   flatitervalsr(   curstackops          r   rP   z_Unflattener.unflatten   s     X** 
	"BZS!

2"g))

4<<>***

2tiik
	" %yx
r-   N)r3   r4   r5   r6   r   rx   rP   r7   r-   r   r@   r@      s    9(r-   r@   N)collectionsr   
numba.corer   r   objectr   r9   rC   r}   r   r   r~   r@   r7   r-   r   <module>r      sP     %21 21jM= M=` 
  66 6r-   