12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465 |
- package lua
- ////////////////////////////////////////////////////////
- // This file was generated by go-inline. DO NOT EDIT. //
- ////////////////////////////////////////////////////////
- import (
- "fmt"
- "math"
- "strings"
- )
- func mainLoop(L *LState, baseframe *callFrame) {
- var inst uint32
- var cf *callFrame
- if L.stack.IsEmpty() {
- return
- }
- L.currentFrame = L.stack.Last()
- if L.currentFrame.Fn.IsG {
- callGFunction(L, false)
- return
- }
- for {
- cf = L.currentFrame
- inst = cf.Fn.Proto.Code[cf.Pc]
- cf.Pc++
- if jumpTable[int(inst>>26)](L, inst, baseframe) == 1 {
- return
- }
- }
- }
- func mainLoopWithContext(L *LState, baseframe *callFrame) {
- var inst uint32
- var cf *callFrame
- if L.stack.IsEmpty() {
- return
- }
- L.currentFrame = L.stack.Last()
- if L.currentFrame.Fn.IsG {
- callGFunction(L, false)
- return
- }
- for {
- cf = L.currentFrame
- inst = cf.Fn.Proto.Code[cf.Pc]
- cf.Pc++
- select {
- case <-L.ctx.Done():
- L.RaiseError(L.ctx.Err().Error())
- return
- default:
- if jumpTable[int(inst>>26)](L, inst, baseframe) == 1 {
- return
- }
- }
- }
- }
- // regv is the first target register to copy the return values to.
- // It can be reg.top, indicating that the copied values are going into new registers, or it can be below reg.top
- // Indicating that the values should be within the existing registers.
- // b is the available number of return values + 1.
- // n is the desired number of return values.
- // If n more than the available return values then the extra values are set to nil.
- // When this function returns the top of the registry will be set to regv+n.
- func copyReturnValues(L *LState, regv, start, n, b int) { // +inline-start
- if b == 1 {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := L.reg
- limit := -1
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- if b > 1 && n > (b-1) {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv + b - 1
- n := n - (b - 1)
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- }
- }
- } // +inline-end
- func switchToParentThread(L *LState, nargs int, haserror bool, kill bool) {
- parent := L.Parent
- if parent == nil {
- L.RaiseError("can not yield from outside of a coroutine")
- }
- L.G.CurrentThread = parent
- L.Parent = nil
- if !L.wrapped {
- if haserror {
- parent.Push(LFalse)
- } else {
- parent.Push(LTrue)
- }
- }
- L.XMoveTo(parent, nargs)
- L.stack.Pop()
- offset := L.currentFrame.LocalBase - L.currentFrame.ReturnBase
- L.currentFrame = L.stack.Last()
- L.reg.SetTop(L.reg.Top() - offset) // remove 'yield' function(including tailcalled functions)
- if kill {
- L.kill()
- }
- }
- func callGFunction(L *LState, tailcall bool) bool {
- frame := L.currentFrame
- gfnret := frame.Fn.GFunction(L)
- if tailcall {
- L.currentFrame = L.RemoveCallerFrame()
- }
- if gfnret < 0 {
- switchToParentThread(L, L.GetTop(), false, false)
- return true
- }
- wantret := frame.NRet
- if wantret == MultRet {
- wantret = gfnret
- }
- if tailcall && L.Parent != nil && L.stack.Sp() == 1 {
- switchToParentThread(L, wantret, false, true)
- return true
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := L.reg
- regv := frame.ReturnBase
- start := L.reg.Top() - gfnret
- limit := -1
- n := wantret
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- L.stack.Pop()
- L.currentFrame = L.stack.Last()
- return false
- }
- func threadRun(L *LState) {
- if L.stack.IsEmpty() {
- return
- }
- defer func() {
- if rcv := recover(); rcv != nil {
- var lv LValue
- if v, ok := rcv.(*ApiError); ok {
- lv = v.Object
- } else {
- lv = LString(fmt.Sprint(rcv))
- }
- if parent := L.Parent; parent != nil {
- if L.wrapped {
- L.Push(lv)
- parent.Panic(L)
- } else {
- L.SetTop(0)
- L.Push(lv)
- switchToParentThread(L, 1, true, true)
- }
- } else {
- panic(rcv)
- }
- }
- }()
- L.mainLoop(L, nil)
- }
- type instFunc func(*LState, uint32, *callFrame) int
- var jumpTable [opCodeMax + 1]instFunc
- func init() {
- jumpTable = [opCodeMax + 1]instFunc{
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_MOVE
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- v := reg.Get(lbase + B)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_MOVEN
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- v := reg.Get(lbase + B)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := lbase + A
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- code := cf.Fn.Proto.Code
- pc := cf.Pc
- for i := 0; i < C; i++ {
- inst = code[pc]
- pc++
- A = int(inst>>18) & 0xff //GETA
- B = int(inst & 0x1ff) //GETB
- v := reg.Get(lbase + B)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := lbase + A
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- cf.Pc = pc
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADK
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- Bx := int(inst & 0x3ffff) //GETBX
- v := cf.Fn.Proto.Constants[Bx]
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADBOOL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- if B != 0 {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LTrue
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LFalse
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- if C != 0 {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADNIL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- for i := RA; i <= lbase+B; i++ {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := i
- vali := LNil
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETUPVAL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- v := cf.Fn.Upvalues[B].Value()
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETGLOBAL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- Bx := int(inst & 0x3ffff) //GETBX
- //reg.Set(RA, L.getField(cf.Fn.Env, cf.Fn.Proto.Constants[Bx]))
- v := L.getFieldString(cf.Fn.Env, cf.Fn.Proto.stringConstants[Bx])
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETTABLE
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- v := L.getField(reg.Get(lbase+B), L.rkValue(C))
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETTABLEKS
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- v := L.getFieldString(reg.Get(lbase+B), L.rkString(C))
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETGLOBAL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- Bx := int(inst & 0x3ffff) //GETBX
- //L.setField(cf.Fn.Env, cf.Fn.Proto.Constants[Bx], reg.Get(RA))
- L.setFieldString(cf.Fn.Env, cf.Fn.Proto.stringConstants[Bx], reg.Get(RA))
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETUPVAL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- cf.Fn.Upvalues[B].SetValue(reg.Get(RA))
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETTABLE
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- L.setField(reg.Get(RA), L.rkValue(B), L.rkValue(C))
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETTABLEKS
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- L.setFieldString(reg.Get(RA), L.rkString(B), L.rkValue(C))
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NEWTABLE
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- v := newLTable(B, C)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SELF
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- selfobj := reg.Get(lbase + B)
- v := L.getFieldString(selfobj, L.rkString(C))
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA + 1
- vali := selfobj
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- opArith, // OP_ADD
- opArith, // OP_SUB
- opArith, // OP_MUL
- opArith, // OP_DIV
- opArith, // OP_MOD
- opArith, // OP_POW
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_UNM
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- unaryv := L.rkValue(B)
- if nm, ok := unaryv.(LNumber); ok {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := -nm
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- op := L.metaOp1(unaryv, "__unm")
- if op.Type() == LTFunction {
- reg.Push(op)
- reg.Push(unaryv)
- L.Call(1, 1)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := reg.Pop()
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else if str, ok1 := unaryv.(LString); ok1 {
- if num, err := parseNumber(string(str)); err == nil {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := -num
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- L.RaiseError("__unm undefined")
- }
- } else {
- L.RaiseError("__unm undefined")
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NOT
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- if LVIsFalse(reg.Get(lbase + B)) {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LTrue
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LFalse
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LEN
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- switch lv := L.rkValue(B).(type) {
- case LString:
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LNumber(len(lv))
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- default:
- op := L.metaOp1(lv, "__len")
- if op.Type() == LTFunction {
- reg.Push(op)
- reg.Push(lv)
- L.Call(1, 1)
- ret := reg.Pop()
- if ret.Type() == LTNumber {
- v, _ := ret.(LNumber)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := ret
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- } else if lv.Type() == LTTable {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LNumber(lv.(*LTable).Len())
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- L.RaiseError("__len undefined")
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CONCAT
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- RC := lbase + C
- RB := lbase + B
- v := stringConcat(L, RC-RB+1, RC)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_JMP
- cf := L.currentFrame
- Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
- cf.Pc += Sbx
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_EQ
- cf := L.currentFrame
- A := int(inst>>18) & 0xff //GETA
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- ret := equals(L, L.rkValue(B), L.rkValue(C), false)
- v := 1
- if ret {
- v = 0
- }
- if v == A {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LT
- cf := L.currentFrame
- A := int(inst>>18) & 0xff //GETA
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- ret := lessThan(L, L.rkValue(B), L.rkValue(C))
- v := 1
- if ret {
- v = 0
- }
- if v == A {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LE
- cf := L.currentFrame
- A := int(inst>>18) & 0xff //GETA
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- lhs := L.rkValue(B)
- rhs := L.rkValue(C)
- ret := false
- if v1, ok1 := lhs.(LNumber); ok1 {
- if v2, ok2 := rhs.(LNumber); ok2 {
- ret = v1 <= v2
- } else {
- L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
- }
- } else {
- if lhs.Type() != rhs.Type() {
- L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
- }
- switch lhs.Type() {
- case LTString:
- ret = strCmp(string(lhs.(LString)), string(rhs.(LString))) <= 0
- default:
- switch objectRational(L, lhs, rhs, "__le") {
- case 1:
- ret = true
- case 0:
- ret = false
- default:
- ret = !objectRationalWithError(L, rhs, lhs, "__lt")
- }
- }
- }
- v := 1
- if ret {
- v = 0
- }
- if v == A {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TEST
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- C := int(inst>>9) & 0x1ff //GETC
- if LVAsBool(reg.Get(RA)) == (C == 0) {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TESTSET
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- if value := reg.Get(lbase + B); LVAsBool(value) != (C == 0) {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := value
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- cf.Pc++
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CALL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- nargs := B - 1
- if B == 0 {
- nargs = reg.Top() - (RA + 1)
- }
- lv := reg.Get(RA)
- nret := C - 1
- var callable *LFunction
- var meta bool
- if fn, ok := lv.(*LFunction); ok {
- callable = fn
- meta = false
- } else {
- callable, meta = L.metaCall(lv)
- }
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) pushCallFrame(cf callFrame, fn LValue, meta bool) ' in '_state.go'
- {
- ls := L
- cf := callFrame{Fn: callable, Pc: 0, Base: RA, LocalBase: RA + 1, ReturnBase: RA, NArgs: nargs, NRet: nret, Parent: cf, TailCall: 0}
- fn := lv
- if meta {
- cf.NArgs++
- ls.reg.Insert(fn, cf.LocalBase)
- }
- if cf.Fn == nil {
- ls.RaiseError("attempt to call a non-function object")
- }
- if ls.stack.IsFull() {
- ls.RaiseError("stack overflow")
- }
- ls.stack.Push(cf)
- newcf := ls.stack.Last()
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go'
- {
- cf := newcf
- if cf.Fn.IsG {
- ls.reg.SetTop(cf.LocalBase + cf.NArgs)
- } else {
- proto := cf.Fn.Proto
- nargs := cf.NArgs
- np := int(proto.NumParameters)
- if nargs < np {
- // default any missing arguments to nil
- newSize := cf.LocalBase + np
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- rg := ls.reg
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := nargs; i < np; i++ {
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- nargs = np
- ls.reg.top = newSize
- }
- if (proto.IsVarArg & VarArgIsVarArg) == 0 {
- if nargs < int(proto.NumUsedRegisters) {
- nargs = int(proto.NumUsedRegisters)
- }
- newSize := cf.LocalBase + nargs
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- rg := ls.reg
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := np; i < nargs; i++ {
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- ls.reg.top = cf.LocalBase + int(proto.NumUsedRegisters)
- } else {
- /* swap vararg positions:
- closure
- namedparam1 <- lbase
- namedparam2
- vararg1
- vararg2
- TO
- closure
- nil
- nil
- vararg1
- vararg2
- namedparam1 <- lbase
- namedparam2
- */
- nvarargs := nargs - np
- if nvarargs < 0 {
- nvarargs = 0
- }
- ls.reg.SetTop(cf.LocalBase + nargs + np)
- for i := 0; i < np; i++ {
- //ls.reg.Set(cf.LocalBase+nargs+i, ls.reg.Get(cf.LocalBase+i))
- ls.reg.array[cf.LocalBase+nargs+i] = ls.reg.array[cf.LocalBase+i]
- //ls.reg.Set(cf.LocalBase+i, LNil)
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- if CompatVarArg {
- ls.reg.SetTop(cf.LocalBase + nargs + np + 1)
- if (proto.IsVarArg & VarArgNeedsArg) != 0 {
- argtb := newLTable(nvarargs, 0)
- for i := 0; i < nvarargs; i++ {
- argtb.RawSetInt(i+1, ls.reg.Get(cf.LocalBase+np+i))
- }
- argtb.RawSetString("n", LNumber(nvarargs))
- //ls.reg.Set(cf.LocalBase+nargs+np, argtb)
- ls.reg.array[cf.LocalBase+nargs+np] = argtb
- } else {
- ls.reg.array[cf.LocalBase+nargs+np] = LNil
- }
- }
- cf.LocalBase += nargs
- maxreg := cf.LocalBase + int(proto.NumUsedRegisters)
- ls.reg.SetTop(maxreg)
- }
- }
- }
- ls.currentFrame = newcf
- }
- if callable.IsG && callGFunction(L, false) {
- return 1
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TAILCALL
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- nargs := B - 1
- if B == 0 {
- nargs = reg.Top() - (RA + 1)
- }
- lv := reg.Get(RA)
- var callable *LFunction
- var meta bool
- if fn, ok := lv.(*LFunction); ok {
- callable = fn
- meta = false
- } else {
- callable, meta = L.metaCall(lv)
- }
- if callable == nil {
- L.RaiseError("attempt to call a non-function object")
- }
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
- {
- ls := L
- idx := lbase
- if ls.uvcache != nil {
- var prev *Upvalue
- for uv := ls.uvcache; uv != nil; uv = uv.next {
- if uv.index >= idx {
- if prev != nil {
- prev.next = nil
- } else {
- ls.uvcache = nil
- }
- uv.Close()
- }
- prev = uv
- }
- }
- }
- if callable.IsG {
- luaframe := cf
- L.pushCallFrame(callFrame{
- Fn: callable,
- Pc: 0,
- Base: RA,
- LocalBase: RA + 1,
- ReturnBase: cf.ReturnBase,
- NArgs: nargs,
- NRet: cf.NRet,
- Parent: cf,
- TailCall: 0,
- }, lv, meta)
- if callGFunction(L, true) {
- return 1
- }
- if L.currentFrame == nil || L.currentFrame.Fn.IsG || luaframe == baseframe {
- return 1
- }
- } else {
- base := cf.Base
- cf.Fn = callable
- cf.Pc = 0
- cf.Base = RA
- cf.LocalBase = RA + 1
- cf.ReturnBase = cf.ReturnBase
- cf.NArgs = nargs
- cf.NRet = cf.NRet
- cf.TailCall++
- lbase := cf.LocalBase
- if meta {
- cf.NArgs++
- L.reg.Insert(lv, cf.LocalBase)
- }
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go'
- {
- ls := L
- if cf.Fn.IsG {
- ls.reg.SetTop(cf.LocalBase + cf.NArgs)
- } else {
- proto := cf.Fn.Proto
- nargs := cf.NArgs
- np := int(proto.NumParameters)
- if nargs < np {
- // default any missing arguments to nil
- newSize := cf.LocalBase + np
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- rg := ls.reg
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := nargs; i < np; i++ {
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- nargs = np
- ls.reg.top = newSize
- }
- if (proto.IsVarArg & VarArgIsVarArg) == 0 {
- if nargs < int(proto.NumUsedRegisters) {
- nargs = int(proto.NumUsedRegisters)
- }
- newSize := cf.LocalBase + nargs
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- rg := ls.reg
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := np; i < nargs; i++ {
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- ls.reg.top = cf.LocalBase + int(proto.NumUsedRegisters)
- } else {
- /* swap vararg positions:
- closure
- namedparam1 <- lbase
- namedparam2
- vararg1
- vararg2
- TO
- closure
- nil
- nil
- vararg1
- vararg2
- namedparam1 <- lbase
- namedparam2
- */
- nvarargs := nargs - np
- if nvarargs < 0 {
- nvarargs = 0
- }
- ls.reg.SetTop(cf.LocalBase + nargs + np)
- for i := 0; i < np; i++ {
- //ls.reg.Set(cf.LocalBase+nargs+i, ls.reg.Get(cf.LocalBase+i))
- ls.reg.array[cf.LocalBase+nargs+i] = ls.reg.array[cf.LocalBase+i]
- //ls.reg.Set(cf.LocalBase+i, LNil)
- ls.reg.array[cf.LocalBase+i] = LNil
- }
- if CompatVarArg {
- ls.reg.SetTop(cf.LocalBase + nargs + np + 1)
- if (proto.IsVarArg & VarArgNeedsArg) != 0 {
- argtb := newLTable(nvarargs, 0)
- for i := 0; i < nvarargs; i++ {
- argtb.RawSetInt(i+1, ls.reg.Get(cf.LocalBase+np+i))
- }
- argtb.RawSetString("n", LNumber(nvarargs))
- //ls.reg.Set(cf.LocalBase+nargs+np, argtb)
- ls.reg.array[cf.LocalBase+nargs+np] = argtb
- } else {
- ls.reg.array[cf.LocalBase+nargs+np] = LNil
- }
- }
- cf.LocalBase += nargs
- maxreg := cf.LocalBase + int(proto.NumUsedRegisters)
- ls.reg.SetTop(maxreg)
- }
- }
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := L.reg
- regv := base
- start := RA
- limit := -1
- n := reg.Top() - RA - 1
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- cf.Base = base
- cf.LocalBase = base + (cf.LocalBase - lbase + 1)
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_RETURN
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
- {
- ls := L
- idx := lbase
- if ls.uvcache != nil {
- var prev *Upvalue
- for uv := ls.uvcache; uv != nil; uv = uv.next {
- if uv.index >= idx {
- if prev != nil {
- prev.next = nil
- } else {
- ls.uvcache = nil
- }
- uv.Close()
- }
- prev = uv
- }
- }
- }
- nret := B - 1
- if B == 0 {
- nret = reg.Top() - RA
- }
- n := cf.NRet
- if cf.NRet == MultRet {
- n = nret
- }
- if L.Parent != nil && L.stack.Sp() == 1 {
- // this section is inlined by go-inline
- // source function is 'func copyReturnValues(L *LState, regv, start, n, b int) ' in '_vm.go'
- {
- regv := reg.Top()
- start := RA
- b := B
- if b == 1 {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := L.reg
- limit := -1
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- if b > 1 && n > (b-1) {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv + b - 1
- n := n - (b - 1)
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- }
- }
- }
- switchToParentThread(L, n, false, true)
- return 1
- }
- islast := baseframe == L.stack.Pop() || L.stack.IsEmpty()
- // this section is inlined by go-inline
- // source function is 'func copyReturnValues(L *LState, regv, start, n, b int) ' in '_vm.go'
- {
- regv := cf.ReturnBase
- start := RA
- b := B
- if b == 1 {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := L.reg
- limit := -1
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- if b > 1 && n > (b-1) {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
- {
- rg := L.reg
- regm := regv + b - 1
- n := n - (b - 1)
- newSize := regm + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- for i := 0; i < n; i++ {
- rg.array[regm+i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regm + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- }
- }
- }
- L.currentFrame = L.stack.Last()
- if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG {
- return 1
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_FORLOOP
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- if init, ok1 := reg.Get(RA).(LNumber); ok1 {
- if limit, ok2 := reg.Get(RA + 1).(LNumber); ok2 {
- if step, ok3 := reg.Get(RA + 2).(LNumber); ok3 {
- init += step
- v := LNumber(init)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- if (step > 0 && init <= limit) || (step <= 0 && init >= limit) {
- Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
- cf.Pc += Sbx
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA + 3
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetTop(topi int) ' in '_state.go'
- {
- rg := reg
- topi := RA + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := topi
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- oldtopi := rg.top
- rg.top = topi
- for i := oldtopi; i < rg.top; i++ {
- rg.array[i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- if rg.top < oldtopi {
- nilRange := rg.array[rg.top:oldtopi]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- //for i := rg.top; i < oldtop; i++ {
- // rg.array[i] = LNil
- //}
- }
- }
- } else {
- L.RaiseError("for statement step must be a number")
- }
- } else {
- L.RaiseError("for statement limit must be a number")
- }
- } else {
- L.RaiseError("for statement init must be a number")
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_FORPREP
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
- if init, ok1 := reg.Get(RA).(LNumber); ok1 {
- if step, ok2 := reg.Get(RA + 2).(LNumber); ok2 {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := LNumber(init - step)
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- L.RaiseError("for statement step must be a number")
- }
- } else {
- L.RaiseError("for statement init must be a number")
- }
- cf.Pc += Sbx
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TFORLOOP
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- C := int(inst>>9) & 0x1ff //GETC
- nret := C
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetTop(topi int) ' in '_state.go'
- {
- rg := reg
- topi := RA + 3 + 2
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := topi
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- oldtopi := rg.top
- rg.top = topi
- for i := oldtopi; i < rg.top; i++ {
- rg.array[i] = LNil
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- if rg.top < oldtopi {
- nilRange := rg.array[rg.top:oldtopi]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- //for i := rg.top; i < oldtop; i++ {
- // rg.array[i] = LNil
- //}
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA + 3 + 2
- vali := reg.Get(RA + 2)
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA + 3 + 1
- vali := reg.Get(RA + 1)
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA + 3
- vali := reg.Get(RA)
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- L.callR(2, nret, RA+3)
- if value := reg.Get(RA + 3); value != LNil {
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA + 2
- vali := value
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- pc := cf.Fn.Proto.Code[cf.Pc]
- cf.Pc += int(pc&0x3ffff) - opMaxArgSbx
- }
- cf.Pc++
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETLIST
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- if C == 0 {
- C = int(cf.Fn.Proto.Code[cf.Pc])
- cf.Pc++
- }
- offset := (C - 1) * FieldsPerFlush
- table := reg.Get(RA).(*LTable)
- nelem := B
- if B == 0 {
- nelem = reg.Top() - RA - 1
- }
- for i := 1; i <= nelem; i++ {
- table.RawSetInt(offset+i, reg.Get(RA+i))
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CLOSE
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- // this section is inlined by go-inline
- // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
- {
- ls := L
- idx := RA
- if ls.uvcache != nil {
- var prev *Upvalue
- for uv := ls.uvcache; uv != nil; uv = uv.next {
- if uv.index >= idx {
- if prev != nil {
- prev.next = nil
- } else {
- ls.uvcache = nil
- }
- uv.Close()
- }
- prev = uv
- }
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CLOSURE
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- Bx := int(inst & 0x3ffff) //GETBX
- proto := cf.Fn.Proto.FunctionPrototypes[Bx]
- closure := newLFunctionL(proto, cf.Fn.Env, int(proto.NumUpvalues))
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := closure
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- for i := 0; i < int(proto.NumUpvalues); i++ {
- inst = cf.Fn.Proto.Code[cf.Pc]
- cf.Pc++
- B := opGetArgB(inst)
- switch opGetOpCode(inst) {
- case OP_MOVE:
- closure.Upvalues[i] = L.findUpvalue(lbase + B)
- case OP_GETUPVAL:
- closure.Upvalues[i] = cf.Fn.Upvalues[B]
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_VARARG
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- B := int(inst & 0x1ff) //GETB
- nparams := int(cf.Fn.Proto.NumParameters)
- nvarargs := cf.NArgs - nparams
- if nvarargs < 0 {
- nvarargs = 0
- }
- nwant := B - 1
- if B == 0 {
- nwant = nvarargs
- }
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
- {
- rg := reg
- regv := RA
- start := cf.Base + nparams + 1
- limit := cf.LocalBase
- n := nwant
- newSize := regv + n
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- if limit == -1 || limit > rg.top {
- limit = rg.top
- }
- for i := 0; i < n; i++ {
- srcIdx := start + i
- if srcIdx >= limit || srcIdx < 0 {
- rg.array[regv+i] = LNil
- } else {
- rg.array[regv+i] = rg.array[srcIdx]
- }
- }
- // values beyond top don't need to be valid LValues, so setting them to nil is fine
- // setting them to nil rather than LNil lets us invoke the golang memclr opto
- oldtop := rg.top
- rg.top = regv + n
- if rg.top < oldtop {
- nilRange := rg.array[rg.top:oldtop]
- for i := range nilRange {
- nilRange[i] = nil
- }
- }
- }
- return 0
- },
- func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NOP
- return 0
- },
- }
- }
- func opArith(L *LState, inst uint32, baseframe *callFrame) int { //OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW
- reg := L.reg
- cf := L.currentFrame
- lbase := cf.LocalBase
- A := int(inst>>18) & 0xff //GETA
- RA := lbase + A
- opcode := int(inst >> 26) //GETOPCODE
- B := int(inst & 0x1ff) //GETB
- C := int(inst>>9) & 0x1ff //GETC
- lhs := L.rkValue(B)
- rhs := L.rkValue(C)
- v1, ok1 := lhs.(LNumber)
- v2, ok2 := rhs.(LNumber)
- if ok1 && ok2 {
- v := numberArith(L, opcode, LNumber(v1), LNumber(v2))
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = rg.alloc.LNumber2I(vali)
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- } else {
- v := objectArith(L, opcode, lhs, rhs)
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
- {
- rg := reg
- regi := RA
- vali := v
- newSize := regi + 1
- // this section is inlined by go-inline
- // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
- {
- requiredSize := newSize
- if requiredSize > cap(rg.array) {
- rg.resize(requiredSize)
- }
- }
- rg.array[regi] = vali
- if regi >= rg.top {
- rg.top = regi + 1
- }
- }
- }
- return 0
- }
- func luaModulo(lhs, rhs LNumber) LNumber {
- flhs := float64(lhs)
- frhs := float64(rhs)
- v := math.Mod(flhs, frhs)
- if frhs > 0 && v < 0 || frhs < 0 && v > 0 {
- v += frhs
- }
- return LNumber(v)
- }
- func numberArith(L *LState, opcode int, lhs, rhs LNumber) LNumber {
- switch opcode {
- case OP_ADD:
- return lhs + rhs
- case OP_SUB:
- return lhs - rhs
- case OP_MUL:
- return lhs * rhs
- case OP_DIV:
- return lhs / rhs
- case OP_MOD:
- return luaModulo(lhs, rhs)
- case OP_POW:
- flhs := float64(lhs)
- frhs := float64(rhs)
- return LNumber(math.Pow(flhs, frhs))
- }
- panic("should not reach here")
- return LNumber(0)
- }
- func objectArith(L *LState, opcode int, lhs, rhs LValue) LValue {
- event := ""
- switch opcode {
- case OP_ADD:
- event = "__add"
- case OP_SUB:
- event = "__sub"
- case OP_MUL:
- event = "__mul"
- case OP_DIV:
- event = "__div"
- case OP_MOD:
- event = "__mod"
- case OP_POW:
- event = "__pow"
- }
- op := L.metaOp2(lhs, rhs, event)
- if _, ok := op.(*LFunction); ok {
- L.reg.Push(op)
- L.reg.Push(lhs)
- L.reg.Push(rhs)
- L.Call(2, 1)
- return L.reg.Pop()
- }
- if str, ok := lhs.(LString); ok {
- if lnum, err := parseNumber(string(str)); err == nil {
- lhs = lnum
- }
- }
- if str, ok := rhs.(LString); ok {
- if rnum, err := parseNumber(string(str)); err == nil {
- rhs = rnum
- }
- }
- if v1, ok1 := lhs.(LNumber); ok1 {
- if v2, ok2 := rhs.(LNumber); ok2 {
- return numberArith(L, opcode, LNumber(v1), LNumber(v2))
- }
- }
- L.RaiseError(fmt.Sprintf("cannot perform %v operation between %v and %v",
- strings.TrimLeft(event, "_"), lhs.Type().String(), rhs.Type().String()))
- return LNil
- }
- func stringConcat(L *LState, total, last int) LValue {
- rhs := L.reg.Get(last)
- total--
- for i := last - 1; total > 0; {
- lhs := L.reg.Get(i)
- if !(LVCanConvToString(lhs) && LVCanConvToString(rhs)) {
- op := L.metaOp2(lhs, rhs, "__concat")
- if op.Type() == LTFunction {
- L.reg.Push(op)
- L.reg.Push(lhs)
- L.reg.Push(rhs)
- L.Call(2, 1)
- rhs = L.reg.Pop()
- total--
- i--
- } else {
- L.RaiseError("cannot perform concat operation between %v and %v", lhs.Type().String(), rhs.Type().String())
- return LNil
- }
- } else {
- buf := make([]string, total+1)
- buf[total] = LVAsString(rhs)
- for total > 0 {
- lhs = L.reg.Get(i)
- if !LVCanConvToString(lhs) {
- break
- }
- buf[total-1] = LVAsString(lhs)
- i--
- total--
- }
- rhs = LString(strings.Join(buf, ""))
- }
- }
- return rhs
- }
- func lessThan(L *LState, lhs, rhs LValue) bool {
- // optimization for numbers
- if v1, ok1 := lhs.(LNumber); ok1 {
- if v2, ok2 := rhs.(LNumber); ok2 {
- return v1 < v2
- }
- L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
- }
- if lhs.Type() != rhs.Type() {
- L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
- return false
- }
- ret := false
- switch lhs.Type() {
- case LTString:
- ret = strCmp(string(lhs.(LString)), string(rhs.(LString))) < 0
- default:
- ret = objectRationalWithError(L, lhs, rhs, "__lt")
- }
- return ret
- }
- func equals(L *LState, lhs, rhs LValue, raw bool) bool {
- lt := lhs.Type()
- if lt != rhs.Type() {
- return false
- }
- ret := false
- switch lt {
- case LTNil:
- ret = true
- case LTNumber:
- v1, _ := lhs.(LNumber)
- v2, _ := rhs.(LNumber)
- ret = v1 == v2
- case LTBool:
- ret = bool(lhs.(LBool)) == bool(rhs.(LBool))
- case LTString:
- ret = string(lhs.(LString)) == string(rhs.(LString))
- case LTUserData, LTTable:
- if lhs == rhs {
- ret = true
- } else if !raw {
- switch objectRational(L, lhs, rhs, "__eq") {
- case 1:
- ret = true
- default:
- ret = false
- }
- }
- default:
- ret = lhs == rhs
- }
- return ret
- }
- func objectRationalWithError(L *LState, lhs, rhs LValue, event string) bool {
- switch objectRational(L, lhs, rhs, event) {
- case 1:
- return true
- case 0:
- return false
- }
- L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
- return false
- }
- func objectRational(L *LState, lhs, rhs LValue, event string) int {
- m1 := L.metaOp1(lhs, event)
- m2 := L.metaOp1(rhs, event)
- if m1.Type() == LTFunction && m1 == m2 {
- L.reg.Push(m1)
- L.reg.Push(lhs)
- L.reg.Push(rhs)
- L.Call(2, 1)
- if LVAsBool(L.reg.Pop()) {
- return 1
- }
- return 0
- }
- return -1
- }
|