NL iWBdZddlmZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZmZddlmZddlmZddlmZmZerdd lmZGd d ZGd d eZGddeZGddeZGddeZGddeZ GddeZ!GddeZ"y)zHelpers for dealing with nonlocal control such as 'break' and 'return'. Model how these behave differently in different contexts. ) annotations)abstractmethod) TYPE_CHECKING) NO_TRACEBACK_LINE_NO BasicBlockBranchGotoIntegerRegisterReturnSetMem UnreachableValue)object_rprimitive)AssignmentTarget)restore_exc_info_opset_stop_iteration_value) IRBuildercFeZdZdZeddZeddZeddZy)NonlocalControlaABC representing a stack frame of constructs that modify nonlocal control flow. The nonlocal control flow constructs are break, continue, and return, and their behavior is modified by a number of other constructs. The most obvious is loop, which override where break and continue jump to, but also `except` (which needs to clear exc_info when left) and (eventually) finally blocks (which need to ensure that the finally block is always executed when leaving the try/except blocks). cyNselfbuilderlines c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypyc/irbuild/nonlocalcontrol.py gen_breakzNonlocalControl.gen_break+ cyrrrs r gen_continuezNonlocalControl.gen_continue/r r!cyrrrrvaluers r gen_returnzNonlocalControl.gen_return3r r!NrrrintreturnNonerrr&rrr)r*r+)__name__ __module__ __qualname____doc__rrr#r'rr!rrrsC       r!rc(eZdZdZddZddZddZy)BaseNonlocalControlz?Default nonlocal control outside any statements that affect it.cJd)Nzbreak outside of looprrs rrzBaseNonlocalControl.gen_break;s ---ur!cJd)Nzcontinue outside of looprrs rr#z BaseNonlocalControl.gen_continue>s 000ur!c8|jt|yr)addr r%s rr'zBaseNonlocalControl.gen_returnAs F5M"r!Nr(r,)r-r.r/r0rr#r'rr!rr2r28sI.1#r!r2c@eZdZdZ ddZddZddZd dZy) LoopNonlocalControlzNonlocal control within a loop.c.||_||_||_yr)outercontinue_block break_block)rr:r;r<s r__init__zLoopNonlocalControl.__init__Hs ,&r!cL|jt|jyr)r6r r<rs rrzLoopNonlocalControl.gen_breakOs D))*+r!cL|jt|jyr)r6r r;rs rr#z LoopNonlocalControl.gen_continueRs D,,-.r!c>|jj|||yr)r:r'r%s rr'zLoopNonlocalControl.gen_returnUs gud3r!N)r:rr;rr<rr*r+r(r,r-r.r/r0r=rr#r'rr!rr8r8Es9)'$'6@'OY' ',/4r!r8ceZdZdZddZy)GeneratorNonlocalControlzDDefault nonlocal control in a generator function outside statements.c|j|jjjt d||j j d|jttt}}|jjj}|J|jt|||tj|j||jt|gt |jt#|j j%|j||jt't(|||jt+t dt(y)Nr)assignfn_infogenerator_classnext_label_targetr rpush_error_handlergoto_and_activaterstop_iter_value_regr6rIS_ERRORactivate_blockcall_crrrpop_error_handlerr rr )rrr&rtruefalse stop_iter_regs rr'z#GeneratorNonlocalControl.gen_return\s w66HH'RT+W[\ **40!!*,/!lJLe77KK ((( F=$vGHt$ /%:NO KM"))+u%  F,mUCD F71&789:r!Nr,)r-r.r/r0r'rr!rrCrCYs N(;r!rCcBeZdZdZddZed dZd dZd dZd dZ y) CleanupNonlocalControlz6Abstract nonlocal control that runs some cleanup code.c||_yr)r:)rr:s rr=zCleanupNonlocalControl.__init__s  r!cyrrrs r gen_cleanupz"CleanupNonlocalControl.gen_cleanupsBEr!c`|j|||jj||yr)rXr:rrs rrz CleanupNonlocalControl.gen_breaks& $' Wd+r!c`|j|||jj||yr)rXr:r#rs rr#z#CleanupNonlocalControl.gen_continues& $' .r!cb|j|||jj|||yr)rXr:r'r%s rr'z!CleanupNonlocalControl.gen_returns( $' gud3r!N)r:rr*r+r(r,) r-r.r/r0r=rrXrr#r'rr!rrUrUs)@EE,/4r!rUc0eZdZdZddZddZddZd dZy) TryFinallyNonlocalControlz$Nonlocal control within try/finally.c ||_d|_yr)targetret_reg)rr_s rr=z"TryFinallyNonlocalControl.__init__s ;? r!c(|jd|y)Nz/break inside try/finally block is unimplementederrorrs rrz#TryFinallyNonlocalControl.gen_breaks GNr!c(|jd|y)Nz2continue inside try/finally block is unimplementedrbrs rr#z&TryFinallyNonlocalControl.gen_continues JDQr!c|jW|jjr$|j|jd|_nt |jd|_t |jt tfsJ|j|j|j|||jt|jy)NrE) r`rG is_generatormake_spill_target ret_typesr isinstancerrFr6r r_r%s rr'z$TryFinallyNonlocalControl.gen_returns << ++&889J9J29NO '(9(9"(=> $,,3C(DESt||SEt||UD1 D%&r!N)r_rr*r+r(r,rArr!rr]r]s.@OR 'r!r]c,eZdZdZdfd ZddZxZS)ExceptNonlocalControlzNonlocal control for except blocks. Just makes sure that sys.exc_info always gets restored when we leave. This is super annoying. c2t||||_yrsuperr=savedrr:ro __class__s rr=zExceptNonlocalControl.__init__  r!cf|jt|j|jg|yr)rOrreadrors rrXz!ExceptNonlocalControl.gen_cleanups#*W\\$**-E,FMr!)r:rrozValue | AssignmentTargetr*r+r(r-r.r/r0r=rX __classcell__rqs@rrkrks Nr!rkc,eZdZdZdfd ZddZxZS)FinallyNonlocalControlzNonlocal control for finally blocks. Just makes sure that sys.exc_info always gets restored when we leave and the return register is decrefed if it isn't null. c2t||||_yrrmrps rr=zFinallyNonlocalControl.__init__rrr!ctt}}|jt|j||tj|j ||j t|jg||j|yr) rr6rrorMrNrOrrK)rrrr_cleanups rrXz"FinallyNonlocalControl.gen_cleanupsa$,  F4::vwHIw'*TZZL$?!!&)r!)r:rrorr*r+r(rurws@rryrys *r!ryN)#r0 __future__rabcrtypingr mypyc.ir.opsrrrr r r r r rrmypyc.ir.rtypesrmypyc.irbuild.targetsrmypyc.primitives.exc_opsrrmypyc.irbuild.builderrrr2r8rCrUr]rkryrr!rrs #    .2R/  2 #/ #4/4(+;2+;\4_4,''6 N2 N*3*r!