
    xKg=&                         d Z ddlZddlZddlZddlmZ ddlmZ  G d d      Z G d dej                  d	
      Z
 G d d      Z G d de      Z G d d      Z e       Z G d de      Zy)z[
This module contains utils for manipulating target configurations such as
compiler flags.
    N)MappingProxyType)utilsc                   J    e Zd ZdZdZd Zed        Zed        Zed        Z	y)Optionz.An option to be used in ``TargetConfig``.
    _type_default_docc                .    || _         || _        || _        y)a-  
        Parameters
        ----------
        type :
            Type of the option value. It can be a callable.
            The setter always calls ``self._type(value)``.
        default :
            The default value for the option.
        doc : str
            Docstring for the option.
        Nr   )selftypedefaultdocs       [/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/targetconfig.py__init__zOption.__init__   s     
	    c                     | j                   S N)r   r   s    r   r   zOption.type"   s    zzr   c                     | j                   S r   )r	   r   s    r   r   zOption.default&   s    }}r   c                     | j                   S r   )r
   r   s    r   r   z
Option.doc*   s    yyr   N)
__name__
__module____qualname____doc__	__slots__r   propertyr   r   r    r   r   r   r      sM    +I       r   r   c                       e Zd Zy)_FlagsStackN)r   r   r   r   r   r   r    r    /   s    r   r    flags)
stack_namec                   8    e Zd ZdZed        Zd Zd Zd Zd Z	y)ConfigStackzA stack for tracking target configurations in the compiler.

    It stores the stack in a thread-local class attribute. All instances in the
    same thread will see the same stack.
    c                 @     |        }|r|j                         }|S d}|S )z8Get the TOS or return None if no config is set.
        N)top)clsr   r!   s      r   top_or_nonezConfigStack.top_or_none9   s,     uHHJE  Er   c                 "    t               | _        y r   )r    _stkr   s    r   r   zConfigStack.__init__E   s    M	r   c                 6    | j                   j                         S r   )r*   r&   r   s    r   r&   zConfigStack.topH   s    yy}}r   c                 ,    t        | j                        S r   )lenr*   r   s    r   __len__zConfigStack.__len__K   s    499~r   c                 8    | j                   j                  |      S )zgReturns a contextmanager that performs ``push(flags)`` on enter and
        ``pop()`` on exit.
        )r*   enter)r   r!   s     r   r0   zConfigStack.enterN   s     yyu%%r   N)
r   r   r   r   classmethodr(   r   r&   r.   r0   r   r   r   r$   r$   3   s/    
 	 	"&r   r$   c                       e Zd ZdZd Zd Zy)_MetaTargetConfigzMetaclass for ``TargetConfig``.

    When a subclass of ``TargetConfig`` is created, all ``Option`` defined
    as class members will be parsed and corresponding getters, setters, and
    delters will be inserted.
    c           	      0   i }t        |      D ]  }|j                  |j                          |j                  | j                  |             t	        |      | _        d }| j                  j                         D ]  \  }}t        | | |||              y)zInvoked when subclass is created.

        Insert properties for each ``Option`` that are class members.
        All the options will be grouped inside the ``.options`` class
        attribute.
        c                 X      fd} fd} fd}t        |||j                        S )Nc                 P    | j                   j                  j                        S r   )_valuesgetr   )r   nameoptions    r   getterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.gettero   s    ||''fnn==r   c                 B    j                  |      | j                  <   y r   )r   r7   )r   valr9   r:   s     r   setterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.setterr   s    %+[[%5T"r   c                      | j                   = y r   )r7   r   r9   s    r   delterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.delteru   s    LL&r   )r   r   )r9   r:   r;   r>   rA   s   ``   r   	make_propz-_MetaTargetConfig.__init__.<locals>.make_propn   s)    >6' FFFFJJ??r   N)reversedupdateoptionsfind_optionsr   itemssetattr)r'   r9   basesdctoptsbase_clsrB   r:   s           r   r   z_MetaTargetConfig.__init__\   s      !HKK(() (C$$S)*&t,
	@  KK--/LD&Cyv67 0r   c                 x    |j                         D ci c]  \  }}t        |t              s|| c}}S c c}}w )z[Returns a new dict with all the items that are a mapping to an
        ``Option``.
        )rG   
isinstancer   )r'   rJ   kvs       r   rF   z_MetaTargetConfig.find_options}   s3     "%FA
1f0E1FFFs   66N)r   r   r   r   r   rF   r   r   r   r3   r3   U   s    8BGr   r3   c                       e Zd Zd Zy)_NotSetTypec                      y)Nz<NotSet>r   r   s    r   __repr__z_NotSetType.__repr__   s    r   N)r   r   r   rT   r   r   r   rR   rR      s    r   rR   c                       e Zd ZdZddiZddZd Zd Zd Zd	 Z	d
 Z
d ZefdZd ZdefdZd Zd Zedefd       ZdefdZededefd       Zy)TargetConfiga  Base class for ``TargetConfig``.

    Subclass should fill class members with ``Option``. For example:

    >>> class MyTargetConfig(TargetConfig):
    >>>     a_bool_option = Option(type=bool, default=False, doc="a bool")
    >>>     an_int_option = Option(type=int, default=0, doc="an int")

    The metaclass will insert properties for each ``Option``. For example:

    >>> tc = MyTargetConfig()
    >>> tc.a_bool_option = True  # invokes the setter
    >>> print(tc.an_int_option)  # print the default
    wbitsiNc                     i | _         |8t        |t              sJ | j                   j                  |j                          yy)z
        Parameters
        ----------
        copy_from : TargetConfig or None
            if None, creates an empty ``TargetConfig``.
            Otherwise, creates a copy.
        N)r7   rN   rV   rD   )r   	copy_froms     r   r   zTargetConfig.__init__   s>      i666LL	 1 12 !r   c                 4   g }g }| j                   D ]G  }| dt        | |       }| j                  |      s|j                  |       7|j                  |       I | j                  j
                  }| ddj                  |       ddj                  |       dS )N=(, z, [z]))rE   getattris_setappend	__class__r   join)r   argsdefsrO   msgclsnames         r   rT   zTargetConfig.__repr__   s     ACqq)*+C;;q>C C   ..))!DIIdO,C		$/@CCr   c                 X    t        t        t        | j                                           S r   )hashtuplesortedvaluesr   s    r   __hash__zTargetConfig.__hash__   s    E&/011r   c                 p    t        |t              r!| j                         |j                         k(  S t        S r   )rN   rV   rk   NotImplemented)r   others     r   __eq__zTargetConfig.__eq__   s)    e\*;;=ELLN22!!r   c                 V    | j                   D ci c]  }|t        | |       c}S c c}w )z)Returns a dict of all the values
        )rE   r^   )r   rO   s     r   rk   zTargetConfig.values   s,     .2\\:\74##\:::s   &c                 @    | j                  |       || j                  v S )zIs the option set?
        )_guard_optionr7   r@   s     r   r_   zTargetConfig.is_set   s!     	4 t||##r   c                 ^    | j                  |       | j                  j                  |d       y)zRemove the option by name if it is defined.

        After this, the value for the option will be set to its default value.
        N)rs   r7   popr@   s     r   discardzTargetConfig.discard   s&    
 	4 t$r   c                     | j                  |       | j                  |      sKt               }|r(|j                         }t	        | |t        ||             y|t        urt	        | ||       yyy)aL  Inherit flag from ``ConfigStack``.

        Parameters
        ----------
        name : str
            Option name.
        default : optional
            When given, it overrides the default value.
            It is only used when the flag is not defined locally and there is
            no entry in the ``ConfigStack``.
        N)rs   r_   r$   r&   rH   r^   _NotSet)r   r9   r   cstkr&   s        r   inherit_if_not_setzTargetConfig.inherit_if_not_set   sd     	4 {{4 =DhhjdGC$67'dG, ( !r   c                 $     t        |       |       S )zClone this instance.
        )r   r   s    r   copyzTargetConfig.copy   s     tDz$r   returnc                     | j                         D cg c]  \  }}| d|  }}}| j                  j                  }| ddj                  |       dS c c}}w )zReturns a ``str`` that summarizes this instance.

        In contrast to ``__repr__``, only options that are explicitly set will
        be shown.
        r[   r\   r]   ))_summary_argsra   r   rb   )r   rO   rP   rc   rf   s        r   summaryzTargetConfig.summary   sa     (,'9'9';<';tq!1#Qqc
';<..))!DIIdO,A.. =s   Ac                 V    || j                   vr|dt        |        }t        |      y )Nz is not a valid option for )rE   r   
ValueError)r   r9   re   s      r   rs   zTargetConfig._guard_option   s2    t||#H7T
|DCS/! $r   c                     g }t        | j                        D ]T  }| j                  |   }| j                  |      s$t        | |      }|j                  |k7  s@||f}|j                  |       V |S )zreturns a sorted sequence of 2-tuple containing the
        ``(flag_name, flag_value)`` for flag that are set with a non-default
        value.
        )rj   rE   r_   r^   r   r`   )r   rc   rO   optflagvalrP   s         r   r   zTargetConfig._summary_args  sg    
 %A,,q/C{{1~!$*;;')GAKKN & r   c                    g }|j                  d       |j                  | j                  j                         |j                  ddg       | j                  j                         D ]:  \  }}|j                  |       |j                  t        |j                               < dj                  |      j                         S )z]Returns a ``bytes`` object suitable for use as a dictionary for
        compression.
        numbaTrueFalse )
r`   ra   r   extendrE   rG   strr   rb   encode)r'   bufrO   r   s       r   _make_compression_dictionaryz)TargetConfig._make_compression_dictionary  s    
 

7

3==))*

FG$%kk'')FAsJJqMJJs3;;'( * wws|""$$r   c                    | j                         }t        j                  d|t        j                  d| j                  }|j                  | j                         j                               g}|j                  |j                                t        j                  dj                  |            j                         S )z6Return a string suitable for symbol mangling.
        )zdictlevelr   r   )r   zlibcompressobjZ_BEST_COMPRESSION_ZLIB_CONFIGcompressr   r   r`   flushbase64	b64encoderb   decode)r   r   compr   s       r   get_mangle_stringzTargetConfig.get_mangle_string"  s     113 5e43J3J 5"&"3"35 }}T\\^22456

4::< .5577r   mangledc                    d }t        j                  d||      }t        j                  |      }| j	                         }t        j                  dd|i| j                  }g }|r/|j                  |j                  |             |j                  }|r/|j                  |j                                dj                  |      j                         S )zCReturns the demangled result from ``.get_mangle_string()``
        c                 V    t        t        d| j                  d      dd  z   d            S )N0xr         )chrintgroup)xs    r   replz#TargetConfig.demangle.<locals>.repl4  s'    s4!''!*QR.0"566r   z_[a-zA-Z0-9][a-zA-Z0-9]r   r   r   )resubr   	b64decoder   r   decompressobjr   r`   
decompressunconsumed_tailr   rb   r   )r'   r   r   	unescapedrawr   dcr   s           r   demanglezTargetConfig.demangle/  s    
	7FF5tWE	y)002@e@s/?/?@JJr}}S)*$$C  	

288:xx}##%%r   r   )r   r   r   r   r   r   rT   rl   rp   rk   r_   rv   rx   rz   r|   r   r   rs   r   r1   bytesr   r   r   r   r   r   rV   rV      s    " S>L3D2";
$% 07 -, 
/ /"
 %U % %"83 8 &s &s & &r   rV   )	metaclass)r   r   r   r   typesr   
numba.corer   r   ThreadLocalStackr    r$   r   r3   rR   rx   rV   r   r   r   <module>r      sv    
   "  D	%((W 	& &D,G ,G^ 
 -u&. u&r   