Ë
    pPêj„,  ã                  ó,  — d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlm Z  dd	l!m"Z"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, dd„Z-	 	 	 	 	 	 	 	 dd„Z.	 	 	 	 	 	 	 	 	 	 	 	 dd„Z/dd„Z0dd„Z1y)z«Generate a class that represents a nested function.

The class defines __call__ for calling the function and allows access to
non-local variables defined in outer scopes.
é    )Úannotations)ÚCPYFUNCTION_NAMEÚENV_ATTR_NAMEÚIS_FREE_THREADEDÚPROPSET_PREFIXÚ	SELF_NAME)ÚClassIR)ÚFuncDeclÚFuncIRÚFuncSignatureÚ
RuntimeArg)	Ú
BasicBlockÚBranchÚCallÚGetAttrÚIntegerÚRegisterÚReturnÚSetAttrÚValue)Ú	RInstanceÚc_pointer_rprimitiveÚint_rprimitiveÚobject_rprimitive)Ú	IRBuilder)ÚFuncInfoÚImplicitClass)Úcpyfunction_get_annotationsÚcpyfunction_get_codeÚcpyfunction_get_defaultsÚcpyfunction_get_kwdefaultsÚcpyfunction_get_nameÚcpyfunction_set_annotationsÚcpyfunction_set_nameÚmethod_new_opc                óþ  — | j                   j                  «       › d�x}}d}|| j                  v r%|dz   t        |«      z   }|dz  }|| j                  v rŒ%| j                  j	                  |«       t        || j                  dd¬«      }d|_        | j                   j                  rd|_	        | j                  d   j                  rRt        | j                  d   j                  «      |j                  t        <   |j                   j	                  t        «       |g|_        t%        |«      | j                   _        | j(                  j+                  |«       | j-                  |«      }| j/                  || j                   j0                  j2                  «      | j                   j&                  _        | j                   j6                  s9| j                   j8                  r"t;        | || j                   j<                  «       yyy)	aé  Generate an (incomplete) callable class representing a function.

    This can be a nested function or a function within a non-extension
    class.  Also set up the 'self' variable for that class.

    This takes the most recently visited function and returns a
    ClassIR to represent that function. Each callable class contains
    an environment attribute which points to another ClassIR
    representing the environment class where some of its variables can
    be accessed.

    Note that some methods, such as '__call__', are not yet
    created here. Use additional functions, such as
    add_call_to_callable_class(), to add them.

    Return a newly constructed ClassIR representing the callable
    class for the nested function.
    Ú_objr   Ú_é   T)Úis_generatedÚis_final_classéþÿÿÿN)Úfn_infoÚnamespaced_nameÚcallable_class_namesÚstrÚaddr	   Úmodule_nameÚreuse_freed_instanceÚ	is_nestedÚhas_dictÚfn_infosÚcontains_nestedr   Ú	env_classÚ
attributesr   Úfinal_attributesÚmror   Úcallable_classÚclassesÚappendÚadd_self_to_envÚreadÚfitemÚlineÚself_regÚ
in_non_extÚis_coroutineÚadd_coroutine_propertiesÚname)ÚbuilderrG   Ú	base_nameÚcountÚcallable_class_irÚself_targets         úa/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/mypyc/irbuild/callable_class.pyÚsetup_callable_classrN   ,   s°  € ð: "Ÿ/™/×9Ñ9Ó;Ð<¸DÐAÐA€Dˆ9Ø€EØ
�'×.Ñ.Ñ
.Ø˜3‰¤ U£Ñ+ˆØ�‰
ˆð �'×.Ñ.Ò
.ð × Ñ ×$Ñ$ TÔ*ô
    g×&9Ñ&9ÈÐ]aÔbÐØ-1ÐÔ*ð ‡�× Ò Ø%)ÐÔ"ð ×Ñ˜Ñ×+Ò+Ü6?À×@PÑ@PÐQSÑ@T×@^Ñ@^Ó6_Ð×$Ñ$¤]Ñ3ð 	×*Ñ*×.Ñ.¬}Ô=Ø.Ð/ÐÔÜ%2Ð3DÓ%E€G‡O�OÔ"Ø‡O�O×ÑÐ,Ô-ð ×)Ñ)Ð*;Ó<€KØ.5¯l©l¸;ÈÏÉ×H]ÑH]×HbÑHbÓ.c€G‡O�O×"Ñ"Ô+à�?‰?×%Ò%¨'¯/©/×*FÒ*FÜ  Ð*;¸W¿_¹_×=QÑ=QÕRð +GÐ%ó    c                óÜ  ‡ ‡‡— |‰_         t        ‰j                  t        <   t        t
        t        t        t        dœ}t        t        dœ}‰ j                  j                  j                  Šd	ˆ ˆˆfd„}|j                  «       D ]k  \  }}‰ j                  ‰|t        d¬«      5   |«       }‰ j!                  ||t#        dt$        «      g‰«      }	‰ j'                  t)        |	«      «       ddd«       Œm |j                  «       D ]Š  \  }}‰ j                  ‰t*        › |› �t,        d¬«      5  ‰ j/                  dt        «      }
 |«       }‰ j!                  |||
t#        dt$        «      g‰«      }‰ j'                  t)        |«      «       ddd«       ŒŒ |D ]A  }‰j1                  |«      }|sJ ‚‰j1                  t*        › |› �«      }||f‰j2                  |<   ŒC y# 1 sw Y   �Œ\xY w# 1 sw Y   ŒêxY w)
z£Adds properties to the class to make it look like a regular python function.
    Needed to make introspection functions like inspect.iscoroutinefunction work.
    )Ú__name__Ú__code__Ú__annotations__Ú__defaults__Ú__kwdefaults__)rQ   rS   c            	     ó®  •— ‰j                  «       } t        «       t        «       }}‰j                  t        | t        ‰t
         d¬«      «      }‰j                  t        |||t        j                  «      «       ‰j                  |«       ‰j                  ‰j                  | «       ‰j                  |«       ‰j                  t        | t        ‰«      «      S )NT)ÚborrowÚallow_error_value)Úselfr   r1   r   r   r   r   ÚIS_ERRORÚactivate_blockÚadd_coroutine_setup_callrG   Úgoto_and_activate)rC   ÚinitÚdoneÚcurrH   rK   rB   s       €€€rM   Úget_func_wrapperz2add_coroutine_properties.<locals>.get_func_wrapper‰   s®   ø€ ð —<‘<“>ˆÜ“\¤:£<ˆdˆØ�k‰kÜØÜ ØÜ+Ð+Ø"&ôó
ˆð 	�‰”F˜3  d¬F¯O©OÓ<Ô=Ø×Ñ˜tÔ$Ø×(Ñ(Ð):×)?Ñ)?ÀÔJØ×!Ñ! $Ô'Ø�{‰{œ7 8Ô-=¸tÓDÓEÐErO   T)Úinternalr   NÚvalue)Úreturnr   )Úcoroutine_namer   r9   r   r"   r   r   r    r!   r$   r#   r-   rA   rB   ÚitemsÚenter_methodÚprimitive_opr   r   r1   r   r   r   Úadd_argumentÚ
get_methodÚ
properties)rH   rK   re   rk   Úwritable_propsra   rG   Ú	primitiveÚfuncÚvalrc   ÚrvÚgetterÚsetterrB   s   ``            @rM   rF   rF   q   sü  ú€ ð (6ÐÔ$Ü5FÐ× Ñ Ô!1Ñ2ô )Ü(Ü6Ü0Ü4ñ€Jô )Ü6ñ€Nð
 �?‰?× Ñ ×%Ñ%€D÷Fð( &×+Ñ+Ó-ò %‰ˆˆiØ×!Ñ!Ð"3°TÔ;LÐW[Ð!Ó\ñ 	%Ù#Ó%ˆDØ×&Ñ& y°4¼ÀÔDXÓ9YÐ2ZÐ\`ÓaˆCØ�K‰Kœ˜s›Ô$÷	%ð 	%ð%ð *×/Ñ/Ó1ò 	$‰ˆˆiØ×!Ñ!Ø¤.Ð!1°$°Ð8¼.ÐSWð "ó 
ñ 	$ð ×(Ñ(¨Ô2CÓDˆEÙ#Ó%ˆDØ×%Ñ%Ø˜D %¬°Ô4HÓ)IÐJÈDóˆBð �K‰Kœ˜r›
Ô#÷	$ð 	$ð	$ð ò >ˆØ"×-Ñ-¨dÓ3ˆÙˆˆvØ"×-Ñ-´Ð0@ÀÀÐ.GÓHˆØ.4°fÐ-=Ð×$Ñ$ TÒ*ñ	>÷!	%ñ 	%ú÷	$ð 	$ús   Â"AGÄ(AG"ÇG	Ç"G+	c                ó$  — t        |j                  «      |j                  z
  }t        t	        t
        t        «      f|j                  d| z   |j                  «      }t        d|j                  j                  j                  | j                  |«      }t        ||||j                  j                  |j                  j                  ¬«      }||j                  j                  j                   d<   ||j                  j                  j"                  d<   |S )a  Generate a '__call__' method for a callable class representing a nested function.

    This takes the blocks and signature associated with a function
    definition and uses those to build the '__call__' method of a
    given callable class, used to represent that function.
    NÚ__call__)Útraceback_name)ÚlenÚargsÚnum_bitmap_argsr   r   r   r   Úret_typer
   r<   ÚirrG   r2   r   rA   rB   ÚmethodsÚmethod_decls)rH   rw   ÚblocksÚsigr-   ÚnargsÚcall_fn_declÚ
call_fn_irs           rM   Úadd_call_to_callable_classr‚   µ   sÞ   € ô �—‘‹M˜C×/Ñ/Ñ/€EÜ
Ü	”IÔ0Ó	1Ð3°c·h±h¸vÀÐ6FÑFÈÏÉó€Cô ˜J¨×(>Ñ(>×(AÑ(A×(FÑ(FÈ×H[ÑH[Ð]`Óa€LÜØ�d˜F G§M¡M×$6Ñ$6ÀwÇ}Á}×GYÑGYô€Jð 5?€G×Ñ×Ñ×%Ñ% jÑ1Ø9E€G×Ñ×Ñ×*Ñ*¨:Ñ6ØÐrO   c                óø  — |j                   j                  }| j                  |j                  j                  dt
        |t
        ¬«      5  | j                  dt
        «      }| j                  dt
        «       t        «       t        «       }}| j                  | j                  |«      | j                  |«      d|«      }| j                  |||«       | j                  |«       | j                  t        | j                  «       «      «       | j                  |«       | j                  t        | j!                  t"        | j                  «       | j                  |«      g|«      «      «       ddd«       y# 1 sw Y   yxY w)z3Generate the '__get__' method for a callable class.Ú__get__)Ú	self_typeÚinstanceÚownerÚisN)rA   rB   rg   r<   rz   r   ri   r   Útranslate_is_opr@   Únone_objectÚadd_bool_branchr[   r1   r   rY   Úcall_cr%   )rH   r-   rB   r†   Úinstance_blockÚclass_blockÚ
comparisons          rM   Úadd_get_to_callable_classr�   Ð   s3  € à�=‰=×Ñ€DØ	×	Ñ	Ø×Ñ×!Ñ!ØÜØÜ#ð 
ó 
ñ 
ð ×'Ñ'¨
Ô4EÓFˆØ×Ñ˜WÔ&7Ô8ô
 '1£l´J³L˜ˆØ×,Ñ,Ø�L‰L˜Ó" G×$7Ñ$7¸Ó$=¸tÀTó
ˆ
ð 	×Ñ 
¨K¸ÔHà×Ñ˜{Ô+Ø�‰”F˜7Ÿ<™<›>Ó*Ô+à×Ñ˜~Ô.Ø�‰Ü�7—>‘>¤-°'·,±,³.À'Ç,Á,ÈxÓBXÐ1YÐ[_Ó`Óaô	
÷/
÷ 
ñ 
ús   Á	DE0Å0E9c                óˆ  — |j                   }| j                  t        |j                  j                  j
                  g |j                  «      «      }d}| j                  j                  r!| j                  j                  j                  }ny| j                  j                  r7| j                  j                  s!| j                  j                  j                  }n,| j                  j                  r| j                  j                  }|r=t        |t        ||j                  «      }|j!                  «        | j                  |«       |S )a,  Create an instance of a callable class for a function.

    Calls to the function will actually call this instance.

    Note that fn_info refers to the function being assigned, whereas
    builder.fn_info refers to the function encapsulating the function
    being turned into a callable class.
    N)rA   r1   r   r<   rz   ÚctorrB   r-   Úis_generatorÚgenerator_classÚcurr_env_regr4   Úis_comprehension_scoper7   r   r   Úmark_as_initializer)rH   r-   rA   Úfunc_regr•   Úset_envs         rM   Úinstantiate_callable_classrš   ï   så   € ð �M‰M€EØ�{‰{œ4 × 6Ñ 6× 9Ñ 9× >Ñ >ÀÀEÇJÁJÓOÓP€Hð" €LØ‡�×#Ò#Ø—‘×6Ñ6×CÑC‰Ø	�‰×	"Ò	"¨7¯?©?×+QÒ+QØ—‘×5Ñ5×BÑB‰Ø	�‰×	(Ò	(Ø—‘×3Ñ3ˆÙÜ˜(¤M°<ÀÇÁÓLˆð 	×#Ñ#Ô%Ø�‰�GÔð €OrO   N)rH   r   rd   ÚNone)rH   r   rK   r	   re   r0   rd   r›   )rH   r   rw   zlist[Register]r}   zlist[BasicBlock]r~   r   r-   r   rd   r   )rH   r   r-   r   rd   r›   )rH   r   r-   r   rd   r   )2Ú__doc__Ú
__future__r   Úmypyc.commonr   r   r   r   r   Úmypyc.ir.class_irr	   Úmypyc.ir.func_irr
   r   r   r   Úmypyc.ir.opsr   r   r   r   r   r   r   r   r   Úmypyc.ir.rtypesr   r   r   r   Úmypyc.irbuild.builderr   Úmypyc.irbuild.contextr   r   Úmypyc.primitives.misc_opsr   r   r    r!   r"   r#   r$   r%   rN   rF   r‚   r�   rš   © rO   rM   ú<module>r§      sË   ðñõ #÷õ õ &ß HÓ H÷
÷ 
õ 
÷ _Ó ^Ý +ß 9÷	÷ 	ó 	óBSðJA>ØðA>Ø+2ðA>ØDGðA>à	óA>ðHØðà
ðð ðð 
ð	ð
 ðð óó6
ô>*rO   