
    ڏDjG                       d dl Z  e j                  di 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  	 d d$l!mZ"  ee"d%&      Z"	 d d'l$mZ%m&Z'm(Z)  ee%e'jT                  e)jV                  e'jX                  e'jX                  j[                         d   i(      Z%['[)dd) ee d%*      fd d+e"fd,d-e%fgZ.d.d.d/d0d1Z/d2d2d3d4d5Z0d6d7iZ1d8Z2 e3g d9      Z4g d:Z5 e j                  e3 e3d;            Z6d<d=ijn                  Z8 e j                  edd d d>jn                        Z9 G d? d@      Z:dA Z;dZ<	 dB Z=e=Z< G dC dD      Z> G dE dFe>      Z?e
 G dG dH             Z@ G dI dJe?      ZAddKdgdLdMZB eBdNdOP      dQ        ZC eB       dReAfdS       ZD eBdTdUdVW      dX        ZE eBdYdZdUd[W      d\        ZF eBd]d^P      d_        ZG eBd`dKdaW      db        ZH eB       dc        ZIddi fddZJ G de dfeA      ZK G dg dhe?      ZL G di dj      ZM G dk dl      ZN G dm dn      ZO e j                  eeeeo        ej                  dpej                        j                  ZS ej                  dq      j                  ZT ej                  dr      j                  ZV ej                  ds      j                  ZX G dt du      ZY G dv dw      ZZ G dx dy      Z[dz Z\ G d{ d|      Z] G d} d~      Z^ G d d      Z_ G d d      Z`e j                  e j                  decde j                  decfd              Ze e j                  d      e j                  decde j                  fd              Zh G d d      Ziy# e#$ r dZ"Y $w xY w# e#$ r dZ%Y w xY w)    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ImportCycleError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____lazy_import__
__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
frozendict	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sentinelsetsetattrslicesortedstaticmethodr(   sumsupertupletypevarszip)r   r   rS   r   r   ri   r;   rK   r   r   rH   r   r   _)		__cinit____dealloc____richcmp____next__	__await__	__aiter__	__anext____getbuffer____releasebuffer__inlineCYTHON_INLINE)ustringr   r   c                   @    e Zd ZdZdZdZdZdZddZd Z	d Z
d	 Zd
 Zy)IncludeCodez]
    An include file and/or verbatim C code to be included in the
    generated sources.
    r   r   r   Nc                    | j                   | _        t        |       xj                   dz  c_         i | _        |rO|d   dk(  r)|d   dk(  r!dj	                  |      | j                  d<   d}ndj	                  |      | j                  d<   |r|| j                  | j                  <   |r| j
                  | _        y |r| j                  | _        y | j                  | _        y )	Nr   r   <>z#include {}Fz#include "{}")	counterorderr   piecesr   INITIALlocationLATEEARLY)selfincludeverbatimlateinitials        XC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\Cython/Compiler/Code.py__init__zIncludeCode.__init__I  s    \\
T
aqzS WR[C%7!.!5!5g!>A!0!7!7!@A&.DKK

# LLDM IIDM JJDM    c                     ||v rP||   }t        | j                  |j                        |_        |j                  j                  | j                         y| ||<   y)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others       r   dict_updatezIncludeCode.dict_update_  sI    
 !8cFE ?ENLL,AcFr   c                     | j                   S N)r   r   s    r   sortkeyzIncludeCode.sortkeyk  s    zzr   c                 8    | j                   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   s    r   	mainpiecezIncludeCode.mainpiecen  s    
 {{q!!r   c                 t    t        | j                        D ]   }|j                  | j                  |          " y r   )r   r   putln)r   codeks      r   writezIncludeCode.writeu  s.    $ 	'AJJt{{1~&	'r   )NNTF)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r  r   r   r   r   r   /  s6    & GEDG',
"'r   r   c                      t         j                  j                  t         j                  j                  t         j                  j                  t                          } t         j                  j                  | d      S )NUtility)r   pathdirnameabspath__file__join)
Cython_dirs    r   get_utility_dirr  {  sE     1J!KLJ77<<
I..r   c                     t         j                  j                  t               |       }t	        t        j                  |d            5 }|j                         cddd       S # 1 sw Y   yxY w)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fs      r   read_utilities_from_utility_dirr    sP    
 ww||O-t4H	''7C	D {{}  s   	A##A,c                   &    e Zd ZdZdddZd Zd Zy)AbstractUtilityCodeNc                      y r   r  )r   globalstateused_bys      r   put_codezAbstractUtilityCode.put_code  s    r   c                      y r   r  r   kwargss     r   get_treezAbstractUtilityCode.get_tree      r   c                      y r   r  r$  s     r   get_shared_library_scopez,AbstractUtilityCode.get_shared_library_scope  r'  r   r   r   GlobalStatereturnN)r  r  r	  requiresr"  r&  r)  r  r   r   r  r    s    Hr   r  c                      e Zd ZdZdZi Z ej                  d      j                  Z	e
d        Zedd       Zed        Zed        Zei fd	       Zedd
       Z ej                  d      j$                  fdZd Zd Zd ZddZy)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                     t        j                  ddt        j                  |       iz  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_chars    r   get_special_comment_matcherz+UtilityCodeBase.get_special_comment_matcher  sC    zz& "))-./0
 24=
 >CU	Cr   Nc                    |y dj                  |      }|rPd|v rLd|d   v rE	 t        |      j                  t        t                    }||k(  rt        d	| d| d
|dd      |}d|z  |z   }|dk(  r||d<   n|dk(  r||d<   n
|d   }
||
|<   |rG|d   }
|j                         D ].  \  }}|
j                  |t                     j                  |       0 y y # t
        t        f$ r}	t        d| d| d|dd|	       d }	~	ww xY w)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   r9  r   r   rZ   r   rm   items
setdefaultr   r   )clsutilitynamer   linesbegin_linenotagsr  new_codeeall_tagstag_name
tag_valuess                r   _add_utilityzUtilityCodeBase._add_utility  sg   ?yyLD(Xl9K-Kk#D>44T&\B 4"\]a\bbcdhciijkwxyjzz{|~ ~D l"T)7?GAJV^GAJqzH!HTNqzH(,

 H$*##Hce4;;JGH ' j) k"<TF!D6T`abSccefgehik kks   'C D(D  Dc           	         | j                   j                  |      }|r|S t        j                  j	                  |      \  }}|dv r<d}t        t        j                  d      j                  d      }t        j                  }nTd}t        t        j                  d      j                  d      }t        t        j                  d      j                  d      }| j                  |      }| j                  }	t        |      }
t        d	       }g }t        t              }d x}x}}d
}t!        |
      D ]k  \  }} ||      }||j#                   | ||                   /|j%                  d      rg| j'                  ||||||       |dz   }|d d = |j)                          |j%                  d      } |	|      }|r|j+                         \  }}nd}||   }|j%                  d      }d|vrt-        d| d| d|       |j/                  d      \  }}}|j                         }|j1                         }|dvrt-        d| d| d|       t        j2                  d|      st-        d| d| d|       ||   j5                  |       |j#                  d       n |t7        d      | j'                  ||||||       t9        |      }|| j                   |<   |S )N)z.pyxz.pyz.pxdz.pxi#z^\s*#(?!\s*cython\s*:).* /z^\s*//.*|/\*[^*]*\*/z	\s+(\\?)$z\1c                      d d i gS r   r  r  r   r   <lambda>z:UtilityCodeBase.load_utilities_from_file.<locals>.<lambda>  s    tR(8 r   r   rD  r   r?  tagr<  zFound invalid tag 'z' in utility section r;  )r-  r9  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(   rstripr6  match_section_titleread_utilities_hookr   r   r   appendgrouprM  cleargroupsrm   	partitionstripr4  addr   r   )rB  r  	utilitiesr   extcommentstrip_commentsrY  match_special
match_type	all_linesrE  rG  rC  rD  r   rF  linenolinemmtype	tag_valuerK  s                          r   load_utilities_from_filez(UtilityCodeBase.load_utilities_from_file  s   &&**40	!!$'311G$RZZ0K%L%P%PRTUNZZFG$RZZ0G%H%L%LbQNRZZ5995AF77@,,
'-	 89	3 $$$$%i0 !	!LFDd#AyVN4$89:  $e\4P%z!H

wwv"4(!&JD$!D#D/GGEN	i'&)<YKG\]a\bbcdhci'jkk)2)<)<S)A&!Y#??,%OO-	#LL&)A(K`ae`ffghlgm'nooxx3&)B9+Mbcgbhhijnio'pqqX""9-R C!	!F ?677 	$e\4HO	#,4 r   c           	         d|v r|j                  dd      \  }}|sJ | j                  |      }||   \  }}}|rd|v r.d|d   v r't        | t              st        j                  ||fi |S |j                         }|j                         D ]  \  }	}
|	|v r|	dk(  rV|r+t        |
      D cg c]  } | j                  ||fi | }
}nYt        |
      D cg c]  }| j                  ||       }
}n0|	dk(  r
|
ddhz
  }
|
s"u|
sd}
nt        |
      dk(  rt        |
      d   }
|
||	<    |||d	<   |||d
<   d|vr||d<   d|vr|r||d<    | di |S c c}w c c}w )z
        Load utility code from a file specified by from_file (relative to
        Cython/Utility) and name util_code_name.
        z::r   r9  tempitar-  r:  Nr   r>  r?  rD  filer  )rsplitro  r   TempitaUtilityCodeloadcopyr@  r   load_cachedr   r   )rB  util_code_name	from_filer%  rc  r>  r?  rG  orig_kwargsrD  valuesdeps               r   ru  zUtilityCodeBase.loadF  s    >!(6(=(=dA(F%I~00;	%n5tTt#	T,5G(G!#'9:-22>9WPVWW ++-K $

 &f6>:%"-3F^"=&) #+#((3	"I["I "= "=
 .4F^"=&) #&//#y"A "= "=\) $x&;;F! !F[A%!&\!_F%t-&0 #F7O!F6N+F6NI&F6N}V}9"="=s   +EEc                 h    ||| f}	 ||   S # t         $ r Y nw xY w| j                  ||      x}||<   |S )z`
        Calls .load(), but using a per-type cache based on utility name and file name.
        )rZ   ru  )rB  utility_code_namery  _UtilityCodeBase__cacher   r  s         r   rw  zUtilityCodeBase.load_cached|  sP    
 !)S1	3< 		!hh'8)DDws|s    	c                     | j                   ||fi |}|s6|j                  |j                        |j                  |j                        fS g g cfd |       dj	                        dj	                        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                 *   | j                   r| j                   D ]
  } |        | j                  r*j                  | j                  | j                               | j                  r+j                  | j                  | j                               y y r   )r-  r>  r\  format_coder?  )	util_coder|  implsprependprotoss     r   r  z/UtilityCodeBase.load_as_string.<locals>.prepend  sq    !!$-- !CCL!i33IOODE~~Y229>>BC r   rP  )ru  r  r>  r?  r  )	rB  rx  ry  include_requiresr%  utilr  r  r  s	         @@@r   load_as_stringzUtilityCodeBase.load_as_string  s     sxx	<V<$$TZZ0$$TYY/1 1 B	D 	wwv..r   z\n\n+c                 >    |r |d|j                               dz   }|S )z3
        Format a code section for output.
        r8  z

)ra  )r   code_stringreplace_empty_liness      r   r  zUtilityCodeBase.format_code  s'     -dK4E4E4GH6QKr   c                 N    dt        |       j                  d| j                  dS )Nr   (z)>)r   r  rD  r   s    r   __repr__zUtilityCodeBase.__repr__  s    !$Z00$))<<r   c                      y r   r  r$  s     r   r&  zUtilityCodeBase.get_tree  r'  r   c                      y r   r  r$  s     r   r)  z(UtilityCodeBase.get_shared_library_scope  r'  r   c                     | S r   r  )r   memodicts     r   __deepcopy__zUtilityCodeBase.__deepcopy__  s    r   r   F)r  r  r	  r
  is_cython_utilityrV  r   r   r4  rZ  r   r6  r   rM  ro  ru  rw  r  rX  r  r  r&  r)  r  r  r   r   r/  r/    s    #J N$"**ze  C C H H@ E EN 3 3j ?A 
 
 / /: <F2::h;O;S;S =r   r/  c                   0    e Zd ZU dZeed<   eed<   eed<   y)SharedFunctionDeclz6Contains parsed declaration of shared utility functionrD  retparamsN)r  r  r	  r
  r(   __annotations__r  r   r   r  r    s    @
I	HKr   r  c                       e Zd ZdZg dZ	 	 	 	 ddZdedefdZd Z	d	 Z
d
 ZddZd Zej                  ddddddefd       Zd ZddZdddZy)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_clearNc                 h    | _         | _        | _        | _        | _        | _        | _        | _        i  _        g  _	        |	 _
        |
 _        | _        | _        |r j                  |      ng  _        |r j!                          t#         fd j$                  D               _        y )Nc              3   8   K   | ]  }t        |d         y wr   r   ).0partr   s     r   	<genexpr>z'UtilityCode.__init__.<locals>.<genexpr>  s     !X'$d";!Xs   )r>  r?  r  r  r  r  r  r-  _cachespecialize_listrU  rD  rr  r  parse_export_functionsshared_utility_functions_validate_suitable_for_sharingr   
code_parts_parts_tuple)r   r>  r?  r  r  r  r  r  r-  rU  rD  rr  r  s   `            r   r   zUtilityCode.__init__  s    
 
		"4%:""4 !&		OU(C(CF(K[]%//1 "!X!XXr   export_protor,  c           	      Z   d|vrd|vrd|vs%J d|j                          d| j                          g }d}|j                  d      D ]  }|j                         j                  dd	      }t	        j
                  d
d|      }t        |      dk(  rIt	        j                  ||t        j                        }|J d|d| j                          |j                         \  }}}|j                  t        |j                         |j                         |j                                       |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;
r8  rP  z\s+ r   z5Wrong format of function definition in export block 
z
 in )rD  r  r  )ra  rr  splitreplacer   rX  r   r4  r3  r_  r\  r  )	r   r  parsed_protosproto_regexr>  matchedret_type	func_namefunc_paramss	            r   r  z"UtilityCode.parse_export_functions  s9   <'D,DUaIa 	e78J8J8L7M[Y]YbYbXcd	e  "''. 	EKKM))$3EFF63.E5zQhh{E2::>G& dH	QWX\XaXaWbcd 07~~/?,Hi  "	(9x~~?OXcXiXiXkl	 r   c                 ,    t        | j                        S r   )r   r  r   s    r   __hash__zUtilityCode.__hash__  s    D%%&&r   c                     | |u ryt        |       t        |      }}||urt        ||      st        | |      sy| j                  |j                  k(  S )NTF)r   r   r  )r   r   	self_type
other_types       r   __eq__zUtilityCode.__eq__  sT    5= $T
DK:	J&
5)0LPZ[_akPl  E$6$666r   c                     |y||z  S zY
        Format a string in this utility code with context. If None, do nothing.
        Nr  r   scontexts      r   none_or_subzUtilityCode.none_or_sub  s     97{r   c                 ~   | j                   }|1|j                         |d<   |j                         |d<   |d|d   d}t        t	        |j                                     }	 | j                  |   S # t        $ r@ | j                  d }n.| j                  D cg c]  }|j                  |       nc c}w }}t        | j                  | j                  |      | j                  | j                  |      | j                  | j                  |      | j                  | j                  |      | j                  | j                   |      | j                  | j"                  |      | j                  | j$                  |      || j&                  |
      x}| j                  |<   | j(                  j+                  |       |cY S w xY w)Nr   	type_name[])rD  empty_declaration_codespecialization_namer   r   r@  r  rZ   r-  
specializer  r  r>  r?  r  r  r  r  r  rU  r  r\  )r   
pyrex_typedatarD  r   r-  rr  s           r   r  zUtilityCode.specialize%  s   yy!%<<>DL * > > @D#T+%67DF4::<()	;;s## 	}}$8<F1ALL.FFF#.  T2  D1  D1  t4  !8!8$?  !;!;TB  !8!8$?  $ AC    ''*H)	s   #A2 2'F<B21DF<;F<c                 >    t        | d      }|sy d|vs
J d|         y )Nr?  zNAMED_CGLOBAL(moddict_cname)z$moddict_cname should not be shared: r  )r   r  s     r   r  z*UtilityCode._validate_suitable_for_sharingE  s2    dF+F-[@ 	:24&9	:@r   writerCCodeWriteroutputr+  	code_typec                 >   t        | |      }|sy |dv }t        | ||      \  }}|rd| dnd}|dk7  r| j                   d| n| j                  }|j                  d| | d       |r$|s"|j	                  || j                   d	|        y |j                  |       y )
N)r>  r?  z
 (used by r=  rP  r?  r;  /*  */r   )r   process_utility_ccoderD  r  put_or_includeput_multilines)	r   r  r  r  r!  r  can_be_reusedresult_is_module_specificrD  s	            r   _put_code_sectionzUtilityCode._put_code_sectionK  s    dI.!%661FtVU`1a..-4Jwiq)"-6&-@$))Ai[)diis4&	-.!:!!+$))Ai[/IJ!!+.r   c                     | j                   sy |d   }| j                  ||d       |j                  d|j                  |j                        z          |j                          y )Ninit_globalsr    )r  r  r  error_goto_if_PyErr
module_pos)r   r  r  s      r   _put_init_code_sectionz"UtilityCode._put_init_code_section`  sU    yy'vvv6 	TF66v7H7HIIJr   c           
          |j                  d| j                   d       | j                  D ];  }|j                  d|j                   d|j                   d|j                   d       = |j                          y )Nr  r  static z(*z)(z); /*proto*/)r  rD  r  r  r  )r   r  shareds      r   !_put_shared_function_declarationsz-UtilityCode._put_shared_function_declarationsj  sj    

S3'(33 	[FJJBv{{m2fmm_LYZ	[ 	

r   c                    t        | j                  xr* |j                  j                  j                  j
                        }| j                  r0|s.| j                  D ]  }|j                  || j                         ! |r| j                  || j                            |j                  j                  | j                         | j                  r"| j                  || j                     |d|       |s | j                  || j                     |d       | j                  r|s| j                  |d   |d|       | j                  r&t         j"                  r| j                  |d   |d       | j$                  r| j                  |d   |d	       | j&                  r| j                  |d
   |d       | j(                  r| j                  |d   |d       | j*                  r| j-                  |       y y )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_coderD  r  rU  extendr>  r  r?  r  r	   generate_cleanup_coder  r  r  r  r  )r   r   r!  has_shared_utility_code
dependencys        r   r"  zUtilityCode.put_codeq  s   "&))qk.E.E.K.K.S.S.q.q#
 ==!8"mm L
,,Z,KL #22;t?O?O3PQ,,33D4Q4QR::"";t/?/?#@+w`g"h&"";t/?/?#@+xX994"";/A#BKQWah"i<<G99"";/@#A;PYZ"""";/F#GVjk%%"";/O#PR]_vw"""";/L#M{\pq99''4 r   )NNNNNNNNutility_code_protoNNNr   )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    & EJAE@D37PTY43 4 <'7@: \\/ /} /Y\ / /(5r   r  F)regexis_module_specific_last_macro_processorc                 ,     d    fd}|S )z8Decorator to chain the code macro processors below.
    r   c                 \     t               dt        dt        f fd       }|d<   |S )Nutility_coder  c                    d} | ||      \  }}rD ]  }||v s n ||fS 	 | ||      }n!t        j                  	t        |      |      }D ]"  }||v st        d| d| j                   d       |z  }||fS )NFzLeft-over utility code macro 'z()' found in '')r   rX  r   rm   rD  )
r  r  r  r  macrofuncr  last_processormacro_namesr  s
        r   processz=add_macro_processor.<locals>.build_processor.<locals>.process  s     ).%)9GV\^i9j66 ( BE+B '(AAA }"<E ffUGD&,A;O % sK'&)Gwn]i]n]n\oop'qrrs &);;% 999r   r   )r   r  r(   )r  r
  r   r  r  r	  r  s   ` r   build_processorz,add_macro_processor.<locals>.build_processor  s>    	t	:+ 	:C 	: 	: 
	:8 $+a r   r  )r  r  r   r	  r  r  s   ```` @r   add_macro_processorr    s"     +1-N B r   CSTRINGz)CSTRING\(\s*"""([^"]*(?:"[^"]+)*)"""\s*\))r  c                     |j                  d      j                  dd      }dj                  d |j                         D              S )zUReplace CSTRING('''xyz''') by a C compatible string, taking care of line breaks.
    r   "z\042rP  c              3   ~   K   | ]5  }|j                  d       r|j                  d      rd| dnd|dd  d 7 yw)\z\\r  z\n"
Nr   "
)endswith)r  rk  s     r   r  z!_wrap_c_string.<locals>.<genexpr>  sR      * !%d 3t}}V7L!D6TUVZ[^\^V_U``cRdd*s   ;=)r]  r  r  
splitlines)r   matchobjcontents      r   _wrap_c_stringr    sF     nnQ''W5G77 *&&(* * *r   r  c                 $    | j                  |      S r   )r  )r  r   r?  s      r   _format_impl_coder    s    ##D))r   CALL_UNBOUND_METHODTzLCALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)",\s*([^),\s]+)((?:,[^),]+)*)\))r  r  c                 :   |j                         \  }}}}d|z  }|r0|dd j                  d      D cg c]  }|j                          c}ng }t        |      dk  sJ dt        |      dd       | j	                  t
        j                   d	||||      S c c}w )
zRReplace 'UNBOUND_METHOD(type, "name")' by a constant Python identifier cname.
    z&%sr   N,r&   z'CALL_UNBOUND_METHOD() does not support r   z call arguments->)r_  r  ra  r   cached_unbound_method_call_coder   modulestateglobal_cname)r  r  
type_cnamemethod_name	obj_cnameargsargs          r   _inject_unbound_methodr%    s     08/@,JY#J;?48>>##67CCIIK7RDt9q=`CCIa=P_``11))
*"-:{D2 2 8s   BPYIDENT	PYUNICODEzPY(IDENT|UNICODE)\("([^"]+)"\)c                     |j                         \  }}t        j                  d| j                  t	        j
                  |      |dk(        j                  S )zDReplace 'PYIDENT("xyz")' by a constant Python identifier cname.
    r  IDENT
identifier)r_  r   r  get_py_string_constr
   EncodedStringcname)r  r  str_typerD  s       r   _inject_string_constantr0    s^     __&NHd&&""((.8w;N 	# 	PPUPU	VW Wr   EMPTYzEMPTY\((bytes|unicode|tuple)\)c                 p    |j                  d      }t        j                  dt        t        d|       S )zLReplace 'EMPTY(bytes|tuple|...)' by a constant Python identifier cname.
    r   r  empty_)r]  r   r  r   )r  r  r  s      r   !_inject_empty_collection_constantr4    s6     q!I&&&,-/ /r   CGLOBALz(NAMED_)?CGLOBAL\(([^)]+)\)c                 v    |j                         \  }}|rt        t        |      }t        j                   d| S Nr  )r_  r   r   r  )r  r  is_namedrD  s       r   _inject_cglobalr9    s;     __&NHdvt$,,-Rv66r   c                     |S )z;Entry point for code processors, must be defined last.
    r  )r  r   r  s      r   r  r    s
     r   c                     | sy|r| d| }|r||d<   	 ||    }|j                  |      S # t         $ r ddlm}  || |      x}|| <   Y 1w xY w)z+Run tempita on string s with given context.Nr<  __namer   r   )rD  )rZ   Tempitar   r9  )r  r  rr  rD  __cachetemplater   s          r   sub_tempitar@    sr    q 71:
 w''	  7& ( 6671:7s   + AAc                   >     e Zd Zd fd	Zeddi fd       Zd Z xZS )rt  Nc                     |i }n|j                         }t        ||||      }t        ||||      }t        ||||      }t        |   ||f|||d| y )N)r  rD  rr  )rv  r@  r   r   )	r   rD  r>  r?  r  rr  r  r%  	__class__s	           r   r   zTempitaUtilityCode.__init__)  ss    ?G llnGE7D$74$54$54	D"D	D<B	Dr   c                     |r"t        t        |j                                     nd }t        |      J | |||f}	 ||   S # t        $ r Y nw xY w| j                  |||      x}||<   |S )N)r  )r   r   r@  r   rZ   ru  )rB  r~  ry  r  _TempitaUtilityCode__cachecontext_keyr   r  s           r   rw  zTempitaUtilityCode.load_cached5  s|    8?eF7==?34TK ,,I0+>	3< 		!hh'8)WhUUws|s   A   	AAc                 L    |yt        ||| j                  | j                        S r  )r@  rr  rD  r  s      r   r  zTempitaUtilityCode.none_or_subA  s%     91gtyy$))<<r   )NNNNNN)r  r  r	  r   r   rw  r  __classcell__)rC  s   @r   rt  rt  (  s*    
D 6:DRT 	 	=r   rt  c                   (    e Zd ZdZdZ dZd ZdddZy)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                     || _         y r   )callback)r   rL  s     r   r   zLazyUtilityCode.__init__R  s	     r   c                 `    | j                  |j                        }|j                  ||       y )Nr  )rL  
rootwriterr  )r   r   r!  rC  s       r   r"  zLazyUtilityCode.put_codeU  s)    -- 6 67$$Wg$>r   r   r*  )r  r  r	  r
  r-  r   r"  r  r   r   rJ  rJ  J  s     HH!?r   rJ  c                       e Zd Z e       dfdZd ZddZddZddZd Z	d Z
dd	Zd
 Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zy)FunctionStateNc                    || _         || _        || _        d | _        d| _        t               | _        | j                         | _        | j                          d | _
        d | _        g | _        d | _        d | _        d| _        d| _        g | _        i | _        i | _        t               | _        d| _        d | _        g | _        d| _        d| _        d| _        d| _        y )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   rS  rR  r  s       r   r   zFunctionState.__init__g  s    &

5 NN,""!!E! $&  /4+$)!',$#r   c                    | j                   rn| j                         }|r[d| j                  j                  ddj	                  t        |      D cg c]  \  }}}|d|d c}}}      }t        |      y y c c}}}w )Nz&TEMPGUARD: Temps left over at end of 'z': , z [r  )ra  temps_in_user  rD  r  r   rm   )r   	leftoversrD  ctype	is_pytempmsgs         r   validate_exitzFunctionState.validate_exit  s    ))+IIMZ^ZcZc282CeE eE.eY "&u-eE [F 
 #3''   eEs   A<c                 p    | j                   }|dz   | _         dt        j                  |fz  }||d|z   z  }|S )Nr   %s%dr   )rU  r   label_prefix)r   rD  nlabels       r   rW  zFunctionState.new_label  sG    --U&--q11S4ZEr   c                     | j                  d|z        }t        | j                        dz   |f}| j                  j                  |       |S )Nzresume_from_%sr   )rW  r   r\  r\  )r   	expr_typerx  num_and_labels       r   new_yield_labelzFunctionState.new_yield_label  sJ    /);<T../!3U;  /r   c                 P    | j                   }| j                  |dz         | _         |S )Nerror)rT  rW  )r   prefixold_err_lbls      r   rY  zFunctionState.new_error_label  s)    &&>>&7*:;r   c                 2    | j                   | j                  fS r   rZ  r[  r   s    r   get_loop_labelszFunctionState.get_loop_labels  s     	r   c                 "    |\  | _         | _        y r   r  r   labelss     r   set_loop_labelszFunctionState.set_loop_labels  s    #				r   c                     | j                         }| j                  | j                  |dz         | j                  |dz         f       |S )Ncontinuebreak)r  r  rW  )r   r  
old_labelss      r   new_loop_labelszFunctionState.new_loop_labels  sM    ))+
^^FZ/0^^FW,-/	0 r   c                 ^    | j                   | j                  | j                  | j                  fS r   rZ  r[  rX  rT  r   s    r   get_all_labelszFunctionState.get_all_labels  s0    	 	r   c                 :    |\  | _         | _        | _        | _        y r   r  r  s     r   set_all_labelszFunctionState.set_all_labels  s#     $								r   c                     | j                         }g }t        |g d      D ]9  \  }}|r!|j                  | j                  |             )|j                  |       ; | j	                  |       |S )N)r  r  r,  r~  )r  r   r\  rW  r  )r   r  
new_labels	old_labelrD  s        r   all_new_labelszFunctionState.all_new_labels  sn    ((*

":/WX 	-OIt!!$.."67!!),		-
 	J'r   c                 :    | j                   j                  |       y r   )rV  rb  r   lbls     r   	use_labelzFunctionState.use_label  s    S!r   c                     || j                   v S r   )rV  r  s     r   
label_usedzFunctionState.label_used  s    d&&&&r   c           	      H   |j                   r|j                  s|j                  }n|j                  r|j                  s|j                  }n|j
                  rddlm} |j                  |      }n`|j                  rT|j                  sH| j                  j                  d   r/| j                  j                  t        j                  dd             |j                  sd}| j                   j#                  ||f      }|r/|-|d   r(|d   j%                         }|d   j'                  |       n	 | xj(                  dz  c_        dt*        j,                  | j(                  fz  }|| j.                  vrnD| j0                  j3                  ||||f       |s| j4                  j7                  |       ||f| j8                  |<   t:        j<                  r)| j>                  jA                  d	|d
|d|rdndd       | jB                  r | jB                  d   j7                  ||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.cppFr   ru  r  z allocated (r=  rP  	 - zombier  r   )"is_cv_qualifiedis_referencecv_base_typeis_fake_referenceref_base_typeis_cfunctionrP  r  
c_ptr_typeis_cpp_classr  
directivesr  r  rw  needs_refcountingrb  r   popremovere  r   codewriter_temp_prefixrR  ra  r\  rd  rb  rc  r   debug_temp_code_commentsrS  r  rg  )r   r   
manage_refstaticreusabler  freelistresults           r   allocate_tempzFunctionState.allocate_temp  s   . (9(9$$Dt'='=%%D$((.Dt'='=$**BWBWXdBeJJ''(?(?@PRb(cd%% J??&&j'9:,!a[__&FQKv&!!Q&!6#@#@$BSBS"TT!1!115    ''z6(JK!!%%f-(,j'9V$..JJFDPX"^iJijk##$$R(,,fd^<r   c                    | j                   |   \  }}| j                  j                  ||f      }|g t               f}|| j                  ||f<   ||d   v rt	        d|z        || j
                  vr|d   j                  |       |d   j                  |       t        j                  r3| j                  j                  d|d|| j
                  v rdndd	       yy)
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   r  z
 released r  rP  r  )rc  rb  r   r   rm   rd  r\  rb  r   r  rS  r  )r   rD  r   r  r  s        r   release_tempzFunctionState.release_temp  s    
  //5j??&&j'9:CE{H2:DOOT:./8A;5<==t(((QKt$..JJTT->->%>kBFH I /r   c                     g }| j                   D ]P  \  }}}}| j                  j                  ||f      }|||d   vs/|j                  |||xr |j                  f       R |S )zxReturn a list of (cname,type,manage_ref) tuples of temp names and their type
        that are currently in use.
        r   )ra  rb  r   r\  r  )r   usedrD  r   r  r  r  s          r   rn  zFunctionState.temps_in_use0  sx     .2.B.B 	Q*D$
F**D*+=>H4x{#:T4)N8N8NOP	Q r   c                 |    | j                         D cg c]  \  }}}|r|j                  r||f c}}}S c c}}}w )zReturn 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.
        )rn  r  )r   rD  r   r  s       r   temps_holding_referencez%FunctionState.temps_holding_reference;  sG     /3.?.?.A: :*D$
$"8"8 t : 	: :s   7c           
      d    | j                   D cg c]  \  }}}}|r||f c}}}}S c c}}}}w )zRReturn a list of (cname, type) tuples of refcount-managed Python objects.
        )ra  )r   r.  r   r  r  s        r   all_managed_tempszFunctionState.all_managed_tempsD  s>     8<7K7K 3E4V   	 s   *
c                     t        | j                  j                         D cg c]  \  \  }}}|r|d   D ]  }||f  c}}}}      S c c}}}}w )zReturn 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.
        r   )r   rb  r@  )r   r   r  r  r.  s        r   all_free_managed_tempsz$FunctionState.all_free_managed_tempsK  sf     040E0E0G
 
,"zH:!!
  DM

  	 
s   Ac                 J    | j                   j                  t                      y)zJ
        Useful to find out which temps were used in a code block
        N)rg  r\  r   r   s    r   start_collecting_tempsz$FunctionState.start_collecting_tempsW  s     	  ''.r   c                 6    | j                   j                         S r   )rg  r  r   s    r   stop_collecting_tempsz#FunctionState.stop_collecting_temps]  s    ''++--r   c                 $    t        |      | _        y r   )ClosureTempAllocatorrf  r   r  s     r   init_closure_tempsz FunctionState.init_closure_temps`  s    1%8r   r   )yield)rP  )FT)r  r  r	  r   r   rs  rW  r|  rY  r  r  r  r  r  r  r  r  r  r  rn  r  r  r  r  r  r  r  r   r   rP  rP  Z  s|     +.%t '$V
(

$$	"'
8tI&	:
/.9r   rP  c                       e Zd ZdZddZy)NumConstzGlobal 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                 D    || _         || _        || _        |xs || _        y r   )r.  valuepy_type
value_code)r   r.  r  r  r  s        r   r   zNumConst.__init__m  s#    

$-r   r   r  r  r	  r
  r   r  r   r   r  r  d  s    .r   r  c                       e Zd ZdZd Zy)PyObjectConstz>Global info about a generic constant held by GlobalState.
    c                      || _         || _        y r   )r.  r   r   r.  r   s      r   r   zPyObjectConst.__init__z  s    
	r   Nr  r  r   r   r  r  t  s    
r   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                       e Zd ZdZd ZddZy)StringConstz?Global info about a C string constant held by GlobalState.
    c                 p    || _         || _        t        j                  |      | _        d | _        d| _        y NF)r.  textr
   escape_byte_stringescaped_value
py_stringsc_used)r   r.  r  byte_strings       r   r   zStringConst.__init__  s1    
	+>>{Kr   Nc                    | j                   }|s|d x}}d}n5d}|j                         }|dv rd }d }ndj                  t        |            }|rd}n>|:t	        |t
              rt        t        |            }nt        t        |            }nd}|||f}| j                  i | _	        n	 | j                  |   S |rt        j                  d   nt        j                   |rdnd |rd|z   nd d| j                  t        t        j                         d   }t#        ||||      }	|	| j                  |<   |	S # t        $ r Y w xY w)	NTF)utf8utf-8r   usasciizus-asciirP  r(   ubr   )r  lowerr  r  r   r   r   r  r  r  rZ   r   interned_prefixespy_const_prefixr.  r   const_prefixPyStringConst)
r   r  r+  r  encoding_key
is_unicodeinternr   pystring_cname	py_strings
             r   r,  zStringConst.get_py_string_const  sd   yy )&**H|J J~~'HLL#!ww~h'?@F$&7=>9$?@Fz<0??" DOs++
 39v''.f>T>TU sc*%1s\!r:

3v2234568 	 ".(FJO	(  s   *D5 5	E Er   )r  r  r	  r
  r   r,  r  r   r   r  r    s    /r   r  c                       e Zd ZdZddZd Zy)r  zDGlobal info about a Python string constant held by GlobalState.
    c                 <    || _         || _        || _        || _        y r   )r.  r  r  r  )r   r.  r  r  r  s        r   r   zPyStringConst.__init__  s    
 $r   c                 4    | j                   |j                   k  S r   r.  r   r   s     r   __lt__zPyStringConst.__lt__  s    zzEKK''r   NFF)r  r  r	  r
  r   r  r  r   r   r  r    s    (r   r  c                   J   e Zd Zi Zg dZg dZd1dZd Zd Zd Z	d Z
d	 Zd
 Zd1dZd2dZd Zd1dZd Zd3dZd Zd1dZd Zd Zd Zd1dZd Zd Zd Zd4dZdefdZd Zd Z d Z!d  Z"d! Z#d3d"Z$d# Z%d$ Z&d% Z'd&e(d'e(fd(Z)d) Z*d* Z+e,d+        Z-d, Z.d- Z/d. Z0d1d/Z1d0 Z2y)5r+  ))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                 z   i | _         g | _        i | _        t               | _        i | _        d| _        || _        || _        i | _	        || _
        i | _        i | _        i | _        i | _        g | _        i | _        g | _        i | _        i | _        t               | _        g | _        |j-                  |        || _        y 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_staterN  )r   r  r  r!  r"  s        r   r   zGlobalState.__init__.  s     #%  U!*/'&*D'
& "$"$!#)+&$&!!%'"$&!!%(U"(*%% r   c                    | j                   }t        | j                        D ]>  \  }}|j                         x}| j                  |<   |dkD  s+|j                  d|z         @ | j                  d   }|j                  dt        j                   dt        j                   d       |j                  dt        j                   d       | j                  d	   }|j                  d
t        j                   dt        j                   dd       |j                  dt        j                   d       |j                  t        j                  d             | j                  d   }|j                  d       | j                  d   }|j                  dt        j                   dt        j                   d       |j                  dt        j                   d       t        j                  s| j                  d= nf| j                  d   }|j                  dt        j                   dt        j                   d       |j                  dt        j                   d       | j                  d   }|j                  d       |j                  d       | j                  d   }| j                  j                   r|j#                  d       |j                  d       |j                  d       y )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  rP  z)/* --- Runtime support code (head) --- */r  z
#line 1 "cython_utility"
z"/* --- Runtime support code --- */)rN  r   code_layoutinsertion_pointr#  r  start_initcfuncr   modulestatetype_cnamemodulestatevalue_cnameput_setup_refcount_contextr
   r-  r	   r  r!  emit_linenumsr  )r   rN  ir  wr  s         r   initialize_main_c_codez"GlobalState.initialize_main_c_codeJ  s   __
 !1!12 	BGAt#-#=#=#??A

4 1u9D@A	B
 JJ()	+++,Bv/L/L.MQP	Q 	
$V%B%B$C2FGJJ)*	,++,Bv/L/L.MQP 	 	 	
$V%B%B$C2FG	$$^%A%AB]%^_JJ~&	78JJ'(	&++,Bv/L/L.MQP	Q 	
$V%B%B$C2FG,,

,-

,-A,//063P3P2QQRTU GG()F)F(GrJKzz./

2

>?zz,-))JJ56

2

78r   c                 x    | j                   }| j                  D ]  }|j                         | j                  |<   ! y r   )rN  h_code_layoutr6  r#  )r   rN  r  s      r   initialize_main_h_codez"GlobalState.initialize_main_h_code{  s7    __
&& 	<D)99;DJJt	<r   c                 d   | j                          | j                  d   }t        j                  dd      }|j	                  |j                  |j                               |j                  d       | j                  d   }t        j                  dd      }|j                  |j                  |j                               |j                  d       | j                  d   }t        j                  d	d      }|j                  |j                  |j                               |j                  d       y )
Nr  TypeConversionszTypeConversion.crP  r  UtilityCodePragmasModuleSetupCode.cr  UtilityCodePragmasEnd)	close_global_declsr#  rt  rw  putr  r?  r  r  )r   r  r  s      r   finalize_main_c_codez GlobalState.finalize_main_c_code  s    !
 zz,-!--.?AST!!$)),-

2
 zz01&&';=PQ

4##DII./

2zz45&&'>@ST

4##DII./

2r   c                      | j                   |   S r   )r#  )r   r   s     r   __getitem__zGlobalState.__getitem__  s    zz#r   c                 P   | j                          | j                  d   }|j                  d       |j                  |j                        r,|j                  |j                         |j                  d       |j                  d       |j                          | j                  d   }dD ]Q  }|| j                  v s| j                  |j                  t        j                  |z         | j                  |   |       S |j                          |j                  d       |j                  |j                        r<|j                  |j                         |j                          |j                  d       |j                  d       |j                          dD ]  }| j                  |   }|j                  d       |j                  |j                        r,|j                  |j                         |j                  d       |j                  d       |j                           t        j                  r0| j                  d   }|j                  d       |j                          t        j                  r1| j                  d	   }|j                  d       |j                          y y )
Nr  	return 0;
return -1;}r  )r   r   )r  r  r  r  )generate_const_declarationsr#  r  r  rT  	put_labelexit_cfunc_scoper+  immortalize_constantsname_in_module_stater   pyrex_prefixput_finish_refcount_contextr	   r  )r   r=  
const_typer  s       r   rG  zGlobalState.close_global_decls  s    	((*JJ()	<<&KK&GGL!		JJ)*, 	JT666****6+>+>+KL--j9	 	
%%'	<<&KK&))+GGL!		6 	!D

4 AGGK ||AMM*AMM*%GGCL 	! ((

,-AGGCL ((

+,AGGCL  )r   c                 F    | d   j                  d|j                  z         y )Nr  zstatic PyObject *%s;)r  r.  r   entrys     r   put_pyobject_declzGlobalState.put_pyobject_decl  s    \  !7%++!EFr   c                 x    |*|| j                   v ry | j                   j                  |       | j                  d   S )Nr  )r-  rb  r#  r   targets     r   get_cached_constants_writerz'GlobalState.get_cached_constants_writer  s=    333&&**62zz,--r   c                     |xr dxs d}	 | j                   ||f   }|S # t        $ r | j                  ||      }Y |S w xY w)Nlongr   r)  rZ   new_num_const)r   	str_valuelongnessr  cs        r   get_int_constzGlobalState.get_int_const  sZ    %v.	7$$i%9:A   	7""9g6A	7s    >>c                 p    	 | j                   |df   }|S # t        $ r | j                  |d|      }Y |S w xY w)Nr   rb  )r   rd  r  rf  s       r   get_float_constzGlobalState.get_float_const  sP    	C$$i%9:A   	C""9gzBA	Cs    55c                     || j                   j                  |      }||S | j                  |      }||| j                   |<   |S r   )r&  r   new_array_const_cname)r   r  	dedup_keyconsts       r   get_py_constzGlobalState.get_py_const  sT     **..y9E **62 05D""9-r   c                 v    | j                  d      }t        ||      }| j                  j                  |       |S NrP  )new_const_cnamer  r*  r\  )r   r   r.  rf  s       r   get_argument_default_constz&GlobalState.get_argument_default_const  s9    $$R(%&""))!, r   c                     |j                   r|j                         }n|j                         }	 | j                  |   }|rd|_        |S # t        $ r | j                  ||      }Y (w xY wNT)r  
utf8encode
byteencoder%  rZ   new_string_constr  )r   r  r  r  rf  s        r   get_string_constzGlobalState.get_string_const  sj    ??//+K//+K	9''4A AH	  	9%%dK8A	9s   A	 	A'&A'c                     |j                   sJ 	 | j                  |   }|S # t        $ r# | j                         x}| j                  |<   Y |S w xY wr   )r  r'  rZ   rq  )r   r  rf  s      r   get_pyunicode_ptr_constz#GlobalState.get_pyunicode_ptr_const
  s_    	N..t4A   	N7;7K7K7MMA..t4	Ns   ! (AAc                 d    | j                  |d      }|j                  |j                  |      }|S )NF)r  )rx  r,  r  )r   r  r+  c_stringr  s        r   r,  zGlobalState.get_py_string_const  s3     $ 5 5d5 5 I00
K	r   c                     t        | j                        }t        j                   d| d}| j                  j	                  |       |S )Nr  r  )r   r(  r   codeobjtab_cnamer\  )r   nodeidxrD  s       r   get_py_codeobj_constz GlobalState.get_py_codeobj_const  sD    $++,))*!C52!!((.r   c                 (    | j                  |d      S NTr*  r,  r   r  s     r   get_interned_identifierz#GlobalState.get_interned_identifier      '''>>r   c                 `    | j                  |      }t        |||      }|| j                  |<   |S r   )new_string_const_cnamer  r%  )r   r  r  r.  rf  s        r   rw  zGlobalState.new_string_const"  s5    ++K8t[1/0,r   c                 h    | j                  ||      }t        ||||      }|| j                  ||f<   |S r   )new_num_const_cnamer  r)  )r   r  r  r  r.  rf  s         r   rc  zGlobalState.new_num_const(  s>    ((8UE7J712eW-.r   c                 J    |j                  dd      }| j                  |      S )NASCIIignore)r  )decoderq  )r   bytes_valuer  s      r   r  z"GlobalState.new_string_const_cname.  s(    ""7H5##%#00r   c                     | j                   }|j                  dd      x}}||v r%||   dz   x}||<   |j                  d|      }||v r%d||<   |S )NrP  )sepr   r   r   )r$  r   )r   
format_strr  r.  r  r   s         r   unique_const_cnamezGlobalState.unique_const_cname3  sr    %%"))b")==tm$(K!O3Gd5k%%#w%?E tm Ur   c                    |dk(  r|dz  }d}t         j                  |   }|j                  dd      j                  dd      j                  dd      }t        |      d	kD  r%| j	                  |d
z   |d d z   dz   |dd  z         }|S ||}|S )Nra  Lr   r;  r   +-neg_*   zlarge{counter}_   _xxx_i)r   r  r  r   r  )r   r  r  r  r.  s        r   r  zGlobalState.new_num_const_cname<  s    fSLEG))'2c3'//S9AA#vNu:?++**U3BZ7'AE#$KOQE  %e,Er   c                     t        d|      d d j                  d      }| j                  |dz         }|rt        j                  |   }nt        j
                  }||S )Nr       z{sep}{counter})r  ra  r  r   r  r  )r   r  r  name_suffixs       r   rq  zGlobalState.new_const_cnameK  s_    "3.s399#>--e6F.FG--f5F((F--r   r  c                     | j                   j                  |d      }|dz   | j                   |<   t        j                   | d| dS )Nr   r   r  r  )r+  r   r   rU  )r   r  counts      r   rk  z!GlobalState.new_array_const_cnameT  sL    ))--fa8,1!G!!&)%%&vhawa88r   c                     ||f}	 | j                   |   }|S # t        $ r* | j                  d|d|      x}| j                   |<   Y |S w xY w)Numethodr   )r,  rZ   rq  )r   r   r!  r   r.  s        r   get_cached_unbound_methodz%GlobalState.get_cached_unbound_methodY  so    ;'	@((-E   	@040D0Dj+>1@ @ED((-	@s    /A
	A
c           	          dt        |      z  }| j                  t        j                  |d             | j	                  ||      }|g|z   }d|d||ddj                  |      dS )NzCallUnboundCMethod%dObjectHandling.c__Pyx_z(&rm  r=  )r   r  r  rw  r  r  )	r   modulestate_cnamer"  r   r!  
arg_cnamesr~  cache_cnamer#  s	            r   r  z+GlobalState.cached_unbound_method_call_codeb  sj    2S_Dk556GI[\]44ZM{Z'IIdO	
 	
r   c                 B   |j                   r|j                  r| j                  |j                  |      ri| j	                  |       |j
                  }|t        v r	t        |   }| j                  |j                  t        j                  |      |j                         y y y y r   )
is_builtinis_constshould_declarer.  r[  rD  renamed_py2_builtins_mapput_cached_builtin_initposr
   r-  )r   rZ  rD  s      r   add_cached_builtin_declz#GlobalState.add_cached_builtin_declo  s    ""5;;6&&u-zz333D9D,,II~;;DAKK! 7 !/r   c                    | j                   d   }|j                  | j                  |      j                        }| j	                  t
        j                  dd             |j                  |d|d|d|j                  |             y )Nr  GetBuiltinNamer  z = __Pyx_GetBuiltinName(z); if (!) )	r#   name_in_main_c_code_module_stater  r.  r  r  rw  r  
error_goto)r   r  rD  r.  r=  cname_in_modulestates         r   r  z#GlobalState.put_cached_builtin_initz  s}    JJ() AA((.44 6##$46HI	K	 LL	 	 r   c                     | j                          | j                          | j                          | j                          | j	                          y r   )generate_cached_methods_declsgenerate_object_constant_declsgenerate_codeobject_constantsgenerate_string_constantsgenerate_num_constantsr   s    r   rP  z'GlobalState.generate_const_declarations  s@    **,++-**, 	&&(##%r   c                     |dk  rdnd}|rdnd}| j                   d   }|j                  d| d| d	| d
| d	       | j                   d   }|j                  d| d| d| d       y )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_cnamer  may_have_refcyclescounter_type
visit_callr  s          r   )_generate_module_array_traverse_and_clearz5GlobalState._generate_module_array_traverse_and_clear  s     %u<#5Z;N
34u\N(5'J<Oghygz  {C  D  	E01u\N(5'9`ar`ss{|}r   c                    | j                   D cg c]$  }t        |j                        |j                  |f& }}|j                          |D ]  \  }}}| j                  d   j                  d|j                  j                  |      z         |j                  j                  sX| j                  d   j                  d| |j                  dd       |j                  j                  r|dz  }| j                  d	   j                  d
| d        t        | j                  j                               D ]  \  }}t        j                   | }| j                  d   j                  d| d| d       | j!                  ||d       t#        |      }|a|t$        j&                  k  su| j                  d   }	|	j)                  d| d       |	j                  d|	j+                  | d      z          y c c}w )Nr  z%s;r  zclear_module_state->TF)clear_before_decrefnannyz	->memviewr  z Py_VISIT(traverse_module_state->r2  
PyObject *r  ];r  r  zfor (size_t i=0; i<z; ++i) z{ Py_CLEAR(%s); }z[i])r*  r   r.  sortr#  r  r   declaration_coder  put_xdecref_clearis_memoryviewslicer   r+  r@  r   rU  r  cleanup_level_for_type_prefixr	   r  rH  r  )
r   rf  constsr   r.  r  r  r  cleanup_levelpart_writers
             r   r  z*GlobalState.generate_object_constant_decls  s   557 qww<!, 7 7! 	>KAuaJJ~&,,UQVV5L5LU5S-ST66++ JJ+,>>&ug.$(	 ?  vv(($JJ./5525'<>'	>, $D$=$=$C$C$EF 	MFE#)#6#6"7x @JJ~&,,z:K9LAeWTV-WX ::;Lehm:n9&AM(]g>[>[-["jj):;"5eWG DE!!'#DDHYGZZ]E^_`	37s   )G7c                    | j                   sy | j                  d   }| j                  d   }|j                  d       |j                  d       g }t        | j                   j	                               D ]  \  \  }}}|j                  |       | j                  t        j                  |            j                  }|j                  d|z         |j                  |j                  |      d|d       |j                  |j                  |       d|j                  |       d        t        j                  r;| j                  d	   }|D ]&  }|j                  d
|j                  |       d       ( y y )Nr  r  rP  z/* Cached unbound methods */z__Pyx_CachedCFunction %s;z.type = (PyObject*);z.method_name = &r  z	Py_CLEAR(z	.method);)r,  r#  r  r   r@  r\  r  r
   r-  r.  r  r	   r  )	r   declr  cnamesr   r!  r.  method_name_cnamer  s	            r   r  z)GlobalState.generate_cached_methods_decls  su   ##zz.)zz+,

2

1206t7K7K7Q7Q7S0T 	Q,%ZuMM%  $ < <^=Y=YZe=f g m mJJ2  JJ55e<jJ K JJ88?@ A99:KLMQPQ	Q ((jj!23G c	$*O*OPU*V)WW`abc )r   c                 8   g }g }g }t        | j                  j                         D cg c]$  }t        |j                        |j                  |f& c}      D ]  \  }}}|j
                  r;|j                  t        |j                        |j                  |j                  f       |j                  s\|j                  j                         D ]  }|j                  }|j                  rBt        |t              s2t        j                  |j                  |j                   xs d            }|j                  r|n|j                  |j"                  xr |j                  |j                  |f         |j%                          |j%                          |j%                          | j&                  d   }|D ]5  \  }}	}
t        j(                  |
      }|j+                  d|	 d| dd       7 t        | j,                  j/                               D ]  \  }}	t        j0                  |      \  }}|r|j+                  d       |j+                  d	|	d
|d       |sL|j+                  d       |j+                  d	|	d
|d       |j+                  d        t        |      t        |      z   }| j&                  d   j+                  dt2        j4                   d| d       | j7                  t2        j4                  |d       | j9                  ||       y c c}w )Nr  r  zstatic const char z[] = "";Tsafez#ifdef Py_UNICODE_WIDEzstatic Py_UNICODE z[] = { z };#else#endifr  r  r  r  Fr  )r   r%  r{  r   r.  r  r\  r  r  r  r  r   r(   r
   r-  r  r  r  r  r#  split_string_literalr  r'  r@  encode_pyunicode_stringr   stringtab_cnamer  generate_pystring_constants)r   c_constspy_bytes_constspy_unicode_constsrf  r   r  r  decls_writerr.  r  cliteralutf16_arrayutf32_arraypy_string_counts                  r   r  z%GlobalState.generate_string_constants  s    4CZCZCaCaCcdaAGGaggq9de 	GAq!xxQWWqww HI||!"!4!4!6 	I66D ++JtS4I-;;DKK	HZHZHe^e<fg*3*>*>&O[[!((AY-A-A!] 			 	  zz.1'/ 	#Aum%::=IH$UG6(2>  	 t==CCEF 		-HAu'5'M'Ma'P$K""#;<UKXY""7+""P[#\]""8,		- o.5F1GG

>"((:f6L6L5MQN__a)bc66v7M7Msx6y(():OL[ es   )Ltext_stringsbyte_stringsc                    | j                   d   }g }d}d}t        |      D ]`  \  }\  }}	}
|j                  |
j                  d             |dk(  r|r|}|j	                  d|	 dt
        j                   d| d       |d	z  }b t        |      }|D ]o  \  }}	}
|j                  |
j                  r|
j                         n|
j                                |j	                  d|	 dt
        j                   d| d       |d	z  }q t        t        t        |            }d
j                  |      }| j                   d   }|j	                  d       |j	                  dt        |      j                          ddj                  |D cg c]  }d|z  	 c}       d       | j!                  t"        j%                  dd             d}t'        t(              D ]k  \  }}}| ||      }t        |      t        |      dz
  k\  r.|dk(  r|d	k(  sJ d       d}n|dk(  rd| d}nd| }|j	                  d|sdnd d| d| d t        |       d!	       d"}t+        j,                  t+        j.                  |            }|j	                  d#| d$d"%       |j	                  d&t        |       d'| d(       |j	                  |j1                  d)| j2                               |j	                  d*       |j	                  d+       |j	                  d,|j5                  | j2                         d-       |j	                  d.       n |r|j	                  d/t        |       d!       t+        j,                  t+        j.                  |            }|j	                  d0| d$d"%       |j	                  d1       |j	                  d2       |r|j	                  d.       |j	                  d3|j7                  t
        j                         d4       |j	                  d5       |dkD  r|j	                  d6|d7k  rd8nd9 d:| d;       |j	                  d<       |j	                  d=       |dk\  r|j	                  d>| d?       |j	                  d@       |j	                  dA       |j	                  |j5                  | j2                               |j	                  dB       |j	                  dC       |j	                  dD       |j	                  dB       |t        |      k  r|j	                  d6t        |      d7k  rd8nd9 dE| dFt        |       d;       |j	                  d<       |j	                  dG       |j	                  dC       |j	                  dD       |j	                  d@       |j	                  dA       |j	                  |j5                  | j2                               |j	                  dB       |j	                  dB       |j	                  dA       |j	                  dHt        |       d;       |j	                  dI       |j	                  |j5                  | j2                               |j	                  dB       |j	                  dB       |t        |      k  r"| j9                  dJ| t        |      |z
  |       |j	                  dB       y c c}w )KNr
  r   r   r  #define r  r  r  r   r   r  {z*const struct { const unsigned int length: z; } index[] = {r  z{%d}};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 >= 0x030e0000rO  ifelifz /* compression: z (z
 bytes) */Tzconst char* const cstring = "r  r  z1PyObject *data = __Pyx_DecompressString(cstring, rm  r2  r  z7const char* const bytes = __Pyx_PyBytes_AsString(data);z#if !CYTHON_ASSUME_SAFE_MACROSz,if (likely(bytes)); else { Py_DECREF(data);  }r  z#else /* compression: none (zconst char* const bytes = "zPyObject *data = NULL;z*CYTHON_UNUSED_VAR(__Pyx_DecompressString);zPyObject **stringtab = r  zPy_ssize_t pos = 0;r  r  r   r   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);rO  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   r\  encoder  r   r  r   r  rv  ru  r   r   r  r   
bit_lengthr  r  rw  r   compression_algorithmsr
   r  r  error_goto_if_nullr  r  r  rS  )r   r  r  definesbytes_valuesfirst_internedstringtab_posr<  is_internedr.  r  stringtab_bytes_startr   indexconcat_bytesr=  lengthhas_ifalgo_number	algo_namer   compressed_bytesguardescaped_bytess                           r   r  z'GlobalState.generate_pystring_constants  sr   **45,.+, .7|-D 	)A)UDG 45#!"MMHUG1V-C-C,DAm_TUVWQM	 47|3D + 	NAudT]] 1HYZMMHUG1V-C-C,DAm_TUVWQM	
 Sl+,xx-JJ'(	 	
**-e**?*?*A)B C885$IVf_$IJK3P	
 	k556H/Z[089O0P 	,KH'5#$L(9B(>>F""a'n+mn8f$7}Dop7}EGGaF7q?PQZP[[]^abr^s]tt~  AF*??112BCEMGG3M?"EDGQGGGL\H]G^^`al`mmopqGGA((ABGGMNGG45GGCALLQUQ`Q`DaCbbefgGGH9	< GG23|3D2EZPQ&;;--l;=	-m_B?dK	()	<=GGH 	
)!*L*LVMcMc*d)eefgh	%& !1$ GGe%:U%BEUUabwax  yB  C  DGG@AGG_`"5n5EEhijGG./GG'(GGALL12GGCLGG,-GG*+GGCL !3u:-GGeSZ%%7E\J%PeOfflmpqvmwlx  yB  C  DGG@AGG^_GG,-GG*+GG./GG'(GGALL12GGCLGGCL	#$ 	
-c%j\CD	DE	T__-.		
 !3u:-&&6K5L'MsSXz\qOqstu	S %Js   [
c                    | j                   d   }dt        j                   dt        j                   d}| j                  sg|j                  |       |j                  dt        j                   d       |j                  d       |j                          |j                  d       y d	}d
}d
}d
}d
}d
}| j                  D ]  }	|	j                  }
|
j                  sXt        |t        |
j                        |
j                  z
        }t        ||
j                        }t        ||
j                        }t        |t        |	j                              }t        ||
j                   d
         } |j#                  t%        j&                  d|j)                          d|j)                          d|j)                          d|j)                          d|j)                          d|j)                          d             | j+                  t,        j/                  dd             |j                  |       |j                  d       |j                  d       | j                  D ]  }	|	j1                  |d        |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                          |j                  d       t        | j                        }| j                   d   j                  dt        j2                   d| d       | j5                  t        j2                  |d       y ) Nr  zint __Pyx_CreateCodeObjects(r0  r=  r1  r2  rM  rO  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;
        
NewCodeObjrE  z)PyObject* tuple_dedup_map = PyDict_New();z*if (unlikely(!tuple_dedup_map)) return -1;badzPy_DECREF(tuple_dedup_map);zbad:rN  r  r  r  r  Fr  )r#  r   r8  r9  r(  r7  r  rR  def_nodeis_generator_expressionr   r   r#  num_kwonly_argsnum_posonly_argsvarnamesr  rH  r   dedentr  r  r  rw  generate_codeobjr~  r  )r   r=  init_function	max_flagsmax_func_argsmax_kwonly_argsmax_posonly_argsmax_varsmax_liner  r  code_object_counts               r   r  z)GlobalState.generate_codeobject_constants  s   JJ)**6+G+G*H6KhKhJiijk 	 ((m,GG()F)F(GrJKGGK  GGCL 	-- 	6D}}H33 #M3x}}3EH`H`3` a"%ox7O7O"P#&'79R9R#S 8S%78H8X\\!_5H	6 	
hoo #%%2%=%=%?$@ A--=-H-H-J,K L,,;,F,F,H+I J$$,$7$7$9#: ;""+"6"6"8!9 :''/':':'<&= >		 	 		 	k55lDWXY	-(	;<	<=-- 	,D!!!U+	, 	
-.			-.			 9 9:

>"((:f6M6M5NaPaObbd)ef66v7N7NPav{6|r   c           	         | j                   j                         D cg c]c  }|j                  t        |j                  j                  d            |j                  j                  d      |j                  |j                  |fe }}|j                          |sy t        |      }| j                  d   j                  dt        j                   d| d       | j                  t        j                  |d       g }g g}g }d}d	}|D ]  \  }	}
}
}}}|j                  }|	d
k(  r|j                  ||f       /t        j                   |      }|j#                         }|dk  rw|dz   dz  dt        |      dz
  z  kD  r=|j                  g        dd t        |      dz
   }|dz   dz  dt        |      dz
  z  kD  r=|dz  }|d   j                  || | f       |j                  ||f        | j                  d   }| j                  d   }dt$        dt$        dt&        fd}dt(        j*                  fd}dt$        fd}d:dt&        dt(        j*                  fd}d}|r|j                  d       |j                  d|j-                  t        j                         d        ||d d!|        ||||        ||t        |              ||| j.                  d"       |j                  d#       |j                  d#       |t        |      z  }|dkD  r|j                  d       |j                  d|j-                  t        j                         d$| d       g d%}d&}d}t1        |d      D ]`  \  }}|s	d'd|dz
  z   } |||||   |        |||||z          | d(| d)}|t        |      z  }||t        |      k(  r|nd*| d+| d,z  }b  |||       t        |      d-k  rd.nd/} ||| j.                  | d0| d1       |j                  d#       |j                  d#       ||z  }|rd2 }|j                  d       |j                  d|j-                  t        j                         d$| d       d3j3                  |D cg c]  } ||d          c}      j5                  d4      } |j                  d5t7        j8                  |        d6        ||||        ||t        |             |j                  d7        ||| j.                  d8       |j                  d9       |j                  d#       |j                  d#       | j;                  |j-                  t        j                        ||       y c c}w c c}w );Nr  r  r  r  r  Fr  r   rP  r   ?      r   LLr   r   r  r
  rD  rp  	constantsc                     dj                  |D cg c]  }|d   	 c}      }| j                  | d| d| d       y c c}w )Nr  r   z const z[] = {r  )r  r  )r=  rD  rp  r%  rf  r{  s         r   store_arrayz7GlobalState.generate_num_constants.<locals>.store_array	  sC    XXY7qt78FGGugWTF'&=> 8s   >r  c                 F    |dk  rdnd}| j                  d| d| d       y )Nr  r   r  r  r  r  r  )r=  r  r  s      r   generate_forloop_startzBGlobalState.generate_num_constants.<locals>.generate_forloop_start	  s*    $'%K5\LGGeL>cU)DEr   rhs_codec                 p    | j                  d| d       | j                  | j                  d|             y )Nznumbertab[i] = r  znumbertab[i])r  r  )r=  	error_posr+  s      r   assign_constantz;GlobalState.generate_num_constants.<locals>.assign_constant	  s0    GGohZq12GGA((CDr   start_offsetc           
          t         j                  }t        |      D ](  \  }}|d   }| j                  d| d| d||z    d       * y )Nr   r  r  r  r  )r   numbertab_cnamer   r  )r   r%  r/  r1  r<  rf  r.  s          r   define_constantsz<GlobalState.generate_num_constants.<locals>.define_constants	  s\     $*#9#9O!), X1qTq0A<RSCSBTTUVWXr   r  zPyObject **numbertab = r  c_constantsdoublez"PyFloat_FromDouble(c_constants[i])rO  z + )rP  int8_tint16_tint32_tint64_t%scint_constants_z[i - r  z(i < z ? z : %s)r&   PyLong_FromLongPyLong_FromLongLongr  r=  c                     | dk  }|r|  } t               }| r#| dz  }d|   }|j                  |       | dz  } | r#|sy|r|j                  t        d             |j                          |S )Nr      s    0123456789abcdefghijklmnopqrstuv      0   -)r   r\  r   reverse)numberis_negdigitsdigit
digit_chars        r   	to_base32z5GlobalState.generate_num_constants.<locals>.to_base32T	  sw    %z$WF")/"E.QRW.XJMM*-qLF	 
 MM#d), r   s   \000r   zconst char* c_constant = "r  zchar *end_pos;z+PyLong_FromString(c_constant, &end_pos, 32)zc_constant = end_pos + 1;r   )r)  r{  r  r   r  lstripr  r  r#  r  r   r1  r  r.  r\  r   str_to_numberr  r(   r   r  r  r  r  r   r  r  r
   r  rS  )!r   rf  r  constant_countfloat_constantsint_constants_by_bytesizelarge_constantsint_constant_count
int_suffixr  r   r  r  r.  number_valuer  r=  r   r'  r*  r.  r2  constant_offset	int_typesarray_accessint_constants_seen	byte_sizer%  
array_name	read_item	capi_funcrH  r|  s!                                    r   r  z"GlobalState.generate_num_constants  s   //668: 99c!''.."56s8KQWWVWVbVbdef : :V

>"((:f6L6L5MQ~N^^`)ab66v7M7M~rw6x%'D!
39 	B/GQ5*aGGE'!&&z':;$2259)446
#%>a/!<U8VYZ8Z2[[188<
 &**M3/H+IA+M%N
 &>a/!<U8VYZ8Z2[[ '!+&-b188%L>R\Q]A^9_`#**E<+@A%	B( JJ'(**45	? 	?S 	?T 	?
	F6+<+< 	F	EC 	E	X 	XVEVEV 	X ./GGCLGG-a.P.PQWQgQg.h-iijkl=(ODWoG"1c/&:;At0TUGGCLGGCLs?33O!GGCLGG-a.P.PQWQgQg.h-iilm|l}}~  AGIL45(12KQ(O $	9 .qY]/C.DE
Az9Y+?K )_GY5YZ)l%0B/C1E	"c)n4"!*c2K.L!LI !3 4C	{&I #1&89-01J-Kq-P)VkIAt9+Q|nA0NOGGCLGGCL11O& GGCLGG-a.P.PQWQgQg.h-iilm|l}}~  A}}%O!i!o%OPWWX_`HGG01T1TU]1^0__abcWoG"1c/&:;GG$%At0]^GG/0GGCLGGCL""..v/E/EF	_:F &Ps   A(U:U?c                 "   |j                  d       |j                  d       |j                  d|  d       |j                  d| d       |j                  d       |j                  d       |j                  d	       |j                  d
       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       y )Nz#if CYTHON_IMMORTAL_CONSTANTSr  zPyObject **table = r  zfor (Py_ssize_t i=0; i<z; ++i) {z #if PY_VERSION_HEX >= 0x030F0000z!PyUnstable_SetImmortal(table[i]);z/#elif CYTHON_COMPILING_IN_CPYTHON_FREETHREADINGz9if ((PY_SSIZE_T_MAX <= _Py_IMMORTAL_REFCNT_LOCAL)) break;z#if PY_VERSION_HEX < 0x030E0000zEif (_Py_IsOwnedByCurrentThread(table[i]) && Py_REFCNT(table[i]) == 1)r  z5if (PyUnstable_Object_IsUniquelyReferenced(table[i]))r  zEPy_SET_REFCNT(table[i], ((Py_ssize_t)_Py_IMMORTAL_REFCNT_LOCAL + 1));rO  z:if ((PY_SSIZE_T_MAX < _Py_IMMORTAL_INITIAL_REFCNT)) break;z5Py_SET_REFCNT(table[i], _Py_IMMORTAL_INITIAL_REFCNT);r)  )array_cnamerL  r  s      r   rS  z!GlobalState.immortalize_constantsz	  s8   45S*;-q9:.~.>iHI7889FG
 	PQ67\]WLMXS\]SWQRLMXSSXr   c                     || j                   v rX| j                   |   }t        |j                        t        |j                        k(  sJ |j                  |j                  k(  sJ y|| j                   |<   y)NFT)r  r(   r   r  )r   r.  rZ  r   s       r   r  zGlobalState.should_declare	  sd    D(((((/Euzz?c%**o55::++*/D  'r   c                     |j                         }	 | j                  |   }|S # t        $ rC t        | j                        }| j                  j                  |       || j                  |<   Y |S w xY wr   )get_filenametable_entryr  rZ   r   r  r\  )r   source_descrZ  r  s       r   lookup_filenamezGlobalState.lookup_filename	  sv    335	/''.E
 	  	/**+E%%k2).D&		/s   # AA/.A/c                 *   	 | j                   |   S # t        $ r Y nw xY w|j                  dd      }|D cg c]-  }dd|v r"|j                  dd      j                  dd	      n|z   / nc c}w }}|s|j	                  d
       || j                   |<   |S )Nr  r  )r  error_handlingz * rQ  r  z.*[inserted by cython to avoid comment closer]/r  z-/[inserted by cython to avoid comment start]*rP  )r  rZ   	get_linesr  r\  )r   r`  source_filerk  Fs        r   commented_file_contentsz#GlobalState.commented_file_contents	  s    	++K88 		!++WX+V $
  
 D[	 J'I&*, 
 
 
 !((2,01  -s    	2A*c                     |r>|| j                   vr/| j                   j                  |       |j                  | |       yyy)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  rb  r"  )r   r  r!  s      r   r  zGlobalState.use_utility_code	  sC     L0B0BB""<0!!$!8 C<r   c                 `   |y |j                   r| j                  |j                          |j                  r| j                  |j                         ddlm} |j                  |j                        D ]9  }t        |d      s|j                  |us| j                  |j                         ; y )Nr   r  rZ  )
r  r  utility_code_definitionrP  r  get_all_subtypesr   r   rZ  use_entry_utility_code)r   rZ  r  tps       r   rl  z"GlobalState.use_entry_utility_code	  s    =!!%"4"45((!!%"?"?@ --ejj9 	6Br7#(=++BHH5	6r   r   r  T)rP  rP  )3r  r  r	  r  r5  r@  r   r>  rA  rI  rK  rG  r[  r_  rg  ri  rn  rr  rx  rz  r,  r  r  rw  rc  r  r  r  rq  r(   rk  r  r  r  r  rP  r  r  r  r  r   r  r  r  r   rS  r  ra  rg  r  rl  r  r   r   r+  r+    s   : J*KZM!8/9b<
..!`G
.?1
.9C 9

	!
 &~(Tc:3MjL LD L\?}BSj  H,9
6r   r+  c                 t    | j                   t        j                        fd}fd}t        ||      S )Nc                 (     | j                         S r   )	funcstate)r   attribute_ofs    r   r   z!funccontext_property.<locals>.get	  s    DNN++r   c                 4    t        | j                  |       y r   )r   rq  )r   r  rD  s     r   r   z!funccontext_property.<locals>.set	  s    e,r   )r  r   
attrgetterr   )r  r   r   rr  rD  s      @@r   funccontext_propertyru  	  s3    ==D&&t,L,-Cr   c                       e Zd ZddZy)CCodeConfigc                 .    || _         || _        || _        y r   )emit_code_commentsr;  c_line_in_traceback)r   r;  ry  rz  s       r   r   zCCodeConfig.__init__	  s    "4*#6 r   N)TTT)r  r  r	  r   r  r   r   rw  rw  	  s    
7r   rw  c                      e Zd ZdZ ej
                  d       dd       Zd Zd Zd Z	d Z
d	 Zej                  d
        Zd Zd Zd Zd Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        ZddZddZd Zd Zd Zd Z d Z!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(dd%Z)dd&Z*d' Z+d( Z,dd)Z-d* Z.d+ Z/dd,Z0d- Z1d. Z2d/ Z3d0 Z4dd1Z5d2 Z6e7d3        Z8e7d4        Z9d5 Z:d6 Z;dd7Z<dd8Z=ej                  d9        Z>ej                  d:        Z?ej                  d;        Z@d< ZAej                  d=        ZBej                  d>        ZCd? ZDd@eEfdAZFej                  dB        ZGej                  dC        ZHej                  dD        ZIej                  dE        ZJej                  dF        ZKdG ZLdH ZMdI ZN	 	 ddJZOdKePfdLZQdM ZRdN ZSdO ZTeUfdPZVdQ ZWdR ZXdS ZYdT ZZdU Z[dV Z\ddWZ]ddXZ^ddYZ_ddZZ`dd[Zadd\Zbd] Zcd^ Zdd_ Zed` Zfda Zgdb Zhdc Zidd Zjde Zkdf Zldg Zmdh Zndi Zodj Zpdk Zqdl ZrddmZsdn Ztdo Zudp ZvddqZwddrZxddsZydt Zzdu Z{ddvZ|ddwZ}dx Z~dy ZddzZdd{Zd| Zd} Zdd~ZddZddZd Zd Zd Zd Zd Zd ZddZddZddZddZd Zd ZddZddZddZddZd Zd ZddZd Zd ZddZd ZddZeEj?                  dd      fdZd Zd Zd Zy)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_fromNc                    |
t               }|| _        d | _        d | _        g | _        d | _        d | _        d | _        d| _        d| _	        d| _
        || j                  |j                         |j
                  | _        |r3|j                  | _        |j                  | _
        |j                  | _	        |j                  | _        |j                  | _        y y )Nr   r   )r   bufferlast_poslast_marked_pospyclass_stackrq  r   r!  r$   
call_levelbolr.  )r   r}  r  copy_formattings       r   r   zCCodeWriter.__init__
  s    >LN6#
"!!+"9"9:(22DN(..
&??"-"8"8'00DM#.#>#>D  #r   c                      t        |||      }|S r   r  )r   r}  r  r  r  s        r   
create_newzCCodeWriter.create_new6
  s     [&/Br   c                 P    | j                   J || _         |j                  | _        y r   )r   r!  )r   global_states     r   r.  zCCodeWriter.set_global_state<
  s'    ''''33r   c                 :    | j                   j                  |       y r   )r  copyto)r   r  s     r   r  zCCodeWriter.copytoA
  s    1r   c                 6    | j                   j                         S r   )r  getvaluer   s    r   r  zCCodeWriter.getvalueD
  s    {{##%%r   c                 R    d|v r| j                  |       y | j                  |       y Nr8  )_write_lines_write_to_bufferr   r  s     r   r  zCCodeWriter.writeG
  s%    19a !!!$r   c                     | j                   r| j                   d d nd}| j                  j                  j                  |g|j	                  d      z         | j                  |       y )Nr   Nr   r8  )r  r  markersr  r  r  )r   r  filename_lines      r   r  zCCodeWriter._write_linesM
  sU    
 594H4H,,Ra0i""M?QWWT]#BCa r   c                 :    | j                   j                  |       y r   )r  r  r  s     r   r  zCCodeWriter._write_to_bufferW
  s    !r   c                 ^    | j                  | | j                  j                         d      }|S )NT)r}  r  r  )r  r  r6  r  s     r   r6  zCCodeWriter.insertion_pointZ
  s)    D9T9T9Vhlmr   c                     t        |       S )z
        Creates a new CCodeWriter connected to the same global state, which
        can later be inserted using insert.
        r|  r  r   s    r   
new_writerzCCodeWriter.new_writer^
  s    
 t,,r   c                     |j                   | j                   u sJ | j                  j                  |j                         y)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  s     r   r  zCCodeWriter.inserte
  s1     !!T%5%5556==)r   c                      y r   r  r   s    r   rU  zCCodeWriter.label_counterp
  s    !r   c                      y r   r  r   s    r   rX  zCCodeWriter.return_labelr
       r   c                      y r   r  r   s    r   rT  zCCodeWriter.error_labelt
      r   c                      y r   r  r   s    r   rV  zCCodeWriter.labels_usedv
  r  r   c                      y r   r  r   s    r   rZ  zCCodeWriter.continue_labelx
  s    "r   c                      y r   r  r   s    r   r[  zCCodeWriter.break_labelz
  r  r   c                      y r   r  r   s    r   return_from_error_cleanup_labelz+CCodeWriter.return_from_error_cleanup_label|
  s    /3r   c                      y r   r  r   s    r   r\  zCCodeWriter.yield_labels~
  r  r   c              #      K   t        ||      D ]i  \  }}| j                  |      s|r| j                  |       d}|| j                  ||       | j	                  |       ||f | j                  |       k yw)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_posrQ  )r   r  orig_labelsskip_to_labelr  r  rx  
orig_labels           r   label_interceptorzCCodeWriter.label_interceptor
  s~      "%Z!= 	&E:??5)m, $c/NN5!*%%MM*%	&s   A:A<c                 8    | j                   j                  |      S r   )rq  rW  r   rD  s     r   rW  zCCodeWriter.new_label
  s    dnn.F.Ft.L'Lr   c                 4     | j                   j                  | S r   )rq  rY  r   r#  s     r   rY  zCCodeWriter.new_error_label
      .Ldnn.L.Ld.S'Sr   c                 4     | j                   j                  | S r   )rq  r|  r  s     r   r|  zCCodeWriter.new_yield_label
  r  r   c                 6    | j                   j                         S r   )rq  r  r   s    r   r  zCCodeWriter.get_loop_labels
  s    dnn.L.L.N'Nr   c                 8    | j                   j                  |      S r   )rq  r  r  s     r   r  zCCodeWriter.set_loop_labels
  s    dnn.L.LV.T'Tr   c                 4     | j                   j                  | S r   )rq  r  r  s     r   r  zCCodeWriter.new_loop_labels
  r  r   c                 6    | j                   j                         S r   )rq  r  r   s    r   r  zCCodeWriter.get_all_labels
      dnn.K.K.M'Mr   c                 8    | j                   j                  |      S r   )rq  r  r  s     r   r  zCCodeWriter.set_all_labels
  s    dnn.K.KF.S'Sr   c                 6    | j                   j                         S r   )rq  r  r   s    r   r  zCCodeWriter.all_new_labels
  r  r   c                 8    | j                   j                  |      S r   )rq  r  r  s     r   r  zCCodeWriter.use_label
  s    dnn.F.Fs.K'Kr   c                 8    | j                   j                  |      S r   )rq  r  r  s     r   r  zCCodeWriter.label_used
  s    dnn.G.G.L'Lr   c                 (    t        | |      | _        y )N)r  )rP  rq  r  s     r   enter_cfunc_scopezCCodeWriter.enter_cfunc_scope
  s    &t59r   c                 `    | j                   y | j                   j                          d | _         y r   )rq  rs  r   s    r   rR  zCCodeWriter.exit_cfunc_scope
  s&    >>!$$&r   c                     | j                   j                  d   }|j                  d| d       | j                  |       | j                  d       | j                  d| d       |r| j	                          yy)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*/rP  r   {N)r   r#  r  r  put_declare_refcount_context)r   	signaturer  r3  r>  s        r   r7  zCCodeWriter.start_initcfunc
  ss    
   &&'>?/	{+FGu%

2

WYKs+,--/ r   c                 ,   |j                  |      }d|j                  |       d| d}|r1| j                  d   j                  |j	                  dd      dz          |r| j                  |       | j                  d       | j                  |dz          y )	Nr  r  r=  r  CYTHON_UNUSED rP  r  r  )mangle_internalr  r   r  r  r  )	r   class_scopereturn_typec_slot_nameargs_signatureneeds_funcstateneeds_prototypeslotfunc_cnamedeclarations	            r   start_slotfunczCCodeWriter.start_slotfunc
  s    $44[A < <^ LMQ~N^^_`W%++K,?,?@PRT,UXe,ef"";/

2

;%&r   c                 l    | j                  | j                  j                  ||      j                        S r   )rT  r   rg  r.  )r   rd  re  s      r   
get_py_intzCCodeWriter.get_py_int
  s1    ((**9h?EE
 	
r   c                 l    | j                  | j                  j                  ||      j                        S r   )rT  r   ri  r.  )r   rd  r  s      r   get_py_floatzCCodeWriter.get_py_float
  s1    ((,,Y
CII
 	
r   c                 X    | j                  | j                  j                  ||            S r   )rT  r   rn  )r   r  rl  s      r   rn  zCCodeWriter.get_py_const
  s+    (())&)<
 	
r   c                 L    | j                   j                  |      j                  S r   )r   rx  r.  r  s     r   rx  zCCodeWriter.get_string_const
  s    006<<<r   c                 8    | j                   j                  |      S r   )r   rz  r  s     r   rz  z#CCodeWriter.get_pyunicode_ptr_const
  s    77==r   c                 p    | j                   j                  ||      j                  }| j                  |      S r   )r   r,  r.  rT  )r   r  r+  r.  s       r   r,  zCCodeWriter.get_py_string_const
  s6      44*#e 	((//r   c                 V    | j                  | j                  j                  |            S r   )rT  r   r  )r   r  s     r   r  z CCodeWriter.get_py_codeobj_const
  s$    (()9)9)N)Nt)TUUr   c                 j    | j                  | j                  j                  |      j                        S r   )rT  r   rr  r.  r   r   s     r   rr  z&CCodeWriter.get_argument_default_const
  s+    (()9)9)T)TUY)Z)`)`aar   c                 $    | j                  |      S r   r  r  s     r   r  zCCodeWriter.intern
  s    ''--r   c                 (    | j                  |d      S r  r  r  s     r   intern_identifierzCCodeWriter.intern_identifier
  r  r   c                 8    | j                   j                  |      S r   )r   r_  r]  s     r   r_  z'CCodeWriter.get_cached_constants_writer
  s    ;;FCCr   c                     | j                   j                  | j                  |      S | j                   j                  j                  |      S r   )rq  r  r  rT  r   r.  s     r   rT  z CCodeWriter.name_in_module_state
  s@    >>' 88??~~##88??r   c                 ,    t         j                   d|  S r7  )r   r9  r  s    r   r  z,CCodeWriter.name_in_main_c_code_module_state
  s    
 //05'::r   c                 ,    t         j                   d|  S r7  )r   r  r  s    r   name_in_slot_module_statez%CCodeWriter.name_in_slot_module_state  s     001E7;;r   c                 h    |j                   r|j                  S | j                  |j                        S r   )is_py_class_scopenamespace_cnamerT  r  s     r   namespace_cname_in_module_statez+CCodeWriter.namespace_cname_in_module_state  s.    ""(((,,U-B-BCCr   c                 h    |j                   r| j                  |j                        S |j                  S r   )is_extension_typerT  typeptr_cnamer  s     r   typeptr_cname_in_module_statez)CCodeWriter.typeptr_cname_in_module_state  s.    !!,,T-?-?@@%%%r   c                    | j                   r| j                  r| j                          | j                  j                  rB| j
                  r6| j
                  \  }}}| j                  d| d|j                          d       |r%|r| j                  |       n| j                  |       | j                  d       d| _        y )Nz
#line z "r  r8  r   )
r  r  emit_markerr!  r;  r  r  get_escaped_descriptionput_saferH  )r   r  r  r`  rk  r   s         r   r  zCCodeWriter.putln  s    ==TXX))d.B.B#'#7#7 Kqb1T1T1V0WWZ[\d#$r   c                 `    |y | j                   r| j                   d d |d d k(  ry ||f| _        y )Nr   )r  r  r   r  r  s      r   r  zCCodeWriter.mark_pos'  s;    ;D$8$8!$<BQ$Ger   c                    | j                   \  }}|| _        d | _         | j                  d       | j                  j                  r0| j                          | j                  | j                  |             |r| j                  |       y y r  )r  r  r  r!  ry  indent_build_markerwrite_trace_liner  s      r   r  zCCodeWriter.emit_marker.  ss    ]]
U"$..KKMd0056!!#& r   c                 N   | j                   r| j                   j                  r| j                  j                  d   rh| j	                          | j                  d|d   dd| j                  |      dd| j                   j                   dd| j                  |       d	       y y y y )N	linetracez__Pyx_TraceLine(r   r   r  z)
)	rq  r_  r   r  r  r  pos_to_offsetr`  r  r   r  s     r   r  zCCodeWriter.write_trace_line:  s    >>dnn664;K;K;V;VWb;cKKM"3q6!*Ad.@.@.Ea-HdnnNfNfJfghIiijkokzkz{~k  kA  AD  EF <d6>r   c                    |\  }}}t        |t              sJ | j                  j                  |      }|t	        d|dz
        | }|dxx   dz  cc<   ||||dz    z  }dj                  |      }d|j                          d|d	d| d
S )Nr   r&   r   z             # <<<<<<<<<<<<<<r   r8  z/* "z":r   z
*/
)r   r   r   rg  r   r  r  )r   r  r`  rk  colcontentsrE  r  s           r   r  zCCodeWriter._build_markerA  s    !$T3+'788##;;KHQQ-b	44	$tAv&&yyk99;<BtAhbfUUr   c                 4    | j                  |       d| _        y r  )r  r  r   r  s     r   r  zCCodeWriter.put_safeL  s    

4r   c                    | j                   j                  }|r:t        |      dkD  r+t        j                  |j                  d            j                         }| d| d}t        j                  j                  ||      }t        j                  j                  |      s| dt        j                          }d}	 t        j                  |      5 }	|	j                  |       d d d        t        j                   ||       d}|s5t        j                  j                  |      rt        j&                  |       	 |j)                  dd	      }
d
|
 d}| j+                  |       y # 1 sw Y   xY w# t"        t$        f$ r# t        j                  j                  |      s Y w xY w# |s6t        j                  j                  |      rt        j&                  |       w w w xY w)Ni   r  r   z.hz.tmpFTr  rQ  z
#include "r  )r   r"  r   hashlibsha256r  	hexdigestr   r  r  existsgetpidr   open_new_filer  shutilmoverM   rg   unlinkr  r  )r   r  rD  include_dirr   include_filer  tmp_pathdoner  c_paths              r   r  zCCodeWriter.put_or_includeQ  s   &&AA3t9t+>>$++f"56@@BD"V1TF"-L77<<\:D77>>$'"V4		}5,,,X6 &!&KK$/D  BGGNN8$<		(+ \\$,Fxs+DD!!& & (9  77>>$/ 0  BGGNN8$<		(+ %=4s<   >E2 E&% E2 &E/+E2 2/F$!F' #F$$F' ':G!c                     | j                   r2d|v r.d| j                   z  j                  |j                  d            }| j                  |       y )Nr8  r  Tkeepends)r$   r  r  rH  r  s     r   r  zCCodeWriter.put_multilinesn  s@     ::$$,4::%++DOOTO,JKDr   c                    d}d|v r|j                  d      nd}d|v rS||j                  d      z  }|dk  r| xj                  |z  c_        n$|dk(  r|d   dk(  rd}| xj                  dz  c_        | j                  r| j                          | j	                  |       d| _        |dkD  r| xj                  |z  c_        y |r| xj                  dz  c_        y y )NFr  r   rO  Tr   )r  r$   r  r  r  )r   r  
fix_indentdls       r   rH  zCCodeWriter.putv  s    
36$;

3A$;$**S/!BAv

b 
qT!W^!


a
88KKM

46JJ"JJJ!OJ r   rC  c                 >   |j                   rJ |j                         |j                  | | j                  d       |j	                  | j                         |j
                  r<t        j                  r+|j                  | j                  d   | j                  d       y y y )Nr?  r  r  )r>  rD  r  r   r  r  r	   r  )r   rC  s     r   put_code_herezCCodeWriter.put_code_here  s     ==.',,.!!$(8(8&A&&t'7'78??w<<%%  !23T5E5EyR  =?r   c                 .    | xj                   dz  c_         y Nr   r#   r   s    r   increase_indentzCCodeWriter.increase_indent      

a
r   c                 .    | xj                   dz  c_         y r  r#   r   s    r   decrease_indentzCCodeWriter.decrease_indent  r  r   c                 F    | j                  d       | j                          y )Nr  )r  r  r   s    r   begin_blockzCCodeWriter.begin_block  s    

3r   c                 F    | j                          | j                  d       y )NrO  )r  r  r   s    r   	end_blockzCCodeWriter.end_block  s    

3r   c                 @    | j                  d| j                  z         y )Nr  )r  r$   r   s    r   r  zCCodeWriter.indent  s    dTZZ/0r   c                 *    dt        |      dz   d d z  S )Nz0x%02X%02X%02X%02X)r   r   r   r      )r   )r   	pyversions     r   get_py_version_hexzCCodeWriter.get_py_version_hex  s    #uY'7)'CRa&HHHr   c                 ^    || j                   j                  v r| j                  d|z         y y )Nz%s:;)rq  rV  r  r  s     r   rQ  zCCodeWriter.put_label  s)    $..,,,JJv|$ -r   c                 b    | j                   j                  |       | j                  d|z         y )Ngoto %s;)rq  r  r  r  s     r   r  zCCodeWriter.put_goto  s%      %

:#$r   c                    |j                   dk(  r|s|j                  sy |j                   dk(  r|j                  sy |j                  s| j	                  d       |r| j	                  d|z         |j
                  r7| j	                  |j                  j                  |j                  |             n6| j	                  |j                  j                  |j                  |             |j                  8| j                  d|j                  j                  |j                        z         n'|j                  j                  r| j	                  d       | j                  d       | j                  j!                  |       y )Nprivater  %s )dll_linkagez = %sz = NULLr  )
visibilitydefined_in_pxdr  cf_usedrH  is_cpp_optionalr   cpp_optional_declaration_coder.  r  r  r  literal_codeis_pyobjectr  r   rl  )r   rZ  storage_classr/  
definitions        r   put_var_declarationzCCodeWriter.put_var_declaration  s%    y(*@T@Ty(}}HH%&HHU]*+  HHUZZ== > 6 7 HHUZZ00 1 6 7::!MM'EJJ$;$;EJJ$GGHZZ##HHY

3//6r   func_contextc                    |j                   D ]  \  }}}}|j                  r7|j                  s+|j                  j                  d   r|j                  |      }n|j                  |      }|j                  r| j                  d|z         }|j                  r1| j                  |d|j                  |j                        d       | j                  |xr dxs d|d        |j                  r| j                  j                  rd}nd}| j                  |dt        j                   d	       | j                  |d
t        j"                  d       | j                  |dt        j$                  d	       y y )Nr  z
%s = NULL; = r  r  rP  r  zint z = 0;zconst char *z = NULL;)ra  r  r  r  r  r4  r  r6  r  r  r5  default_valuerh  rq  ri  r   lineno_cnamefilename_cnameclineno_cname)r   r:  rD  r   r  r  r  unuseds           r   put_temp_declarationsz!CCodeWriter.put_temp_declarations  s6   .:.J.J 
	I*D$
F  )?)?LDVDVDaDabnDo99$?,,T2

<$./((

t/@/@ASAS/TUV

f&:&@b&@$GH
	I 66~~22)JJ&&2E2EFGJJVV=R=RSTJJ&&2F2FGH 7r   c                 d    | j                  t        j                         | j                  d       y rp  )r  r   GENERATED_BY_MARKERr   s    r   put_generated_byzCCodeWriter.put_generated_by  s    

5,,-

2r   c                 T    | j                  d|z         | j                  d|z         y )Nz
#ifndef %sz
#define %sr)  )r   r  s     r   put_h_guardzCCodeWriter.put_h_guard  s$    

<%'(

<%'(r   c                 0    t         j                  rd|z  S |S )Nzunlikely(%s))r	   gcc_branch_hintsr   conds     r   unlikelyzCCodeWriter.unlikely  s    ##!D((Kr   c           
      d    |syddj                  |D cg c]  } |||       c}      z  S c c}w )NrP  r.  r  )r  )r   	modifiersmapperrl  s       r   build_function_modifiersz$CCodeWriter.build_function_modifiers  s0    sxxi @! @AAA @s   -
c                     |j                   }|j                  s|j                   j                         r|j                   j                  rd|j                  z   S |j                  S )Nz(PyObject *))r   is_self_argis_completer  r.  )r   rZ  r   s      r   entry_as_pyobjectzCCodeWriter.entry_as_pyobject  sI    zz!!%***@*@*B:://!EKK//;;r   c                 &    ddl m}m}  ||||      S )Nr   py_object_typetypecast)r  rW  rX  )r   r.  r   rW  rX  s        r   as_pyobjectzCCodeWriter.as_pyobject  s    8e44r   c                 (    |j                  | |       y r   )generate_gotrefr  s      r   
put_gotrefzCCodeWriter.put_gotref  s    T5)r   c                 (    |j                  | |       y r   )generate_giverefr  s      r   put_giverefzCCodeWriter.put_giveref      dE*r   c                 (    |j                  | |       y r   )generate_xgiverefr  s      r   put_xgiverefzCCodeWriter.put_xgiveref  s    tU+r   c                 (    |j                  | |       y r   )generate_xgotrefr  s      r   put_xgotrefzCCodeWriter.put_xgotref  r`  r   c                 ,    |j                  | ||       y N)r  )generate_increfr   r.  r   r  s       r   
put_increfzCCodeWriter.put_incref  s     	T56r   c                 ,    |j                  | ||       y rh  )generate_xincrefrj  s       r   put_xincrefzCCodeWriter.put_xincref  s    dE7r   c                 .    |j                  | |||       y N)r  have_gil)generate_decrefr   r.  r   r  rq  s        r   
put_decrefzCCodeWriter.put_decref  s    T5Ir   c                 .    |j                  | |||       y rp  )generate_xdecrefrs  s        r   put_xdecrefzCCodeWriter.put_xdecref   s    dEJr   c                 0    |j                  | ||||       y N)r  r  rq  )generate_decref_clearr   r.  r   r  r  rq  s         r   put_decref_clearzCCodeWriter.put_decref_clear#  s!    ""4DW$)H 	# 	>r   c                 0    |j                  | ||||       y ry  )generate_xdecref_clearr{  s         r   r  zCCodeWriter.put_xdecref_clear'  s!    ##D%EX$)H 	$ 	>r   c                 *    |j                  | ||       y r   )generate_decref_setr   r.  r   	rhs_cnames       r   put_decref_setzCCodeWriter.put_decref_set+  s      ui8r   c                 *    |j                  | ||       y r   )generate_xdecref_setr  s       r   put_xdecref_setzCCodeWriter.put_xdecref_set.  s    !!$y9r   c                 ,    |j                  | ||       y N)rq  )generate_incref_memoryviewslice)r   slice_cnamer   rq  s       r   put_incref_memoryviewslicez&CCodeWriter.put_incref_memoryviewslice1  s    ,,T;,Rr   c                 T    | j                  |j                  |j                  |       y r  )r  r.  r   )r   rZ  rq  s      r   put_var_incref_memoryviewslicez*CCodeWriter.put_var_incref_memoryviewslice5  s    ''UZZ('Sr   c                 P    | j                  |j                  |j                         y r   )r\  r.  r   rY  s     r   put_var_gotrefzCCodeWriter.put_var_gotref8  s    UZZ0r   c                 P    | j                  |j                  |j                         y r   )r_  r.  r   rY  s     r   put_var_giverefzCCodeWriter.put_var_giveref;      ejj1r   c                 P    | j                  |j                  |j                         y r   )rf  r.  r   rY  s     r   put_var_xgotrefzCCodeWriter.put_var_xgotref>  r  r   c                 P    | j                  |j                  |j                         y r   )rc  r.  r   rY  s     r   put_var_xgiverefzCCodeWriter.put_var_xgiverefA  s    %++uzz2r   c                 T     | j                   |j                  |j                  fi | y r   )rk  r.  r   r   rZ  kwdss      r   put_var_increfzCCodeWriter.put_var_increfD      UZZ848r   c                 T     | j                   |j                  |j                  fi | y r   )rn  r.  r   r  s      r   put_var_xincrefzCCodeWriter.put_var_xincrefG  !    ejj9D9r   c                 T     | j                   |j                  |j                  fi | y r   )rt  r.  r   r  s      r   put_var_decrefzCCodeWriter.put_var_decrefJ  r  r   c                 T     | j                   |j                  |j                  fi | y r   )rw  r.  r   r  s      r   put_var_xdecrefzCCodeWriter.put_var_xdecrefM  r  r   c                 l     | j                   |j                  |j                  fd|j                  i| y Nr  )r|  r.  r   
in_closurer  s      r   put_var_decref_clearz CCodeWriter.put_var_decref_clearP  s-    ekk5::d5K[K[d_cdr   c                 V     | j                   |j                  |j                  |fi | y r   )r  r.  r   r   rZ  r  r  s       r   put_var_decref_setzCCodeWriter.put_var_decref_setS  s#    EKKYG$Gr   c                 V     | j                   |j                  |j                  |fi | y r   )r  r.  r   r  s       r   put_var_xdecref_setzCCodeWriter.put_var_xdecref_setV  s#    U[[%**iH4Hr   c                 l     | j                   |j                  |j                  fd|j                  i| y r  )r  r.  r   r  r  s      r   put_var_xdecref_clearz!CCodeWriter.put_var_xdecref_clearY  s-    u{{EJJeEL\L\e`der   c                     |D ]@  }|r|j                   s|j                  r| j                  |       0| j                  |       B y r   )r  xdecref_cleanupr  r  )r   entries	used_onlyrZ  s       r   put_var_decrefszCCodeWriter.put_var_decrefs\  s?     	/E

((((/''.	/r   c                 4    |D ]  }| j                  |        y r   )r  r   r  rZ  s      r   put_var_xdecrefszCCodeWriter.put_var_xdecrefsd  s     	(E  '	(r   c                 4    |D ]  }| j                  |        y r   )r  r  s      r   put_var_xdecrefs_clearz"CCodeWriter.put_var_xdecrefs_clearh  s     	.E&&u-	.r   c                 4   | j                   j                  j                  s@| j                   j                  j                  s | j                   j                  j                  r8| j                  d       | j                  d| d       | j                  d       y y )Nz?#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000z)PyUnstable_Object_EnableDeferredRefcount(r2  r  )rq  r  is_module_scopeis_c_class_scoper  r  r  s     r   put_make_object_deferredz$CCodeWriter.put_make_object_deferredl  sq     NN  00$$55$$66JJXYJJB5'LMJJx  7r   c                     ddl m}m}  |||d      }|r| j                  |d|d       y | j                  |d|d       y )Nr   rV  Py_Noner<  z; __Pyx_INCREF(Py_None);z; Py_INCREF(Py_None);)r  rW  rX  r  )r   r.  r   r  rW  rX  py_nones          r   put_init_to_py_nonezCCodeWriter.put_init_to_py_nonew  s8    84;JJE7KLJJHIr   c                     ||j                   z  }| j                  ||j                  |       |j                  r| j	                  d       y y )Nr  )r.  r  r   r  r_  )r   rZ  r?  r  r  s        r   put_init_var_to_py_nonez#CCodeWriter.put_init_var_to_py_none  sD    %++% 	  uzz59Y' r   c                    d}|j                   s|j                  dk(  rbddlm} |j                  t        vrJ|j                  |j                        rd}n,|j                  dk(  r| j                  j                  d   sn|ry |j                  j                         }|sy |j                   r|j                  gz  }|r|j                  |      n|j                  }|j                  j                         }	|	dk7  rd	|	d
|}|j                  j                         }
|raj                  | j                  j                        j!                  |j                        }|j#                         }|r| j%                  |       | j%                  d|
d|ddj'                  |      d|j(                  r|j*                  ndd|
       |rr| j%                  d       y y y )NF__getattribute__r   )	TypeSlotsT__getattr__fast_getattrPyCFunctionz(void(*)(void))(r=  r  z, (PyCFunction)rm  |0rO  r  )
is_specialrD  rP  r  special_py_methodsis_binop_number_slotr   r  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   rZ  term
allow_skipwrapper_code_writeris_number_slotr  r  func_ptrcast
entry_nameslotpreproc_guards                r   put_pymethoddefzCCodeWriter.put_pymethoddef  s   uzz-??#zz!3311%**= &*NZZ=09I9I9T9TUc9d  335Y5566LI\&>>uEbgbrbr335= 26AHZZ335
 ++D,<,<,G,GH``afakaklD 88:M

=)

&#(99#5	 mJJx  ,>r   c                    |j                   }|j                  r|j                  j                         xs g }ddlm} ||v rt        j                  |z   }| j                  d|z         d|j                   z  }|j                  dk(  r7| j                  d|z         | j                  d       | j                  d       n| j                  d	|z         | j                  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;rO  )
r  r  r  r  r  r  r   method_wrapper_prefixr  rD  )r   rZ  r  r  r  	func_calls         r   r  z#CCodeWriter.put_pymethoddef_wrapper  s    %%
 ??779?RL0,#99JF


_bllm&)9)99	::+JJ4y@AJJghJJ}-JJ|i78

3r   c                     | j                   j                  d   r0| j                   j                  t        j	                  dd             y | j                   j                  t        j	                  dd             y )Nfast_gilFastGilrE  	NoFastGil)r   r  r  r  rw  r   s    r   use_fast_gil_utility_codez%CCodeWriter.use_fast_gil_utility_code  sZ    &&z2--k.E.EiQd.ef--k.E.EkSf.ghr   c                 D   | j                   j                  d   dk7  rddlm}  || j                  dd       | j                   j                  t        j                  dd             | j                          |sd	}|r| j                  d
       | j                  d|z         y)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   ForceInitThreadsrE  __pyx_gilstate_savezPyGILState_STATE z%s = __Pyx_PyGILState_Ensure();N)r   r  Errorsr  r  r  r  rw  r  rH  r  )r   declare_gilstatevariabler  s       r   put_ensure_gilzCCodeWriter.put_ensure_gil  s     &&'CDL'$$f
 	))##$68KL	N&&(,H,-

4x?@r   c                 T    | j                          |sd}| j                  d|z         y)zD
        Releases the GIL, corresponds to `put_ensure_gil`.
        r  z__Pyx_PyGILState_Release(%s);N)r  r  )r   r  s     r   put_release_ensured_gilz#CCodeWriter.put_release_ensured_gil  s*     	&&(,H

2X=>r   c                     | j                  d       | j                  dt        j                   d       | j                  d       y )N-#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADINGzPyMutex_Lock(&r2  r  r  r   parallel_freethreading_mutexr   s    r   put_acquire_freethreading_lockz*CCodeWriter.put_acquire_freethreading_lock  s7    

BC

^F$G$G#HKL

8r   c                     | j                  d       | j                  dt        j                   d       | j                  d       y )Nr  zPyMutex_Unlock(&r2  r  r  r   s    r   put_release_freethreading_lockz*CCodeWriter.put_release_freethreading_lock  s8    

BC

%f&I&I%J"MN

8r   c                    | j                          | j                  d       |r| j                  d|z         |r2d}| j                  j                  t        j                  dd             nd}| j                  | d       y)	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ReleaseUnknownGilrE  PyEval_RestoreThreadz(_save);N)r  r  r   r  r  rw  )r   r  unknown_gil_stater  s       r   put_acquire_gilzCCodeWriter.put_acquire_gil  sz    
 	&&(

,-JJ}x/04I--''(;=PQS /I

i[)*r   c                 8   | j                          |r4| j                  j                  t        j	                  dd             d}d}nd}d}| j                  | d       | j                  d| d	       |r| j                  d
|z         | j                  d       y)z2Release the GIL, corresponds to `put_acquire_gil`.r   rE  __Pyx_SaveUnknownThread__Pyx_UnknownThreadStatePyEval_SaveThreadzPyThreadState *z _save;z_save = z();z%s = _save;z__Pyx_FastGIL_Remember();N)r  r   r  r  rw  r  )r   r  r  r  result_types        r   put_release_gilzCCodeWriter.put_release_gil  s    &&(--''(;=PQS1I4K+I+K

k]'*+

Xi[,-JJ}x/0

./r   c                 &    | j                  d       y )Nz%PyGILState_STATE __pyx_gilstate_save;r)  r   s    r   r  zCCodeWriter.declare_gilstate   s    

:;r   c                 N    | j                  d|d| j                  |            S )Nif (z < (0)) )r  r  )r   r  r  s      r   put_error_if_negzCCodeWriter.put_error_if_neg%  s!     zzts7KLMMr   c                 R   |rdnd}|j                   rd}nn|j                  j                  r|j                  rd}nI|j                  j                  r1|j                  r%|j
                  s|j                  j                  rd}nd}| j                  j                  t        j                  | | d             |s%|j                  j                  |j                        }| j                  d|d	d
| | d|j                  j!                         d| j#                  |      d	       y )NNogilrP  RaiseClosureNameErrorRaiseCppGlobalNameErrorRaiseCppAttributeErrorRaiseUnboundLocalErrorr  zif (unlikely(!z)) { r  r  z); r  )from_closurer   r  
is_cglobalis_variable	is_memberr  r  r   r  r  rw  check_for_null_coder.  r  rD  r  r  )r   r  rZ  in_nogil_contextunbound_check_code	nogil_tagr  s          r   put_error_if_unboundz CCodeWriter.put_error_if_unbound*  s    /GR	*DZZ$$)9)9,DZZ$$):):5??W\WbWbWsWs ,D+D))''4&(<>PQ	S "!&!?!?!L

 2"(yk : %

 > > @ $ 4	6 	7r   c                     d| j                   _        |rd| j                   _        d| j                  |d         d|d   dS )NTz__PYX_MARK_ERR_POS(r   rm  r   r=  )rq  rh  ri  ra  )r   r  r  s      r   set_error_infozCCodeWriter.set_error_infoB  sA    8<526DNN/  Q(F 	r   c                     | j                   j                  }| j                   j                  |       |d|z  S d| j                   _        |rd| j                   _        d| j                  |d         d|d   d|dS )Nr+  Tz
__PYX_ERR(r   rm  r   r=  )rq  rT  r  rh  ri  ra  )r   r  r  r  s       r   r  zCCodeWriter.error_gotoJ  su    nn((  %;##8<526DNN/  Q(F 	r   c                 N    d| j                  |      d| j                  |      S )Nr  r  )rL  r  )r   rK  r  s      r   error_goto_ifzCCodeWriter.error_goto_ifW  s    #}}T2DOOC4HIIr   c                 ,    | j                  d|z  |      S )Nz!%sr!  r   r.  r  s      r   r  zCCodeWriter.error_goto_if_nullZ  s    !!%%-55r   c                 ,    | j                  d|z  |      S )Nz(%s < 0)r#  r$  s      r   error_goto_if_negzCCodeWriter.error_goto_if_neg]  s    !!*u"4c::r   c                 &    | j                  d|      S )NzPyErr_Occurred()r#  r  s     r   r  zCCodeWriter.error_goto_if_PyErra  s    !!"4c::r   c                 8    | j                   j                  |      S r   )r   ra  )r   r  s     r   ra  zCCodeWriter.lookup_filenamed  s    //99r   c                 &    | j                  d       y )N__Pyx_RefNannyDeclarationsr)  r   s    r   r  z(CCodeWriter.put_declare_refcount_contextg  s    

/0r   c                     |j                         }|r/| j                  j                  t        j	                  dd             | j                  d||xr dxs dfz         y )Nr  rE  z#__Pyx_RefNannySetupContext(%s, %d);r   r   )r  r   r  r  rw  r  )r   rD  acquire_gils      r   r:  z&CCodeWriter.put_setup_refcount_contextj  s]    '')--''(:<OPR

8D+BSRSBXWX;YYZr   c                 8    | j                  |rd       y d       y )Nz"__Pyx_RefNannyFinishContextNogil()z__Pyx_RefNannyFinishContext();r)  r   nogils     r   rV  z'CCodeWriter.put_finish_refcount_contextq  s    

57gFfgr   c                     |j                         }||rt        j                  ndt        j                  t        j                  f}d| j
                  _        | j                  d|z         y)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?  rq  ri  r  )r   qualified_nameinclude_clineformat_tuples       r   put_add_tracebackzCCodeWriter.put_add_tracebackt  s[     (;;=$1F  q!!	
 /3+

8<GHr   c           	      :   d| j                   _        | j                  d|t        j                  t        j
                  t        j                  | j                  j                  d   |fz         | j                  j                  t        j                  dd             y)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)rq  ri  r  r   r@  r>  r?  r   r  r  r  rw  )r   r1  r/  s      r   put_unraisablezCCodeWriter.put_unraisable  s     /3+

E  !!''(?@I
 
 	 	))##$>O	Qr   c                 j    | j                   j                  d   xs | j                   j                  d   S )Nprofiler  )r   r  r   s    r   
is_tracingzCCodeWriter.is_tracing  s0    **95a9I9I9T9TU`9aar   c                     | j                   j                  }|r+||j                  vr|j                  }|r||j                  vr|r|j                  |   S dS )zk
        Calculate a fake 'instruction offset' from a node position as 31 bit int (32 bit signed).
        r   )rq  r  node_positions_to_offsetparent_scope)r   r  r  s      r   r  zCCodeWriter.pos_to_offset  sX     $$5#A#AA&&E 5#A#AA6;u--c2BBr   c                 8    | j                  |rd       y d       y )N__Pyx_TraceDeclarationsGen__Pyx_TraceDeclarationsFuncr)  )r   is_generators     r   put_trace_declarationsz"CCodeWriter.put_trace_declarations  s    

</cEbcr   c                 2    |r| j                  d|z         y y )Nz__Pyx_TraceFrameInit(%s)r)  )r   codeobjs     r   put_trace_frame_initz CCodeWriter.put_trace_frame_init  s    JJ1G;< r   c                 .   |rdnd}| j                  | d|j                          dt        j                   d| j	                  |d          d|d    d| j                  |      d	d|d	d|rt        j                  nd
 d| j                  |       d       y )N__Pyx_TraceStartGen__Pyx_TraceStartFuncr  rm  r  r   ], r   r   r  r2  )r  r  r   filetable_cnamera  r  skip_dispatch_cnamer  )r   rD  r  r/  rB  is_cpdef_func
trace_funcs          r   put_trace_startzCCodeWriter.put_trace_start  s    .:*@V


l!'')*"%%&a(<(<SV(D'ES1vhb!!#&q)Qir-:v))DBs#$
	
r   c                 B    | j                  dt        |      dd       y )Nz__Pyx_PyMonitoring_ExitScope(r   r2  )r  r   r.  s     r   put_trace_exitzCCodeWriter.put_trace_exit  s    

24;q/DEr   c           	      z    | j                  |      }| j                  d| d| j                  |       d| d       y )Nz__Pyx_TraceYield(rm  r2  r  r  r  )r   retvalue_cnamer  r  s       r   put_trace_yieldzCCodeWriter.put_trace_yield  sC    __S)


&~&6b9K9KC9P8QQST^S__abcr   c                    | j                   j                  }|j                  r|j                  j                  d   n|d   }|j                  j                         }| j                  |d         }| j                  |      }| j                  d| dt        j                   d| d| d| j                  |       d| d       y )Nr   r   z__Pyx_TraceResumeGen(rm  r  rJ  r2  )rq  r  scope_classr  rD  r  ra  r  r  r   rK  r  )r   r  r  
first_linerD  filename_indexr  s          r   put_trace_resumezCCodeWriter.put_trace_resume  s    $$161B1BU&&**1-A
zz--/--c!f5__S)


#fB%%&a'7sl"!!#&'rl	
r   c           
          | j                  d| j                  |       dt        |      ddt        |      dd       y )N__Pyx_TraceException(rm  r   r2  r  r  r   )r   r  reraisefreshs       r   put_trace_exceptionzCCodeWriter.put_trace_exception  sE    

*4+=+=c+B*C2d7mTUEVVXY]^cYdefXggijkr   c                 J    | j                  dt        j                   d       y )Nr\  z, 0, 0);)r  r   r>  r   s    r   put_trace_exception_propagatingz+CCodeWriter.put_trace_exception_propagating  s    

*6+>+>*?xHIr   c                 L    | j                  d| j                  |       d       y )Nz__Pyx_TraceExceptionHandled(r2  )r  r  r  s     r   put_trace_exception_handledz'CCodeWriter.put_trace_exception_handled  s$    

1$2D2DS2I1J"MNr   c                 f    | j                  d| j                  |       dt        |      dd       y )Nz__Pyx_TraceExceptionUnwind(rm  r   r2  r]  )r   r  r/  s      r   put_trace_unwindzCCodeWriter.put_trace_unwind  s3    

01C1CC1H0IDQVKXY?Z\]^r   c           	      z    | j                  |      }| j                  d| d| j                  |       d| d       y )Nz__Pyx_TraceStopIteration(rm  r2  rS  )r   r  r  r  s       r   put_trace_stopiterationz#CCodeWriter.put_trace_stopiteration  sB    __S)


.ugR8J8J38O7PPRS]R^^`abr   c                 b   d}d}|n\|j                   r|j                  |      }n>|j                  rd}n/|j                  rd}n |j                  rd}d|j                   }nd}| j                  |      }| j                  | d| | d| j                  |       dt        |      dd| d       y )	NrP  __Pyx_TraceReturnValuer  __Pyx_TraceReturnCValuerm  r  r   r2  )	r6  rY  is_void	is_stringto_py_functionr  r  r  r   )r   rT  r  r  r/  	extra_argrN  rc  s           r   put_trace_returnzCCodeWriter.put_trace_return  s    	-
$$(44^DN  &N""&N''2J[7789I 'N-

j\>"29+R@R@RSV@W?XXZ[_`e[fghZiiklzk{{}~r   DefaultPlacementNewr  c                 d    | j                   j                  |       | j                  d| d       y )Nz$__Pyx_default_placement_construct(&(z));)r   r  r  )r   r^  _utility_codes      r   put_cpp_placement_newz!CCodeWriter.put_cpp_placement_new  s,    ))-8

9&EFr   c                 j    | j                  d       | j                  |       | j                  d       y )Nz#ifdef _OPENMPz#endif /* _OPENMP */r)  )r   strings     r   putln_openmpzCCodeWriter.putln_openmp  s(    

#$

6

)*r   c                     | j                  d|z         | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y)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)r  Nr)  rJ  s     r   undef_builtin_expectz CCodeWriter.undef_builtin_expect  sT    
 	

8d?#

&'

()

01

01

8r   c                     | j                  d|z         | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )Nry  rz  r{  z2    #define likely(x)   __builtin_expect(!!(x), 1)z2    #define unlikely(x) __builtin_expect(!!(x), 0)r  r)  rJ  s     r   redef_builtin_expectz CCodeWriter.redef_builtin_expect  sR    

8d?#

&'

()

GH

GH

8r   )NNF)NNTr   r  )TF)rP  Frn  )rP  NT)TT)FTTrI  )r9  T)TNrt  )FNr  )FFFr  )r  r  r	  r
  r  r   r   r  r.  r  r  r  r  r  r  r6  r  r  ru  rU  rX  rT  rV  rZ  r[  r  r\  r  rW  rY  r|  r  r  r  r  r  r  r  r  r  rR  r7  r  r  r  rn  rx  rz  r,  r  rr  r  r  r_  rT  r   r  r  r  r  r  r  r  r  r  r  r  r  rH  r  r  r  r  r!  r#  r  r(  rQ  r  r9  rP  rB  rE  rG  rL  modifier_output_mapperrP  rT  rY  r\  r_  rc  rf  rk  rn  rt  rw  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  r  r  r  r!  r  r&  r  ra  r  r:  rV  r4  r8  r;  r  rC  rF  rO  rQ  rU  rZ  r`  rb  rd  rf  rh  rp  ru  rt  rw  r|  r~  r  r   r   r  r  	  s   < V]]}-? .?44
&% \\! !-* ! !     " " 3 3   &2 MSSNTSMSMKL:0
'





=>0
Vb.?D@ ; ; < <
D&% \\	' 	' \\F F \\V V
 \\" "8 \\ (	R[ 	R \\  \\  \\  \\  \\1 1I%% 8:9=74I- I.) :P B5*+,+78JK>>9:ST12239:9:eHIf/(.	!J(/!b,iA.?

+"0"<
N
70J6;;:1[hI"Q$bCd=
Fd
"lJO_c@2 -8,<,<=RTd,eG
+

r   r  c                   $    e Zd Zd Zd Zd Zd Zy)PyrexCodeWriterc                 F    t        j                  |      | _        d| _        y r  )r   r	  r  r$   )r   outfile_names     r   r   zPyrexCodeWriter.__init__  s    $$\2
r   c                 ^    | j                   j                  d| j                  z  |d       y )Nr  r8  )r  r  r$   r  s     r   r  zPyrexCodeWriter.putln  s     tzz!1489r   c                 .    | xj                   dz  c_         y r  r#   r   s    r   r  zPyrexCodeWriter.indent"      

a
r   c                 .    | xj                   dz  c_         y r  r#   r   s    r   r  zPyrexCodeWriter.dedent%  r  r   N)r  r  r	  r   r  r  r  r  r   r   r  r    s    :r   r  c                   l    e Zd ZdZddZddZddZed        Zd Z	d Z
dd	Zdd
Zd Zd Zd Zd Zy)PyxCodeWriterz7
    Can be used for writing out some Cython code.
    Nc                 p    |xs
 t               | _        || _        || _        || _        || _        i | _        y r   )r   r  r$   original_levelr  r  _insertion_points)r   r  indent_levelr  r  s        r   r   zPyxCodeWriter.__init__.  s5    .!
* !#r   c                 .    | xj                   |z  c_         yrt  r#   r   levelss     r   r  zPyxCodeWriter.indent6  s    

f
r   c                 .    | xj                   |z  c_         y r   r#   r  s     r   r  zPyxCodeWriter.dedent:  s    

f
r   c              #   v   K   | j                  |       | j                          d | j                          yw)zf
        with pyx_code.indenter("for i in range(10):"):
            pyx_code.putln("print i")
        N)r  r  r  )r   rk  s     r   indenterzPyxCodeWriter.indenter=  s)      	

4s   79c                 6    | j                   j                         S r   )r  emptyr   s    r   r  zPyxCodeWriter.emptyH  s    {{  ""r   c                     | j                   j                         }t        |t              r|j	                  | j
                        }|S r   )r  r  r   r   r  r  )r   r  s     r   r  zPyxCodeWriter.getvalueK  s5    %%'fe$]]4==1Fr   c                     || j                   | j                   }|t        ||      }| j                  j                  |r| j                  dz   | d       y d       y )Nz    r8  )r  r@  r  r  r$   )r   rk  r  s      r   r  zPyxCodeWriter.putlnQ  sZ    ?||',,tW-DdTZZ&01$r:MMr   c                     || j                   | j                   }|t        ||      }t        || j                  dz        }| j                  j                  |       y )Nr&  )r  r@  _indent_chunkr$   r  r  )r   chunkr  s      r   	put_chunkzPyxCodeWriter.put_chunkZ  sR    ?||',,w/EeTZZ!^4% r   c                      t        |       | j                  j                         | j                  | j                        S r   )r   r  r6  r$   r  r   s    r   r6  zPyxCodeWriter.insertion_pointd  s,    tDz$++557T\\RRr   c                 Z    | j                   j                          | j                  | _        y r   )r  resetr  r$   r   s    r   r  zPyxCodeWriter.resetg  s!     	((
r   c                 >    | j                         | j                  |<   y r   )r6  r  r  s     r   named_insertion_pointz#PyxCodeWriter.named_insertion_pointm  s    '+';';'=t$r   c                      | j                   |   S r   )r  r  s     r   rK  zPyxCodeWriter.__getitem__p  s    %%d++r   )Nr   Nr   )r   r   )r  r  r	  r
  r   r  r  r   r  r  r  r  r  r6  r  r  rK  r  r   r   r  r  )  sT    $  #N!S)>,r   r  r  indentation_lengthr,  c                    d| vsJ | j                  d      }|s| S |d   j                  d      }|r||d<   n|d= |syt        |       dz   }t        |      D ]/  \  }}t	        |      }|dz   t        |      k(  rd||<   (||k  s.|}1 |t        |       kD  rd}||k  r"d||z
  z  }|D cg c]  }|dk7  r||z   nd }}n#||kD  r||z
  }	|D cg c]  }|dk7  r||	d	 nd }}d
j                  |      S c c}w c c}w )zONormalise leading space to the intended indentation and strip empty lines.
    	Tr  r   r  r8  r   r   NrP  )r  rY  r   r   _count_indentationr  )
r  r  rE  	last_linemin_indentationr<  rk  line_indentation
add_indentstarts
             r   r  r  t  sm   
 ud+Eb	  %Ib	"I #&e*q.O U# /4-d3a3t9,E!H/.O/ U#++.@A
 
 "&J47
 
 
-	-+.@@ 
 !DLDLd2
 

 775>

s   +C5C:r   r  c                 @    d}t        |       D ]  \  }}|dk7  s |S  |S )Nr   r  )r   )r  r<  chs      r   r  r    s6     A1 29H Hr   c                       e Zd Zd Zd Zd Zy)r  c                 <    || _         i | _        i | _        d| _        y r  )klassra  rb  temps_count)r   r  s     r   r   zClosureTempAllocator.__init__  s     
!r   c                 x    | j                   j                         D ]  \  }}t        |      | j                  |<    y r   )ra  r@  r   rb  )r   r   r  s      r   r  zClosureTempAllocator.reset  s6     00668 	1LD&$(LDOOD!	1r   c                    || j                   vrg | j                   |<   g | j                  |<   n-| j                  |   r| j                  |   j                  d      S dt        j                  | j
                  fz  }| j                  j                  d |||d       | j                   |   j                  |       | xj
                  dz  c_        |S )Nr   ru  T)r  rD  r.  r   is_cdefr   )	ra  rb  r  r   r  r  r  declare_varr\  )r   r   r.  s      r   r  z"ClosureTempAllocator.allocate_temp  s    t+++)+D  &$&DOOD!__T"??4(,,Q//&779I9IJJ

4e5tUYZT"))%0Ar   N)r  r  r	  r   r  r  r  r   r   r  r    s    1
r   r  r  )jr  declarer   r  r   r   r   r
  r   dataclassesr   rv  r   	functoolsr   r   
contextlibr   r   collectionsr   rP  r   r	   r   r
   r   Scanningr   r   r"   r   r   r%   r   rT   compression.zstdr   r   zstd_CompressionParameterr    zstd_Strategystrategybtultra2compression_levelboundsr  r  ctypedef_builtins_mapbasicsize_builtins_mapKNOWN_PYTHON_BUILTINS_VERSIONr   KNOWN_PYTHON_BUILTINSuncachable_builtinsr  r   r  r  r   r  r[  r  r  r/  r  r  r  r  r  r%  r0  r4  r9  r  r@  rt  rJ  rP  r  r  r   Ur4  r  r  rX  r  findallr  r  r  r+  ru  rw  r  r  r  r  ccallr(   r   r  	exceptvalcfuncr  r  r  r   r   <module>r     s     f& fV ff fv ff'-f7=fNTff.4fCIf !f /5f 	f (.	f 6<	f
 $f
 39f
 IOf
 _ef   	 	   !  $ . #      & ' +:, <q9L
  M!**M,B,B!335N5`5`5g5g5ijk5l4 M 	" Q/0|	    *)*1  &  !6 ! `# ` D 2 $V^^Iy : 0   o#  !/v8 #	! I' I'X/   6  S) Sj   K5/ K5\ -1Ueidj &R 
6*	* *K * * 			2	2 {
+
W
W  ,	// 
(
7
7   "&D" (&= =D?o ? G9 G9T. .   6V"(A(bjj)9244@FF &BJJ'89?? RZZ 1266 ,-55? ?D( ($J6 J6Z 7 7X Xv  $H, H,V , ,&** , ,  ,^ "# &**    St  L  Ms$   <O& 
O4 &O10O14O?>O?