o
    ÆN i 6 ć                   @   sź  d dl Z e jdi dededededededed	ed
ededededededededededede d dlZd dlZd dlZd dlZd dlZd dlZd dl	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 ddlmZ ddlmZ ddlmZ ddlmZ d d!lmZ dd"lmZ d d#lmZ d d$lmZ  zd d$l!mZ" W n e#yĆ   dZ"Y nw ee"d%d&Z"zd d'l$mZ%m&Z'm(Z) W n e#yį   dZ%Y nw ee%e'j*e)j+e'j,e'j, -” d id(Z%['[)dd)ee d%d*fd d+e"fd,d-e%fgZ.d.d.d/d0d1Z/d2d2d3d4d5Z0d6d7iZ1d8Z2e3g d9¢Z4g d:¢Z5e  e3e3d;”Z6d<d=ij7Z8e  edd d d>j7”Z9G d?d@ d@Z:dAdB Z;dZ<	 dCdD Z=e=Z<G dEdF dFZ>G dGdH dHe>Z?e
G dIdJ dJZ@G dKdL dLe?ZAddMdgdNdOdPZBeBdQdRdSdTdU ZCeB dVeAfdWdXZDeBdYdZd[d\d]d^ ZEeBd_d`dZdad\dbdc ZFeBdddedSdfdg ZGeBdhdMdid\djdk ZHeB dldm ZIddi fdndoZJG dpdq dqeAZKG drds dse?ZLG dtdu duZMG dvdw dwZNG dxdy dyZOe jeeeedz e Pd{ejQ”jRZSe Pd|”jRZTe Pd}”jUZVe Pd~”jWZXG dd dZYG dd dZZG dd dZ[dd Z\G dd dZ]G dd dZ^G dd dZ_G dd dZ`e jae jbdecde jddecfddZee  fd”e jgdecde jdfddZhG dd dZidS )é    NŚosŚreŚoperatorŚtextwrapŚTemplateŚNamingŚOptionsŚStringEncodingŚUtilsŚSourceDescriptorŚStringIOTreeŚ
DebugFlagsŚdefaultdictŚclosingŚpartialŚwrapsŚzlib_compressŚbz2_compressŚlzma_compressŚzstd_compress)Ś	dataclass©r   )r   r   )r   Ścontextmanager)r   é   )r   )r   )r   )r	   é   )r
   )r   )r   )Ścompressé	   )Ścompresslevel)r   ŚCompressionParameterŚStrategy)ŚoptionsŚzlib©ŚlevelŚbz2é   ŚzstdŚstrŚrangeŚinput)ŚunicodeŚ
basestringŚxrangeŚ	raw_inputz&PyLong_Typez&PyFloat_Typez&PyWrapperDescr_Type)Śpy_intŚpy_longŚpy_floatŚwrapper_descriptorŚPyTypeObjectŚPyHeapTypeObject)r%   é   r   Śbetar   )ŚArithmeticErrorŚAssertionErrorŚAttributeErrorŚBaseExceptionŚBaseExceptionGroupŚBlockingIOErrorŚBrokenPipeErrorŚBufferErrorŚBytesWarningŚChildProcessErrorŚConnectionAbortedErrorŚConnectionErrorŚConnectionRefusedErrorŚConnectionResetErrorŚDeprecationWarningŚEOFErrorŚEllipsisŚEncodingWarningŚEnvironmentErrorŚ	ExceptionŚExceptionGroupŚFalseŚFileExistsErrorŚFileNotFoundErrorŚFloatingPointErrorŚFutureWarningŚGeneratorExitŚIOErrorŚImportErrorŚImportWarningŚIndentationErrorŚ
IndexErrorŚInterruptedErrorŚIsADirectoryErrorŚKeyErrorŚKeyboardInterruptŚLookupErrorŚMemoryErrorŚModuleNotFoundErrorŚ	NameErrorŚNoneŚNotADirectoryErrorŚNotImplementedŚNotImplementedErrorŚOSErrorŚOverflowErrorŚPendingDeprecationWarningŚPermissionErrorŚProcessLookupErrorŚPythonFinalizationErrorŚRecursionErrorŚReferenceErrorŚResourceWarningŚRuntimeErrorŚRuntimeWarningŚStopAsyncIterationŚStopIterationŚSyntaxErrorŚSyntaxWarningŚSystemErrorŚ
SystemExitŚTabErrorŚTimeoutErrorŚTrueŚ	TypeErrorŚUnboundLocalErrorŚUnicodeDecodeErrorŚUnicodeEncodeErrorŚUnicodeErrorŚUnicodeTranslateErrorŚUnicodeWarningŚUserWarningŚ
ValueErrorŚWarningŚWindowsErrorŚZeroDivisionErrorŚ_IncompleteInputErrorŚ__build_class__Ś	__debug__Ś
__import__ŚabsŚaiterŚallŚanextŚanyŚasciiŚbinŚboolŚ
breakpointŚ	bytearrayŚbytesŚcallableŚchrŚclassmethodŚcompileŚcomplexŚ	copyrightŚcreditsŚdelattrŚdictŚdirŚdivmodŚ	enumerateŚevalŚexecŚexitŚfilterŚfloatŚformatŚ	frozensetŚgetattrŚglobalsŚhasattrŚhashŚhelpŚhexŚidr)   ŚintŚ
isinstanceŚ
issubclassŚiterŚlenŚlicenseŚlistŚlocalsŚmapŚmaxŚ
memoryviewŚminŚnextŚobjectŚoctŚopenŚordŚpowŚprintŚpropertyŚquitr(   ŚreprŚreversedŚroundŚsetŚsetattrŚsliceŚsortedŚstaticmethodr'   ŚsumŚsuperŚtupleŚtypeŚvarsŚzip)
r   rg   r:   rJ   r   r   rG   r   r   Ś_)	Ś	__cinit__Ś__dealloc__Ś__richcmp__Ś__next__Ś	__await__Ś	__aiter__Ś	__anext__Ś__getbuffer__Ś__releasebuffer__ŚinlineŚCYTHON_INLINE)ŚustringrŹ   rÅ   c                   @   sJ   e Zd ZdZdZdZdZdZddd	Zd
d Z	dd Z
dd Zdd ZdS )ŚIncludeCodez]
    An include file and/or verbatim C code to be included in the
    generated sources.
    r   r   r   NTFc                 C   s   | j | _t|  j d7  _ i | _|r1|d dkr)|d dkr)d |”| jd< d}nd |”| jd< |r9|| j| j< |rA| j| _d S |rI| j| _d S | j| _d S )	Nr   r   ś<é’’’’ś>z#include {}Fz#include "{}")	ŚcounterŚorderrĖ   Śpiecesr¢   ŚINITIALŚlocationŚLATEŚEARLY)ŚselfŚincludeŚverbatimŚlateŚinitial© rė   śH/home/ubuntu/.local/lib/python3.10/site-packages/Cython/Compiler/Code.pyŚ__init__A  s   zIncludeCode.__init__c                 C   s>   ||v r|| }t | j|j|_|j | j” dS | ||< dS )z
        Insert `self` in dict `d` with key `key`. If that key already
        exists, update the attributes of the existing value with `self`.
        N)r¶   rć   rį   Śupdate)rę   ŚdŚkeyŚotherrė   rė   rģ   Śdict_updateW  s
   zIncludeCode.dict_updatec                 C   s   | j S ©N)rą   ©rę   rė   rė   rģ   Śsortkeyc  s   zIncludeCode.sortkeyc                 C   s   | j  d”S )z
        Return the main piece of C code, corresponding to the include
        file. If there was no include file, return None.
        r   )rį   Śgetrō   rė   rė   rģ   Ś	mainpiecef  s   zIncludeCode.mainpiecec                 C   s$   t | jD ]
}| | j| ” qd S ró   )rĘ   rį   Śputln)rę   ŚcodeŚkrė   rė   rģ   Śwritem  s   ’zIncludeCode.write)NNTF)Ś__name__Ś
__module__Ś__qualname__Ś__doc__rā   rå   rä   rß   rķ   rņ   rõ   r÷   rū   rė   rė   rė   rģ   rŪ   '  s    
rŪ   c                  C   s*   t j t j t j t”””} t j | d”S )NŚUtility)r   ŚpathŚdirnameŚabspathŚ__file__Śjoin)Ś
Cython_dirrė   rė   rģ   Śget_utility_dirs  s   r  c                 C   sN   t j t | ”}ttj|dd}| ” W  d   S 1 s w   Y  dS )zh
    Read all lines of the file at the provided path from a path relative
    to get_utility_dir().
    śUTF-8)ŚencodingN)r   r  r  r  r   r
   Śopen_source_fileŚ	readlines)r  ŚfilenameŚfrė   rė   rģ   Śread_utilities_from_utility_dir  s   $’r  c                   @   s,   e Zd ZdZddddZdd Zd	d
 ZdS )ŚAbstractUtilityCodeNŚglobalstateŚGlobalStateŚreturnc                 C   ó   d S ró   rė   )rę   r  Śused_byrė   rė   rģ   Śput_code  ó   zAbstractUtilityCode.put_codec                 K   r  ró   rė   ©rę   Śkwargsrė   rė   rģ   Śget_tree  r  zAbstractUtilityCode.get_treec                 K   r  ró   rė   r  rė   rė   rģ   Śget_shared_library_scope  r  z,AbstractUtilityCode.get_shared_library_scoperó   ©r  r  r  N)rü   rż   rž   Śrequiresr  r  r  rė   rė   rė   rģ   r    s
    r  c                   @   sŖ   e Zd ZdZdZi Ze d”jZ	e
dd ZedddZed	d
 Zedd Zei fddZedddZe d”jfddZdd Zdd Zdd ZdddZdS )ŚUtilityCodeBasea(  
    Support for loading utility code from a file.

    Code sections in the file can be specified as follows:

        ##### MyUtility.proto #####

        [proto declarations]

        ##### MyUtility.init #####

        [code run at module initialization]

        ##### MyUtility #####
        #@requires: MyOtherUtility
        #@substitute: naming

        [definitions]

        ##### MyUtility #####
        #@substitute: tempita

        [requires tempita substitution
         - context can't be specified here though so only
           tempita utility that requires no external context
           will benefit from this tag
         - only necessary when @required from non-tempita code]

    for prototypes and implementation respectively.  For non-python or
    -cython files backslashes should be used instead.  5 to 30 comment
    characters may be used on either side.

    If the @cname decorator is not used and this is a CythonUtilityCode,
    one should pass in the 'name' keyword argument to be used for name
    mangling of such entries.
    Fzo(.+)[.](proto(?:[.]\S+)?|impl|init|cleanup|module_state_decls|module_state_traverse|module_state_clear|export)$c                 C   s   t  ddt  | ”i t j”jS )NzS^%(C)s{5,30}  \s*  (?P<name> (?:\w|\.)+ )  \s*  %(C)s{5,30} |^%(C)s+  @(?P<tag> .+)ŚC)r   r   ŚescapeŚVERBOSEŚmatch)Śline_comment_charrė   rė   rģ   Śget_special_comment_matcherĢ  s   ūūūz+UtilityCodeBase.get_special_comment_matcherNc                 C   s(  |d u rd S d  |”}|rWd|v rWd|d v rWzt| tt”}W n ttfyA }	 ztd| d| d|dd|	 d }	~	ww ||krUtd	| d| d
|dd|}d| | }|dkrf||d< n|dkro||d< n|d }
||
|< |r|d }
| ” D ]\}}|
 	|t
 ” |” qd S d S )NŚ
Ś
substituteŚnamingz&Error parsing templated utility code 'Ś.z
' at line rļ   z: zFFound useless 'substitute: naming' declaration without replacements. (ś:ś)Śprotor   Śimplr   r   )r  r   r%  rĢ   r   rX   r~   rk   ŚitemsŚ
setdefaultrĆ   rī   )ŚclsŚutilityŚnamerĖ   ŚlinesŚbegin_linenoŚtagsrł   Śnew_codeŚeŚall_tagsŚtag_nameŚ
tag_valuesrė   rė   rģ   Ś_add_utilityÕ  s<   
’’’

żzUtilityCodeBase._add_utilityc              	   C   s:  | j  |”}|r
|S tj |”\}}|dv r%d}tt d”jd}t	j
}nd}tt d”jd}tt d”jd}|  |”}| j}	t|}
td	d
 }g }tt}d  } }}d}t|
D ]”\}}||}|d u rs| |||” q]| d”rØ|  ||||||” |d }|d d = | ”  | d”}|	|}|r”| ” \}}nd}|| }q]| d”}d|vr¾td| d| d| | d”\}}}| 
” }| ” }|dvrßtd| d| d| t d|”sņtd| d| d| ||  |” | d” q]|d u rtd|  ||||||” t|}|| j |< |S )N)z.pyxz.pyz.pxdz.pxiś#z^\s*#(?!\s*cython\s*:).*Ś ś/z^\s*//.*|/\*[^*]*\*/z	\s+(\\?)$z\1c                   S   s
   d d i gS ró   rė   rė   rė   rė   rģ   Ś<lambda>  ó   
 z:UtilityCodeBase.load_utilities_from_file.<locals>.<lambda>r   r0  r   r+  Śtagr(  zFound invalid tag 'z' in utility section r'  )r  r%  Śproto_blockzFound unknown tag name 'z\S+$zFound invalid tag value 'zEmpty utility code file)Ś_utility_cacherö   r   r  Śsplitextr   r   r   Śsubr'   Śrstripr#  Śmatch_section_titleŚread_utilities_hookr   rĆ   r   ŚappendŚgroupr9  ŚclearŚgroupsrk   Ś	partitionŚstripr!  Śaddr~   r   )r.  r  Ś	utilitiesrĪ   ŚextŚcommentŚstrip_commentsrD  Śmatch_specialŚ
match_typeŚ	all_linesr1  r3  r/  r0  rĖ   r2  ŚlinenoŚlineŚmŚmtypeŚ	tag_valuer7  rė   rė   rģ   Śload_utilities_from_fileö  sh   







z(UtilityCodeBase.load_utilities_from_filec           
         sl  d|v r|  dd”\}sJ   ”}|| \}}}|rd|v r7d|d v r7t ts7tj|fi |¤S | ” | ” D ]M\}}	||v rHq?|dkrir\ fddt|	D }	n, fddt|	D }	n|dkrw|	d	dh }	|	svq?n|	s|d
}	nt|	dkrt	|	d }	|	||< q?|d
ur||d< |d
ur||d< d|vr„||d< d|vrÆrÆ|d<  di |¤S )z
        Load utility code from a file specified by from_file (relative to
        Cython/Utility) and name util_code_name.
        z::r   r%  Śtempitar  c                    s    g | ]} j |fi ¤qS rė   )Śload©Ś.0Śdep©r.  Ś	from_fileŚorig_kwargsrė   rģ   Ś
<listcomp>V  s    ’z(UtilityCodeBase.load.<locals>.<listcomp>c                    s   g | ]}   |”qS rė   )Śload_cachedr]  )r.  ra  rė   rģ   rc  Z  s    ’r&  Nr   r*  r+  r0  Śfilerė   )
ŚrsplitrZ  r­   ŚTempitaUtilityCoder\  Ścopyr,  rĘ   rÆ   r±   )
r.  Śutil_code_namera  r  rN  r*  r+  r3  r0  Śvaluesrė   r`  rģ   r\  >  sP   

’’’
zUtilityCodeBase.loadc                 C   s@   ||| f}z|| W S  t y   Y nw |  ||” }||< |S )z`
        Calls .load(), but using a per-type cache based on utility name and file name.
        )rX   r\  )r.  Śutility_code_namera  Ś_UtilityCodeBase__cacherš   rł   rė   rė   rģ   rd  t  s   

’zUtilityCodeBase.load_cachedc                    sf   | j ||fi |¤}|s| |j”| |j”fS g g   fdd| d ”d  ”fS )a  
        Load a utility code as a string. Returns (proto, implementation).

        If 'include_requires=True', concatenates all requirements before the actually
        requested utility code, separately for proto and impl part.

        In a lot of cases it may be better to use regular "load" and "CCodeWriter.put_code_here"
        since that is able to apply the code transformations to the code too.
        c                    sR   | j r| j D ]}| q| jr |  | j”” | jr'  |  | j”” d S d S ró   )r  r*  rG  Śformat_coder+  )Ś	util_coder_  ©ŚimplsŚprependŚprotosrė   rģ   rq    s   

’z/UtilityCodeBase.load_as_string.<locals>.prependr;  )r\  rm  r*  r+  r  )r.  ri  ra  Śinclude_requiresr  Śutilrė   ro  rģ   Śload_as_string  s   

’
	zUtilityCodeBase.load_as_stringz\n\n+c                 C   s   |r|d|  ” d }|S )z3
        Format a code section for output.
        r$  z

©rL  )rę   Ścode_stringŚreplace_empty_linesrė   rė   rģ   rm    s   zUtilityCodeBase.format_codec                 C   s   dt | j| jf S )Nz<%s(%s)>)rĖ   rü   r0  rō   rė   rė   rģ   Ś__repr__§  ó   zUtilityCodeBase.__repr__c                 K   r  ró   rė   r  rė   rė   rģ   r  Ŗ  r  zUtilityCodeBase.get_treec                 K   r  ró   rė   r  rė   rė   rģ   r  ­  r  z(UtilityCodeBase.get_shared_library_scopec                 C   s   | S ró   rė   )rę   Śmemodictrė   rė   rģ   Ś__deepcopy__°  s   zUtilityCodeBase.__deepcopy__ró   ©F)rü   rż   rž   r’   Śis_cython_utilityrA  r   r   r!  rE  rĒ   r#  r   r9  rZ  r\  rd  ru  rC  rm  ry  r  r  r|  rė   rė   rė   rģ   r    s4    %’ž
 
G
5r  c                   @   s*   e Zd ZU dZeed< eed< eed< dS )ŚSharedFunctionDeclz6Contains parsed declaration of shared utility functionr0  ŚretŚparamsN)rü   rż   rž   r’   r'   Ś__annotations__rė   rė   rė   rģ   r  “  s
   
 r  c                   @   s¢   e Zd ZdZg d¢Z				d$ddZdedefd	d
Zdd Z	dd Z
dd Zd%ddZdd Zejd%dddddefddZdd Zd&dd Zd%d'd"d#ZdS )(ŚUtilityCodea÷  
    Stores utility code to add during code generation.

    See GlobalState.put_utility_code.

    hashes/equals by instance

    proto           C prototypes
    export          C prototypes exported from the shared utility code module
    impl            implementation code
    init            code to call on module initialization
    requires        utility code dependencies
    proto_block     the place in the resulting file where the prototype should
                    end up
    name            name of the utility code (or None)
    file            filename of the utility code file this utility was loaded
                    from (or None)
    shared_utility_functions        List of parsed declaration line of the shared utility function
    )r*  Śexportr+  ŚinitŚcleanupŚmodule_state_declsŚmodule_state_traverseŚmodule_state_clearNŚutility_code_protoc                    s   | _ | _| _| _| _| _| _| _i  _g  _	|	 _
|
 _| _| _|r1  |”ng  _|r:  ”  t fdd jD  _d S )Nc                 3   s    | ]	}t  |d V  qd S ró   ©r¤   )r^  Śpartrō   rė   rģ   Ś	<genexpr>é  s    z'UtilityCode.__init__.<locals>.<genexpr>)r*  r+  r  r  r  r  r  r  Ś_cacheŚspecialize_listr@  r0  re  r  Śparse_export_functionsŚshared_utility_functionsŚ_validate_suitable_for_sharingrŹ   Ś
code_partsŚ_parts_tuple)rę   r*  r+  r  r  r  r  r  r  r@  r0  re  r  rė   rō   rģ   rķ   Ń  s$   zUtilityCode.__init__Śexport_protor  c           	      C   sÖ   d|vrd|vrd|vsJ d|  ”  d| j g }d}| d”D ]F}|  ”  dd	”}t d
d|”}t|dkr:q"t ||tj”}|d usQJ d|d| j | 	” \}}}| 
t|  ” |  ” |  ” d” q"|S )Nz//ś/*ś*/z(Export block must not contain comments:
z

 in file a_  
            ^static\s                                         # `static` keyword
            (?P<ret_type>[^;()]+[\s*])                        # return type + modifier with optional * - e.g.: int *, float, const str *, ...
            (?P<func_name>\w+)\((?P<func_params>[^)]*)\)$     # function with params - e.g. foo(int, float, *PyObject)
        z;
r$  r;  z\s+ś r   z5Wrong format of function definition in export block 
z
 in )r0  r  r  )rL  re  ŚsplitŚreplacer   rC  rÆ   r!  r   rJ  rG  r  )	rę   r  Śparsed_protosŚproto_regexr*  ŚmatchedŚret_typeŚ	func_nameŚfunc_paramsrė   rė   rģ   r  ė  s&   ’
’’z"UtilityCode.parse_export_functionsc                 C   s
   t | jS ró   )r§   r  rō   rė   rė   rģ   Ś__hash__	  ó   
zUtilityCode.__hash__c                 C   sJ   | |u rdS t | t |}}||urt||st| |sdS | j|jkS )NTF)rĖ   r¬   r  )rę   rń   Ś	self_typeŚ
other_typerė   rė   rģ   Ś__eq__  s   zUtilityCode.__eq__c                 C   s   |du rdS || S ©zY
        Format a string in this utility code with context. If None, do nothing.
        Nrė   ©rę   ŚsŚcontextrė   rė   rģ   Śnone_or_sub  s   zUtilityCode.none_or_subc                    s  | j }|d ur| ”  d< | ”  d< d| d f }tt  ” }z| j| W S  ty   | jd u r8d }n
 fdd| jD }t	|  
| j ”|  
| j ”|  
| j ”|  
| j ”|  
| j ”|  
| j ”|  
| j ”|| j|
 }| j|< | j |” | Y S w )NrĖ   Ś	type_namez%s[%s]c                    s   g | ]}|   ”qS rė   )Ś
specialize)r^  Śr©Śdatarė   rģ   rc  +  ó    z*UtilityCode.specialize.<locals>.<listcomp>)r0  Śempty_declaration_codeŚspecialization_namerŹ   rĘ   r,  r  rX   r  r  rŖ  r*  r+  r  r  r  r  r  r@  r  rG  )rę   Ś
pyrex_typerÆ  r0  rš   r  rØ  rė   r®  rģ   r¬    s6   
öģzUtilityCode.specializec                 C   s,   t | d}|s	d S d|vsJ d|  d S )Nr+  zNAMED_CGLOBAL(moddict_cname)z$moddict_cname should not be shared: r  )rę   rw  rė   rė   rģ   r  =  s
   

’z*UtilityCode._validate_suitable_for_sharingŚwriterŚCCodeWriterŚoutputr  Ś	code_typec           	      C   s¤   t | |}|s	d S |dv }t| ||\}}|rd| dnd}|dkr+| j d| n| j}| d| | d” |rK|sK| || j d	| ” d S | |” d S )
N)r*  r+  z
 (used by r)  r;  r+  r'  ś/* ś */rĪ   )r¤   Śprocess_utility_ccoder0  rų   Śput_or_includeŚput_multilines)	rę   r“  r¶  r·  r  rw  Ścan_be_reusedŚresult_is_module_specificr0  rė   rė   rģ   Ś_put_code_sectionC  s   
zUtilityCode._put_code_sectionc                 C   sB   | j sd S |d }|  ||d” | d| |j” ” | ”  d S )NŚinit_globalsr  ś  )r  ræ  rų   Śerror_goto_if_PyErrŚ
module_pos)rę   r¶  r“  rė   rė   rģ   Ś_put_init_code_sectionX  s   z"UtilityCode._put_init_code_sectionrł   c              
   C   sP   |  d| j d” | jD ]}|  d|j d|j d|j d” q|  ”  d S )Nrø  r¹  śstatic z(*z)(z); /*proto*/)rų   r0  r  r  r  )rę   rł   Śsharedrė   rė   rģ   Ś!_put_shared_function_declarationsb  s   
&z-UtilityCode._put_shared_function_declarationsr  c                 C   s2  t | jo	|jjjj}| jr|s| jD ]
}|j|| jd q|r(|  	|| j
 ” |j | j” | jr>| j|| j
 |d|d |sJ|  || j
 |d” | jrZ|sZ| j|d |d|d | jritjri|  |d |d” | jru|  |d |d	” | jr|  |d
 |d” | jr|  |d |d” | jr|  |” d S d S )N©r  r*  r  Śutility_code_defr+  Ścleanup_globalsr  Śmodule_state_contentsr  Śmodule_state_traverse_contentsr  Śmodule_state_clear_contentsr  )r   r  Śmodule_nodeŚscoper©  Śshared_utility_qualified_namer  Śuse_utility_coder0  rĒ  r@  Śextendr*  ræ  r+  r  r   Śgenerate_cleanup_coder  r  r  r  rÄ  )rę   r  r  Śhas_shared_utility_codeŚ
dependencyrė   rė   rģ   r  i  s4   ’


’zUtilityCode.put_code)NNNNNNNNr  NNNró   )rł   rµ  r  Nr  )rü   rż   rž   r’   r  rķ   r'   r±   r  r”  r„  rŖ  r¬  r  ŚcythonŚfinalræ  rÄ  rĒ  r  rė   rė   rė   rģ   r  »  s&    
ż	
 

r  F)ŚregexŚis_module_specificŚ_last_macro_processorc                    s     d  fdd}|S )z8Decorator to chain the code macro processors below.
    r   c                    s2   t  dtdtf fdd}|d< |S )NŚutility_coderw  c                    s¢   d}d ur| ||\}}rD ]}||v r nq||fS d u r* | ||}n
t  t ||”}D ]}||v rHtd| d| j dq6|O }||fS )NFzLeft-over utility code macro 'z()' found in 'ś')r   rC  r   rk   r0  )rŪ  r¶  rw  r¾  Śmacro)ŚfuncrŁ  Ślast_processorŚmacro_namesrŲ  rė   rģ   Śprocess  s$   ’’z=add_macro_processor.<locals>.build_processor.<locals>.processr   )r   r  r'   )rŽ  rį  ©rŚ  rŁ  rß  rą  rŲ  )rŽ  rģ   Śbuild_processor  s    z,add_macro_processor.<locals>.build_processorrė   )rŲ  rŁ  rŚ  rą  rć  rė   rā  rģ   Śadd_macro_processor  s   !rä  ŚCSTRINGz)CSTRING\(\s*"""([^"]*(?:"[^"]+)*)"""\s*\))rŲ  c                 C   s*   |  d” dd”}d dd | ” D ”S )zUReplace CSTRING('''xyz''') by a C compatible string, taking care of line breaks.
    r   ś"z\042r;  c                 s   sD    | ]}|  d ”r|  d”rd| dn	d|dd  dV  qdS )ś\z\\rę  z\n"
NrŻ   ś"
)Śendswith©r^  rV  rė   rė   rģ   r  ŗ  s
    2’
’z!_wrap_c_string.<locals>.<genexpr>)rH  r  r  Ś
splitlines)rĪ   ŚmatchobjŚcontentrė   rė   rģ   Ś_wrap_c_string²  s   
žrī  rŪ  c                 C   s
   |   |”S ró   )rm  )rŪ  rĪ   r+  rė   rė   rģ   Ś_format_impl_codeæ  s   
rļ  ŚCALL_UNBOUND_METHODTzLCALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)",\s*([^),\s]+)((?:,[^),]+)*)\))rŁ  rŲ  c                 C   sx   |  ” \}}}}d| }|rdd |dd  d”D ng }t|dk s/J dt|d	d
|  tj d||||”S )zRReplace 'UNBOUND_METHOD(type, "name")' by a constant Python identifier cname.
    z&%sc                 S   s   g | ]}|  ” qS rė   rv  )r^  Śargrė   rė   rģ   rc  Õ  ó    z*_inject_unbound_method.<locals>.<listcomp>r   Nś,r%   z'CALL_UNBOUND_METHOD() does not support rļ   z call argumentsś->)rJ  r  rÆ   Ścached_unbound_method_call_coder   Śmodulestateglobal_cname)r¶  rģ  Ś
type_cnameŚmethod_nameŚ	obj_cnameŚargsrė   rė   rģ   Ś_inject_unbound_methodÄ  s   $"
žrū  ŚPYIDENTŚ	PYUNICODEzPY(IDENT|UNICODE)\("([^"]+)"\)c                 C   s0   |  ” \}}dtj| jt |”|dkdjf S )zDReplace 'PYIDENT("xyz")' by a constant Python identifier cname.
    ś%s->%sŚIDENT©Ś
identifier)rJ  r   rö  Śget_py_string_constr	   ŚEncodedStringŚcname)r¶  rģ  Śstr_typer0  rė   rė   rģ   Ś_inject_string_constantÜ  s   ’żr  ŚEMPTYzEMPTY\((bytes|unicode|tuple)\)c                 C   s$   |  d”}dtjttd| f S )zLReplace 'EMPTY(bytes|tuple|...)' by a constant Python identifier cname.
    r   rž  Śempty_)rH  r   rö  r¤   )r¶  rģ  r«  rė   rė   rģ   Ś!_inject_empty_collection_constantė  s
   
	žr	  ŚCGLOBALz(NAMED_)?CGLOBAL\(([^)]+)\)c                 C   s*   |  ” \}}|rtt|}tj d| S ©Nrō  )rJ  r¤   r   rö  )r¶  rģ  Śis_namedr0  rė   rė   rģ   Ś_inject_cglobalś  s   
r  c                 C   s   |S )z;Entry point for code processors, must be defined last.
    rė   )rŪ  rĪ   rw  rė   rė   rģ   rŗ    s   rŗ  c                 C   sp   | sdS |r| d| }|r||d< z||  }W n t y2   ddlm} || |d }|| < Y nw | |”S )z+Run tempita on string s with given context.Nr(  Ś__namer   r   ©r0  )rX   ŚTempitar   r%  )rØ  r©  re  r0  Ś__cacheŚtemplater   rė   rė   rģ   Śsub_tempita  s   ž
r  c                       s:   e Zd Zd fdd	Zeddi fddZdd Z  ZS )	rg  Nc                    sb   |d u ri }n|  ” }t||||}t||||}t||||}t j||f|||d|¤ d S )N)r  r0  re  )rh  r  rÉ   rķ   )rę   r0  r*  r+  r  re  r©  r  ©Ś	__class__rė   rģ   rķ   !  s   ’’
’zTempitaUtilityCode.__init__c                 C   sn   |r
t t| ” nd }t|d usJ | |||f}z|| W S  ty(   Y nw | j|||d }||< |S )N)r©  )rŹ   rĘ   r,  r§   rX   r\  )r.  rk  ra  r©  Ś_TempitaUtilityCode__cacheŚcontext_keyrš   rł   rė   rė   rģ   rd  -  s   
’zTempitaUtilityCode.load_cachedc                 C   s   |du rdS t ||| j| jS r¦  )r  re  r0  r§  rė   rė   rģ   rŖ  9  s   zTempitaUtilityCode.none_or_sub)NNNNNN)rü   rż   rž   rķ   r   rd  rŖ  Ś__classcell__rė   rė   r  rģ   rg     s
    rg  c                   @   s,   e Zd ZdZdZ dZdd Zddd	d
ZdS )ŚLazyUtilityCodez
    Utility code that calls a callback with the root code writer when
    available. Useful when you only have 'env' but not 'code'.
    z<lazy>Nc                 C   s
   || _ d S ró   )Ścallback)rę   r  rė   rė   rģ   rķ   J  r¢  zLazyUtilityCode.__init__r  r  r  c                 C   s   |   |j”}|j||d d S )NrČ  )r  Ś
rootwriterrŃ  )rę   r  r  r/  rė   rė   rģ   r  M  ó   zLazyUtilityCode.put_coderó   r  )rü   rż   rž   r’   r  rķ   r  rė   rė   rė   rģ   r  B  s    r  c                   @   sĪ   e Zd Ze dfddZdd Zd2ddZd3d	d
Zd4ddZdd Z	dd Z
d4ddZdd Zdd Zdd Zdd Zdd Zd5d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 ZdS )6ŚFunctionStateNc                 C   sŖ   || _ || _|| _d | _d| _t | _|  ” | _|  	”  d | _
d | _g | _d | _d | _d| _d| _g | _i | _i | _t | _d| _d | _g | _d| _d| _d| _d| _d S )Nr   FT)Śnames_takenŚownerrĻ  Śerror_labelŚlabel_counterrĆ   Ślabels_usedŚ	new_labelŚreturn_labelŚnew_error_labelŚcontinue_labelŚbreak_labelŚyield_labelsŚexc_varsŚcurrent_exceptŚ	can_traceŚ	gil_ownedŚtemps_allocatedŚ
temps_freeŚtemps_used_typeŚzombie_tempsŚtemp_counterŚclosure_tempsŚcollect_temps_stackŚshould_declare_error_indicatorŚuses_error_indicatorŚerror_without_exceptionŚneeds_refnanny)rę   r  r  rĻ  rė   rė   rģ   rķ   _  s4   

zFunctionState.__init__c                 C   sF   | j r|  ” }|r!d| jjd dd t|D ”f }t|d S d S )Nz-TEMPGUARD: Temps left over at end of '%s': %sś, c                 S   s   g | ]\}}}d ||f qS )z%s [%s]rė   )r^  r0  ŚctypeŚ	is_pytemprė   rė   rģ   rc    s    
’’z/FunctionState.validate_exit.<locals>.<listcomp>)r-  Śtemps_in_userĻ  r0  r  rĘ   rk   )rę   Ś	leftoversŚmsgrė   rė   rģ   Śvalidate_exit  s   žųzFunctionState.validate_exitc                 C   s6   | j }|d | _ dtj|f }|d ur|d| 7 }|S )Nr   ś%s%drĪ   )r!  r   Ślabel_prefix)rę   r0  ŚnŚlabelrė   rė   rģ   r#    s   
zFunctionState.new_labelŚyieldc                 C   s0   |   d| ”}t| jd |f}| j |” |S )Nzresume_from_%sr   )r#  rÆ   r(  rG  )rę   Ś	expr_typerB  Śnum_and_labelrė   rė   rģ   Śnew_yield_label   s   zFunctionState.new_yield_labelr;  c                 C   s   | j }|  |d ”| _ |S )NŚerror)r   r#  )rę   ŚprefixŚold_err_lblrė   rė   rģ   r%  ¦  s   zFunctionState.new_error_labelc                 C   s   | j | jfS ró   ©r&  r'  rō   rė   rė   rģ   Śget_loop_labels«  s   žzFunctionState.get_loop_labelsc                 C   s   |\| _ | _d S ró   rJ  ©rę   Ślabelsrė   rė   rģ   Śset_loop_labels°  s   ’zFunctionState.set_loop_labelsc                 C   s.   |   ” }|  |  |d ”|  |d ”f” |S )NŚcontinueŚbreak)rK  rN  r#  )rę   rH  Ś
old_labelsrė   rė   rģ   Śnew_loop_labels“  s   ’’zFunctionState.new_loop_labelsc                 C   s   | j | j| j| jfS ró   ©r&  r'  r$  r   rō   rė   rė   rģ   Śget_all_labels»  s
   üzFunctionState.get_all_labelsc                 C   s   |\| _ | _| _| _d S ró   rS  rL  rė   rė   rģ   Śset_all_labelsĀ  s
   żzFunctionState.set_all_labelsc                 C   sR   |   ” }g }t|g d¢D ]\}}|r| |  |”” q| |” q|  |” |S )N)rO  rP  r  rG  )rT  rĶ   rG  r#  rU  )rę   rQ  Ś
new_labelsŚ	old_labelr0  rė   rė   rģ   Śall_new_labelsČ  s   
zFunctionState.all_new_labelsc                 C   ó   | j  |” d S ró   )r"  rM  ©rę   Ślblrė   rė   rģ   Ś	use_labelÓ  ó   zFunctionState.use_labelc                 C   s
   || j v S ró   )r"  rZ  rė   rė   rģ   Ś
label_usedÖ  r¢  zFunctionState.label_usedFTc                 C   s^  |j r
|js
|j}n/|jr|js|j}n%|jr#ddlm} | |”}n|j	r9|js9| j
jd r9| j
 t dd”” |js>d}| j ||f”}|r^|dur^|d r^|d  ” }|d  |” n)	 |  jd7  _d
tj| jf }|| jvrtnq_| j ||||f” |s| j |” ||f| j|< tjr | j  d|||rdndf ” | j!r­| j!d  ||f” |S )a
  
        Allocates a temporary (which may create a new one or get a previously
        allocated and released one of the same type). Type is simply registered
        and handed back, but will usually be a PyrexType.

        If type.needs_refcounting, manage_ref comes into play. If manage_ref is set to
        True, the temp will be decref-ed on return statements and in exception
        handling clauses. Otherwise the caller has to deal with any reference
        counting of the variable.

        If not type.needs_refcounting, then manage_ref will be ignored, but it
        still has to be passed. It is recommended to pass False by convention
        if it is known that type will never be a reference counted type.

        static=True marks the temporary declaration with "static".
        This is only used when allocating backing store for a module-level
        C array literals.

        if reusable=False, the temp will not be reused after release.

        A C string referring to the variable is returned.
        r   ©Ś
PyrexTypesŚ
cpp_localsŚOptionalLocalsśCppSupport.cppFNr   Tr?  z/* %s allocated (%s)%s */r;  ś	 - zombierŻ   )"Śis_cv_qualifiedŚis_referenceŚcv_base_typeŚis_fake_referenceŚref_base_typeŚis_cfunctionr;  r`  Ś
c_ptr_typeŚis_cpp_classrĻ  Ś
directivesrŃ  r  rd  Śneeds_refcountingr.  rö   ŚpopŚremover1  r   Ścodewriter_temp_prefixr  r-  rG  r0  rM  r/  r   Śdebug_temp_code_commentsr  rų   r3  )rę   rĖ   Ś
manage_refŚstaticŚreusabler`  ŚfreelistŚresultrė   rė   rģ   Śallocate_tempŪ  s:   żzFunctionState.allocate_tempc                 C   s¬   | j | \}}| j ||f”}|du rg t f}|| j||f< ||d v r+td| || jvr7|d  |” |d  |” tj	rT| j
 d||| jv rMdndf ” dS dS )zv
        Releases a temporary so that it can be reused by other code needing
        a temp of the same type.
        Nr   zTemp %s freed twice!r   z/* %s released %s*/rd  r;  )r/  r.  rö   rĆ   rk   r0  rG  rM  r   rr  r  rų   )rę   r0  rĖ   rs  rv  rė   rė   rģ   Śrelease_temp  s   

’’zFunctionState.release_tempc                 C   sV   g }| j D ]#\}}}}| j ||f”}|du s||d vr(| |||o%|jf” q|S )zxReturn a list of (cname,type,manage_ref) tuples of temp names and their type
        that are currently in use.
        Nr   )r-  r.  rö   rG  rn  )rę   Śusedr0  rĖ   rs  rt  rv  rė   rė   rģ   r;  (  s   zFunctionState.temps_in_usec                 C   s   dd |   ” D S )zĘReturn a list of (cname,type) tuples of temp names and their type
        that are currently in use. This includes only temps
        with a reference counted type which owns its reference.
        c                 S   s$   g | ]\}}}|r|j r||fqS rė   )rn  )r^  r0  rĖ   rs  rė   rė   rģ   rc  8  s    žžz9FunctionState.temps_holding_reference.<locals>.<listcomp>)r;  rō   rė   rė   rģ   Śtemps_holding_reference3  s   ’z%FunctionState.temps_holding_referencec                 C   s   dd | j D S )zRReturn a list of (cname, type) tuples of refcount-managed Python objects.
        c                 S   s    g | ]\}}}}|r||fqS rė   rė   )r^  r  rĖ   rs  rt  rė   rė   rģ   rc  ?  s    
žz3FunctionState.all_managed_temps.<locals>.<listcomp>)r-  rō   rė   rė   rģ   Śall_managed_temps<  s   ’zFunctionState.all_managed_tempsc                 C   s   t dd | j ” D S )ząReturn a list of (cname, type) tuples of refcount-managed Python
        objects that are not currently in use.  This is used by
        try-except and try-finally blocks to clean up temps in the
        error case.
        c                 S   s.   g | ]\\}}}|r|d  D ]}||fqqS ©r   rė   )r^  rĖ   rs  rv  r  rė   rė   rģ   rc  I  s    žżž’z8FunctionState.all_free_managed_temps.<locals>.<listcomp>)rĘ   r.  r,  rō   rė   rė   rģ   Śall_free_managed_tempsC  s   žz$FunctionState.all_free_managed_tempsc                 C   s   | j  t ” dS )zJ
        Useful to find out which temps were used in a code block
        N)r3  rG  rĆ   rō   rė   rė   rģ   Śstart_collecting_tempsO  s   z$FunctionState.start_collecting_tempsc                 C   ó
   | j  ” S ró   )r3  ro  rō   rė   rė   rģ   Śstop_collecting_tempsU  r¢  z#FunctionState.stop_collecting_tempsc                 C   s   t || _d S ró   )ŚClosureTempAllocatorr2  ©rę   rĻ  rė   rė   rģ   Śinit_closure_tempsX  ó   z FunctionState.init_closure_tempsró   )rC  )r;  )FT)rü   rż   rž   rĆ   rķ   r>  r#  rF  r%  rK  rN  rR  rT  rU  rX  r\  r^  rx  ry  r;  r{  r|  r~  r  r  r  rė   rė   rė   rģ   r  R  s.    +




:	r  c                   @   s   e Zd ZdZdddZdS )ŚNumConstzāGlobal info about a Python number constant held by GlobalState.

    cname       string
    value       string
    py_type     string     int, long, float
    value_code  string     evaluation code if different from value
    Nc                 C   s    || _ || _|| _|p|| _d S ró   )r  ŚvalueŚpy_typeŚ
value_code)rę   r  r  r  r  rė   rė   rģ   rķ   e  s   zNumConst.__init__ró   ©rü   rż   rž   r’   rķ   rė   rė   rė   rģ   r  \  s    r  c                   @   s   e Zd ZdZdd ZdS )ŚPyObjectConstz>Global info about a generic constant held by GlobalState.
    c                 C   s   || _ || _d S ró   )r  rĖ   ©rę   r  rĖ   rė   rė   rģ   rķ   r  s   
zPyObjectConst.__init__Nr  rė   rė   rė   rģ   r  l  s    r  )Śpossible_unicode_identifierŚpossible_bytes_identifierŚreplace_identifierŚfind_alphanumsz(?![0-9])\w+$s   (?![0-9])\w+$z[^a-zA-Z0-9_]+z([a-zA-Z0-9]+)c                   @   s"   e Zd ZdZdd ZdddZdS )ŚStringConstz?Global info about a C string constant held by GlobalState.
    c                 C   s(   || _ || _t |”| _d | _d| _d S ©NF)r  Śtextr	   Śescape_byte_stringŚescaped_valueŚ
py_stringsŚc_used)rę   r  r  Śbyte_stringrė   rė   rģ   rķ     s
   
zStringConst.__init__Nc           
      C   s*  | j }|s	|d u rd  }}d}nd}| ” }|dv rd }d }nd t|”}|r+d}n|d u rBt|tr;tt|}n	tt|}nd}|||f}| j	d u rRi | _	nz| j	| W S  t
ya   Y nw |ritjd ntj |rpdnd |rxd| nd d| jttjd   }t||||}	|	| j	|< |	S )	NTF)Śutf8śutf-8r   Śusasciizus-asciir;  r'   ŚuŚbrĪ   )r  Ślowerr  r  r¬   r   r   r  r  r  rX   r   Śinterned_prefixesŚpy_const_prefixr  rÆ   Śconst_prefixŚPyStringConst)
rę   r	  r  r  Śencoding_keyŚ
is_unicodeŚinternrš   Śpystring_cnameŚ	py_stringrė   rė   rģ   r    sH   


’
’žż’
zStringConst.get_py_string_constró   )rü   rż   rž   r’   rķ   r  rė   rė   rė   rģ   r  ~  s    r  c                   @   s"   e Zd ZdZdddZdd ZdS )	r¢  zDGlobal info about a Python string constant held by GlobalState.
    Fc                 C   s   || _ || _|| _|| _d S ró   )r  r	  r¤  r„  )rę   r  r	  r„  r¤  rė   rė   rģ   rķ   Č  ó   
zPyStringConst.__init__c                 C   s   | j |j k S ró   ©r  ©rę   rń   rė   rė   rģ   Ś__lt__Ī  ó   zPyStringConst.__lt__N©FF)rü   rż   rž   r’   rķ   r«  rė   rė   rė   rģ   r¢  Ą  s    
r¢  c                   @   s  e Zd Zi Zg d¢Zg d¢Zd^ddZdd Zdd	 Zd
d Z	dd Z
dd Zdd Zd^ddZd_ddZdd Zd^ddZdd Zd`ddZd d! Zd^d"d#Zd$d% Zd&d' Zd(d) Zd^d*d+Zd,d- Zd.d/ Zd0d1 Zdad3d4Zd5efd6d7Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#d`dBdCZ$dDdE Z%dFdG Z&dHdI Z'dJe(dKe(fdLdMZ)dNdO Z*dPdQ Z+e,dRdS Z-dTdU Z.dVdW Z/dXdY Z0d^dZd[Z1d\d] Z2dS )br  ))Śh_codeŚfilename_tableŚutility_code_proto_before_typesŚnumeric_typedefsŚcomplex_type_declarationsŚtype_declarationsr  Śmodule_declarationsŚtypeinfoŚbefore_global_varŚ
global_varŚstring_declsŚdeclsŚlate_includesŚmodule_staterĖ  Śmodule_state_endŚconstant_name_definesr  rĶ  Śmodule_state_clear_endr  rĢ  Śmodule_state_traverse_endŚmodule_codeŚmodule_exttypesŚinitfunc_declarationsŚinit_moduleŚpystring_tableŚcached_builtinsŚcached_constantsŚinit_constantsŚinit_codeobjectsrĄ  rŹ  Ścleanup_moduleŚmain_methodŚutility_code_pragmasrÉ  Śutility_code_pragmas_endŚend)r®  r°  r³  r  rĶ  Nc                 C   s   i | _ g | _i | _t | _i | _d| _|| _|| _i | _	|| _
i | _i | _i | _i | _g | _i | _g | _i | _i | _t | _g | _| | ” || _d S r  )rÆ  Śfilename_listŚinput_file_contentsrĆ   Śutility_codesŚdeclared_cnamesŚin_utility_code_generationŚcode_configŚcommon_utility_include_dirŚpartsrĪ  Śconst_cnames_usedŚstring_const_indexŚdedup_const_indexŚpyunicode_ptr_const_indexŚcodeobject_constantsŚnum_const_indexŚarg_default_constantsŚconst_array_countersŚcached_cmethodsŚinitialised_constantsr  Śset_global_stater  )rę   r“  rĪ  rÓ  rŌ  rė   rė   rģ   rķ   &  s.   

zGlobalState.__init__c                 C   s“  | j }t| jD ]\}}| ”  }| j|< |dkr | d| ” q| jd }| dtj dtj	 d” | dtj	 d” | jd	 }|jd
tj dtj	 ddd | dtj	 d” | 
t d”” | jd }| d” | jd }| dtj dtj	 d” | dtj	 d” tjs| jd= n| jd }| dtj dtj	 d” | dtj	 d” | jd }| d” | d” | jd }| jjrĪ| d” | d” | d” d S )Nr   z/* #### Code section: %s ### */rÅ  zint __Pyx_InitCachedBuiltins(ś *r)  śCYTHON_UNUSED_VAR(ś);rĘ  zint __Pyx_InitCachedConstants(T)ŚrefnannyŚ__Pyx_InitCachedConstantsrĄ  zint __Pyx_InitGlobals(void)rĒ  zint __Pyx_InitConstants(rŹ  zvoid __Pyx_CleanupGlobals(r  r;  z)/* --- Runtime support code (head) --- */rÉ  z
#line 1 "cython_utility"
z"/* --- Runtime support code --- */)r  r   Ścode_layoutŚinsertion_pointrÕ  rų   Śstart_initcfuncr   Śmodulestatetype_cnameŚmodulestatevalue_cnameŚput_setup_refcount_contextr	   r  r   rÓ  rÓ  Śemit_linenumsrū   )rę   r  Śir  Śwrł   rė   rė   rģ   Śinitialize_main_c_codeB  sp   
’’’
’’ż


’’’

’’’





z"GlobalState.initialize_main_c_codec                 C   s$   | j }| jD ]	}| ” | j|< qd S ró   )r  Śh_code_layoutrē  rÕ  )rę   r  r  rė   rė   rģ   Śinitialize_main_h_codes  s   
’z"GlobalState.initialize_main_h_codec                 C   s¢   |   ”  | jd }t dd”}| | |j”” | d” | jd }t dd”}| | |j”” | d” | jd }t d	d”}| | |j”” | d” d S )
NrÉ  ŚTypeConversionszTypeConversion.cr;  rĖ  ŚUtilityCodePragmasśModuleSetupCode.crĢ  ŚUtilityCodePragmasEnd)	Śclose_global_declsrÕ  rg  rd  Śputrm  r+  rų   r  )rę   rł   rt  rė   rė   rģ   Śfinalize_main_c_codex  s   




z GlobalState.finalize_main_c_codec                 C   ó
   | j | S ró   )rÕ  )rę   rš   rė   rė   rģ   Ś__getitem__  r¢  zGlobalState.__getitem__c                 C   sz  |   ”  | jd }| d” | |j”r| |j” | d” | d” | ”  | jd }dD ]}|| jv rF|  | 	t
j| ”| j| |” q/| ”  | d” | |j”re| |j” | ”  | d” | d” | ”  dD ]&}| j| }| d” | |j”r| |j” | d” | d” | ”  qptjrØ| jd }| d” | ”  tjr»| jd	 }| d” | ”  d S d S )
NrÅ  ś	return 0;ś
return -1;Ś}rĘ  )rŹ   rÅ   )rĄ  rĒ  rŹ  rÉ  )Śgenerate_const_declarationsrÕ  rų   r^  r   Ś	put_labelŚexit_cfunc_scoperŻ  Śimmortalize_constantsŚname_in_module_stater   Śpyrex_prefixŚput_finish_refcount_contextr   rÓ  )rę   rī  Ś
const_typer  rė   rė   rģ   rö    sT   





ż











żzGlobalState.close_global_declsc                 C   s   | d   d|j ” d S )Nr·  zstatic PyObject *%s;)rų   r  ©rę   Śentryrė   rė   rģ   Śput_pyobject_declÅ  ó   zGlobalState.put_pyobject_declc                 C   s,   |d ur|| j v rd S | j  |” | jd S )NrĘ  )rß  rM  rÕ  ©rę   Śtargetrė   rė   rģ   Śget_cached_constants_writerŹ  s
   

z'GlobalState.get_cached_constants_writerFc                 C   sB   |rdpd}z
| j ||f }W |S  ty    |  ||”}Y |S w )NŚlongr«   ©rŪ  rX   Śnew_num_const)rę   Ś	str_valueŚlongnessr  Ścrė   rė   rģ   Śget_int_constŅ  s   žžzGlobalState.get_int_constc                 C   s8   z
| j |df }W |S  ty   |  |d|”}Y |S w )Nr”   r  )rę   r  r  r  rė   rė   rģ   Śget_float_constŚ  s   žžzGlobalState.get_float_constc                 C   s@   |d ur| j  |”}|d ur|S |  |”}|d ur|| j |< |S ró   )rŲ  rö   Śnew_array_const_cname)rę   rH  Ś	dedup_keyŚconstrė   rė   rģ   Śget_py_constį  s   

zGlobalState.get_py_constc                 C   s$   |   d”}t||}| j |” |S ©Nr;  )Śnew_const_cnamer  rÜ  rG  )rę   rĖ   r  r  rė   rė   rģ   Śget_argument_default_constė  s   

z&GlobalState.get_argument_default_constTc                 C   sT   |j r| ” }n| ” }z| j| }W n ty"   |  ||”}Y nw |r(d|_|S ©NT)r¤  Ś
utf8encodeŚ
byteencoder×  rX   Śnew_string_constr  )rę   r  r  r  r  rė   rė   rģ   Śget_string_constō  s   
’zGlobalState.get_string_constc                 C   sB   |j sJ z| j| }W |S  ty    |  ”  }| j|< Y |S w ró   )r¤  rŁ  rX   r  )rę   r  r  rė   rė   rģ   Śget_pyunicode_ptr_const  s   
žžz#GlobalState.get_pyunicode_ptr_constc                 C   s    | j |dd}| |j|”}|S )NF)r  )r   r  r	  )rę   r  r  Śc_stringr§  rė   rė   rģ   r    s   zGlobalState.get_py_string_constc                 C   s,   t | j}tj d| d}| j |” |S )Nś[ś])rÆ   rŚ  r   Ścodeobjtab_cnamerG  )rę   ŚnodeŚidxr0  rė   rė   rģ   Śget_py_codeobj_const  s   
z GlobalState.get_py_codeobj_constc                 C   ó   | j |ddS ©NTr   ©r  ©rę   r  rė   rė   rģ   Śget_interned_identifier  r  z#GlobalState.get_interned_identifierc                 C   s$   |   |”}t|||}|| j|< |S ró   )Śnew_string_const_cnamer  r×  )rę   r  r  r  r  rė   rė   rģ   r    s   

zGlobalState.new_string_constc                 C   s,   |   ||”}t||||}|| j||f< |S ró   )Śnew_num_const_cnamer  rŪ  )rę   r  r  r  r  r  rė   rė   rģ   r     s   zGlobalState.new_num_constc                 C   s   |  dd”}| j|dS )NŚASCIIŚignore)r  )Śdecoder  )rę   Śbytes_valuer  rė   rė   rģ   r.  &  s   z"GlobalState.new_string_const_cnamec                 C   sV   | j }|jddd }}||v r%|| d  }||< |jd|d}||v sd||< |S )Nr;  )Śseprß   r   rĪ   )rÖ  r¢   )rę   Ś
format_strrz  r  r  rß   rė   rė   rģ   Śunique_const_cname+  s   žzGlobalState.unique_const_cnamec                 C   s   |dkr
|d7 }d}t j| }| dd” dd” dd”}t|d	kr:|  |d
 |d d  d |dd   ”}|S d||f }|S )Nr  ŚLr«   r'  rĪ   ś+ś-Śneg_é*   zlarge{counter}_é   Ś_xxx_iī’’’ś%s%s)r   r  r  rÆ   r6  )rę   r  r  rH  r  rė   rė   rģ   r/  4  s   
"’’zGlobalState.new_num_const_cnamer;  c                 C   sH   t d|d d  d”}|  |d ”}|rtj| }ntj}d||f S )NrĪ   é    z{sep}{counter}r>  )r  rL  r6  r   r  r”  )rę   rH  r  Śname_suffixrė   rė   rģ   r  C  s   zGlobalState.new_const_cnamerH  c                 C   s2   | j  |d”}|d | j |< tj | d| dS )Nr   r   r#  r$  )rŻ  rö   r   r  )rę   rH  Ścountrė   rė   rģ   r  L  s   z!GlobalState.new_array_const_cnamec              	   C   sL   ||f}z| j | }W |S  ty%   |  dd||f ” }| j |< Y |S w )NŚumethodz%s_%s)rŽ  rX   r  )rę   r÷  rų  rš   r  rė   rė   rģ   Śget_cached_unbound_methodQ  s   ż’żz%GlobalState.get_cached_unbound_methodc           	      C   sJ   dt | }|  t |d”” |  ||”}|g| }d|||d |”f S )NzCallUnboundCMethod%dśObjectHandling.cz__Pyx_%s(&%s%s, %s)r8  )rÆ   rŃ  r  rd  rC  r  )	rę   Śmodulestate_cnamerł  r÷  rų  Ś
arg_cnamesrk  Ścache_cnamerś  rė   rė   rģ   rõ  Z  s   
üz+GlobalState.cached_unbound_method_call_codec                 C   sb   |j r+|jr-|  |j|”r/|  |” |j}|tv rt| }|  |jt	 
|”|j” d S d S d S d S ró   )Ś
is_builtinŚis_constŚshould_declarer  r  r0  Śrenamed_py2_builtins_mapŚput_cached_builtin_initŚposr	   r  )rę   r  r0  rė   rė   rģ   Śadd_cached_builtin_declg  s   
žśz#GlobalState.add_cached_builtin_declc              	   C   sN   | j d }| |  |”j”}|  t dd”” | d|||| |”f ” d S )NrÅ  ŚGetBuiltinNamerD  z*%s = __Pyx_GetBuiltinName(%s); if (!%s) %s)	rÕ  Ś name_in_main_c_code_module_stater-  r  rŃ  r  rd  rų   Ś
error_goto)rę   rM  r0  r  rī  Ścname_in_modulestaterė   rė   rģ   rL  r  s   

’
’üz#GlobalState.put_cached_builtin_initc                 C   s,   |   ”  |  ”  |  ”  |  ”  |  ”  d S ró   )Śgenerate_cached_methods_declsŚgenerate_object_constant_declsŚgenerate_codeobject_constantsŚgenerate_string_constantsŚgenerate_num_constantsrō   rė   rė   rģ   rž  ~  s
   z'GlobalState.generate_const_declarationsc                 C   sv   |dk rdnd}|rdnd}| j d }| d| d| d	| d
| d	” | j d }| d| d| d| d” d S )Né   r«   Ś
Py_ssize_tŚPy_VISITŚ__Pyx_VISIT_CONSTr  śfor (z i=0; i<z	; ++i) { z(traverse_module_state->z[i]); }r  z&; ++i) { Py_CLEAR(clear_module_state->)rÕ  rų   )rę   Śstruct_attr_cnamerA  Śmay_have_refcyclesŚcounter_typeŚ
visit_callr“  rė   rė   rģ   Ś)_generate_module_array_traverse_and_clear  s   
$
"z5GlobalState._generate_module_array_traverse_and_clearc           
      C   s>  dd | j D }| ”  |D ]<\}}}| jd  d|j |” ” |jjs&q| jd jd| |jddd	 |jjr>|d
7 }| jd  d| d” qt	| j
 ” D ]J\}}tj | }| jd  d| d| d” | j||dd t|}|d ur|tjkr| jd }	|	 d| d” |	 d|	 | d” ” qRd S )Nc                 S   ó   g | ]}t |j|j|fqS rė   ©rÆ   r  ©r^  r  rė   rė   rģ   rc    s    ’z>GlobalState.generate_object_constant_decls.<locals>.<listcomp>r»  z%s;r  zclear_module_state->TF)Śclear_before_decrefŚnannyz	->memviewr  z Py_VISIT(traverse_module_state->rć  ś
PyObject *r#  ś];©r^  rŹ  zfor (size_t i=0; i<z; ++i) z{ Py_CLEAR(%s); }z[i])rÜ  ŚsortrÕ  rų   rĖ   Śdeclaration_codern  Śput_xdecref_clearŚis_memoryviewslicerĘ   rŻ  r,  r   r  ra  Ścleanup_level_for_type_prefixr   rÓ  r÷  rP  )
rę   ŚconstsrĪ   r  r  rH  rA  r]  Ścleanup_levelŚpart_writerrė   rė   rģ   rT    sD   ’
ü

’
’’õz*GlobalState.generate_object_constant_declsc           	      C   sš   | j sd S | jd }| jd }| d” | d” g }t| j  ” D ]8\\}}}| |” |  t |””j	}| d| ” | d| 
|”|f ” | | 
|” d| 
|” d” q"tjrt| jd	 }|D ]}| d
| 
|” d” qed S d S )Nr»  rÅ  r;  z/* Cached unbound methods */z__Pyx_CachedCFunction %s;z%s.type = (PyObject*)%s;z.method_name = &ś;rŹ  z	Py_CLEAR(z	.method);)rŽ  rÕ  rų   rĘ   r,  rG  r-  r	   r  r  rP  r   rÓ  )	rę   Śdeclr  Ścnamesr÷  rų  r  Śmethod_name_cnamer  rė   rė   rģ   rS  ¼  s6   




’
’’’
żz)GlobalState.generate_cached_methods_declsc                 C   sŠ  g }g }g }t dd | j ” D D ]H\}}}|jr'| t|j|j|jf” |jrZ|j ” D ]*}|j	}|j
rGt|tsGt | |jpDd””}|j
rL|n| |joS|j
|j|f” q/q| ”  | ”  | ”  | jd }|D ]\}}	}
t |
”}|jd|	 d| ddd	 qnt | j ” D ]0\}}	t |”\}}|r | d
” | d|	|f ” |r¾| d” | d|	|f ” | d” qt|t| }| jd  dtj d| d” | jtj|dd |  ||” d S )Nc                 S   rb  rė   rc  rd  rė   rė   rģ   rc  ß  s    z9GlobalState.generate_string_constants.<locals>.<listcomp>r  rø  zstatic const char z[] = "ś";T©Śsafez#ifdef Py_UNICODE_WIDEz static Py_UNICODE %s[] = { %s };ś#elseś#endifr»  rg  r#  rh  Fri  )rĘ   r×  rj  r  rG  rÆ   r  r  r  r  r¤  r¬   r'   r	   r  r2  r	  r„  rj  rÕ  Śsplit_string_literalrų   rŁ  r,  Śencode_pyunicode_stringr   Śstringtab_cnamera  Śgenerate_pystring_constants)rę   Śc_constsŚpy_bytes_constsŚpy_unicode_constsrĪ   r  r§  r  Śdecls_writerr  r  ŚcliteralŚutf16_arrayŚutf32_arrayŚpy_string_countrė   rė   rģ   rV  Ł  sR   "
ż

ž


 z%GlobalState.generate_string_constantsŚtext_stringsŚbyte_stringsc                 C   sä  | j d }g }d}d}t|D ]+\}\}}	}
| |
 d”” |dkr&|r&|}| d|	 dtj d| d” |d	7 }qt|}|D ]'\}}	}
| |
jrO|
 	” n|
 
” ” | d|	 dtj d| d” |d	7 }qAttt|}d
 |”}| j d }| d” | dt| ”  dd dd |D ” d” |  t dd”” d}ttD ]\}}}|d u r°q¦||}t|t|d kræq¦|dkrĪ|d	ksĖJ dd}n|dkrŁd| d}nd| }| d|sådnd d| d | d!t| d"	” d#}t t |””}|jd$| d%d#d& | d't| d(| d)” | | d*| j”” | d+” | d,” | d-| | j” d.” | d/” q¦|rN| d0t| d"” t t |””}|jd1| d%d#d& | d2” | d3” |rs| d/” | d4| tj” d5” | d6” |dkrÜ| d7|d8k rd9nd: d;| d<” | d=” | d>” |dkrµ| d?| d@” | dA” | dB” | | | j”” | dC” | dD” | dE” | dC” |t|k r.| d7t|d8k rļd9nd: dF| dGt| d<” | d=” | dH” | dD” | dE” | dA” | dB” | | | j”” | dC” | dC” | dB” | dIt| d<” | dJ” | | | j”” | dC” | dC” |t|k rk|  dK| t|| |” | dC” d S )LNr½  rŻ   r   r  ś#define r  r#  r$  r   ó    rĒ  Ś{z*const struct { const unsigned int length: z; } index[] = {ró  c                 S   s   g | ]}d | qS )z{%d}rė   )r^  Ślengthrė   rė   rģ   rc  1  rņ  z;GlobalState.generate_pystring_constants.<locals>.<listcomp>ś};ŚDecompressStringzStringTools.cFé
   r!   zBCompression algorithm no. 1 must be 'zlib' to be used as fallback.z(CYTHON_COMPRESS_STRINGS) != 0r&   z(CYTHON_COMPRESS_STRINGS) == z+ && __PYX_LIMITED_VERSION_HEX >= 0x030e0000r:  ŚifŚelifz /* compression: z (z
 bytes) */Tzconst char* const cstring = "rv  rw  z1PyObject *data = __Pyx_DecompressString(cstring, r8  rć  rÆ  z7const char* const bytes = __Pyx_PyBytes_AsString(data);z#if !CYTHON_ASSUME_SAFE_MACROSz,if (likely(bytes)); else { Py_DECREF(data); z }rz  z#else /* compression: none (zconst char* const bytes = "zPyObject *data = NULL;z*CYTHON_UNUSED_VAR(__Pyx_DecompressString);zPyObject **stringtab = rr  zPy_ssize_t pos = 0;r\  rX  r«   rY  ś i = 0; i < ś; i++) {z*Py_ssize_t bytes_length = index[i].length;zIPyObject *string = PyUnicode_DecodeUTF8(bytes + pos, bytes_length, NULL);zif (likely(string) && i >= z#) PyUnicode_InternInPlace(&string);zif (unlikely(!string)) {zPy_XDECREF(data);rż  zstringtab[i] = string;zpos += bytes_length;z i = z; i < zHPyObject *string = PyBytes_FromStringAndSize(bytes + pos, bytes_length);zfor (Py_ssize_t i = 0; i < z2if (unlikely(PyObject_Hash(stringtab[i]) == -1)) {zstringtab + )rÕ  r   rG  Śencoderų   r   r}  rÆ   r	  r  r  r±   r³   r  r“   Ś
bit_lengthrŃ  r  rd  rĮ   Ścompression_algorithmsr	   r{  r  Śerror_goto_if_nullrĆ  rQ  rP  r  )rę   r  r  ŚdefinesŚbytes_valuesŚfirst_internedŚstringtab_posrķ  Śis_internedr  r  Śstringtab_bytes_startrĪ   ŚindexŚconcat_bytesrī  Śhas_ifŚalgo_numberŚ	algo_namer   Ścompressed_bytesŚguardŚescaped_bytesrė   rė   rģ   r~    sĀ   
 
 




’ż’
0’

’




&








4











z'GlobalState.generate_pystring_constantsc                 C   sü  | j d }dtj dtj d}| js2| |” | dtj d” | d” | ”  | d” d S d	}d
}d
}d
}d
}d
}| jD ]/}	|	j}
|
j	s`t
|t|
j|
j }t
||
j}t
||
j}t
|t|	j}t
||
jd
 }qA| t d| ”  d| ”  d| ”  d| ”  d| ”  d| ”  d”” |  t dd”” | |” | d” | d” | jD ]}	|	 |d” q³| d” | d” | d” | d” | d” | ”  | d” t| j}| j d  dtj d| d” | jtj|dd d S ) NrČ  zint __Pyx_CreateCodeObjects(rį  r)  rā  rć  rū  rż  i’  r   z=        typedef struct {
            unsigned int argcount : z.;
            unsigned int num_posonly_args : z-;
            unsigned int num_kwonly_args : z%;
            unsigned int nlocals : z#;
            unsigned int flags : z(;
            unsigned int first_line : z;;
        } __Pyx_PyCode_New_function_description;
        Ś
NewCodeObjrō  z)PyObject* tuple_dedup_map = PyDict_New();z*if (unlikely(!tuple_dedup_map)) return -1;ŚbadzPy_DECREF(tuple_dedup_map);zbad:rü  r»  rg  r#  rh  Fri  )rÕ  r   ré  rź  rŚ  rč  rų   r   Śdef_nodeŚis_generator_expressionr“   rÆ   rś  Śnum_kwonly_argsŚnum_posonly_argsŚvarnamesrM  r÷  r   Śdedentr  rŃ  r  rd  Śgenerate_codeobjr%  ra  )rę   rī  Śinit_functionŚ	max_flagsŚmax_func_argsŚmax_kwonly_argsŚmax_posonly_argsŚmax_varsŚmax_liner&  rØ  Ścode_object_countrė   rė   rģ   rU    sj   
’




žżüūśł










 z)GlobalState.generate_codeobject_constantsc                     s6  dd | j  ” D }| ”  |sd S t|}| jd  dtj d| d” | jtj|dd g }g g}g }d	}d
}|D ]h\}}	}	}
}}|j	}|dkrS| 
||f” q<t |
”}| ” }|dkr|d d dt|d > kr| 
g ” dd t|d  }|d d dt|d > ksn|d7 }|d  
|| | f” q<| 
||f” q<| jd }| jd }dtdtdtfdd}dtjfdd}dtfdd}dAdtdtjfd d!}d	}|r| d"” | d#| tj” d$” ||d%d&| |||| ||t| ||| jd' | d(” | d(” |t|7 }|d	krÆ| d"” | d#| tj” d)| d$” g d*¢}d+}d	}t|dD ]F\}}|sFq=d,d|d >  }||||| | |||||  | d-| d.}|t|7 }||t|krx|nd/| d0| d1; }q=||| t|d2krd3nd4}||| j| d5| d6 | d(” | d(” ||7 }|rd7d8  | d"” | d#| tj” d)| d$” d9  fd:d|D ” d;”}| d<t |” d=” |||| ||t| | d>” ||| jd? | d@” | d(” | d(” |  | tj”||” d S )BNc                 S   s6   g | ]}|j t|j d ”|j d ”|j|j|fqS )r9  )r  rÆ   r  Ślstripr  rd  rė   rė   rģ   rc  Ž  s    .’z6GlobalState.generate_num_constants.<locals>.<listcomp>r»  rg  r#  rh  Fri  r   r;  r”   é?   é   r   ŚLLr   rŻ   rĒ  r½  r0  r9  Ś	constantsc                 S   s4   d  dd |D ”}|  | d| d| d” d S )Nró  c                 S   s   g | ]}|d  qS ©r   rė   rd  rė   rė   rģ   rc  	  rņ  zKGlobalState.generate_num_constants.<locals>.store_array.<locals>.<listcomp>z const z[] = {r  )r  rų   )rī  r0  r9  r»  rj  rė   rė   rģ   Śstore_array	  s    z7GlobalState.generate_num_constants.<locals>.store_arrayrĶ  c                 S   s,   |dk rdnd}|   d| d| d” d S )NrX  r«   rY  r\  r  r  ©rų   )rī  rĶ  r_  rė   rė   rģ   Śgenerate_forloop_start	  s   zBGlobalState.generate_num_constants.<locals>.generate_forloop_startŚrhs_codec                 S   s(   |   d| d” |   |  d|”” d S )Nznumbertab[i] = rr  znumbertab[i])rų   r  )rī  Ś	error_posrĄ  rė   rė   rģ   Śassign_constant	  s   z;GlobalState.generate_num_constants.<locals>.assign_constantŚstart_offsetc              
   S   sF   t j}t|D ]\}}|d }|  d| d| d||  d” qd S )Nr   r  r  r#  r$  )r   Śnumbertab_cnamer   rų   )r  r»  rĆ  rÄ  rķ  r  r  rė   rė   rģ   Śdefine_constants	  s
   $žz<GlobalState.generate_num_constants.<locals>.define_constantsr  zPyObject **numbertab = rr  Śc_constantsŚdoublez"PyFloat_FromDouble(c_constants[i])rż  z + )r;  Śint8_tŚint16_tŚint32_tŚint64_tś%sŚcint_constants_z[i - r$  z(i < z ? z : %s)r%   ŚPyLong_FromLongŚPyLong_FromLongLongś(r)  c                 S   sh   | dk }|r	|  } t  }| r!| d@ }d| }| |” | dL } | s|s%dS |r.| td” | ”  |S )Nr   é   s    0123456789abcdefghijklmnopqrstuvé   ó   0ó   -)r   rG  r»   Śreverse)ŚnumberŚis_negŚdigitsŚdigitŚ
digit_charrė   rė   rģ   Ś	to_base32L	  s    
üz5GlobalState.generate_num_constants.<locals>.to_base32s   \000c                    s   g | ]} |d  qS r¼  rė   rd  ©rŪ  rė   rģ   rc  a	  s    r   zconst char* c_constant = "rv  zchar *end_pos;z+PyLong_FromString(c_constant, &end_pos, 32)zc_constant = end_pos + 1;r}  )rŪ  rj  rj  rÆ   rÕ  rų   r   rÄ  ra  r  rG  r
   Śstr_to_numberr  r'   r±   rÖ  rY  rP  rĆ  r   r  r2  r	   r{  r  ) rę   ro  Śconstant_countŚfloat_constantsŚint_constants_by_bytesizeŚlarge_constantsŚint_constant_countŚ
int_suffixr  rĪ   r  r  r  r  Śnumber_valuer  rī  r  r½  ræ  rĀ  rÅ  Śconstant_offsetŚ	int_typesŚarray_accessŚint_constants_seenŚ	byte_sizer»  Ś
array_nameŚ	read_itemŚ	capi_funcr"  rė   rÜ  rģ   rW  Ż  s®   ’ 

ś






 ž



 




żz"GlobalState.generate_num_constantsc                 C   sŅ   |  d” |  d” |  d|  d” |  d| d” |  d” |  d” |  d	” |  d
” |  d” |  d” |  d” |  d” |  d” |  d
” |  d” |  d” |  d” |  d” |  d” d S )Nz#if CYTHON_IMMORTAL_CONSTANTSr  zPyObject **table = rr  zfor (Py_ssize_t i=0; i<z; ++i) {ś-#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADINGz#if PY_VERSION_HEX < 0x030E0000zEif (_Py_IsOwnedByCurrentThread(table[i]) && Py_REFCNT(table[i]) == 1)ry  z5if (PyUnstable_Object_IsUniquelyReferenced(table[i]))rz  z3Py_SET_REFCNT(table[i], _Py_IMMORTAL_REFCNT_LOCAL);rż  z5Py_SET_REFCNT(table[i], _Py_IMMORTAL_INITIAL_REFCNT);r¾  )Śarray_cnamerŽ  r“  rė   rė   rģ   r  r	  s&   















z!GlobalState.immortalize_constantsc                 C   sN   || j v r | j | }t|jt|jksJ |j|jksJ dS || j |< dS )NFT)rŃ  r'   rĖ   r  )rę   r  r  rń   rė   rė   rģ   rJ  	  s   


zGlobalState.should_declarec                 C   sN   |  ” }z| j| }W |S  ty&   t| j}| j |” || j|< Y |S w ró   )Śget_filenametable_entryrÆ  rX   rÆ   rĪ  rG  )rę   Śsource_descr  r  rė   rė   rģ   Ślookup_filename	  s   ü
üzGlobalState.lookup_filenamec                 C   sX   z| j | W S  ty   Y nw |jddd}dd |D }|s%| d” || j |< |S )Nr0  r1  )r	  Śerror_handlingc                 S   s0   g | ]}d d|v r|  dd”  dd”n| qS )z * r<  r  z.*[inserted by cython to avoid comment closer]/r  z-/[inserted by cython to avoid comment start]*)r  rź  rė   rė   rģ   rc  ®	  s    śü’’ūz7GlobalState.commented_file_contents.<locals>.<listcomp>r;  )rĻ  rX   Ś	get_linesrG  )rę   rš  Śsource_fileŚFrė   rė   rģ   Ścommented_file_contentsØ	  s   ’ś
z#GlobalState.commented_file_contentsc                 C   s4   |r|| j vr| j  |” |j| |d dS dS dS )a  
        Adds code to the C file. utility_code should
        a) implement __eq__/__hash__ for the purpose of knowing whether the same
           code has already been included
        b) implement put_code, which takes a globalstate instance

        See UtilityCode.
        rČ  N)rŠ  rM  r  )rę   rŪ  r  rė   rė   rģ   rŃ  ¾	  s   	žzGlobalState.use_utility_codec                 C   sr   |d u rd S |j r|  |j ” |jr|  |j” ddlm} | |j”D ]}t|dr6|j|ur6|  	|j” q$d S )Nr   r_  r  )
rŪ  rŃ  Śutility_code_definitionr;  r`  Śget_all_subtypesrĖ   r¦   r  Śuse_entry_utility_code)rę   r  r`  Śtprė   rė   rģ   rł  Ė	  s   žz"GlobalState.use_entry_utility_coderó   r}  ©T)r;  r;  )3rü   rż   rž   rm  rę  rš  rķ   rļ  rń  rų  rś  rö  r  r  r  r  r  r  r   r!  r  r(  r-  r  r  r.  r6  r/  r  r'   r  rC  rõ  rN  rL  rž  ra  rT  rS  rV  r±   r~  rU  rW  rĒ   r  rJ  rń  rö  rŃ  rł  rė   rė   rė   rģ   r  Ņ  sb    -
10




	
	
	
		


*5 A 


r  c                    s2   | j t ”  fdd}fdd}t||S )Nc                    s
    | j S ró   )Ś	funcstaterō   )Śattribute_ofrė   rģ   rö   Ū	  r¢  z!funccontext_property.<locals>.getc                    s   t | j | d S ró   )rÄ   rü  )rę   r  r  rė   rģ   rĆ   Ż	  ó   z!funccontext_property.<locals>.set)rü   r   Ś
attrgetterr¾   )rŽ  rö   rĆ   rė   )rż  r0  rģ   Śfunccontext_propertyŲ	  s
   

r   c                   @   s   e Zd ZdddZdS )ŚCCodeConfigTc                 C   s   || _ || _|| _d S ró   )Śemit_code_commentsrģ  Śc_line_in_traceback)rę   rģ  r  r  rė   rė   rģ   rķ   ē	  s   
zCCodeConfig.__init__N)TTT)rü   rż   rž   rķ   rė   rė   rė   rģ   r  ā	  s    r  c                   @   sp  e Zd ZdZejd dd;ddZdd Zd	d
 Zdd Z	dd Z
dd Zejdd Zdd Zdd Zdd Zdd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zd<d,d-Zd=d.d/Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(d>dHdIZ)d?dJdKZ*dLdM Z+dNdO Z,d=dPdQZ-dRdS Z.dTdU Z/d=dVdWZ0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d=d`daZ5dbdc Z6e7ddde Z8e7dfdg Z9dhdi Z:djdk Z;d@dmdnZ<dAdodpZ=ejdqdr Z>ejdsdt Z?ejdudv Z@dwdx ZAejdydz ZBejd{d| ZCd}d~ ZDdeEfddZFejdd ZGejdd ZHejdd ZIejdd ZJejdd ZKdd ZLdd ZMdd ZN	l	+dBddZOdePfddZQdd ZRdd ZSdd ZTeUfddZVdd  ZWd”d¢ ZXd£d¤ ZYd„d¦ ZZd§dØ Z[d©dŖ Z\dAd«d¬Z]dAd­d®Z^dCdÆd°Z_dCd±d²Z`dDd³d“ZadDdµd¶Zbd·dø Zcd¹dŗ Zdd»d¼ Zed½d¾ ZfdædĄ ZgdĮdĀ ZhdĆdÄ ZidÅdĘ ZjdĒdČ ZkdÉdŹ ZldĖdĢ ZmdĶdĪ ZndĻdŠ ZodŃdŅ ZpdÓdŌ ZqdÕdÖ ZrdEdŲdŁZsdŚdŪ ZtdÜdŻ ZudŽdß ZvdAdądįZwdFdćdäZxdGdådęZydēdč Zzdédź Z{dGdėdģZ|d=dķdīZ}dļdš Z~dńdņ ZdHdódōZdHdõdöZd÷dų Zdłdś ZdIdūdüZdJdżdžZdAd’d Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdJddZdJddZdAddZdJddZdd Zdd ZdJddZd=ddZdKddZdJdd Zd!d" Zd#d$ ZdLd%d&Zd'd( Zd)d* ZdJd+d,Zd-d. Zd>d/d0ZeE d1d2”fd3d4Z d5d6 Z”d7d8 Z¢d9d: Z£dS (M  rµ  a¦  
    Utility class to output C code.

    When creating an insertion point one must care about the state that is
    kept:
    - formatting state (level, bol) is cloned and used in insertion points
      as well
    - labels, temps, exc_vars: One must construct a scope in which these can
      exist by calling enter_cfunc_scope/exit_cfunc_scope (these are for
      sanity checking and forward compatibility). Created insertion points
      looses this scope and cannot access it.
    - marker: Not copied to insertion point
    - filename_table, filename_list, input_file_contents: All codewriters
      coming from the same root share the same instances simultaneously.
    ©Ścreate_fromNFc                 C   s   |d u rt  }|| _d | _d | _g | _d | _d | _d | _d| _d| _	d| _
|d urK|  |j” |j| _|rA|j| _|j
| _
|j	| _	|j| _|j| _d S d S )Nr   r   )r   ŚbufferŚlast_posŚlast_marked_posŚpyclass_stackrü  r  rÓ  r#   Ś
call_levelŚbolrą  )rę   r  r  Ścopy_formattingrė   rė   rģ   rķ   
  s*   özCCodeWriter.__init__c                 C   s   t |||}|S ró   ©rµ  )rę   r  r  r  rw  rė   rė   rģ   Ś
create_new'
  s   zCCodeWriter.create_newc                 C   s    | j d u sJ || _ |j| _d S ró   )r  rÓ  )rę   Śglobal_staterė   rė   rģ   rą  -
  s   zCCodeWriter.set_global_statec                 C   rY  ró   )r  Ścopyto)rę   r  rė   rė   rģ   r  2
  r]  zCCodeWriter.copytoc                 C   r  ró   )r  Śgetvaluerō   rė   rė   rģ   r  5
  r¢  zCCodeWriter.getvaluec                 C   s$   d|v r|   |” d S |  |” d S ©Nr$  )Ś_write_linesŚ_write_to_buffer©rę   rØ  rė   rė   rģ   rū   8
  s   zCCodeWriter.writec                 C   s@   | j r
| j d d nd}| jj |g| d” ” |  |” d S )Nr   ©Nr   r$  )r  r  ŚmarkersrŅ  rA  r  )rę   rØ  Śfilename_linerė   rė   rģ   r  >
  s   zCCodeWriter._write_linesc                 C   rY  ró   )r  rū   r  rė   rė   rģ   r  H
  r]  zCCodeWriter._write_to_bufferc                 C   s   | j | | j ” dd}|S )NT)r  r  r  )r  r  rē  rŖ  rė   rė   rģ   rē  K
  s   zCCodeWriter.insertion_pointc                 C   s
   t | dS )z
        Creates a new CCodeWriter connected to the same global state, which
        can later be inserted using insert.
        r  r  rō   rė   rė   rģ   Ś
new_writerO
  s   
zCCodeWriter.new_writerc                 C   s"   |j | j u sJ | j |j” dS )zĖ
        Inserts the contents of another code writer (created with
        the same global state) in the current location.

        It is ok to write to the inserted writer also after insertion.
        N)r  r  Śinsert)rę   r“  rė   rė   rģ   r  V
  s   zCCodeWriter.insertc                 C   r  ró   rė   rō   rė   rė   rģ   r!  a
  r  zCCodeWriter.label_counterc                 C   r  ró   rė   rō   rė   rė   rģ   r$  c
  r  zCCodeWriter.return_labelc                 C   r  ró   rė   rō   rė   rė   rģ   r   e
  r  zCCodeWriter.error_labelc                 C   r  ró   rė   rō   rė   rė   rģ   r"  g
  r  zCCodeWriter.labels_usedc                 C   r  ró   rė   rō   rė   rė   rģ   r&  i
  r  zCCodeWriter.continue_labelc                 C   r  ró   rė   rō   rė   rė   rģ   r'  k
  r  zCCodeWriter.break_labelc                 C   r  ró   rė   rō   rė   rė   rģ   Śreturn_from_error_cleanup_labelm
  r  z+CCodeWriter.return_from_error_cleanup_labelc                 C   r  ró   rė   rō   rė   rė   rģ   r(  o
  r  zCCodeWriter.yield_labelsTc                 c   sl    t ||D ]-\}}|  |”sq|r|  |” d}|dur$| j||d |  |” ||fV  |  |” qdS )aŅ  
        Helper for generating multiple label interceptor code blocks.

        @param new_labels: the new labels that should be intercepted
        @param orig_labels: the original labels that we should dispatch to after the interception
        @param skip_to_label: a label to skip to before starting the code blocks
        @param pos: the node position to mark for each interceptor block
        @param trace: add a trace line for the pos marker or not
        N)Śtrace)rĶ   r^  Śput_gotoŚmark_posr’  )rę   rV  Śorig_labelsŚskip_to_labelrM  r  rB  Ś
orig_labelrė   rė   rģ   Ślabel_interceptorr
  s   




ōzCCodeWriter.label_interceptorc                 C   ó   | j  |”S ró   )rü  r#  ©rę   r0  rė   rė   rģ   r#  
  ó    zCCodeWriter.new_labelc                 G   ó   | j j| S ró   )rü  r%  ©rę   rś  rė   rė   rģ   r%  
  r%  zCCodeWriter.new_error_labelc                 G   r&  ró   )rü  rF  r'  rė   rė   rģ   rF  
  r%  zCCodeWriter.new_yield_labelc                 C   r  ró   )rü  rK  rō   rė   rė   rģ   rK  
  r>  zCCodeWriter.get_loop_labelsc                 C   r#  ró   )rü  rN  rL  rė   rė   rģ   rN  
  r%  zCCodeWriter.set_loop_labelsc                 G   r&  ró   )rü  rR  r'  rė   rė   rģ   rR  
  r%  zCCodeWriter.new_loop_labelsc                 C   r  ró   )rü  rT  rō   rė   rė   rģ   rT  
  r>  zCCodeWriter.get_all_labelsc                 C   r#  ró   )rü  rU  rL  rė   rė   rģ   rU  
  r%  zCCodeWriter.set_all_labelsc                 C   r  ró   )rü  rX  rō   rė   rė   rģ   rX  
  r>  zCCodeWriter.all_new_labelsc                 C   r#  ró   )rü  r\  rZ  rė   rė   rģ   r\  
  r%  zCCodeWriter.use_labelc                 C   r#  ró   )rü  r^  rZ  rė   rė   rģ   r^  
  r%  zCCodeWriter.label_usedc                 C   s   t | |d| _d S )N)rĻ  )r  rü  r  rė   rė   rģ   Śenter_cfunc_scope
  rž  zCCodeWriter.enter_cfunc_scopec                 C   s"   | j d u rd S | j  ”  d | _ d S ró   )rü  r>  rō   rė   rė   rģ   r   
  s   


zCCodeWriter.exit_cfunc_scopec                 C   sX   | j jd }| d| d” |  |” |  d” |  d| d” |r*|  ”  dS dS )z
        Init code helper function to start a cfunc scope and generate
        the prototype and function header ("static SIG {") of the function.
        rĀ  zstatic CYTHON_SMALL_CODE ś; /*proto*/r;  rÅ  ś {N)r  rÕ  rų   r(  Śput_declare_refcount_context)rę   Ś	signaturerĻ  rä  r*  rė   rė   rģ   rč  ”
  s   

’zCCodeWriter.start_initcfuncc           	      C   sl   |  |”}d| |” d| d}|r!| jd  | dd”d ” |r(|  |” |  d” |  |d ” d S )	NrÅ  rŠ  r)  r¹  śCYTHON_UNUSED r;  r)  r*  )Śmangle_internalrk  r  rų   r  r(  )	rę   Śclass_scopeŚreturn_typeŚc_slot_nameŚargs_signatureŚneeds_funcstateŚneeds_prototypeŚslotfunc_cnameŚdeclarationrė   rė   rģ   Śstart_slotfunc®
  s   


zCCodeWriter.start_slotfuncc                 C   ó   |   | j ||”j”S ró   )r  r  r  r  )rę   r  r  rė   rė   rģ   Ś
get_py_int¼
  ó   ’zCCodeWriter.get_py_intc                 C   r8  ró   )r  r  r  r  )rę   r  r  rė   rė   rģ   Śget_py_floatĮ
  r:  zCCodeWriter.get_py_floatc                 C   s   |   | j ||””S ró   )r  r  r  )rę   rH  r  rė   rė   rģ   r  Ę
  s   ’zCCodeWriter.get_py_constc                 C   s   | j  |”jS ró   )r  r   r  r,  rė   rė   rģ   r   Ė
  r  zCCodeWriter.get_string_constc                 C   r#  ró   )r  r!  r,  rė   rė   rģ   r!  Ī
  r¬  z#CCodeWriter.get_pyunicode_ptr_constc                 C   s   | j  ||”j}|  |”S ró   )r  r  r  r  )rę   r  r  r  rė   rė   rģ   r  Ń
  s   ’’
zCCodeWriter.get_py_string_constc                 C   s   |   | j |””S ró   )r  r  r(  )rę   r&  rė   rė   rģ   r(  Ö
  rž  z CCodeWriter.get_py_codeobj_constc                 C   s   |   | j |”j”S ró   )r  r  r  r  ©rę   rĖ   rė   rė   rģ   r  Ł
  rz  z&CCodeWriter.get_argument_default_constc                 C   s
   |   |”S ró   r+  r,  rė   rė   rģ   r„  Ü
  r¢  zCCodeWriter.internc                 C   r)  r*  r+  r,  rė   rė   rģ   Śintern_identifierß
  r  zCCodeWriter.intern_identifierc                 C   r#  ró   )r  r  r
  rė   rė   rģ   r  ā
  r¬  z'CCodeWriter.get_cached_constants_writerc                 C   s$   | j jd u r|  |”S | j j |”S ró   )rü  rĻ  rP  r  ©rę   r  rė   rė   rģ   r  å
  s   
z CCodeWriter.name_in_module_statec                 C   ó   t j d|  S r  )r   rź  r©  rė   rė   rģ   rP  ļ
  s   z,CCodeWriter.name_in_main_c_code_module_statec                 C   r?  r  )r   rö  r©  rė   rė   rģ   Śname_in_slot_module_stateö
  s   z%CCodeWriter.name_in_slot_module_statec                 C   s   |j r|jS |  |j”S ró   )Śis_py_class_scopeŚnamespace_cnamer  r  rė   rė   rģ   Śnamespace_cname_in_module_stateü
  s   z+CCodeWriter.namespace_cname_in_module_statec                 C   s   |j r	|  |j”S |jS ró   )Śis_extension_typer  Śtypeptr_cnamer<  rė   rė   rģ   Śtypeptr_cname_in_module_state  s   z)CCodeWriter.typeptr_cname_in_module_stater;  c                 C   s|   | j r
| jr
|  ”  | jjr%| jr%| j\}}}|  d| d| ”  d” |r4|r/|  |” n|  	|” |  d” d| _d S )Nz
#line z "rč  r$  r   )
r  r  Śemit_markerrÓ  rģ  r  r  Śget_escaped_descriptionŚput_safer÷  )rę   rł   rx  rš  rV  rĪ   rė   rė   rģ   rų   
  s   


zCCodeWriter.putlnc                 C   s>   |d u rd S | j r| j d d |d d krd S ||f| _d S )Nr   )r  r  ©rę   rM  r  rė   rė   rģ   r    s
    zCCodeWriter.mark_posc                 C   sV   | j \}}|| _d | _ |  d” | jjr |  ”  |  |  |”” |r)|  |” d S d S r  )r  r  r  rÓ  r  ŚindentŚ_build_markerŚwrite_trace_linerJ  rė   rė   rģ   rG    s   

’zCCodeWriter.emit_markerc                 C   sr   | j r3| j jr5| jjd r7|  ”  |  d|d dd|  |”dd| j j dd|  |” d	” d S d S d S d S )NŚ	linetracez__Pyx_TraceLine(r   rļ   ró  z)
)	rü  r+  r  rm  rK  r  Śpos_to_offsetr,  rQ  ©rę   rM  rė   rė   rģ   rM  +  s   8’žzCCodeWriter.write_trace_linec                 C   s   |\}}}t |tsJ | j |”}|td|d | }|d  d7  < ||||d  7 }d |”}d| ”  d|d	d| d
S )Nr   r%   rŻ   z             # <<<<<<<<<<<<<<r   r$  z/* "z":rļ   z
*/
)r¬   r   r  rö  r“   r  rH  )rę   rM  rš  rV  ŚcolŚcontentsr1  rł   rė   rė   rģ   rL  2  s   

zCCodeWriter._build_markerc                 C   s   |   |” d| _d S r  )rū   r  ©rę   rł   rė   rė   rģ   rI  =  s   

zCCodeWriter.put_safec              	   C   s@  | j j}|rt|dkrt | d”” ” }| d| d}tj 	||”}tj 
|”s| dt ”  }d}zFz$t |”}	|	 |” W d    n1 sMw   Y  t ||” d}W n ttfym   tj 
|”sk Y nw W |s|tj 
|”r|t |” n|stj 
|”rt |” w w w | dd	”}
d
|
 d}|  |” d S )Ni   r  rĪ   z.hz.tmpFTrē  r<  z
#include "rč  )r  rŌ  rÆ   ŚhashlibŚsha256r  Ś	hexdigestr   r  r  ŚexistsŚgetpidr
   Śopen_new_filerū   ŚshutilŚmoverL   re   Śunlinkr  r¼  )rę   rł   r0  Śinclude_dirr§   Śinclude_filer  Śtmp_pathŚdoner  Śc_pathrė   rė   rģ   r»  B  s:   ’’ż
’’zCCodeWriter.put_or_includec                 C   s4   | j rd|v rd| j   |jdd”}|  |” d S )Nr$  rĮ  T©Śkeepends)r#   r  rė  r÷  rS  rė   rė   rģ   r¼  _  s   zCCodeWriter.put_multilinesc                 C   sĄ   d}d|v r|  d”nd}d|v r7||  d”8 }|dk r$|  j|7  _n|dkr7|d dkr7d}|  jd8  _| jr>|  ”  |  |” d| _|dkrS|  j|7  _d S |r^|  jd7  _d S d S )NFr  r   rż  Tr   )rA  r#   r  rK  rū   )rę   rł   Ś
fix_indentŚdlrė   rė   rģ   r÷  g  s$   
’zCCodeWriter.putr/  c                 C   sZ   |j rJ |j| | | jd” | | j” |jr)tjr+| | jd | jd” d S d S d S )Nr+  rŹ  r  )r*  r0  ræ  r  rÄ  r  r   rÓ  )rę   r/  rė   rė   rģ   Śput_code_here{  s   ’’zCCodeWriter.put_code_herec                 C   ó   |  j d7  _ d S ©Nr   r"   rō   rė   rė   rģ   Śincrease_indent  ó   zCCodeWriter.increase_indentc                 C   ó   |  j d8  _ d S rh  r"   rō   rė   rė   rģ   Śdecrease_indent  rj  zCCodeWriter.decrease_indentc                 C   s   |   d” |  ”  d S )Nr  )rų   ri  rō   rė   rė   rģ   Śbegin_block  s   
zCCodeWriter.begin_blockc                 C   s   |   ”  |  d” d S )Nrż  )rl  rų   rō   rė   rė   rģ   Ś	end_block  s   zCCodeWriter.end_blockc                 C   s   |   d| j ” d S )NrĮ  )r  r#   rō   rė   rė   rģ   rK    ó   zCCodeWriter.indentc                 C   s   dt |d d d  S )Nz0x%02X%02X%02X%02X)r   r   r   r   é   )rŹ   )rę   Ś	pyversionrė   rė   rģ   Śget_py_version_hex  r	  zCCodeWriter.get_py_version_hexc                 C   s"   || j jv r|  d| ” d S d S )Nz%s:;)rü  r"  rų   rZ  rė   rė   rģ   r’    s   ’zCCodeWriter.put_labelc                 C   s   | j  |” |  d| ” d S )Nśgoto %s;)rü  r\  rų   rZ  rė   rė   rģ   r  £  r  zCCodeWriter.put_gotoc                 C   sÖ   |j dkr|s|jsd S |j dkr|jsd S |js|  d” |r'|  d| ” |jr7|  |jj|j|d” n|  |jj	|j|d” |j
d urU|  d|j |j
” ” n	|jjr^|  d” |  d” | j |” d S )NŚprivater-  ś%s )Śdll_linkagez = %sz = NULLrr  )Ś
visibilityŚdefined_in_pxdrz  Ścf_usedr÷  Śis_cpp_optionalrĖ   Ścpp_optional_declaration_coder  rk  r  rI  Śliteral_codeŚis_pyobjectrų   r  rł  )rę   r  Śstorage_classrv  Ś
definitionrė   rė   rģ   Śput_var_declaration§  s*   


’
’


zCCodeWriter.put_var_declarationŚfunc_contextc                 C   sš   |j D ]F\}}}}|jr|js|jjd r| |”}n| |”}|jr+|  d| ” q|j	r<|  d|| 
|j”f ” q|  d|rCdpDd|f ” q|jrv| jjrTd}nd}|  d|tjf ” |  d	|tjf ” |  d|tjf ” d S d S )
Nra  z
%s = NULL;z%s = %s;z%s%s;rÅ  r;  r-  z%sint %s = 0;z%sconst char *%s = NULL;)r-  rl  rh  rĻ  rm  r{  rk  r}  rų   rm  r|  Śdefault_valuer4  rü  r5  r   Ślineno_cnameŚfilename_cnameŚclineno_cname)rę   r  r0  rĖ   rs  rt  rs  Śunusedrė   rė   rģ   Śput_temp_declarationsĮ  s"   
ųz!CCodeWriter.put_temp_declarationsc                 C   s   |   tj” |   d” d S r  )rų   r
   ŚGENERATED_BY_MARKERrō   rė   rė   rģ   Śput_generated_byŲ  s   zCCodeWriter.put_generated_byc                 C   s    |   d| ” |   d| ” d S )Nz
#ifndef %sz
#define %sr¾  )rę   r¤  rė   rė   rģ   Śput_h_guardÜ  s   zCCodeWriter.put_h_guardc                 C   s   t jrd| S |S )Nzunlikely(%s))r   Śgcc_branch_hints©rę   Ścondrė   rė   rģ   Śunlikelyą  s   zCCodeWriter.unlikelyc                    s$   |sdS dd   fdd|D ” S )Nr;  ru  r  c                    s   g | ]} ||qS rė   rė   )r^  rW  ©Śmapperrė   rģ   rc  é  r°  z8CCodeWriter.build_function_modifiers.<locals>.<listcomp>)r  )rę   Ś	modifiersr  rė   r  rģ   Śbuild_function_modifiersę  s   z$CCodeWriter.build_function_modifiersc                 C   s.   |j }|js|j  ” r|j jrd|j S |jS )Nz(PyObject *))rĖ   Śis_self_argŚis_completerD  r  )rę   r  rĖ   rė   rė   rģ   Śentry_as_pyobjectķ  s   ’
zCCodeWriter.entry_as_pyobjectc                 C   s   ddl m}m} ||||S )Nr   ©Śpy_object_typeŚtypecast)r`  r  r  )rę   r  rĖ   r  r  rė   rė   rģ   Śas_pyobjectõ  s   zCCodeWriter.as_pyobjectc                 C   ó   |  | |” d S ró   )Śgenerate_gotrefr  rė   rė   rģ   Ś
put_gotrefł  r]  zCCodeWriter.put_gotrefc                 C   r  ró   )Śgenerate_giverefr  rė   rė   rģ   Śput_giverefü  r]  zCCodeWriter.put_giverefc                 C   r  ró   )Śgenerate_xgiverefr  rė   rė   rģ   Śput_xgiveref’  r]  zCCodeWriter.put_xgiverefc                 C   r  ró   )Śgenerate_xgotrefr  rė   rė   rģ   Śput_xgotref  r]  zCCodeWriter.put_xgotrefc                 C   ó   |j | ||d d S ©N)rf  )Śgenerate_incref©rę   r  rĖ   rf  rė   rė   rģ   Ś
put_incref  s   zCCodeWriter.put_increfc                 C   r£  r¤  )Śgenerate_xincrefr¦  rė   rė   rģ   Śput_xincref  rz  zCCodeWriter.put_xincrefc                 C   ó   |j | |||d d S ©N)rf  Śhave_gil)Śgenerate_decref©rę   r  rĖ   rf  r¬  rė   rė   rģ   Ś
put_decref  ó   zCCodeWriter.put_decrefc                 C   rŖ  r«  )Śgenerate_xdecrefr®  rė   rė   rģ   Śput_xdecref  r°  zCCodeWriter.put_xdecrefc                 C   ó   |j | ||||d d S ©N)re  rf  r¬  )Śgenerate_decref_clear©rę   r  rĖ   re  rf  r¬  rė   rė   rģ   Śput_decref_clear  ó   

’zCCodeWriter.put_decref_clearc                 C   r³  r“  )Śgenerate_xdecref_clearr¶  rė   rė   rģ   rl    rø  zCCodeWriter.put_xdecref_clearc                 C   ó   |  | ||” d S ró   )Śgenerate_decref_set©rę   r  rĖ   Ś	rhs_cnamerė   rė   rģ   Śput_decref_set  rž  zCCodeWriter.put_decref_setc                 C   rŗ  ró   )Śgenerate_xdecref_setr¼  rė   rė   rģ   Śput_xdecref_set  rž  zCCodeWriter.put_xdecref_setc                 C   r£  ©N)r¬  )Śgenerate_incref_memoryviewslice)rę   Śslice_cnamerĖ   r¬  rė   rė   rģ   Śput_incref_memoryviewslice"  ro  z&CCodeWriter.put_incref_memoryviewslicec                 C   s   | j |j|j|d d S rĮ  )rÄ  r  rĖ   )rę   r  r¬  rė   rė   rģ   Śput_var_incref_memoryviewslice&  r	  z*CCodeWriter.put_var_incref_memoryviewslicec                 C   ó   |   |j|j” d S ró   )r  r  rĖ   r  rė   rė   rģ   Śput_var_gotref)  rz  zCCodeWriter.put_var_gotrefc                 C   rĘ  ró   )r  r  rĖ   r  rė   rė   rģ   Śput_var_giveref,  rz  zCCodeWriter.put_var_giverefc                 C   rĘ  ró   )r¢  r  rĖ   r  rė   rė   rģ   Śput_var_xgotref/  rz  zCCodeWriter.put_var_xgotrefc                 C   rĘ  ró   )r   r  rĖ   r  rė   rė   rģ   Śput_var_xgiveref2  rz  zCCodeWriter.put_var_xgiverefc                 K   ó   | j |j|jfi |¤ d S ró   )r§  r  rĖ   ©rę   r  Śkwdsrė   rė   rģ   Śput_var_incref5  ó   zCCodeWriter.put_var_increfc                 K   rĖ  ró   )r©  r  rĖ   rĢ  rė   rė   rģ   Śput_var_xincref8  rĻ  zCCodeWriter.put_var_xincrefc                 K   rĖ  ró   )rÆ  r  rĖ   rĢ  rė   rė   rģ   Śput_var_decref;  rĻ  zCCodeWriter.put_var_decrefc                 K   rĖ  ró   )r²  r  rĖ   rĢ  rė   rė   rģ   Śput_var_xdecref>  rĻ  zCCodeWriter.put_var_xdecrefc                 K   ó"   | j |j|jfd|ji|¤ d S ©Nre  )r·  r  rĖ   Ś
in_closurerĢ  rė   rė   rģ   Śput_var_decref_clearA  ó   "z CCodeWriter.put_var_decref_clearc                 K   ó   | j |j|j|fi |¤ d S ró   )r¾  r  rĖ   ©rę   r  r½  rĶ  rė   rė   rģ   Śput_var_decref_setD  ó   zCCodeWriter.put_var_decref_setc                 K   rŲ  ró   )rĄ  r  rĖ   rŁ  rė   rė   rģ   Śput_var_xdecref_setG  rŪ  zCCodeWriter.put_var_xdecref_setc                 K   rÓ  rŌ  )rl  r  rĖ   rÕ  rĢ  rė   rė   rģ   Śput_var_xdecref_clearJ  r×  z!CCodeWriter.put_var_xdecref_clearr   c                 C   s4   |D ]}|r	|j r|jr|  |” q|  |” qd S ró   )rz  Śxdecref_cleanuprŅ  rŃ  )rę   ŚentriesŚ	used_onlyr  rė   rė   rģ   Śput_var_decrefsM  s   

ūzCCodeWriter.put_var_decrefsc                 C   ó   |D ]}|   |” qd S ró   )rŅ  ©rę   rß  r  rė   rė   rģ   Śput_var_xdecrefsU  ó   ’zCCodeWriter.put_var_xdecrefsc                 C   rā  ró   )rŻ  rć  rė   rė   rģ   Śput_var_xdecrefs_clearY  rå  z"CCodeWriter.put_var_xdecrefs_clearc                 C   sL   | j jjs| j jjs| j jjr$|  d” |  d| d” |  d” d S d S )Nz?#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000z)PyUnstable_Object_EnableDeferredRefcount(rć  rz  )rü  rĻ  Śis_module_scopeŚis_c_class_scoperA  rų   r>  rė   rė   rģ   Śput_make_object_deferred]  s   
’ž
ūz$CCodeWriter.put_make_object_deferredc                 C   sL   ddl m}m} |||d}|r|  d||f ” d S |  d||f ” d S )Nr   r  ŚPy_Nonez%s = %s; __Pyx_INCREF(Py_None);z%s = %s; Py_INCREF(Py_None);)r`  r  r  rų   )rę   r  rĖ   rf  r  r  Śpy_nonerė   rė   rģ   Śput_init_to_py_noneh  s
   zCCodeWriter.put_init_to_py_nonerĢ  c                 C   s2   ||j  }|  ||j|” |jr|  d” d S d S )Nrź  )r  rģ  rĖ   rÕ  r  )rę   r  r  rf  rł   rė   rė   rģ   Śput_init_var_to_py_nonep  s
   
’z#CCodeWriter.put_init_var_to_py_nonec                 C   s4  d}|j s
|jdkr.ddlm} |jtvr.| |j”rd}n|jdkr*| jjd s*n|r.d S |j 	” }|s7d S |j r@||j
g7 }|rG| |”n|j}|j ” }	|	dkrYd	|	|f }|j ” }
|rv| | jj” |j”}| ” }|rv|  |” |  d
|
|d |”|jr|jnd|f ” |r|r|  d” d S d S d S )NFŚ__getattribute__r   )Ś	TypeSlotsTŚ__getattr__Śfast_getattrŚPyCFunctionz(void(*)(void))(%s)%sz{%s, (PyCFunction)%s, %s, %s}%sś|Ś0rz  )Ś
is_specialr0  r;  rļ  Śspecial_py_methodsŚis_binop_number_slotr  rm  r,  Śmethod_flagsŚmethod_coexistŚput_pymethoddef_wrapperŚ
func_cnameŚmethod_function_typeŚas_c_string_literalŚget_slot_tableŚget_slot_by_method_nameŚpreprocessor_guard_coderų   r  ŚdocŚ	doc_cname)rę   r  ŚtermŚ
allow_skipŚwrapper_code_writerŚis_number_slotrļ  rų  Śfunc_ptrŚcastŚ
entry_nameŚslotŚpreproc_guardrė   rė   rģ   Śput_pymethoddefx  sJ   




ū’’zCCodeWriter.put_pymethoddefc                 C   s   |j }|jrK|j ” pg }ddlm} ||v rKtj| }|  d| ” d|j  }|j	dkr?|  d| ” |  d” |  d” n|  d	| ” |  d
” |S )Nr   )Śmethod_noargszBstatic PyObject *%s(PyObject *self, CYTHON_UNUSED PyObject *arg) {z%s(self)rŅ   zPyObject *res = %s;zFif (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }zreturn res;z
return %s;rż  )
rū  rõ  r,  rų  rļ  r  r   Śmethod_wrapper_prefixrų   r0  )rę   r  rū  rų  r  Ś	func_callrė   rė   rģ   rś  ©  s   




z#CCodeWriter.put_pymethoddef_wrapperc                 C   s<   | j jd r| j  t dd”” d S | j  t dd”” d S )NŚfast_gilŚFastGilrō  Ś	NoFastGil)r  rm  rŃ  r  rd  rō   rė   rė   rģ   Śuse_fast_gil_utility_codeæ  s   z%CCodeWriter.use_fast_gil_utility_codec                 C   sn   | j jd dkrddlm} || jdd | j  t dd”” |  ”  |s.d	}|r.|  	d
” |  
d| ” dS )a  
        Acquire the GIL. The generated code is safe even when no PyThreadState
        has been allocated for this thread (for threads not initialized by
        using the Python API). Additionally, the code generated by this method
        may be called recursively.
        Śsubinterpreters_compatibleŚnor   )ŚwarningzTAcquiring the GIL is currently very unlikely to work correctly with subinterpreters.r   ŚForceInitThreadsrō  Ś__pyx_gilstate_savezPyGILState_STATE z%s = __Pyx_PyGILState_Ensure();N)r  rm  ŚErrorsr  r  rŃ  r  rd  r  r÷  rų   )rę   Śdeclare_gilstateŚvariabler  rė   rė   rģ   Śput_ensure_gilÅ  s    ż
’
zCCodeWriter.put_ensure_gilc                 C   s"   |   ”  |sd}|  d| ” dS )zD
        Releases the GIL, corresponds to `put_ensure_gil`.
        r  z__Pyx_PyGILState_Release(%s);N)r  rų   )rę   r  rė   rė   rģ   Śput_release_ensured_gilÜ  s   z#CCodeWriter.put_release_ensured_gilc                 C   ó,   |   d” |   dtj d” |   d” d S )Nrķ  zPyMutex_Lock(&rć  rz  ©rų   r   Śparallel_freethreading_mutexrō   rė   rė   rģ   Śput_acquire_freethreading_lockå  ó   
z*CCodeWriter.put_acquire_freethreading_lockc                 C   r  )Nrķ  zPyMutex_Unlock(&rć  rz  r  rō   rė   rė   rģ   Śput_release_freethreading_lockź  r"  z*CCodeWriter.put_release_freethreading_lockc                 C   sZ   |   ”  |  d” |r|  d| ” |r!d}| j t dd”” nd}|  | d” dS )	z
        Acquire the GIL. The thread's thread state must have been initialized
        by a previous `put_release_gil`
        z__Pyx_FastGIL_Forget();z_save = %s;Ś__Pyx_RestoreUnknownThreadŚReleaseUnknownGilrō  ŚPyEval_RestoreThreadz(_save);N)r  rų   r  rŃ  r  rd  )rę   r  Śunknown_gil_stater  rė   rė   rģ   Śput_acquire_gilļ  s   

’zCCodeWriter.put_acquire_gilc                 C   st   |   ”  |r| j t dd”” d}d}nd}d}|  | d” |  d| d	” |r3|  d
| ” |  d” dS )z2Release the GIL, corresponds to `put_acquire_gil`.r%  rō  Ś__Pyx_SaveUnknownThreadŚ__Pyx_UnknownThreadStateŚPyEval_SaveThreadzPyThreadState *z _save;z_save = z();z%s = _save;z__Pyx_FastGIL_Remember();N)r  r  rŃ  r  rd  rų   )rę   r  r'  r  Śresult_typerė   rė   rģ   Śput_release_gil   s   
’zCCodeWriter.put_release_gilc                 C   ó   |   d” d S )Nz%PyGILState_STATE __pyx_gilstate_save;r¾  rō   rė   rė   rģ   r    r  zCCodeWriter.declare_gilstatec                 C   s   |   d||  |”f ”S )Nzif (%s < (0)) %s)rų   rQ  )rę   rM  r  rė   rė   rģ   Śput_error_if_neg  s   zCCodeWriter.put_error_if_negc              	   C   s°   |rdnd}|j rd}n|jjr|jrd}n|jjr'|jr'|js'|jjr'd}nd}| j 	t
 | | d”” |s@|j |j”}|  d|d	| | |j ” |  |”f ” d S )
NŚNogilr;  ŚRaiseClosureNameErrorŚRaiseCppGlobalNameErrorŚRaiseCppAttributeErrorŚRaiseUnboundLocalErrorrD  z!if (unlikely(!%s)) { %s(%s); %s }Ś__Pyx_)Śfrom_closurerĖ   rl  Ś
is_cglobalŚis_variableŚ	is_memberrĻ  rč  r  rŃ  r  rd  Ścheck_for_null_coder  rų   r0  rż  rQ  )rę   rM  r  Śin_nogil_contextŚunbound_check_codeŚ	nogil_tagrŽ  rė   rė   rģ   Śput_error_if_unbound  s&   ’üz CCodeWriter.put_error_if_unboundc                 C   s.   d| j _|r
d| j _d|  |d ”|d f S )NTz__PYX_MARK_ERR_POS(%s, %s)r   r   )rü  r4  r5  rń  )rę   rM  rz  rė   rė   rģ   Śset_error_info3  s   žzCCodeWriter.set_error_infoc                 C   sT   | j j}| j  |” |d u rd| S d| j _|rd| j _d|  |d ”|d |f S )Nrs  Tz__PYX_ERR(%s, %s, %s)r   r   )rü  r   r\  r4  r5  rń  )rę   rM  rz  r[  rė   rė   rģ   rQ  ;  s   żzCCodeWriter.error_gotoc                 C   s   d|   |”|  |”f S )Nz
if (%s) %s)r  rQ  )rę   r  rM  rė   rė   rģ   Śerror_goto_ifH  r	  zCCodeWriter.error_goto_ifc                 C   ó   |   d| |”S )Nz!%s©r@  ©rę   r  rM  rė   rė   rģ   r  K  r]  zCCodeWriter.error_goto_if_nullc                 C   rA  )Nz(%s < 0)rB  rC  rė   rė   rģ   Śerror_goto_if_negN  s   zCCodeWriter.error_goto_if_negc                 C   s   |   d|”S )NzPyErr_Occurred()rB  rP  rė   rė   rģ   rĀ  R  r¬  zCCodeWriter.error_goto_if_PyErrc                 C   r#  ró   )r  rń  )rę   r  rė   rė   rģ   rń  U  r¬  zCCodeWriter.lookup_filenamec                 C   r.  )NŚ__Pyx_RefNannyDeclarationsr¾  rō   rė   rė   rģ   r+  X  r  z(CCodeWriter.put_declare_refcount_contextc                 C   s>   |  ” }|r| j t dd”” |  d||rdpdf ” d S )Nr  rō  z#__Pyx_RefNannySetupContext(%s, %d);r   r   )rż  r  rŃ  r  rd  rų   )rę   r0  Śacquire_gilrė   rė   rģ   rė  [  s   
’z&CCodeWriter.put_setup_refcount_contextc                 C   ó   |   |r	d” d S d” d S )Nz"__Pyx_RefNannyFinishContextNogil()z__Pyx_RefNannyFinishContext();r¾  ©rę   Śnogilrė   rė   rģ   r  b  rĻ  z'CCodeWriter.put_finish_refcount_contextc                 C   s<   |  ” }||r
tjndtjtjf}d| j_|  d| ” dS )z
        Build a Python traceback for propagating exceptions.

        qualified_name should be the qualified name of the function.
        r   Tz#__Pyx_AddTraceback(%s, %s, %s, %s);N)rż  r   r  r  r  rü  r5  rų   )rę   Śqualified_nameŚinclude_clineŚformat_tuplerė   rė   rģ   Śput_add_tracebacke  s   üzCCodeWriter.put_add_tracebackc              	   C   sH   d| j _|  d|tjtjtj| jjd |f ” | j 	t
 dd”” dS )z
        Generate code to print a Python warning for an unraisable exception.

        qualified_name should be the qualified name of the function.
        Tz0__Pyx_WriteUnraisable("%s", %s, %s, %s, %d, %d);Śunraisable_tracebacksŚWriteUnraisableExceptionzExceptions.cN)rü  r5  rų   r   r  r  r  r  rm  rŃ  r  rd  )rę   rJ  rI  rė   rė   rģ   Śput_unraisablev  s   
ś
’zCCodeWriter.put_unraisablec                 C   s   | j jd p| j jd S )NŚprofilerN  )r  rm  rō   rė   rė   rģ   Ś
is_tracing  r	  zCCodeWriter.is_tracingc                 C   s<   | j j}|r||jvr|j}|r||jvs|r|j| S dS )zk
        Calculate a fake 'instruction offset' from a node position as 31 bit int (32 bit signed).
        r   )rü  rĻ  Śnode_positions_to_offsetŚparent_scope)rę   rM  rĻ  rė   rė   rģ   rO    s
   ’zCCodeWriter.pos_to_offsetc                 C   rG  )NŚ__Pyx_TraceDeclarationsGenŚ__Pyx_TraceDeclarationsFuncr¾  )rę   Śis_generatorrė   rė   rģ   Śput_trace_declarations  rĻ  z"CCodeWriter.put_trace_declarationsc                 C   s   |r|   d| ” d S d S )Nz__Pyx_TraceFrameInit(%s)r¾  )rę   Ścodeobjrė   rė   rģ   Śput_trace_frame_init  s   ’z CCodeWriter.put_trace_frame_initc                 C   s~   |rdnd}|   | d| ”  dtj d|  |d ” d|d  d|  |”d	d|d	d|r1tjnd
 d|  |” d” d S )NŚ__Pyx_TraceStartGenŚ__Pyx_TraceStartFuncrŠ  r8  r#  r   ś], r   rļ   rō  rć  )rų   rż  r   Śfiletable_cnamerń  rO  Śskip_dispatch_cnamerQ  )rę   r0  rM  rI  rW  Śis_cpdef_funcŚ
trace_funcrė   rė   rģ   Śput_trace_start  s(   ’žžż
üūśł’zCCodeWriter.put_trace_startc                 C   s   |   dt|dd” d S )Nz__Pyx_PyMonitoring_ExitScope(rļ   rć  )rų   r   rH  rė   rė   rģ   Śput_trace_exit©  rĻ  zCCodeWriter.put_trace_exitc              	   C   s2   |   |”}|  d| d|  |” d| d” d S )Nz__Pyx_TraceYield(r8  rć  ©rQ  rų   rO  )rę   Śretvalue_cnamerM  rQ  rė   rė   rģ   Śput_trace_yield¬  ó   
(zCCodeWriter.put_trace_yieldc                 C   s   | j j}|jr|jjd n|d }|j ” }|  |d ”}|  |”}|  d| dt	j
 d| d| d|  |” d| d” d S )Nr   r   z__Pyx_TraceResumeGen(r8  r#  r]  rć  )rü  rĻ  Śscope_classrM  r0  rż  rń  rQ  rų   r   r^  rO  )rę   rM  rĻ  Ś
first_liner0  Śfilename_indexrQ  rė   rė   rģ   Śput_trace_resume°  s(   

’žžżüū’zCCodeWriter.put_trace_resumec              	   C   s4   |   d|  |” dt|ddt|dd” d S )Nś__Pyx_TraceException(r8  rļ   rć  ©rų   rO  r   )rę   rM  ŚreraiseŚfreshrė   rė   rģ   Śput_trace_exceptionĮ  s   4zCCodeWriter.put_trace_exceptionc                 C   s   |   dtj d” d S )Nrl  z, 0, 0);)rų   r   r  rō   rė   rė   rģ   Śput_trace_exception_propagatingÄ  r	  z+CCodeWriter.put_trace_exception_propagatingc                 C   s   |   d|  |” d” d S )Nz__Pyx_TraceExceptionHandled(rć  )rų   rO  rP  rė   rė   rģ   Śput_trace_exception_handledĒ  rĻ  z'CCodeWriter.put_trace_exception_handledc                 C   s(   |   d|  |” dt|dd” d S )Nz__Pyx_TraceExceptionUnwind(r8  rļ   rć  rm  )rę   rM  rI  rė   rė   rģ   Śput_trace_unwindŹ  s   (zCCodeWriter.put_trace_unwindc              	   C   s2   |   |”}|  d| d|  |” d| d” d S )Nz__Pyx_TraceStopIteration(r8  rć  rd  )rę   rM  r  rQ  rė   rė   rģ   Śput_trace_stopiterationĶ  rg  z#CCodeWriter.put_trace_stopiterationc                 C   s   d}d}|d u r	n#|j r| |”}n|jrd}n|jrd}n|jr*d}d|j }nd}|  |”}|  | d| | d|  |” dt|dd| d” d S )	Nr;  Ś__Pyx_TraceReturnValuerź  Ś__Pyx_TraceReturnCValuer8  rŠ  rļ   rć  )	r}  r  Śis_voidŚ	is_stringŚto_py_functionrQ  rų   rO  r   )rę   re  rM  r0  rI  Ś	extra_argra  rņ  rė   rė   rģ   Śput_trace_returnŃ  s    
<zCCodeWriter.put_trace_returnŚDefaultPlacementNewrc  c                 C   s"   | j  |” |  d| d” d S )Nz$__Pyx_default_placement_construct(&(z));)r  rŃ  rų   )rę   r  Ś_utility_coderė   rė   rģ   Śput_cpp_placement_newé  s   z!CCodeWriter.put_cpp_placement_newc                 C   s"   |   d” |   |” |   d” d S )Nz#ifdef _OPENMPz#endif /* _OPENMP */r¾  )rę   Śstringrė   rė   rģ   Śputln_openmpī  s   

zCCodeWriter.putln_openmpc                 C   sD   |   d| ” |   d” |   d” |   d” |   d” |   d” dS )zl
        Redefine the macros likely() and unlikely to no-ops, depending on
        condition 'cond'
        ś#if %sś    #undef likelyś    #undef unlikelyz    #define likely(x)   (x)z    #define unlikely(x) (x)rz  Nr¾  r  rė   rė   rģ   Śundef_builtin_expectó  s   



z CCodeWriter.undef_builtin_expectc                 C   sD   |   d| ” |   d” |   d” |   d” |   d” |   d” d S )Nr  r  r  z2    #define likely(x)   __builtin_expect(!!(x), 1)z2    #define unlikely(x) __builtin_expect(!!(x), 0)rz  r¾  r  rė   rė   rģ   Średef_builtin_expect’  s   



z CCodeWriter.redef_builtin_expect)NNF)NNTró   r  )TF)r;  Frū  )r;  NT)TT)FTTr}  )rĢ  T)TNr  )FNr}  )FFFr­  )¤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'  r  r(  r"  r#  r%  rF  rK  rN  rR  rT  rU  rX  r\  r^  r(  r   rč  r7  r9  r;  r  r   r!  r  r(  r  r„  r=  r  r  rĒ   rP  r@  rC  rF  rų   r  rG  rM  rL  rI  r»  r¼  r÷  r  rf  ri  rl  rm  rn  rK  rr  r’  r  r  r  r  r  r  r  Śmodifier_output_mapperr  r  r  r  r  r   r¢  r§  r©  rÆ  r²  r·  rl  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  r  r  r!  r#  r(  r-  r  r/  r>  r?  rQ  r@  r  rD  rĀ  rń  r+  rė  r  rM  rP  rR  rO  rX  rZ  rb  rc  rf  rk  rp  rq  rr  rs  rt  r{  r\  r~  r  r  r  rė   rė   rė   rģ   rµ  ķ	  sd   

	





















’1		’rµ  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ŚPyrexCodeWriterc                 C   s   t  |”| _d| _d S r  )r
   rY  r  r#   )rę   Śoutfile_namerė   rė   rģ   rķ     s   
zPyrexCodeWriter.__init__c                 C   s   | j  dd| j |f ” d S )Nz%s%s
r  )r  rū   r#   rS  rė   rė   rģ   rų     rŪ  zPyrexCodeWriter.putlnc                 C   rg  rh  r"   rō   rė   rė   rģ   rK    rž  zPyrexCodeWriter.indentc                 C   rk  rh  r"   rō   rė   rė   rģ   r­    rž  zPyrexCodeWriter.dedentN)rü   rż   rž   rķ   rų   rK  r­  rė   rė   rė   rģ   r    s
    r  c                   @   s~   e Zd ZdZdddZddd	Zdd
dZedd Zdd Z	dd Z
d ddZd ddZdd Zdd Zdd Zdd ZdS )!ŚPyxCodeWriterz7
    Can be used for writing out some Cython code.
    Nr   r   c                 C   s.   |pt  | _|| _|| _|| _|| _i | _d S ró   )r   r  r#   Śoriginal_levelr©  r	  Ś_insertion_points)rę   r  Śindent_levelr©  r	  rė   rė   rģ   rķ     s   
zPyxCodeWriter.__init__r   c                 C   s   |  j |7  _ dS r  r"   ©rę   Ślevelsrė   rė   rģ   rK  '  s   zPyxCodeWriter.indentc                 C   s   |  j |8  _ d S ró   r"   r  rė   rė   rģ   r­  +  rž  zPyxCodeWriter.dedentc                 c   s&    |   |” |  ”  dV  |  ”  dS )zf
        with pyx_code.indenter("for i in range(10):"):
            pyx_code.putln("print i")
        N)rų   rK  r­  )rę   rV  rė   rė   rģ   Śindenter.  s
   
zPyxCodeWriter.indenterc                 C   r  ró   )r  Śemptyrō   rė   rė   rģ   r  9  r¢  zPyxCodeWriter.emptyc                 C   s$   | j  ” }t|tr| | j”}|S ró   )r  r  r¬   r   r2  r	  )rę   rw  rė   rė   rģ   r  <  s   

zPyxCodeWriter.getvaluec                 C   sX   |d u r| j d ur| j }|d urt||}| j |r'| jd  | d” d S d” d S )Nz    r$  )r©  r  r  rū   r#   )rę   rV  r©  rė   rė   rģ   rų   B  s   

.zPyxCodeWriter.putlnc                 C   sJ   |d u r| j d ur| j }|d urt||}t|| jd }| j |” d S )Nrp  )r©  r  Ś_indent_chunkr#   r  rū   )rę   Śchunkr©  rė   rė   rģ   Ś	put_chunkK  s   

zPyxCodeWriter.put_chunkc                 C   s   t | | j ” | j| jS ró   )rĖ   r  rē  r#   r©  rō   rė   rė   rģ   rē  U  s   zPyxCodeWriter.insertion_pointc                 C   s   | j  ”  | j| _d S ró   )r  Śresetr  r#   rō   rė   rė   rģ   r  X  s   
zPyxCodeWriter.resetc                 C   s   |   ” | j|< d S ró   )rē  r  r$  rė   rė   rģ   Śnamed_insertion_point^  rž  z#PyxCodeWriter.named_insertion_pointc                 C   rł  ró   )r  r$  rė   rė   rģ   rś  a  r¢  zPyxCodeWriter.__getitem__)Nr   Nr   r¼  ró   )rü   rż   rž   r’   rķ   rK  r­  r   r  r  r  rų   r  rē  r  r  rś  rė   rė   rė   rģ   r    s    






	
r  r  Śindentation_lengthr  c                    sś   d| vsJ | j dd}|s| S |d  d”}|r||d< n|d= |s%dS t| d }t|D ]\}}t|}|d t|krDd||< q/||k rJ|}q/|t| krSd}||k rgd||    fd	d
|D }n||krx|| fdd
|D }d |”S )zONormalise leading space to the intended indentation and strip empty lines.
    ś	Trb  rŻ   r  r$  r   r   c                    s    g | ]}|d kr | nd qS )r$  rė   rź  )Ś
add_indentrė   rģ   rc    s    ’’z!_indent_chunk.<locals>.<listcomp>c                    s$   g | ]}|d kr| d nd qS )r$  Nrė   rź  )Śstartrė   rģ   rc    s    ’’r;  )rė  rD  rÆ   r   Ś_count_indentationr  )r  r  r1  Ś	last_lineŚmin_indentationrķ  rV  Śline_indentationrė   )r  r  rģ   r  e  s>   


ž
ž
r  rŻ   rØ  c                 C   s(   d}t | D ]\}}|dkr |S q|S )Nr   r  )r   )rØ  rķ  Śchrė   rė   rģ   r    s   žr  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r  c                 C   s   || _ i | _i | _d| _d S r  )Śklassr-  r.  Śtemps_count)rę   r  rė   rė   rģ   rķ   ¢  rØ  zClosureTempAllocator.__init__c                 C   s&   | j  ” D ]\}}t|| j|< qd S ró   )r-  r,  r±   r.  )rę   rĖ   rt  rė   rė   rģ   r  Ø  s   ’zClosureTempAllocator.resetc                 C   s   || j vrg | j |< g | j|< n| j| r| j|  d”S dtj| jf }| jjd |||dd | j |  |” |  jd7  _|S )Nr   r?  T)rM  r0  r  rĖ   Śis_cdefr   )	r-  r.  ro  r   rq  r   r  Śdeclare_varrG  )rę   rĖ   r  rė   rė   rģ   rx  ¬  s   


z"ClosureTempAllocator.allocate_tempN)rü   rż   rž   rķ   r  rx  rė   rė   rė   rģ   r  ”  s    r  rė   )jrÖ  Śdeclarerø   rT  r   r   r   rZ  r   Śdataclassesr   r  r   Ś	functoolsr   r   Ś
contextlibr   r   Ścollectionsr   r;  r   r   r   r	   r
   ŚScanningr   r   r!   r   r   r$   r   rR   Ścompression.zstdr   r   Śzstd_CompressionParameterr   Śzstd_StrategyŚstrategyŚbtultra2Ścompression_levelŚboundsr  rK  Śctypedef_builtins_mapŚbasicsize_builtins_mapŚKNOWN_PYTHON_BUILTINS_VERSIONr£   ŚKNOWN_PYTHON_BUILTINSŚuncachable_builtinsrö  rö   r  rn  rŪ   r  rF  r  r  r  r  r  rä  rī  rļ  rū  r  r	  r  rŗ  r  rg  r  r  r  r  r   ŚUr!  r  r  rC  r  Śfindallr  r  r¢  r  r   r  rµ  r  r  r×  Śccallr'   r«   r  Ś	exceptvalŚcfuncr  r  rė   rė   rė   rģ   Ś<module>   s  "’’’’žžžżżüüüūūūū’’žüūłž ’žżüL

   O)ž
	ü
ż

ü
	ż

"  ’B        
        #K/	