| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707 |
- [case testTrivialFunction]
- def f() -> int:
- return 1
- [out]
- def f():
- L0:
- return 2
- [case testFunctionArgument]
- def f(x: int) -> int:
- return x
- [out]
- def f(x):
- x :: int
- L0:
- return x
- [case testExplicitNoneReturn]
- def f() -> None:
- return
- [out]
- def f():
- L0:
- return 1
- [case testExplicitNoneReturn2]
- def f() -> None:
- return None
- [out]
- def f():
- L0:
- return 1
- [case testAssignment]
- def f() -> int:
- x = 1
- y = x
- return y
- [out]
- def f():
- x, y :: int
- L0:
- x = 2
- y = x
- return y
- [case testAssignmentTwice]
- def f(x: int) -> None:
- y = 1
- y = x
- return
- [out]
- def f(x):
- x, y :: int
- L0:
- y = 2
- y = x
- return 1
- [case testIntArithmetic]
- def f(x: int, y: int) -> int:
- return x * (y + 1)
- [out]
- def f(x, y):
- x, y, r0, r1 :: int
- L0:
- r0 = CPyTagged_Add(y, 2)
- r1 = CPyTagged_Multiply(x, r0)
- return r1
- [case testIf]
- def f(x: int, y: int) -> int:
- if x < y:
- x = 1
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L4 else goto L5 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L4 else goto L5 :: bool
- L4:
- x = 2
- L5:
- return x
- [case testIfElse]
- def f(x: int, y: int) -> int:
- if x < y:
- x = 1
- else:
- x = 2
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L4 else goto L5 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L4 else goto L5 :: bool
- L4:
- x = 2
- goto L6
- L5:
- x = 4
- L6:
- return x
- [case testAnd1]
- def f(x: int, y: int) -> int:
- if x < y and x > y:
- x = 1
- else:
- x = 2
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- r6 :: native_int
- r7 :: bit
- r8 :: native_int
- r9, r10, r11 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L4 else goto L9 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L4 else goto L9 :: bool
- L4:
- r6 = x & 1
- r7 = r6 != 0
- if r7 goto L6 else goto L5 :: bool
- L5:
- r8 = y & 1
- r9 = r8 != 0
- if r9 goto L6 else goto L7 :: bool
- L6:
- r10 = CPyTagged_IsLt_(y, x)
- if r10 goto L8 else goto L9 :: bool
- L7:
- r11 = x > y :: signed
- if r11 goto L8 else goto L9 :: bool
- L8:
- x = 2
- goto L10
- L9:
- x = 4
- L10:
- return x
- [case testAnd2]
- def f(x: object, y: object) -> str:
- return str(x) or str(y)
- [out]
- def f(x, y):
- x, y :: object
- r0 :: str
- r1 :: bit
- r2, r3 :: str
- L0:
- r0 = PyObject_Str(x)
- r1 = CPyStr_IsTrue(r0)
- if r1 goto L1 else goto L2 :: bool
- L1:
- r2 = r0
- goto L3
- L2:
- r3 = PyObject_Str(y)
- r2 = r3
- L3:
- return r2
- [case testOr]
- def f(x: int, y: int) -> int:
- if x < y or x > y:
- x = 1
- else:
- x = 2
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- r6 :: native_int
- r7 :: bit
- r8 :: native_int
- r9, r10, r11 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L8 else goto L4 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L8 else goto L4 :: bool
- L4:
- r6 = x & 1
- r7 = r6 != 0
- if r7 goto L6 else goto L5 :: bool
- L5:
- r8 = y & 1
- r9 = r8 != 0
- if r9 goto L6 else goto L7 :: bool
- L6:
- r10 = CPyTagged_IsLt_(y, x)
- if r10 goto L8 else goto L9 :: bool
- L7:
- r11 = x > y :: signed
- if r11 goto L8 else goto L9 :: bool
- L8:
- x = 2
- goto L10
- L9:
- x = 4
- L10:
- return x
- [case testOr2]
- def f(x: object, y: object) -> str:
- return str(x) and str(y)
- [out]
- def f(x, y):
- x, y :: object
- r0 :: str
- r1 :: bit
- r2, r3 :: str
- L0:
- r0 = PyObject_Str(x)
- r1 = CPyStr_IsTrue(r0)
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = r0
- goto L3
- L2:
- r3 = PyObject_Str(y)
- r2 = r3
- L3:
- return r2
- [case testSimpleNot]
- def f(x: int, y: int) -> int:
- if not (x < y):
- x = 1
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L5 else goto L4 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L5 else goto L4 :: bool
- L4:
- x = 2
- L5:
- return x
- [case testNotAnd]
- def f(x: int, y: int) -> int:
- if not (x < y and x > y):
- x = 1
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- r6 :: native_int
- r7 :: bit
- r8 :: native_int
- r9, r10, r11 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L4 else goto L8 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L4 else goto L8 :: bool
- L4:
- r6 = x & 1
- r7 = r6 != 0
- if r7 goto L6 else goto L5 :: bool
- L5:
- r8 = y & 1
- r9 = r8 != 0
- if r9 goto L6 else goto L7 :: bool
- L6:
- r10 = CPyTagged_IsLt_(y, x)
- if r10 goto L9 else goto L8 :: bool
- L7:
- r11 = x > y :: signed
- if r11 goto L9 else goto L8 :: bool
- L8:
- x = 2
- L9:
- return x
- [case testWhile]
- def f(x: int, y: int) -> int:
- while x > y:
- x = x - y
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- r6 :: int
- L0:
- L1:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L3 else goto L2 :: bool
- L2:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L3 else goto L4 :: bool
- L3:
- r4 = CPyTagged_IsLt_(y, x)
- if r4 goto L5 else goto L6 :: bool
- L4:
- r5 = x > y :: signed
- if r5 goto L5 else goto L6 :: bool
- L5:
- r6 = CPyTagged_Subtract(x, y)
- x = r6
- goto L1
- L6:
- return x
- [case testWhile2]
- def f(x: int, y: int) -> int:
- x = 1
- while x > y:
- x = x - y
- return x
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- r6 :: int
- L0:
- x = 2
- L1:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L3 else goto L2 :: bool
- L2:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L3 else goto L4 :: bool
- L3:
- r4 = CPyTagged_IsLt_(y, x)
- if r4 goto L5 else goto L6 :: bool
- L4:
- r5 = x > y :: signed
- if r5 goto L5 else goto L6 :: bool
- L5:
- r6 = CPyTagged_Subtract(x, y)
- x = r6
- goto L1
- L6:
- return x
- [case testImplicitNoneReturn]
- def f() -> None:
- pass
- [out]
- def f():
- L0:
- return 1
- [case testImplicitNoneReturn2]
- def f() -> None:
- x = 1
- [out]
- def f():
- x :: int
- L0:
- x = 2
- return 1
- [case testImplicitNoneReturnAndIf]
- def f(x: int, y: int) -> None:
- if x < y:
- x = 1
- else:
- y = 2
- [out]
- def f(x, y):
- x, y :: int
- r0 :: native_int
- r1 :: bit
- r2 :: native_int
- r3, r4, r5 :: bit
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L2 else goto L1 :: bool
- L1:
- r2 = y & 1
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- r4 = CPyTagged_IsLt_(x, y)
- if r4 goto L4 else goto L5 :: bool
- L3:
- r5 = x < y :: signed
- if r5 goto L4 else goto L5 :: bool
- L4:
- x = 2
- goto L6
- L5:
- y = 4
- L6:
- return 1
- [case testRecursion]
- def f(n: int) -> int:
- if n <= 1:
- return 1
- else:
- return f(n - 1) + f(n - 2)
- [out]
- def f(n):
- n :: int
- r0 :: native_int
- r1, r2, r3 :: bit
- r4, r5, r6, r7, r8 :: int
- L0:
- r0 = n & 1
- r1 = r0 != 0
- if r1 goto L1 else goto L2 :: bool
- L1:
- r2 = CPyTagged_IsLt_(2, n)
- if r2 goto L4 else goto L3 :: bool
- L2:
- r3 = n <= 2 :: signed
- if r3 goto L3 else goto L4 :: bool
- L3:
- return 2
- L4:
- r4 = CPyTagged_Subtract(n, 2)
- r5 = f(r4)
- r6 = CPyTagged_Subtract(n, 4)
- r7 = f(r6)
- r8 = CPyTagged_Add(r5, r7)
- return r8
- L5:
- unreachable
- [case testReportTypeCheckError]
- def f() -> None:
- return 1 # E: No return value expected
- [case testReportSemanticaAnalysisError1]
- def f(x: List[int]) -> None: pass # E: Name "List" is not defined \
- # N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
- [case testReportSemanticaAnalysisError2]
- def f() -> None:
- x # E: Name "x" is not defined
- [case testElif]
- def f(n: int) -> int:
- if n < 0:
- x = 1
- elif n == 0:
- x = 1
- else:
- x = 2
- return x
- [out]
- def f(n):
- n :: int
- r0 :: native_int
- r1, r2, r3 :: bit
- x :: int
- r4 :: bit
- L0:
- r0 = n & 1
- r1 = r0 != 0
- if r1 goto L1 else goto L2 :: bool
- L1:
- r2 = CPyTagged_IsLt_(n, 0)
- if r2 goto L3 else goto L4 :: bool
- L2:
- r3 = n < 0 :: signed
- if r3 goto L3 else goto L4 :: bool
- L3:
- x = 2
- goto L8
- L4:
- r4 = n == 0
- if r4 goto L5 else goto L6 :: bool
- L5:
- x = 2
- goto L7
- L6:
- x = 4
- L7:
- L8:
- return x
- [case testUnaryMinus]
- def f(n: int) -> int:
- return -n
- [out]
- def f(n):
- n, r0 :: int
- L0:
- r0 = CPyTagged_Negate(n)
- return r0
- [case testConditionalExpr]
- def f(n: int) -> int:
- return 0 if n == 0 else 1
- [out]
- def f(n):
- n :: int
- r0 :: bit
- r1 :: int
- L0:
- r0 = n == 0
- if r0 goto L1 else goto L2 :: bool
- L1:
- r1 = 0
- goto L3
- L2:
- r1 = 2
- L3:
- return r1
- [case testOperatorAssignment]
- def f() -> int:
- x = 0
- x += 1
- return x
- [out]
- def f():
- x, r0 :: int
- L0:
- x = 0
- r0 = CPyTagged_Add(x, 2)
- x = r0
- return x
- [case testTrue]
- def f() -> bool:
- return True
- [out]
- def f():
- L0:
- return 1
- [case testFalse]
- def f() -> bool:
- return False
- [out]
- def f():
- L0:
- return 0
- [case testBoolCond]
- def f(x: bool) -> bool:
- if x:
- return False
- else:
- return True
- [out]
- def f(x):
- x :: bool
- L0:
- if x goto L1 else goto L2 :: bool
- L1:
- return 0
- L2:
- return 1
- L3:
- unreachable
- [case testPycall]
- import testmodule
- def f(x: int) -> int:
- return testmodule.factorial(x)
- [file testmodule.py]
- def factorial(x: int) -> int:
- if x == 0:
- return 1
- else:
- return x * factorial(x-1)
- [out]
- def f(x):
- x :: int
- r0 :: object
- r1 :: str
- r2, r3, r4 :: object
- r5 :: int
- L0:
- r0 = testmodule :: module
- r1 = 'factorial'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = box(int, x)
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- r5 = unbox(int, r4)
- return r5
- [case testImport_toplevel]
- import sys
- import enum as enum2
- import collections.abc
- import collections.abc as abc2
- _ = "filler"
- import single
- single.hello()
- [file single.py]
- def hello() -> None:
- print("hello, world")
- [out]
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4 :: object
- r5, r6, r7, r8 :: object_ptr
- r9 :: object_ptr[4]
- r10 :: c_ptr
- r11 :: native_int[4]
- r12 :: c_ptr
- r13 :: object
- r14 :: dict
- r15, r16 :: str
- r17 :: bit
- r18 :: str
- r19 :: dict
- r20 :: str
- r21 :: i32
- r22 :: bit
- r23 :: object_ptr
- r24 :: object_ptr[1]
- r25 :: c_ptr
- r26 :: native_int[1]
- r27 :: c_ptr
- r28 :: object
- r29 :: dict
- r30, r31 :: str
- r32 :: bit
- r33 :: object
- r34 :: str
- r35, r36 :: object
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = load_address sys :: module
- r6 = load_address enum :: module
- r7 = load_address collections.abc :: module
- r8 = load_address collections.abc :: module
- r9 = [r5, r6, r7, r8]
- r10 = load_address r9
- r11 = [1, 2, 3, 4]
- r12 = load_address r11
- r13 = (('sys', 'sys', 'sys'), ('enum', 'enum', 'enum2'), ('collections.abc', 'collections', 'collections'), ('collections.abc', 'collections.abc', 'abc2'))
- r14 = __main__.globals :: static
- r15 = 'main'
- r16 = '<module>'
- r17 = CPyImport_ImportMany(r13, r10, r14, r15, r16, r12)
- r18 = 'filler'
- r19 = __main__.globals :: static
- r20 = '_'
- r21 = CPyDict_SetItem(r19, r20, r18)
- r22 = r21 >= 0 :: signed
- r23 = load_address single :: module
- r24 = [r23]
- r25 = load_address r24
- r26 = [6]
- r27 = load_address r26
- r28 = (('single', 'single', 'single'),)
- r29 = __main__.globals :: static
- r30 = 'main'
- r31 = '<module>'
- r32 = CPyImport_ImportMany(r28, r25, r29, r30, r31, r27)
- r33 = single :: module
- r34 = 'hello'
- r35 = CPyObject_GetAttr(r33, r34)
- r36 = PyObject_CallFunctionObjArgs(r35, 0)
- return 1
- [case testFromImport_toplevel]
- from testmodule import g, h
- from testmodule import h as two
- def f(x: int) -> int:
- return g(x) + h() + two()
- [file testmodule.py]
- def g(x: int) -> int:
- return x + 1
- def h() -> int:
- return 2
- [out]
- def f(x):
- x :: int
- r0 :: dict
- r1 :: str
- r2, r3, r4 :: object
- r5 :: int
- r6 :: dict
- r7 :: str
- r8, r9 :: object
- r10, r11 :: int
- r12 :: dict
- r13 :: str
- r14, r15 :: object
- r16, r17 :: int
- L0:
- r0 = __main__.globals :: static
- r1 = 'g'
- r2 = CPyDict_GetItem(r0, r1)
- r3 = box(int, x)
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- r5 = unbox(int, r4)
- r6 = __main__.globals :: static
- r7 = 'h'
- r8 = CPyDict_GetItem(r6, r7)
- r9 = PyObject_CallFunctionObjArgs(r8, 0)
- r10 = unbox(int, r9)
- r11 = CPyTagged_Add(r5, r10)
- r12 = __main__.globals :: static
- r13 = 'two'
- r14 = CPyDict_GetItem(r12, r13)
- r15 = PyObject_CallFunctionObjArgs(r14, 0)
- r16 = unbox(int, r15)
- r17 = CPyTagged_Add(r11, r16)
- return r17
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4, r5 :: object
- r6 :: str
- r7 :: dict
- r8, r9, r10 :: object
- r11 :: str
- r12 :: dict
- r13 :: object
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = ('g', 'h')
- r6 = 'testmodule'
- r7 = __main__.globals :: static
- r8 = CPyImport_ImportFromMany(r6, r5, r5, r7)
- testmodule = r8 :: module
- r9 = ('h',)
- r10 = ('two',)
- r11 = 'testmodule'
- r12 = __main__.globals :: static
- r13 = CPyImport_ImportFromMany(r11, r9, r10, r12)
- testmodule = r13 :: module
- return 1
- [case testPrintFullname]
- import builtins
- def f(x: int) -> None:
- builtins.print(5)
- [out]
- def f(x):
- x :: int
- r0 :: object
- r1 :: str
- r2, r3, r4 :: object
- L0:
- r0 = builtins :: module
- r1 = 'print'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = object 5
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- return 1
- [case testPrint]
- import builtins
- def f(x: int) -> None:
- print(5)
- [out]
- def f(x):
- x :: int
- r0 :: object
- r1 :: str
- r2, r3, r4 :: object
- L0:
- r0 = builtins :: module
- r1 = 'print'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = object 5
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- return 1
- [case testUnicodeLiteral]
- def f() -> str:
- x = "some string"
- return "some other string"
- [out]
- def f():
- r0, x, r1 :: str
- L0:
- r0 = 'some string'
- x = r0
- r1 = 'some other string'
- return r1
- [case testBytesLiteral]
- def f() -> bytes:
- x = b'\xf0'
- return b'1234'
- [out]
- def f():
- r0, x, r1 :: bytes
- L0:
- r0 = b'\xf0'
- x = r0
- r1 = b'1234'
- return r1
- [case testPyMethodCall1]
- from typing import Any
- def f(x: Any) -> int:
- y: int = x.pop()
- return x.pop()
- [out]
- def f(x):
- x :: object
- r0 :: str
- r1 :: object
- r2, y :: int
- r3 :: str
- r4 :: object
- r5 :: int
- L0:
- r0 = 'pop'
- r1 = CPyObject_CallMethodObjArgs(x, r0, 0)
- r2 = unbox(int, r1)
- y = r2
- r3 = 'pop'
- r4 = CPyObject_CallMethodObjArgs(x, r3, 0)
- r5 = unbox(int, r4)
- return r5
- [case testObjectType]
- def g(y: object) -> None:
- g(y)
- g([1])
- g(None)
- [out]
- def g(y):
- y :: object
- r0 :: None
- r1 :: list
- r2 :: object
- r3, r4 :: ptr
- r5 :: None
- r6 :: object
- r7 :: None
- L0:
- r0 = g(y)
- r1 = PyList_New(1)
- r2 = object 1
- r3 = get_element_ptr r1 ob_item :: PyListObject
- r4 = load_mem r3 :: ptr*
- set_mem r4, r2 :: builtins.object*
- keep_alive r1
- r5 = g(r1)
- r6 = box(None, 1)
- r7 = g(r6)
- return 1
- [case testCoerceToObject1]
- def g(y: object) -> object:
- g(1)
- a = [y]
- a[0] = (1, 2)
- y = True
- return 3
- [out]
- def g(y):
- y, r0, r1 :: object
- r2 :: list
- r3, r4 :: ptr
- a :: list
- r5 :: tuple[int, int]
- r6 :: object
- r7 :: bit
- r8, r9 :: object
- L0:
- r0 = object 1
- r1 = g(r0)
- r2 = PyList_New(1)
- r3 = get_element_ptr r2 ob_item :: PyListObject
- r4 = load_mem r3 :: ptr*
- set_mem r4, y :: builtins.object*
- keep_alive r2
- a = r2
- r5 = (2, 4)
- r6 = box(tuple[int, int], r5)
- r7 = CPyList_SetItem(a, 0, r6)
- r8 = box(bool, 1)
- y = r8
- r9 = object 3
- return r9
- [case testCoerceToObject2]
- class A:
- x: object
- n: int
- def f(a: A, o: object) -> None:
- a.x = 1
- o = a.n
- [out]
- def f(a, o):
- a :: __main__.A
- o, r0 :: object
- r1 :: bool
- r2 :: int
- r3 :: object
- L0:
- r0 = object 1
- a.x = r0; r1 = is_error
- r2 = a.n
- r3 = box(int, r2)
- o = r3
- return 1
- [case testAssertType]
- from typing import assert_type
- def f(x: int) -> None:
- y = assert_type(x, int)
- [out]
- def f(x):
- x, y :: int
- L0:
- y = x
- return 1
- [case testDownCast]
- from typing import cast, List, Tuple
- class A: pass
- def f(x: object) -> None:
- n = cast(int, x)
- b = cast(bool, x)
- a = cast(A, x)
- l = cast(List[int], x)
- t = cast(Tuple[int, A], x)
- [out]
- def f(x):
- x :: object
- r0, n :: int
- r1, b :: bool
- r2, a :: __main__.A
- r3, l :: list
- r4, t :: tuple[int, __main__.A]
- L0:
- r0 = unbox(int, x)
- n = r0
- r1 = unbox(bool, x)
- b = r1
- r2 = cast(__main__.A, x)
- a = r2
- r3 = cast(list, x)
- l = r3
- r4 = unbox(tuple[int, __main__.A], x)
- t = r4
- return 1
- [case testDownCastSpecialCases]
- from typing import cast, Optional, Tuple
- class A: pass
- def f(o: Optional[A], n: int, t: Tuple[int, ...], tt: Tuple[int, int]) -> None:
- a = cast(A, o)
- m = cast(bool, n)
- t = tt
- [out]
- def f(o, n, t, tt):
- o :: union[__main__.A, None]
- n :: int
- t :: tuple
- tt :: tuple[int, int]
- r0, a :: __main__.A
- r1 :: object
- r2, m :: bool
- r3 :: object
- L0:
- r0 = cast(__main__.A, o)
- a = r0
- r1 = box(int, n)
- r2 = unbox(bool, r1)
- m = r2
- r3 = box(tuple[int, int], tt)
- t = r3
- return 1
- [case testSuccessfulCast]
- from typing import cast, Optional, Tuple, List, Dict
- class A: pass
- def f(o: object,
- p: Optional[A],
- n: int,
- b: bool,
- t: Tuple[int, ...],
- s: Tuple[int, int],
- a: A,
- l: List[A],
- d: Dict[int, str]) -> None:
- o = cast(object, o)
- p = cast(Optional[A], p)
- n = cast(int, n)
- b = cast(bool, b)
- t = cast(Tuple[int, ...], t)
- s = cast(Tuple[int, int], s)
- o = cast(object, n)
- a = cast(A, a)
- l2 = cast(List[object], l)
- d2 = cast(Dict[object, str], d)
- [out]
- def f(o, p, n, b, t, s, a, l, d):
- o :: object
- p :: union[__main__.A, None]
- n :: int
- b :: bool
- t :: tuple
- s :: tuple[int, int]
- a :: __main__.A
- l :: list
- d :: dict
- r0 :: object
- l2 :: list
- d2 :: dict
- L0:
- o = o
- p = p
- n = n
- b = b
- t = t
- s = s
- r0 = box(int, n)
- o = r0
- a = a
- l2 = l
- d2 = d
- return 1
- [case testGenericSetItem]
- from typing import Any
- def f(x: Any, y: Any, z: Any) -> None:
- x[y] = z
- [out]
- def f(x, y, z):
- x, y, z :: object
- r0 :: i32
- r1 :: bit
- L0:
- r0 = PyObject_SetItem(x, y, z)
- r1 = r0 >= 0 :: signed
- return 1
- [case testLoadFloatSum]
- def assign_and_return_float_sum() -> float:
- f1 = 1.0
- f2 = 2.0
- f3 = 3.0
- return f1 * f2 + f3
- [out]
- def assign_and_return_float_sum():
- f1, f2, f3, r0, r1 :: float
- L0:
- f1 = 1.0
- f2 = 2.0
- f3 = 3.0
- r0 = f1 * f2
- r1 = r0 + f3
- return r1
- [case testLoadComplex]
- def load() -> complex:
- real = 1
- return 5j+real
- [out]
- def load():
- real :: int
- r0, r1, r2 :: object
- L0:
- real = 2
- r0 = 5j
- r1 = box(int, real)
- r2 = PyNumber_Add(r0, r1)
- return r2
- [case testBigIntLiteral_64bit]
- def big_int() -> None:
- a_62_bit = 4611686018427387902
- max_62_bit = 4611686018427387903
- b_63_bit = 4611686018427387904
- c_63_bit = 9223372036854775806
- max_63_bit = 9223372036854775807
- d_64_bit = 9223372036854775808
- max_32_bit = 2147483647
- max_31_bit = 1073741823
- [out]
- def big_int():
- a_62_bit, max_62_bit, r0, b_63_bit, r1, c_63_bit, r2, max_63_bit, r3, d_64_bit, max_32_bit, max_31_bit :: int
- L0:
- a_62_bit = 9223372036854775804
- max_62_bit = 9223372036854775806
- r0 = object 4611686018427387904
- b_63_bit = r0
- r1 = object 9223372036854775806
- c_63_bit = r1
- r2 = object 9223372036854775807
- max_63_bit = r2
- r3 = object 9223372036854775808
- d_64_bit = r3
- max_32_bit = 4294967294
- max_31_bit = 2147483646
- return 1
- [case testBigIntLiteral_32bit]
- def big_int() -> None:
- a_62_bit = 4611686018427387902
- max_62_bit = 4611686018427387903
- b_63_bit = 4611686018427387904
- c_63_bit = 9223372036854775806
- max_63_bit = 9223372036854775807
- d_64_bit = 9223372036854775808
- max_32_bit = 2147483647
- max_31_bit = 1073741823
- [out]
- def big_int():
- r0, a_62_bit, r1, max_62_bit, r2, b_63_bit, r3, c_63_bit, r4, max_63_bit, r5, d_64_bit, r6, max_32_bit, max_31_bit :: int
- L0:
- r0 = object 4611686018427387902
- a_62_bit = r0
- r1 = object 4611686018427387903
- max_62_bit = r1
- r2 = object 4611686018427387904
- b_63_bit = r2
- r3 = object 9223372036854775806
- c_63_bit = r3
- r4 = object 9223372036854775807
- max_63_bit = r4
- r5 = object 9223372036854775808
- d_64_bit = r5
- r6 = object 2147483647
- max_32_bit = r6
- max_31_bit = 2147483646
- return 1
- [case testCallableTypes]
- from typing import Callable, Any
- from m import f
- def absolute_value(x: int) -> int:
- return x if x > 0 else -x
- def call_native_function(x: int) -> int:
- return absolute_value(x)
- def call_python_function(x: int) -> int:
- return f(x)
- def return_float() -> float:
- return 5.0
- def return_callable_type() -> Callable[[], float]:
- return return_float
- def call_callable_type() -> float:
- f = return_callable_type()
- return f()
- [file m.py]
- def f(x: int) -> int:
- return x
- [out]
- def absolute_value(x):
- x :: int
- r0 :: native_int
- r1, r2, r3 :: bit
- r4, r5 :: int
- L0:
- r0 = x & 1
- r1 = r0 != 0
- if r1 goto L1 else goto L2 :: bool
- L1:
- r2 = CPyTagged_IsLt_(0, x)
- if r2 goto L3 else goto L4 :: bool
- L2:
- r3 = x > 0 :: signed
- if r3 goto L3 else goto L4 :: bool
- L3:
- r4 = x
- goto L5
- L4:
- r5 = CPyTagged_Negate(x)
- r4 = r5
- L5:
- return r4
- def call_native_function(x):
- x, r0 :: int
- L0:
- r0 = absolute_value(x)
- return r0
- def call_python_function(x):
- x :: int
- r0 :: dict
- r1 :: str
- r2, r3, r4 :: object
- r5 :: int
- L0:
- r0 = __main__.globals :: static
- r1 = 'f'
- r2 = CPyDict_GetItem(r0, r1)
- r3 = box(int, x)
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- r5 = unbox(int, r4)
- return r5
- def return_float():
- L0:
- return 5.0
- def return_callable_type():
- r0 :: dict
- r1 :: str
- r2 :: object
- L0:
- r0 = __main__.globals :: static
- r1 = 'return_float'
- r2 = CPyDict_GetItem(r0, r1)
- return r2
- def call_callable_type():
- r0, f, r1 :: object
- r2 :: float
- L0:
- r0 = return_callable_type()
- f = r0
- r1 = PyObject_CallFunctionObjArgs(f, 0)
- r2 = unbox(float, r1)
- return r2
- [case testCallableTypesWithKeywordArgs]
- from typing import List
- def call_python_function_with_keyword_arg(x: str) -> int:
- return int(x, base=2)
- def call_python_method_with_keyword_args(xs: List[int], first: int, second: int) -> List[int]:
- xs.insert(0, x=first)
- xs.insert(x=second, i=1)
- return xs
- [out]
- def call_python_function_with_keyword_arg(x):
- x :: str
- r0 :: object
- r1 :: str
- r2 :: tuple
- r3 :: object
- r4 :: dict
- r5 :: object
- r6 :: int
- L0:
- r0 = load_address PyLong_Type
- r1 = 'base'
- r2 = PyTuple_Pack(1, x)
- r3 = object 2
- r4 = CPyDict_Build(1, r1, r3)
- r5 = PyObject_Call(r0, r2, r4)
- r6 = unbox(int, r5)
- return r6
- def call_python_method_with_keyword_args(xs, first, second):
- xs :: list
- first, second :: int
- r0 :: str
- r1 :: object
- r2 :: str
- r3 :: object
- r4 :: tuple
- r5 :: object
- r6 :: dict
- r7 :: object
- r8 :: str
- r9 :: object
- r10, r11 :: str
- r12 :: tuple
- r13, r14 :: object
- r15 :: dict
- r16 :: object
- L0:
- r0 = 'insert'
- r1 = CPyObject_GetAttr(xs, r0)
- r2 = 'x'
- r3 = object 0
- r4 = PyTuple_Pack(1, r3)
- r5 = box(int, first)
- r6 = CPyDict_Build(1, r2, r5)
- r7 = PyObject_Call(r1, r4, r6)
- r8 = 'insert'
- r9 = CPyObject_GetAttr(xs, r8)
- r10 = 'x'
- r11 = 'i'
- r12 = PyTuple_Pack(0)
- r13 = box(int, second)
- r14 = object 1
- r15 = CPyDict_Build(2, r10, r13, r11, r14)
- r16 = PyObject_Call(r9, r12, r15)
- return xs
- [case testObjectAsBoolean]
- from typing import List
- def obj(x: object) -> int:
- if x:
- return 1
- else:
- return 0
- def num(x: int) -> int:
- if x:
- return 1
- else:
- return 0
- def lst(x: List[int]) -> int:
- if x:
- return 1
- else:
- return 0
- [out]
- def obj(x):
- x :: object
- r0 :: i32
- r1 :: bit
- r2 :: bool
- L0:
- r0 = PyObject_IsTrue(x)
- r1 = r0 >= 0 :: signed
- r2 = truncate r0: i32 to builtins.bool
- if r2 goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 0
- L3:
- unreachable
- def num(x):
- x :: int
- r0 :: bit
- L0:
- r0 = x != 0
- if r0 goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 0
- L3:
- unreachable
- def lst(x):
- x :: list
- r0 :: ptr
- r1 :: native_int
- r2 :: short_int
- r3 :: bit
- L0:
- r0 = get_element_ptr x ob_size :: PyVarObject
- r1 = load_mem r0 :: native_int*
- keep_alive x
- r2 = r1 << 1
- r3 = r2 != 0
- if r3 goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 0
- L3:
- unreachable
- [case testOptionalAsBoolean]
- from typing import Optional
- class A: pass
- def opt_int(x: Optional[int]) -> int:
- if x:
- return 1
- else:
- return 0
- def opt_a(x: Optional[A]) -> int:
- if x:
- return 1
- else:
- return 0
- def opt_o(x: Optional[object]) -> int:
- if x:
- return 1
- else:
- return 0
- [out]
- def opt_int(x):
- x :: union[int, None]
- r0 :: object
- r1 :: bit
- r2 :: int
- r3 :: bit
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = x != r0
- if r1 goto L1 else goto L3 :: bool
- L1:
- r2 = unbox(int, x)
- r3 = r2 != 0
- if r3 goto L2 else goto L3 :: bool
- L2:
- return 2
- L3:
- return 0
- L4:
- unreachable
- def opt_a(x):
- x :: union[__main__.A, None]
- r0 :: object
- r1 :: bit
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = x != r0
- if r1 goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 0
- L3:
- unreachable
- def opt_o(x):
- x :: union[object, None]
- r0 :: object
- r1 :: bit
- r2 :: object
- r3 :: i32
- r4 :: bit
- r5 :: bool
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = x != r0
- if r1 goto L1 else goto L3 :: bool
- L1:
- r2 = cast(object, x)
- r3 = PyObject_IsTrue(r2)
- r4 = r3 >= 0 :: signed
- r5 = truncate r3: i32 to builtins.bool
- if r5 goto L2 else goto L3 :: bool
- L2:
- return 2
- L3:
- return 0
- L4:
- unreachable
- [case testRaise]
- def foo() -> None:
- raise Exception()
- def bar() -> None:
- raise Exception
- [out]
- def foo():
- r0 :: object
- r1 :: str
- r2, r3 :: object
- L0:
- r0 = builtins :: module
- r1 = 'Exception'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = PyObject_CallFunctionObjArgs(r2, 0)
- CPy_Raise(r3)
- unreachable
- def bar():
- r0 :: object
- r1 :: str
- r2 :: object
- L0:
- r0 = builtins :: module
- r1 = 'Exception'
- r2 = CPyObject_GetAttr(r0, r1)
- CPy_Raise(r2)
- unreachable
- [case testModuleTopLevel_toplevel]
- x = 1
- print(x)
- def f() -> None:
- print(x)
- [out]
- def f():
- r0 :: dict
- r1 :: str
- r2 :: object
- r3 :: int
- r4 :: object
- r5 :: str
- r6, r7, r8 :: object
- L0:
- r0 = __main__.globals :: static
- r1 = 'x'
- r2 = CPyDict_GetItem(r0, r1)
- r3 = unbox(int, r2)
- r4 = builtins :: module
- r5 = 'print'
- r6 = CPyObject_GetAttr(r4, r5)
- r7 = box(int, r3)
- r8 = PyObject_CallFunctionObjArgs(r6, r7, 0)
- return 1
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4 :: object
- r5 :: dict
- r6 :: str
- r7 :: object
- r8 :: i32
- r9 :: bit
- r10 :: dict
- r11 :: str
- r12 :: object
- r13 :: int
- r14 :: object
- r15 :: str
- r16, r17, r18 :: object
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = __main__.globals :: static
- r6 = 'x'
- r7 = object 1
- r8 = CPyDict_SetItem(r5, r6, r7)
- r9 = r8 >= 0 :: signed
- r10 = __main__.globals :: static
- r11 = 'x'
- r12 = CPyDict_GetItem(r10, r11)
- r13 = unbox(int, r12)
- r14 = builtins :: module
- r15 = 'print'
- r16 = CPyObject_GetAttr(r14, r15)
- r17 = box(int, r13)
- r18 = PyObject_CallFunctionObjArgs(r16, r17, 0)
- return 1
- [case testCallOverloaded]
- import m
- def f() -> str:
- return m.f(1)
- [file m.pyi]
- from typing import overload
- @overload
- def f(x: int) -> str: ...
- @overload
- def f(x: str) -> int: ...
- [out]
- def f():
- r0 :: object
- r1 :: str
- r2, r3, r4 :: object
- r5 :: str
- L0:
- r0 = m :: module
- r1 = 'f'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = object 1
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- r5 = cast(str, r4)
- return r5
- [case testCallOverloadedNative]
- from typing import overload, Union
- @overload
- def foo(x: int) -> int: ...
- @overload
- def foo(x: str) -> str: ...
- def foo(x: Union[int, str]) -> Union[int, str]:
- return x
- def main() -> None:
- x = foo(0)
- [out]
- def foo(x):
- x :: union[int, str]
- L0:
- return x
- def main():
- r0 :: object
- r1 :: union[int, str]
- r2, x :: int
- L0:
- r0 = object 0
- r1 = foo(r0)
- r2 = unbox(int, r1)
- x = r2
- return 1
- [case testCallOverloadedNativeSubclass]
- from typing import overload, Union
- class A:
- x: int
- class B(A):
- y: int
- @overload
- def foo(x: int) -> B: ...
- @overload
- def foo(x: Union[int, str]) -> A: ...
- def foo(x: Union[int, str]) -> A:
- if isinstance(x, int):
- return B()
- return A()
- def main() -> None:
- x = foo(0)
- [out]
- def foo(x):
- x :: union[int, str]
- r0 :: object
- r1 :: i32
- r2 :: bit
- r3 :: bool
- r4 :: __main__.B
- r5 :: __main__.A
- L0:
- r0 = load_address PyLong_Type
- r1 = PyObject_IsInstance(x, r0)
- r2 = r1 >= 0 :: signed
- r3 = truncate r1: i32 to builtins.bool
- if r3 goto L1 else goto L2 :: bool
- L1:
- r4 = B()
- return r4
- L2:
- r5 = A()
- return r5
- def main():
- r0 :: object
- r1 :: __main__.A
- r2, x :: __main__.B
- L0:
- r0 = object 0
- r1 = foo(r0)
- r2 = cast(__main__.B, r1)
- x = r2
- return 1
- [case testFunctionCallWithKeywordArgs]
- def f(x: int, y: str) -> None: pass
- def g() -> None:
- f(y='a', x=0)
- f(1, y='b')
- [out]
- def f(x, y):
- x :: int
- y :: str
- L0:
- return 1
- def g():
- r0 :: str
- r1 :: None
- r2 :: str
- r3 :: None
- L0:
- r0 = 'a'
- r1 = f(0, r0)
- r2 = 'b'
- r3 = f(2, r2)
- return 1
- [case testMethodCallWithKeywordArgs]
- class A:
- def f(self, x: int, y: str) -> None: pass
- def g(a: A) -> None:
- a.f(y='a', x=0)
- a.f(1, y='b')
- [out]
- def A.f(self, x, y):
- self :: __main__.A
- x :: int
- y :: str
- L0:
- return 1
- def g(a):
- a :: __main__.A
- r0 :: str
- r1 :: None
- r2 :: str
- r3 :: None
- L0:
- r0 = 'a'
- r1 = a.f(0, r0)
- r2 = 'b'
- r3 = a.f(2, r2)
- return 1
- [case testStarArgs]
- from typing import Tuple
- def f(a: int, b: int, c: int) -> Tuple[int, int, int]:
- return a, b, c
- def g() -> Tuple[int, int, int]:
- return f(*(1, 2, 3))
- def h() -> Tuple[int, int, int]:
- return f(1, *(2, 3))
- [out]
- def f(a, b, c):
- a, b, c :: int
- r0 :: tuple[int, int, int]
- L0:
- r0 = (a, b, c)
- return r0
- def g():
- r0 :: tuple[int, int, int]
- r1 :: dict
- r2 :: str
- r3 :: object
- r4 :: list
- r5, r6 :: object
- r7 :: tuple
- r8 :: dict
- r9 :: object
- r10 :: tuple[int, int, int]
- L0:
- r0 = (2, 4, 6)
- r1 = __main__.globals :: static
- r2 = 'f'
- r3 = CPyDict_GetItem(r1, r2)
- r4 = PyList_New(0)
- r5 = box(tuple[int, int, int], r0)
- r6 = CPyList_Extend(r4, r5)
- r7 = PyList_AsTuple(r4)
- r8 = PyDict_New()
- r9 = PyObject_Call(r3, r7, r8)
- r10 = unbox(tuple[int, int, int], r9)
- return r10
- def h():
- r0 :: tuple[int, int]
- r1 :: dict
- r2 :: str
- r3 :: object
- r4 :: list
- r5 :: object
- r6, r7 :: ptr
- r8, r9 :: object
- r10 :: tuple
- r11 :: dict
- r12 :: object
- r13 :: tuple[int, int, int]
- L0:
- r0 = (4, 6)
- r1 = __main__.globals :: static
- r2 = 'f'
- r3 = CPyDict_GetItem(r1, r2)
- r4 = PyList_New(1)
- r5 = object 1
- r6 = get_element_ptr r4 ob_item :: PyListObject
- r7 = load_mem r6 :: ptr*
- set_mem r7, r5 :: builtins.object*
- keep_alive r4
- r8 = box(tuple[int, int], r0)
- r9 = CPyList_Extend(r4, r8)
- r10 = PyList_AsTuple(r4)
- r11 = PyDict_New()
- r12 = PyObject_Call(r3, r10, r11)
- r13 = unbox(tuple[int, int, int], r12)
- return r13
- [case testStar2Args]
- from typing import Tuple
- def f(a: int, b: int, c: int) -> Tuple[int, int, int]:
- return a, b, c
- def g() -> Tuple[int, int, int]:
- return f(**{'a': 1, 'b': 2, 'c': 3})
- def h() -> Tuple[int, int, int]:
- return f(1, **{'b': 2, 'c': 3})
- [out]
- def f(a, b, c):
- a, b, c :: int
- r0 :: tuple[int, int, int]
- L0:
- r0 = (a, b, c)
- return r0
- def g():
- r0, r1, r2 :: str
- r3, r4, r5 :: object
- r6, r7 :: dict
- r8 :: str
- r9 :: object
- r10 :: dict
- r11 :: i32
- r12 :: bit
- r13 :: tuple
- r14 :: object
- r15 :: tuple[int, int, int]
- L0:
- r0 = 'a'
- r1 = 'b'
- r2 = 'c'
- r3 = object 1
- r4 = object 2
- r5 = object 3
- r6 = CPyDict_Build(3, r0, r3, r1, r4, r2, r5)
- r7 = __main__.globals :: static
- r8 = 'f'
- r9 = CPyDict_GetItem(r7, r8)
- r10 = PyDict_New()
- r11 = CPyDict_UpdateInDisplay(r10, r6)
- r12 = r11 >= 0 :: signed
- r13 = PyTuple_Pack(0)
- r14 = PyObject_Call(r9, r13, r10)
- r15 = unbox(tuple[int, int, int], r14)
- return r15
- def h():
- r0, r1 :: str
- r2, r3 :: object
- r4, r5 :: dict
- r6 :: str
- r7 :: object
- r8 :: dict
- r9 :: i32
- r10 :: bit
- r11 :: object
- r12 :: tuple
- r13 :: object
- r14 :: tuple[int, int, int]
- L0:
- r0 = 'b'
- r1 = 'c'
- r2 = object 2
- r3 = object 3
- r4 = CPyDict_Build(2, r0, r2, r1, r3)
- r5 = __main__.globals :: static
- r6 = 'f'
- r7 = CPyDict_GetItem(r5, r6)
- r8 = PyDict_New()
- r9 = CPyDict_UpdateInDisplay(r8, r4)
- r10 = r9 >= 0 :: signed
- r11 = object 1
- r12 = PyTuple_Pack(1, r11)
- r13 = PyObject_Call(r7, r12, r8)
- r14 = unbox(tuple[int, int, int], r13)
- return r14
- [case testFunctionCallWithDefaultArgs]
- def f(x: int, y: int = 3, z: str = "test") -> None:
- return None
- def g() -> None:
- f(2)
- f(y = 3, x = 6)
- [out]
- def f(x, y, z):
- x, y :: int
- z, r0 :: str
- L0:
- if is_error(y) goto L1 else goto L2
- L1:
- y = 6
- L2:
- if is_error(z) goto L3 else goto L4
- L3:
- r0 = 'test'
- z = r0
- L4:
- return 1
- def g():
- r0 :: int
- r1 :: str
- r2 :: None
- r3 :: str
- r4 :: None
- L0:
- r0 = <error> :: int
- r1 = <error> :: str
- r2 = f(4, r0, r1)
- r3 = <error> :: str
- r4 = f(12, 6, r3)
- return 1
- [case testMethodCallWithDefaultArgs]
- class A:
- def f(self, x: int, y: int = 3, z: str = "test") -> None:
- return None
- def g() -> None:
- a = A()
- a.f(2)
- a.f(y = 3, x = 6)
- [out]
- def A.f(self, x, y, z):
- self :: __main__.A
- x, y :: int
- z, r0 :: str
- L0:
- if is_error(y) goto L1 else goto L2
- L1:
- y = 6
- L2:
- if is_error(z) goto L3 else goto L4
- L3:
- r0 = 'test'
- z = r0
- L4:
- return 1
- def g():
- r0, a :: __main__.A
- r1 :: int
- r2 :: str
- r3 :: None
- r4 :: str
- r5 :: None
- L0:
- r0 = A()
- a = r0
- r1 = <error> :: int
- r2 = <error> :: str
- r3 = a.f(4, r1, r2)
- r4 = <error> :: str
- r5 = a.f(12, 6, r4)
- return 1
- [case testListComprehension]
- from typing import List
- def f() -> List[int]:
- return [x*x for x in [1,2,3] if x != 2 if x != 3]
- [out]
- def f():
- r0, r1 :: list
- r2, r3, r4 :: object
- r5, r6, r7, r8 :: ptr
- r9 :: short_int
- r10 :: ptr
- r11 :: native_int
- r12 :: short_int
- r13 :: bit
- r14 :: object
- r15, x :: int
- r16 :: native_int
- r17, r18 :: bit
- r19 :: bool
- r20, r21 :: bit
- r22 :: native_int
- r23, r24 :: bit
- r25 :: bool
- r26, r27 :: bit
- r28 :: int
- r29 :: object
- r30 :: i32
- r31 :: bit
- r32 :: short_int
- L0:
- r0 = PyList_New(0)
- r1 = PyList_New(3)
- r2 = object 1
- r3 = object 2
- r4 = object 3
- r5 = get_element_ptr r1 ob_item :: PyListObject
- r6 = load_mem r5 :: ptr*
- set_mem r6, r2 :: builtins.object*
- r7 = r6 + WORD_SIZE*1
- set_mem r7, r3 :: builtins.object*
- r8 = r6 + WORD_SIZE*2
- set_mem r8, r4 :: builtins.object*
- keep_alive r1
- r9 = 0
- L1:
- r10 = get_element_ptr r1 ob_size :: PyVarObject
- r11 = load_mem r10 :: native_int*
- keep_alive r1
- r12 = r11 << 1
- r13 = r9 < r12 :: signed
- if r13 goto L2 else goto L14 :: bool
- L2:
- r14 = CPyList_GetItemUnsafe(r1, r9)
- r15 = unbox(int, r14)
- x = r15
- r16 = x & 1
- r17 = r16 == 0
- if r17 goto L3 else goto L4 :: bool
- L3:
- r18 = x != 4
- r19 = r18
- goto L5
- L4:
- r20 = CPyTagged_IsEq_(x, 4)
- r21 = r20 ^ 1
- r19 = r21
- L5:
- if r19 goto L7 else goto L6 :: bool
- L6:
- goto L13
- L7:
- r22 = x & 1
- r23 = r22 == 0
- if r23 goto L8 else goto L9 :: bool
- L8:
- r24 = x != 6
- r25 = r24
- goto L10
- L9:
- r26 = CPyTagged_IsEq_(x, 6)
- r27 = r26 ^ 1
- r25 = r27
- L10:
- if r25 goto L12 else goto L11 :: bool
- L11:
- goto L13
- L12:
- r28 = CPyTagged_Multiply(x, x)
- r29 = box(int, r28)
- r30 = PyList_Append(r0, r29)
- r31 = r30 >= 0 :: signed
- L13:
- r32 = r9 + 2
- r9 = r32
- goto L1
- L14:
- return r0
- [case testDictComprehension]
- from typing import Dict
- def f() -> Dict[int, int]:
- return {x: x*x for x in [1,2,3] if x != 2 if x != 3}
- [out]
- def f():
- r0 :: dict
- r1 :: list
- r2, r3, r4 :: object
- r5, r6, r7, r8 :: ptr
- r9 :: short_int
- r10 :: ptr
- r11 :: native_int
- r12 :: short_int
- r13 :: bit
- r14 :: object
- r15, x :: int
- r16 :: native_int
- r17, r18 :: bit
- r19 :: bool
- r20, r21 :: bit
- r22 :: native_int
- r23, r24 :: bit
- r25 :: bool
- r26, r27 :: bit
- r28 :: int
- r29, r30 :: object
- r31 :: i32
- r32 :: bit
- r33 :: short_int
- L0:
- r0 = PyDict_New()
- r1 = PyList_New(3)
- r2 = object 1
- r3 = object 2
- r4 = object 3
- r5 = get_element_ptr r1 ob_item :: PyListObject
- r6 = load_mem r5 :: ptr*
- set_mem r6, r2 :: builtins.object*
- r7 = r6 + WORD_SIZE*1
- set_mem r7, r3 :: builtins.object*
- r8 = r6 + WORD_SIZE*2
- set_mem r8, r4 :: builtins.object*
- keep_alive r1
- r9 = 0
- L1:
- r10 = get_element_ptr r1 ob_size :: PyVarObject
- r11 = load_mem r10 :: native_int*
- keep_alive r1
- r12 = r11 << 1
- r13 = r9 < r12 :: signed
- if r13 goto L2 else goto L14 :: bool
- L2:
- r14 = CPyList_GetItemUnsafe(r1, r9)
- r15 = unbox(int, r14)
- x = r15
- r16 = x & 1
- r17 = r16 == 0
- if r17 goto L3 else goto L4 :: bool
- L3:
- r18 = x != 4
- r19 = r18
- goto L5
- L4:
- r20 = CPyTagged_IsEq_(x, 4)
- r21 = r20 ^ 1
- r19 = r21
- L5:
- if r19 goto L7 else goto L6 :: bool
- L6:
- goto L13
- L7:
- r22 = x & 1
- r23 = r22 == 0
- if r23 goto L8 else goto L9 :: bool
- L8:
- r24 = x != 6
- r25 = r24
- goto L10
- L9:
- r26 = CPyTagged_IsEq_(x, 6)
- r27 = r26 ^ 1
- r25 = r27
- L10:
- if r25 goto L12 else goto L11 :: bool
- L11:
- goto L13
- L12:
- r28 = CPyTagged_Multiply(x, x)
- r29 = box(int, x)
- r30 = box(int, r28)
- r31 = CPyDict_SetItem(r0, r29, r30)
- r32 = r31 >= 0 :: signed
- L13:
- r33 = r9 + 2
- r9 = r33
- goto L1
- L14:
- return r0
- [case testLoopsMultipleAssign]
- from typing import List, Tuple
- def f(l: List[Tuple[int, int, int]]) -> List[int]:
- for x, y, z in l:
- pass
- return [x+y+z for x, y, z in l]
- [out]
- def f(l):
- l :: list
- r0 :: short_int
- r1 :: ptr
- r2 :: native_int
- r3 :: short_int
- r4 :: bit
- r5 :: object
- r6 :: tuple[int, int, int]
- r7, x, r8, y, r9, z :: int
- r10 :: short_int
- r11 :: ptr
- r12 :: native_int
- r13 :: list
- r14 :: short_int
- r15 :: ptr
- r16 :: native_int
- r17 :: short_int
- r18 :: bit
- r19 :: object
- r20 :: tuple[int, int, int]
- r21, x_2, r22, y_2, r23, z_2, r24, r25 :: int
- r26 :: object
- r27 :: bit
- r28 :: short_int
- L0:
- r0 = 0
- L1:
- r1 = get_element_ptr l ob_size :: PyVarObject
- r2 = load_mem r1 :: native_int*
- keep_alive l
- r3 = r2 << 1
- r4 = r0 < r3 :: signed
- if r4 goto L2 else goto L4 :: bool
- L2:
- r5 = CPyList_GetItemUnsafe(l, r0)
- r6 = unbox(tuple[int, int, int], r5)
- r7 = r6[0]
- x = r7
- r8 = r6[1]
- y = r8
- r9 = r6[2]
- z = r9
- L3:
- r10 = r0 + 2
- r0 = r10
- goto L1
- L4:
- r11 = get_element_ptr l ob_size :: PyVarObject
- r12 = load_mem r11 :: native_int*
- keep_alive l
- r13 = PyList_New(r12)
- r14 = 0
- L5:
- r15 = get_element_ptr l ob_size :: PyVarObject
- r16 = load_mem r15 :: native_int*
- keep_alive l
- r17 = r16 << 1
- r18 = r14 < r17 :: signed
- if r18 goto L6 else goto L8 :: bool
- L6:
- r19 = CPyList_GetItemUnsafe(l, r14)
- r20 = unbox(tuple[int, int, int], r19)
- r21 = r20[0]
- x_2 = r21
- r22 = r20[1]
- y_2 = r22
- r23 = r20[2]
- z_2 = r23
- r24 = CPyTagged_Add(x_2, y_2)
- r25 = CPyTagged_Add(r24, z_2)
- r26 = box(int, r25)
- r27 = CPyList_SetItemUnsafe(r13, r14, r26)
- L7:
- r28 = r14 + 2
- r14 = r28
- goto L5
- L8:
- return r13
- [case testProperty]
- class PropertyHolder:
- @property
- def value(self) -> int:
- return self.left + self.right if self.is_add else self.left - self.right
- def __init__(self, left: int, right: int, is_add: bool) -> None:
- self.left = left
- self.right = right
- self.is_add = is_add
- def twice_value(self) -> int:
- return 2 * self.value
- [out]
- def PropertyHolder.value(self):
- self :: __main__.PropertyHolder
- r0 :: bool
- r1, r2, r3, r4, r5, r6, r7 :: int
- L0:
- r0 = self.is_add
- if r0 goto L1 else goto L2 :: bool
- L1:
- r1 = borrow self.left
- r2 = borrow self.right
- r3 = CPyTagged_Add(r1, r2)
- keep_alive self, self
- r4 = r3
- goto L3
- L2:
- r5 = borrow self.left
- r6 = borrow self.right
- r7 = CPyTagged_Subtract(r5, r6)
- keep_alive self, self
- r4 = r7
- L3:
- return r4
- def PropertyHolder.__init__(self, left, right, is_add):
- self :: __main__.PropertyHolder
- left, right :: int
- is_add :: bool
- L0:
- self.left = left
- self.right = right
- self.is_add = is_add
- return 1
- def PropertyHolder.twice_value(self):
- self :: __main__.PropertyHolder
- r0, r1 :: int
- L0:
- r0 = self.value
- r1 = CPyTagged_Multiply(4, r0)
- return r1
- [case testNativeIndex]
- from typing import List
- class A:
- def __getitem__(self, index: int) -> int: pass
- def g(a: A, b: List[int], c: int) -> int:
- return a[c] + b[c]
- [out]
- def A.__getitem__(self, index):
- self :: __main__.A
- index :: int
- L0:
- unreachable
- def g(a, b, c):
- a :: __main__.A
- b :: list
- c, r0 :: int
- r1 :: object
- r2, r3 :: int
- L0:
- r0 = a.__getitem__(c)
- r1 = CPyList_GetItemBorrow(b, c)
- r2 = unbox(int, r1)
- r3 = CPyTagged_Add(r0, r2)
- keep_alive b, c
- return r3
- [case testTypeAlias_toplevel]
- from typing import List, NewType, NamedTuple
- Lol = NamedTuple('Lol', (('a', int), ('b', str)))
- x = Lol(1, '')
- Foo = List[int]
- Bar = NewType('Bar', Foo)
- y = Bar([1,2,3])
- [out]
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4, r5 :: object
- r6 :: str
- r7 :: dict
- r8 :: object
- r9, r10 :: str
- r11 :: object
- r12 :: tuple[str, object]
- r13 :: object
- r14 :: str
- r15 :: object
- r16 :: tuple[str, object]
- r17 :: object
- r18 :: tuple[object, object]
- r19 :: object
- r20 :: dict
- r21 :: str
- r22, r23 :: object
- r24 :: dict
- r25 :: str
- r26 :: i32
- r27 :: bit
- r28 :: str
- r29 :: dict
- r30 :: str
- r31, r32, r33 :: object
- r34 :: tuple
- r35 :: dict
- r36 :: str
- r37 :: i32
- r38 :: bit
- r39 :: dict
- r40 :: str
- r41, r42, r43 :: object
- r44 :: dict
- r45 :: str
- r46 :: i32
- r47 :: bit
- r48 :: str
- r49 :: dict
- r50 :: str
- r51 :: object
- r52 :: dict
- r53 :: str
- r54, r55 :: object
- r56 :: dict
- r57 :: str
- r58 :: i32
- r59 :: bit
- r60 :: list
- r61, r62, r63 :: object
- r64, r65, r66, r67 :: ptr
- r68 :: dict
- r69 :: str
- r70 :: i32
- r71 :: bit
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = ('List', 'NewType', 'NamedTuple')
- r6 = 'typing'
- r7 = __main__.globals :: static
- r8 = CPyImport_ImportFromMany(r6, r5, r5, r7)
- typing = r8 :: module
- r9 = 'Lol'
- r10 = 'a'
- r11 = load_address PyLong_Type
- r12 = (r10, r11)
- r13 = box(tuple[str, object], r12)
- r14 = 'b'
- r15 = load_address PyUnicode_Type
- r16 = (r14, r15)
- r17 = box(tuple[str, object], r16)
- r18 = (r13, r17)
- r19 = box(tuple[object, object], r18)
- r20 = __main__.globals :: static
- r21 = 'NamedTuple'
- r22 = CPyDict_GetItem(r20, r21)
- r23 = PyObject_CallFunctionObjArgs(r22, r9, r19, 0)
- r24 = __main__.globals :: static
- r25 = 'Lol'
- r26 = CPyDict_SetItem(r24, r25, r23)
- r27 = r26 >= 0 :: signed
- r28 = ''
- r29 = __main__.globals :: static
- r30 = 'Lol'
- r31 = CPyDict_GetItem(r29, r30)
- r32 = object 1
- r33 = PyObject_CallFunctionObjArgs(r31, r32, r28, 0)
- r34 = cast(tuple, r33)
- r35 = __main__.globals :: static
- r36 = 'x'
- r37 = CPyDict_SetItem(r35, r36, r34)
- r38 = r37 >= 0 :: signed
- r39 = __main__.globals :: static
- r40 = 'List'
- r41 = CPyDict_GetItem(r39, r40)
- r42 = load_address PyLong_Type
- r43 = PyObject_GetItem(r41, r42)
- r44 = __main__.globals :: static
- r45 = 'Foo'
- r46 = CPyDict_SetItem(r44, r45, r43)
- r47 = r46 >= 0 :: signed
- r48 = 'Bar'
- r49 = __main__.globals :: static
- r50 = 'Foo'
- r51 = CPyDict_GetItem(r49, r50)
- r52 = __main__.globals :: static
- r53 = 'NewType'
- r54 = CPyDict_GetItem(r52, r53)
- r55 = PyObject_CallFunctionObjArgs(r54, r48, r51, 0)
- r56 = __main__.globals :: static
- r57 = 'Bar'
- r58 = CPyDict_SetItem(r56, r57, r55)
- r59 = r58 >= 0 :: signed
- r60 = PyList_New(3)
- r61 = object 1
- r62 = object 2
- r63 = object 3
- r64 = get_element_ptr r60 ob_item :: PyListObject
- r65 = load_mem r64 :: ptr*
- set_mem r65, r61 :: builtins.object*
- r66 = r65 + WORD_SIZE*1
- set_mem r66, r62 :: builtins.object*
- r67 = r65 + WORD_SIZE*2
- set_mem r67, r63 :: builtins.object*
- keep_alive r60
- r68 = __main__.globals :: static
- r69 = 'y'
- r70 = CPyDict_SetItem(r68, r69, r60)
- r71 = r70 >= 0 :: signed
- return 1
- [case testChainedConditional]
- def g(x: int) -> int:
- return x
- def f(x: int, y: int, z: int) -> bool:
- return g(x) < g(y) > g(z)
- [out]
- def g(x):
- x :: int
- L0:
- return x
- def f(x, y, z):
- x, y, z, r0, r1 :: int
- r2 :: native_int
- r3 :: bit
- r4 :: native_int
- r5, r6, r7 :: bit
- r8 :: bool
- r9 :: bit
- r10 :: bool
- r11 :: int
- r12 :: native_int
- r13 :: bit
- r14 :: native_int
- r15, r16, r17 :: bit
- r18 :: bool
- r19 :: bit
- L0:
- r0 = g(x)
- r1 = g(y)
- r2 = r0 & 1
- r3 = r2 == 0
- r4 = r1 & 1
- r5 = r4 == 0
- r6 = r3 & r5
- if r6 goto L1 else goto L2 :: bool
- L1:
- r7 = r0 < r1 :: signed
- r8 = r7
- goto L3
- L2:
- r9 = CPyTagged_IsLt_(r0, r1)
- r8 = r9
- L3:
- if r8 goto L5 else goto L4 :: bool
- L4:
- r10 = r8
- goto L9
- L5:
- r11 = g(z)
- r12 = r1 & 1
- r13 = r12 == 0
- r14 = r11 & 1
- r15 = r14 == 0
- r16 = r13 & r15
- if r16 goto L6 else goto L7 :: bool
- L6:
- r17 = r1 > r11 :: signed
- r18 = r17
- goto L8
- L7:
- r19 = CPyTagged_IsLt_(r11, r1)
- r18 = r19
- L8:
- r10 = r18
- L9:
- return r10
- [case testEq]
- class A:
- def __eq__(self, x: object) -> bool:
- return NotImplemented
- [out]
- def A.__eq__(self, x):
- self :: __main__.A
- x, r0 :: object
- L0:
- r0 = load_address _Py_NotImplementedStruct
- return r0
- def A.__ne__(__mypyc_self__, rhs):
- __mypyc_self__ :: __main__.A
- rhs, r0, r1 :: object
- r2 :: bit
- r3 :: i32
- r4 :: bit
- r5 :: bool
- r6 :: object
- L0:
- r0 = __mypyc_self__.__eq__(rhs)
- r1 = load_address _Py_NotImplementedStruct
- r2 = r0 == r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = PyObject_Not(r0)
- r4 = r3 >= 0 :: signed
- r5 = truncate r3: i32 to builtins.bool
- r6 = box(bool, r5)
- return r6
- L2:
- return r1
- [case testDecorators_toplevel]
- from typing import Callable
- def a(f: Callable[[], None]) -> Callable[[], None]:
- def g() -> None:
- print('Entering')
- f()
- print('Exited')
- return g
- def b(f: Callable[[], None]) -> Callable[[], None]:
- def g() -> None:
- print('---')
- f()
- print('---')
- return g
- @a
- @b
- def c() -> None:
- @a
- @b
- def d() -> None:
- print('d')
- print('c')
- d()
- [out]
- def g_a_obj.__get__(__mypyc_self__, instance, owner):
- __mypyc_self__, instance, owner, r0 :: object
- r1 :: bit
- r2 :: object
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = instance == r0
- if r1 goto L1 else goto L2 :: bool
- L1:
- return __mypyc_self__
- L2:
- r2 = PyMethod_New(__mypyc_self__, instance)
- return r2
- def g_a_obj.__call__(__mypyc_self__):
- __mypyc_self__ :: __main__.g_a_obj
- r0 :: __main__.a_env
- r1, g :: object
- r2 :: str
- r3 :: object
- r4 :: str
- r5, r6, r7, r8 :: object
- r9 :: str
- r10 :: object
- r11 :: str
- r12, r13 :: object
- L0:
- r0 = __mypyc_self__.__mypyc_env__
- r1 = r0.g
- g = r1
- r2 = 'Entering'
- r3 = builtins :: module
- r4 = 'print'
- r5 = CPyObject_GetAttr(r3, r4)
- r6 = PyObject_CallFunctionObjArgs(r5, r2, 0)
- r7 = r0.f
- r8 = PyObject_CallFunctionObjArgs(r7, 0)
- r9 = 'Exited'
- r10 = builtins :: module
- r11 = 'print'
- r12 = CPyObject_GetAttr(r10, r11)
- r13 = PyObject_CallFunctionObjArgs(r12, r9, 0)
- return 1
- def a(f):
- f :: object
- r0 :: __main__.a_env
- r1 :: bool
- r2 :: __main__.g_a_obj
- r3, r4 :: bool
- r5 :: object
- L0:
- r0 = a_env()
- r0.f = f; r1 = is_error
- r2 = g_a_obj()
- r2.__mypyc_env__ = r0; r3 = is_error
- r0.g = r2; r4 = is_error
- r5 = r0.g
- return r5
- def g_b_obj.__get__(__mypyc_self__, instance, owner):
- __mypyc_self__, instance, owner, r0 :: object
- r1 :: bit
- r2 :: object
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = instance == r0
- if r1 goto L1 else goto L2 :: bool
- L1:
- return __mypyc_self__
- L2:
- r2 = PyMethod_New(__mypyc_self__, instance)
- return r2
- def g_b_obj.__call__(__mypyc_self__):
- __mypyc_self__ :: __main__.g_b_obj
- r0 :: __main__.b_env
- r1, g :: object
- r2 :: str
- r3 :: object
- r4 :: str
- r5, r6, r7, r8 :: object
- r9 :: str
- r10 :: object
- r11 :: str
- r12, r13 :: object
- L0:
- r0 = __mypyc_self__.__mypyc_env__
- r1 = r0.g
- g = r1
- r2 = '---'
- r3 = builtins :: module
- r4 = 'print'
- r5 = CPyObject_GetAttr(r3, r4)
- r6 = PyObject_CallFunctionObjArgs(r5, r2, 0)
- r7 = r0.f
- r8 = PyObject_CallFunctionObjArgs(r7, 0)
- r9 = '---'
- r10 = builtins :: module
- r11 = 'print'
- r12 = CPyObject_GetAttr(r10, r11)
- r13 = PyObject_CallFunctionObjArgs(r12, r9, 0)
- return 1
- def b(f):
- f :: object
- r0 :: __main__.b_env
- r1 :: bool
- r2 :: __main__.g_b_obj
- r3, r4 :: bool
- r5 :: object
- L0:
- r0 = b_env()
- r0.f = f; r1 = is_error
- r2 = g_b_obj()
- r2.__mypyc_env__ = r0; r3 = is_error
- r0.g = r2; r4 = is_error
- r5 = r0.g
- return r5
- def d_c_obj.__get__(__mypyc_self__, instance, owner):
- __mypyc_self__, instance, owner, r0 :: object
- r1 :: bit
- r2 :: object
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = instance == r0
- if r1 goto L1 else goto L2 :: bool
- L1:
- return __mypyc_self__
- L2:
- r2 = PyMethod_New(__mypyc_self__, instance)
- return r2
- def d_c_obj.__call__(__mypyc_self__):
- __mypyc_self__ :: __main__.d_c_obj
- r0 :: __main__.c_env
- r1, d :: object
- r2 :: str
- r3 :: object
- r4 :: str
- r5, r6 :: object
- L0:
- r0 = __mypyc_self__.__mypyc_env__
- r1 = r0.d
- d = r1
- r2 = 'd'
- r3 = builtins :: module
- r4 = 'print'
- r5 = CPyObject_GetAttr(r3, r4)
- r6 = PyObject_CallFunctionObjArgs(r5, r2, 0)
- return 1
- def c():
- r0 :: __main__.c_env
- r1 :: __main__.d_c_obj
- r2 :: bool
- r3 :: dict
- r4 :: str
- r5, r6 :: object
- r7 :: dict
- r8 :: str
- r9, r10 :: object
- r11 :: bool
- r12 :: dict
- r13 :: str
- r14 :: i32
- r15 :: bit
- r16 :: str
- r17 :: object
- r18 :: str
- r19, r20, r21, r22 :: object
- L0:
- r0 = c_env()
- r1 = d_c_obj()
- r1.__mypyc_env__ = r0; r2 = is_error
- r3 = __main__.globals :: static
- r4 = 'b'
- r5 = CPyDict_GetItem(r3, r4)
- r6 = PyObject_CallFunctionObjArgs(r5, r1, 0)
- r7 = __main__.globals :: static
- r8 = 'a'
- r9 = CPyDict_GetItem(r7, r8)
- r10 = PyObject_CallFunctionObjArgs(r9, r6, 0)
- r0.d = r10; r11 = is_error
- r12 = __main__.globals :: static
- r13 = 'd'
- r14 = CPyDict_SetItem(r12, r13, r10)
- r15 = r14 >= 0 :: signed
- r16 = 'c'
- r17 = builtins :: module
- r18 = 'print'
- r19 = CPyObject_GetAttr(r17, r18)
- r20 = PyObject_CallFunctionObjArgs(r19, r16, 0)
- r21 = r0.d
- r22 = PyObject_CallFunctionObjArgs(r21, 0)
- return 1
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4, r5 :: object
- r6 :: str
- r7 :: dict
- r8 :: object
- r9 :: dict
- r10 :: str
- r11 :: object
- r12 :: dict
- r13 :: str
- r14, r15 :: object
- r16 :: dict
- r17 :: str
- r18, r19 :: object
- r20 :: dict
- r21 :: str
- r22 :: i32
- r23 :: bit
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = ('Callable',)
- r6 = 'typing'
- r7 = __main__.globals :: static
- r8 = CPyImport_ImportFromMany(r6, r5, r5, r7)
- typing = r8 :: module
- r9 = __main__.globals :: static
- r10 = 'c'
- r11 = CPyDict_GetItem(r9, r10)
- r12 = __main__.globals :: static
- r13 = 'b'
- r14 = CPyDict_GetItem(r12, r13)
- r15 = PyObject_CallFunctionObjArgs(r14, r11, 0)
- r16 = __main__.globals :: static
- r17 = 'a'
- r18 = CPyDict_GetItem(r16, r17)
- r19 = PyObject_CallFunctionObjArgs(r18, r15, 0)
- r20 = __main__.globals :: static
- r21 = 'c'
- r22 = CPyDict_SetItem(r20, r21, r19)
- r23 = r22 >= 0 :: signed
- return 1
- [case testDecoratorsSimple_toplevel]
- from typing import Callable
- def a(f: Callable[[], None]) -> Callable[[], None]:
- def g() -> None:
- print('Entering')
- f()
- print('Exited')
- return g
- [out]
- def g_a_obj.__get__(__mypyc_self__, instance, owner):
- __mypyc_self__, instance, owner, r0 :: object
- r1 :: bit
- r2 :: object
- L0:
- r0 = load_address _Py_NoneStruct
- r1 = instance == r0
- if r1 goto L1 else goto L2 :: bool
- L1:
- return __mypyc_self__
- L2:
- r2 = PyMethod_New(__mypyc_self__, instance)
- return r2
- def g_a_obj.__call__(__mypyc_self__):
- __mypyc_self__ :: __main__.g_a_obj
- r0 :: __main__.a_env
- r1, g :: object
- r2 :: str
- r3 :: object
- r4 :: str
- r5, r6, r7, r8 :: object
- r9 :: str
- r10 :: object
- r11 :: str
- r12, r13 :: object
- L0:
- r0 = __mypyc_self__.__mypyc_env__
- r1 = r0.g
- g = r1
- r2 = 'Entering'
- r3 = builtins :: module
- r4 = 'print'
- r5 = CPyObject_GetAttr(r3, r4)
- r6 = PyObject_CallFunctionObjArgs(r5, r2, 0)
- r7 = r0.f
- r8 = PyObject_CallFunctionObjArgs(r7, 0)
- r9 = 'Exited'
- r10 = builtins :: module
- r11 = 'print'
- r12 = CPyObject_GetAttr(r10, r11)
- r13 = PyObject_CallFunctionObjArgs(r12, r9, 0)
- return 1
- def a(f):
- f :: object
- r0 :: __main__.a_env
- r1 :: bool
- r2 :: __main__.g_a_obj
- r3, r4 :: bool
- r5 :: object
- L0:
- r0 = a_env()
- r0.f = f; r1 = is_error
- r2 = g_a_obj()
- r2.__mypyc_env__ = r0; r3 = is_error
- r0.g = r2; r4 = is_error
- r5 = r0.g
- return r5
- def __top_level__():
- r0, r1 :: object
- r2 :: bit
- r3 :: str
- r4, r5 :: object
- r6 :: str
- r7 :: dict
- r8 :: object
- L0:
- r0 = builtins :: module
- r1 = load_address _Py_NoneStruct
- r2 = r0 != r1
- if r2 goto L2 else goto L1 :: bool
- L1:
- r3 = 'builtins'
- r4 = PyImport_Import(r3)
- builtins = r4 :: module
- L2:
- r5 = ('Callable',)
- r6 = 'typing'
- r7 = __main__.globals :: static
- r8 = CPyImport_ImportFromMany(r6, r5, r5, r7)
- typing = r8 :: module
- return 1
- [case testAnyAllG]
- from typing import Iterable
- def call_any(l: Iterable[int]) -> bool:
- return any(i == 0 for i in l)
- def call_all(l: Iterable[int]) -> bool:
- return all(i == 0 for i in l)
- [out]
- def call_any(l):
- l :: object
- r0 :: bool
- r1, r2 :: object
- r3, i :: int
- r4 :: native_int
- r5, r6 :: bit
- r7 :: bool
- r8, r9 :: bit
- L0:
- r0 = 0
- r1 = PyObject_GetIter(l)
- L1:
- r2 = PyIter_Next(r1)
- if is_error(r2) goto L9 else goto L2
- L2:
- r3 = unbox(int, r2)
- i = r3
- r4 = i & 1
- r5 = r4 == 0
- if r5 goto L3 else goto L4 :: bool
- L3:
- r6 = i == 0
- r7 = r6
- goto L5
- L4:
- r8 = CPyTagged_IsEq_(i, 0)
- r7 = r8
- L5:
- if r7 goto L6 else goto L7 :: bool
- L6:
- r0 = 1
- goto L11
- L7:
- L8:
- goto L1
- L9:
- r9 = CPy_NoErrOccured()
- L10:
- L11:
- return r0
- def call_all(l):
- l :: object
- r0 :: bool
- r1, r2 :: object
- r3, i :: int
- r4 :: native_int
- r5, r6 :: bit
- r7 :: bool
- r8 :: bit
- r9 :: bool
- r10 :: bit
- L0:
- r0 = 1
- r1 = PyObject_GetIter(l)
- L1:
- r2 = PyIter_Next(r1)
- if is_error(r2) goto L9 else goto L2
- L2:
- r3 = unbox(int, r2)
- i = r3
- r4 = i & 1
- r5 = r4 == 0
- if r5 goto L3 else goto L4 :: bool
- L3:
- r6 = i == 0
- r7 = r6
- goto L5
- L4:
- r8 = CPyTagged_IsEq_(i, 0)
- r7 = r8
- L5:
- r9 = r7 ^ 1
- if r9 goto L6 else goto L7 :: bool
- L6:
- r0 = 0
- goto L11
- L7:
- L8:
- goto L1
- L9:
- r10 = CPy_NoErrOccured()
- L10:
- L11:
- return r0
- [case testSum]
- from typing import Callable, Iterable
- def call_sum(l: Iterable[int], comparison: Callable[[int], bool]) -> int:
- return sum(comparison(x) for x in l)
- [out]
- def call_sum(l, comparison):
- l, comparison :: object
- r0 :: int
- r1, r2 :: object
- r3, x :: int
- r4, r5 :: object
- r6, r7 :: bool
- r8, r9 :: int
- r10 :: bit
- L0:
- r0 = 0
- r1 = PyObject_GetIter(l)
- L1:
- r2 = PyIter_Next(r1)
- if is_error(r2) goto L4 else goto L2
- L2:
- r3 = unbox(int, r2)
- x = r3
- r4 = box(int, x)
- r5 = PyObject_CallFunctionObjArgs(comparison, r4, 0)
- r6 = unbox(bool, r5)
- r7 = r6 << 1
- r8 = extend r7: builtins.bool to builtins.int
- r9 = CPyTagged_Add(r0, r8)
- r0 = r9
- L3:
- goto L1
- L4:
- r10 = CPy_NoErrOccured()
- L5:
- return r0
- [case testSetAttr1]
- from typing import Any, Dict, List
- def lol(x: Any):
- setattr(x, 'x', '5')
- [out]
- def lol(x):
- x :: object
- r0, r1 :: str
- r2 :: i32
- r3 :: bit
- r4 :: object
- L0:
- r0 = 'x'
- r1 = '5'
- r2 = PyObject_SetAttr(x, r0, r1)
- r3 = r2 >= 0 :: signed
- r4 = box(None, 1)
- return r4
- [case testFinalModuleInt]
- from typing import Final
- x: Final = 1
- y: Final = 2
- def f(a: bool) -> int:
- if a:
- return x
- else:
- return y
- [out]
- def f(a):
- a :: bool
- L0:
- if a goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 4
- L3:
- unreachable
- [case testFinalModuleStr]
- from typing import Final
- x: Final = 'x'
- y: Final = 'y'
- def f(a: bool) -> str:
- if a:
- return x
- else:
- return y
- [out]
- def f(a):
- a :: bool
- r0, r1 :: str
- L0:
- if a goto L1 else goto L2 :: bool
- L1:
- r0 = 'x'
- return r0
- L2:
- r1 = 'y'
- return r1
- L3:
- unreachable
- [case testFinalModuleBool]
- from typing import Final
- x: Final = True
- y: Final = False
- def f(a: bool) -> bool:
- if a:
- return x
- else:
- return y
- [out]
- def f(a):
- a :: bool
- L0:
- if a goto L1 else goto L2 :: bool
- L1:
- return 1
- L2:
- return 0
- L3:
- unreachable
- [case testFinalClass]
- from typing import Final
- class C:
- x: Final = 1
- y: Final = 2
- def f(a: bool) -> int:
- if a:
- return C.x
- else:
- return C.y
- [out]
- def C.__mypyc_defaults_setup(__mypyc_self__):
- __mypyc_self__ :: __main__.C
- L0:
- __mypyc_self__.x = 2
- __mypyc_self__.y = 4
- return 1
- def f(a):
- a :: bool
- L0:
- if a goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 4
- L3:
- unreachable
- [case testFinalStaticList]
- from typing import Final
- x: Final = [1]
- def f() -> int:
- return x[0]
- [out]
- def f():
- r0 :: list
- r1 :: bool
- r2 :: object
- r3 :: int
- L0:
- r0 = __main__.x :: static
- if is_error(r0) goto L1 else goto L2
- L1:
- r1 = raise NameError('value for final name "x" was not set')
- unreachable
- L2:
- r2 = CPyList_GetItemShort(r0, 0)
- r3 = unbox(int, r2)
- return r3
- [case testFinalStaticTuple]
- from typing import Final
- x: Final = (1, 2)
- def f() -> int:
- return x[0]
- [out]
- def f():
- r0 :: tuple[int, int]
- r1 :: bool
- r2 :: int
- L0:
- r0 = __main__.x :: static
- if is_error(r0) goto L1 else goto L2
- L1:
- r1 = raise NameError('value for final name "x" was not set')
- unreachable
- L2:
- r2 = r0[0]
- return r2
- [case testFinalStaticInt]
- from typing import Final
- x: Final = 1 + int()
- def f() -> int:
- return x - 1
- [out]
- def f():
- r0 :: int
- r1 :: bool
- r2 :: int
- L0:
- r0 = __main__.x :: static
- if is_error(r0) goto L1 else goto L2
- L1:
- r1 = raise NameError('value for final name "x" was not set')
- unreachable
- L2:
- r2 = CPyTagged_Subtract(r0, 2)
- return r2
- [case testFinalRestrictedTypeVar]
- from typing import TypeVar
- if False:
- from typing import Final
- FOO = 10 # type: Final
- Targ = TypeVar('Targ', int, str)
- def foo(z: Targ) -> None:
- FOO
- [out]
- def foo(z):
- z :: object
- L0:
- return 1
- [case testDirectlyCall__bool__]
- class A:
- def __bool__(self) -> bool:
- return True
- class B(A):
- def __bool__(self) -> bool:
- return False
- def lol(x: A) -> int:
- if x:
- return 1
- else:
- return 0
- [out]
- def A.__bool__(self):
- self :: __main__.A
- L0:
- return 1
- def B.__bool__(self):
- self :: __main__.B
- L0:
- return 0
- def lol(x):
- x :: __main__.A
- r0 :: bool
- L0:
- r0 = x.__bool__()
- if r0 goto L1 else goto L2 :: bool
- L1:
- return 2
- L2:
- return 0
- L3:
- unreachable
- [case testRevealType]
- def f(x: int) -> None:
- reveal_type(x) # type: ignore
- [out]
- def f(x):
- x :: int
- r0 :: object
- r1 :: str
- r2, r3, r4 :: object
- L0:
- r0 = builtins :: module
- r1 = 'reveal_type'
- r2 = CPyObject_GetAttr(r0, r1)
- r3 = box(int, x)
- r4 = PyObject_CallFunctionObjArgs(r2, r3, 0)
- return 1
- [case testCallCWithStrJoinMethod]
- from typing import List
- def f(x: str, y: List[str]) -> str:
- return x.join(y)
- [out]
- def f(x, y):
- x :: str
- y :: list
- r0 :: str
- L0:
- r0 = PyUnicode_Join(x, y)
- return r0
- [case testCallCWithToListFunction]
- from typing import List, Iterable, Tuple, Dict
- # generic object
- def f(x: Iterable[int]) -> List[int]:
- return list(x)
- # need coercing
- def g(x: Tuple[int, int, int]) -> List[int]:
- return list(x)
- # non-list object
- def h(x: Dict[int, str]) -> List[int]:
- return list(x)
- [out]
- def f(x):
- x :: object
- r0 :: list
- L0:
- r0 = PySequence_List(x)
- return r0
- def g(x):
- x :: tuple[int, int, int]
- r0 :: object
- r1 :: list
- L0:
- r0 = box(tuple[int, int, int], x)
- r1 = PySequence_List(r0)
- return r1
- def h(x):
- x :: dict
- r0 :: list
- L0:
- r0 = PySequence_List(x)
- return r0
- [case testBoolFunction]
- def f(x: object) -> bool:
- return bool(x)
- [out]
- def f(x):
- x :: object
- r0 :: i32
- r1 :: bit
- r2 :: bool
- L0:
- r0 = PyObject_IsTrue(x)
- r1 = r0 >= 0 :: signed
- r2 = truncate r0: i32 to builtins.bool
- return r2
- [case testLocalImports]
- def root() -> None:
- import dataclasses
- import enum
- def submodule() -> int:
- import p.m
- return p.x
- [file p/__init__.py]
- x = 1
- [file p/m.py]
- [out]
- def root():
- r0 :: dict
- r1, r2 :: object
- r3 :: bit
- r4 :: str
- r5 :: object
- r6 :: str
- r7 :: dict
- r8 :: str
- r9 :: object
- r10 :: i32
- r11 :: bit
- r12 :: dict
- r13, r14 :: object
- r15 :: bit
- r16 :: str
- r17 :: object
- r18 :: str
- r19 :: dict
- r20 :: str
- r21 :: object
- r22 :: i32
- r23 :: bit
- L0:
- r0 = __main__.globals :: static
- r1 = dataclasses :: module
- r2 = load_address _Py_NoneStruct
- r3 = r1 != r2
- if r3 goto L2 else goto L1 :: bool
- L1:
- r4 = 'dataclasses'
- r5 = PyImport_Import(r4)
- dataclasses = r5 :: module
- L2:
- r6 = 'dataclasses'
- r7 = PyImport_GetModuleDict()
- r8 = 'dataclasses'
- r9 = CPyDict_GetItem(r7, r8)
- r10 = CPyDict_SetItem(r0, r6, r9)
- r11 = r10 >= 0 :: signed
- r12 = __main__.globals :: static
- r13 = enum :: module
- r14 = load_address _Py_NoneStruct
- r15 = r13 != r14
- if r15 goto L4 else goto L3 :: bool
- L3:
- r16 = 'enum'
- r17 = PyImport_Import(r16)
- enum = r17 :: module
- L4:
- r18 = 'enum'
- r19 = PyImport_GetModuleDict()
- r20 = 'enum'
- r21 = CPyDict_GetItem(r19, r20)
- r22 = CPyDict_SetItem(r12, r18, r21)
- r23 = r22 >= 0 :: signed
- return 1
- def submodule():
- r0 :: dict
- r1, r2 :: object
- r3 :: bit
- r4 :: str
- r5 :: object
- r6 :: str
- r7 :: dict
- r8 :: str
- r9 :: object
- r10 :: i32
- r11 :: bit
- r12 :: dict
- r13 :: str
- r14 :: object
- r15 :: str
- r16 :: object
- r17 :: int
- L0:
- r0 = __main__.globals :: static
- r1 = p.m :: module
- r2 = load_address _Py_NoneStruct
- r3 = r1 != r2
- if r3 goto L2 else goto L1 :: bool
- L1:
- r4 = 'p.m'
- r5 = PyImport_Import(r4)
- p.m = r5 :: module
- L2:
- r6 = 'p'
- r7 = PyImport_GetModuleDict()
- r8 = 'p'
- r9 = CPyDict_GetItem(r7, r8)
- r10 = CPyDict_SetItem(r0, r6, r9)
- r11 = r10 >= 0 :: signed
- r12 = PyImport_GetModuleDict()
- r13 = 'p'
- r14 = CPyDict_GetItem(r12, r13)
- r15 = 'x'
- r16 = CPyObject_GetAttr(r14, r15)
- r17 = unbox(int, r16)
- return r17
- [case testIsinstanceBool]
- def f(x: object) -> bool:
- return isinstance(x, bool)
- [out]
- def f(x):
- x, r0 :: object
- r1 :: i32
- r2 :: bit
- r3 :: bool
- L0:
- r0 = load_address PyBool_Type
- r1 = PyObject_IsInstance(x, r0)
- r2 = r1 >= 0 :: signed
- r3 = truncate r1: i32 to builtins.bool
- return r3
- [case testRangeObject]
- def range_object() -> None:
- r = range(4, 12, 2)
- sum = 0
- for i in r:
- sum += i
- def range_in_loop() -> None:
- sum = 0
- for i in range(4, 12, 2):
- sum += i
- [out]
- def range_object():
- r0, r1, r2, r3, r4 :: object
- r5, r :: range
- sum :: int
- r6, r7 :: object
- r8, i, r9 :: int
- r10 :: bit
- L0:
- r0 = load_address PyRange_Type
- r1 = object 4
- r2 = object 12
- r3 = object 2
- r4 = PyObject_CallFunctionObjArgs(r0, r1, r2, r3, 0)
- r5 = cast(range, r4)
- r = r5
- sum = 0
- r6 = PyObject_GetIter(r)
- L1:
- r7 = PyIter_Next(r6)
- if is_error(r7) goto L4 else goto L2
- L2:
- r8 = unbox(int, r7)
- i = r8
- r9 = CPyTagged_Add(sum, i)
- sum = r9
- L3:
- goto L1
- L4:
- r10 = CPy_NoErrOccured()
- L5:
- return 1
- def range_in_loop():
- sum :: int
- r0 :: short_int
- i :: int
- r1 :: bit
- r2 :: int
- r3 :: short_int
- L0:
- sum = 0
- r0 = 8
- i = r0
- L1:
- r1 = r0 < 24 :: signed
- if r1 goto L2 else goto L4 :: bool
- L2:
- r2 = CPyTagged_Add(sum, i)
- sum = r2
- L3:
- r3 = r0 + 4
- r0 = r3
- i = r3
- goto L1
- L4:
- return 1
- [case testLocalRedefinition]
- # mypy: allow-redefinition
- def f() -> None:
- i = 0
- i += 1
- i = "foo"
- i += i
- i = 0.0
- [out]
- def f():
- i, r0 :: int
- r1, i__redef__, r2 :: str
- i__redef____redef__ :: float
- L0:
- i = 0
- r0 = CPyTagged_Add(i, 2)
- i = r0
- r1 = 'foo'
- i__redef__ = r1
- r2 = CPyStr_Append(i__redef__, i__redef__)
- i__redef__ = r2
- i__redef____redef__ = 0.0
- return 1
- [case testNewType]
- from typing import NewType
- class A: pass
- N = NewType("N", A)
- def f(arg: A) -> N:
- return N(arg)
- [out]
- def f(arg):
- arg :: __main__.A
- L0:
- return arg
|