vm.go 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465
  1. package lua
  2. ////////////////////////////////////////////////////////
  3. // This file was generated by go-inline. DO NOT EDIT. //
  4. ////////////////////////////////////////////////////////
  5. import (
  6. "fmt"
  7. "math"
  8. "strings"
  9. )
  10. func mainLoop(L *LState, baseframe *callFrame) {
  11. var inst uint32
  12. var cf *callFrame
  13. if L.stack.IsEmpty() {
  14. return
  15. }
  16. L.currentFrame = L.stack.Last()
  17. if L.currentFrame.Fn.IsG {
  18. callGFunction(L, false)
  19. return
  20. }
  21. for {
  22. cf = L.currentFrame
  23. inst = cf.Fn.Proto.Code[cf.Pc]
  24. cf.Pc++
  25. if jumpTable[int(inst>>26)](L, inst, baseframe) == 1 {
  26. return
  27. }
  28. }
  29. }
  30. func mainLoopWithContext(L *LState, baseframe *callFrame) {
  31. var inst uint32
  32. var cf *callFrame
  33. if L.stack.IsEmpty() {
  34. return
  35. }
  36. L.currentFrame = L.stack.Last()
  37. if L.currentFrame.Fn.IsG {
  38. callGFunction(L, false)
  39. return
  40. }
  41. for {
  42. cf = L.currentFrame
  43. inst = cf.Fn.Proto.Code[cf.Pc]
  44. cf.Pc++
  45. select {
  46. case <-L.ctx.Done():
  47. L.RaiseError(L.ctx.Err().Error())
  48. return
  49. default:
  50. if jumpTable[int(inst>>26)](L, inst, baseframe) == 1 {
  51. return
  52. }
  53. }
  54. }
  55. }
  56. // regv is the first target register to copy the return values to.
  57. // It can be reg.top, indicating that the copied values are going into new registers, or it can be below reg.top
  58. // Indicating that the values should be within the existing registers.
  59. // b is the available number of return values + 1.
  60. // n is the desired number of return values.
  61. // If n more than the available return values then the extra values are set to nil.
  62. // When this function returns the top of the registry will be set to regv+n.
  63. func copyReturnValues(L *LState, regv, start, n, b int) { // +inline-start
  64. if b == 1 {
  65. // this section is inlined by go-inline
  66. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  67. {
  68. rg := L.reg
  69. regm := regv
  70. newSize := regm + n
  71. // this section is inlined by go-inline
  72. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  73. {
  74. requiredSize := newSize
  75. if requiredSize > cap(rg.array) {
  76. rg.resize(requiredSize)
  77. }
  78. }
  79. for i := 0; i < n; i++ {
  80. rg.array[regm+i] = LNil
  81. }
  82. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  83. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  84. oldtop := rg.top
  85. rg.top = regm + n
  86. if rg.top < oldtop {
  87. nilRange := rg.array[rg.top:oldtop]
  88. for i := range nilRange {
  89. nilRange[i] = nil
  90. }
  91. }
  92. }
  93. } else {
  94. // this section is inlined by go-inline
  95. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  96. {
  97. rg := L.reg
  98. limit := -1
  99. newSize := regv + n
  100. // this section is inlined by go-inline
  101. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  102. {
  103. requiredSize := newSize
  104. if requiredSize > cap(rg.array) {
  105. rg.resize(requiredSize)
  106. }
  107. }
  108. if limit == -1 || limit > rg.top {
  109. limit = rg.top
  110. }
  111. for i := 0; i < n; i++ {
  112. srcIdx := start + i
  113. if srcIdx >= limit || srcIdx < 0 {
  114. rg.array[regv+i] = LNil
  115. } else {
  116. rg.array[regv+i] = rg.array[srcIdx]
  117. }
  118. }
  119. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  120. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  121. oldtop := rg.top
  122. rg.top = regv + n
  123. if rg.top < oldtop {
  124. nilRange := rg.array[rg.top:oldtop]
  125. for i := range nilRange {
  126. nilRange[i] = nil
  127. }
  128. }
  129. }
  130. if b > 1 && n > (b-1) {
  131. // this section is inlined by go-inline
  132. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  133. {
  134. rg := L.reg
  135. regm := regv + b - 1
  136. n := n - (b - 1)
  137. newSize := regm + n
  138. // this section is inlined by go-inline
  139. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  140. {
  141. requiredSize := newSize
  142. if requiredSize > cap(rg.array) {
  143. rg.resize(requiredSize)
  144. }
  145. }
  146. for i := 0; i < n; i++ {
  147. rg.array[regm+i] = LNil
  148. }
  149. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  150. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  151. oldtop := rg.top
  152. rg.top = regm + n
  153. if rg.top < oldtop {
  154. nilRange := rg.array[rg.top:oldtop]
  155. for i := range nilRange {
  156. nilRange[i] = nil
  157. }
  158. }
  159. }
  160. }
  161. }
  162. } // +inline-end
  163. func switchToParentThread(L *LState, nargs int, haserror bool, kill bool) {
  164. parent := L.Parent
  165. if parent == nil {
  166. L.RaiseError("can not yield from outside of a coroutine")
  167. }
  168. L.G.CurrentThread = parent
  169. L.Parent = nil
  170. if !L.wrapped {
  171. if haserror {
  172. parent.Push(LFalse)
  173. } else {
  174. parent.Push(LTrue)
  175. }
  176. }
  177. L.XMoveTo(parent, nargs)
  178. L.stack.Pop()
  179. offset := L.currentFrame.LocalBase - L.currentFrame.ReturnBase
  180. L.currentFrame = L.stack.Last()
  181. L.reg.SetTop(L.reg.Top() - offset) // remove 'yield' function(including tailcalled functions)
  182. if kill {
  183. L.kill()
  184. }
  185. }
  186. func callGFunction(L *LState, tailcall bool) bool {
  187. frame := L.currentFrame
  188. gfnret := frame.Fn.GFunction(L)
  189. if tailcall {
  190. L.currentFrame = L.RemoveCallerFrame()
  191. }
  192. if gfnret < 0 {
  193. switchToParentThread(L, L.GetTop(), false, false)
  194. return true
  195. }
  196. wantret := frame.NRet
  197. if wantret == MultRet {
  198. wantret = gfnret
  199. }
  200. if tailcall && L.Parent != nil && L.stack.Sp() == 1 {
  201. switchToParentThread(L, wantret, false, true)
  202. return true
  203. }
  204. // this section is inlined by go-inline
  205. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  206. {
  207. rg := L.reg
  208. regv := frame.ReturnBase
  209. start := L.reg.Top() - gfnret
  210. limit := -1
  211. n := wantret
  212. newSize := regv + n
  213. // this section is inlined by go-inline
  214. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  215. {
  216. requiredSize := newSize
  217. if requiredSize > cap(rg.array) {
  218. rg.resize(requiredSize)
  219. }
  220. }
  221. if limit == -1 || limit > rg.top {
  222. limit = rg.top
  223. }
  224. for i := 0; i < n; i++ {
  225. srcIdx := start + i
  226. if srcIdx >= limit || srcIdx < 0 {
  227. rg.array[regv+i] = LNil
  228. } else {
  229. rg.array[regv+i] = rg.array[srcIdx]
  230. }
  231. }
  232. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  233. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  234. oldtop := rg.top
  235. rg.top = regv + n
  236. if rg.top < oldtop {
  237. nilRange := rg.array[rg.top:oldtop]
  238. for i := range nilRange {
  239. nilRange[i] = nil
  240. }
  241. }
  242. }
  243. L.stack.Pop()
  244. L.currentFrame = L.stack.Last()
  245. return false
  246. }
  247. func threadRun(L *LState) {
  248. if L.stack.IsEmpty() {
  249. return
  250. }
  251. defer func() {
  252. if rcv := recover(); rcv != nil {
  253. var lv LValue
  254. if v, ok := rcv.(*ApiError); ok {
  255. lv = v.Object
  256. } else {
  257. lv = LString(fmt.Sprint(rcv))
  258. }
  259. if parent := L.Parent; parent != nil {
  260. if L.wrapped {
  261. L.Push(lv)
  262. parent.Panic(L)
  263. } else {
  264. L.SetTop(0)
  265. L.Push(lv)
  266. switchToParentThread(L, 1, true, true)
  267. }
  268. } else {
  269. panic(rcv)
  270. }
  271. }
  272. }()
  273. L.mainLoop(L, nil)
  274. }
  275. type instFunc func(*LState, uint32, *callFrame) int
  276. var jumpTable [opCodeMax + 1]instFunc
  277. func init() {
  278. jumpTable = [opCodeMax + 1]instFunc{
  279. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_MOVE
  280. reg := L.reg
  281. cf := L.currentFrame
  282. lbase := cf.LocalBase
  283. A := int(inst>>18) & 0xff //GETA
  284. RA := lbase + A
  285. B := int(inst & 0x1ff) //GETB
  286. v := reg.Get(lbase + B)
  287. // this section is inlined by go-inline
  288. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  289. {
  290. rg := reg
  291. regi := RA
  292. vali := v
  293. newSize := regi + 1
  294. // this section is inlined by go-inline
  295. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  296. {
  297. requiredSize := newSize
  298. if requiredSize > cap(rg.array) {
  299. rg.resize(requiredSize)
  300. }
  301. }
  302. rg.array[regi] = vali
  303. if regi >= rg.top {
  304. rg.top = regi + 1
  305. }
  306. }
  307. return 0
  308. },
  309. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_MOVEN
  310. reg := L.reg
  311. cf := L.currentFrame
  312. lbase := cf.LocalBase
  313. A := int(inst>>18) & 0xff //GETA
  314. B := int(inst & 0x1ff) //GETB
  315. C := int(inst>>9) & 0x1ff //GETC
  316. v := reg.Get(lbase + B)
  317. // this section is inlined by go-inline
  318. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  319. {
  320. rg := reg
  321. regi := lbase + A
  322. vali := v
  323. newSize := regi + 1
  324. // this section is inlined by go-inline
  325. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  326. {
  327. requiredSize := newSize
  328. if requiredSize > cap(rg.array) {
  329. rg.resize(requiredSize)
  330. }
  331. }
  332. rg.array[regi] = vali
  333. if regi >= rg.top {
  334. rg.top = regi + 1
  335. }
  336. }
  337. code := cf.Fn.Proto.Code
  338. pc := cf.Pc
  339. for i := 0; i < C; i++ {
  340. inst = code[pc]
  341. pc++
  342. A = int(inst>>18) & 0xff //GETA
  343. B = int(inst & 0x1ff) //GETB
  344. v := reg.Get(lbase + B)
  345. // this section is inlined by go-inline
  346. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  347. {
  348. rg := reg
  349. regi := lbase + A
  350. vali := v
  351. newSize := regi + 1
  352. // this section is inlined by go-inline
  353. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  354. {
  355. requiredSize := newSize
  356. if requiredSize > cap(rg.array) {
  357. rg.resize(requiredSize)
  358. }
  359. }
  360. rg.array[regi] = vali
  361. if regi >= rg.top {
  362. rg.top = regi + 1
  363. }
  364. }
  365. }
  366. cf.Pc = pc
  367. return 0
  368. },
  369. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADK
  370. reg := L.reg
  371. cf := L.currentFrame
  372. lbase := cf.LocalBase
  373. A := int(inst>>18) & 0xff //GETA
  374. RA := lbase + A
  375. Bx := int(inst & 0x3ffff) //GETBX
  376. v := cf.Fn.Proto.Constants[Bx]
  377. // this section is inlined by go-inline
  378. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  379. {
  380. rg := reg
  381. regi := RA
  382. vali := v
  383. newSize := regi + 1
  384. // this section is inlined by go-inline
  385. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  386. {
  387. requiredSize := newSize
  388. if requiredSize > cap(rg.array) {
  389. rg.resize(requiredSize)
  390. }
  391. }
  392. rg.array[regi] = vali
  393. if regi >= rg.top {
  394. rg.top = regi + 1
  395. }
  396. }
  397. return 0
  398. },
  399. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADBOOL
  400. reg := L.reg
  401. cf := L.currentFrame
  402. lbase := cf.LocalBase
  403. A := int(inst>>18) & 0xff //GETA
  404. RA := lbase + A
  405. B := int(inst & 0x1ff) //GETB
  406. C := int(inst>>9) & 0x1ff //GETC
  407. if B != 0 {
  408. // this section is inlined by go-inline
  409. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  410. {
  411. rg := reg
  412. regi := RA
  413. vali := LTrue
  414. newSize := regi + 1
  415. // this section is inlined by go-inline
  416. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  417. {
  418. requiredSize := newSize
  419. if requiredSize > cap(rg.array) {
  420. rg.resize(requiredSize)
  421. }
  422. }
  423. rg.array[regi] = vali
  424. if regi >= rg.top {
  425. rg.top = regi + 1
  426. }
  427. }
  428. } else {
  429. // this section is inlined by go-inline
  430. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  431. {
  432. rg := reg
  433. regi := RA
  434. vali := LFalse
  435. newSize := regi + 1
  436. // this section is inlined by go-inline
  437. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  438. {
  439. requiredSize := newSize
  440. if requiredSize > cap(rg.array) {
  441. rg.resize(requiredSize)
  442. }
  443. }
  444. rg.array[regi] = vali
  445. if regi >= rg.top {
  446. rg.top = regi + 1
  447. }
  448. }
  449. }
  450. if C != 0 {
  451. cf.Pc++
  452. }
  453. return 0
  454. },
  455. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LOADNIL
  456. reg := L.reg
  457. cf := L.currentFrame
  458. lbase := cf.LocalBase
  459. A := int(inst>>18) & 0xff //GETA
  460. RA := lbase + A
  461. B := int(inst & 0x1ff) //GETB
  462. for i := RA; i <= lbase+B; i++ {
  463. // this section is inlined by go-inline
  464. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  465. {
  466. rg := reg
  467. regi := i
  468. vali := LNil
  469. newSize := regi + 1
  470. // this section is inlined by go-inline
  471. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  472. {
  473. requiredSize := newSize
  474. if requiredSize > cap(rg.array) {
  475. rg.resize(requiredSize)
  476. }
  477. }
  478. rg.array[regi] = vali
  479. if regi >= rg.top {
  480. rg.top = regi + 1
  481. }
  482. }
  483. }
  484. return 0
  485. },
  486. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETUPVAL
  487. reg := L.reg
  488. cf := L.currentFrame
  489. lbase := cf.LocalBase
  490. A := int(inst>>18) & 0xff //GETA
  491. RA := lbase + A
  492. B := int(inst & 0x1ff) //GETB
  493. v := cf.Fn.Upvalues[B].Value()
  494. // this section is inlined by go-inline
  495. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  496. {
  497. rg := reg
  498. regi := RA
  499. vali := v
  500. newSize := regi + 1
  501. // this section is inlined by go-inline
  502. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  503. {
  504. requiredSize := newSize
  505. if requiredSize > cap(rg.array) {
  506. rg.resize(requiredSize)
  507. }
  508. }
  509. rg.array[regi] = vali
  510. if regi >= rg.top {
  511. rg.top = regi + 1
  512. }
  513. }
  514. return 0
  515. },
  516. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETGLOBAL
  517. reg := L.reg
  518. cf := L.currentFrame
  519. lbase := cf.LocalBase
  520. A := int(inst>>18) & 0xff //GETA
  521. RA := lbase + A
  522. Bx := int(inst & 0x3ffff) //GETBX
  523. //reg.Set(RA, L.getField(cf.Fn.Env, cf.Fn.Proto.Constants[Bx]))
  524. v := L.getFieldString(cf.Fn.Env, cf.Fn.Proto.stringConstants[Bx])
  525. // this section is inlined by go-inline
  526. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  527. {
  528. rg := reg
  529. regi := RA
  530. vali := v
  531. newSize := regi + 1
  532. // this section is inlined by go-inline
  533. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  534. {
  535. requiredSize := newSize
  536. if requiredSize > cap(rg.array) {
  537. rg.resize(requiredSize)
  538. }
  539. }
  540. rg.array[regi] = vali
  541. if regi >= rg.top {
  542. rg.top = regi + 1
  543. }
  544. }
  545. return 0
  546. },
  547. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETTABLE
  548. reg := L.reg
  549. cf := L.currentFrame
  550. lbase := cf.LocalBase
  551. A := int(inst>>18) & 0xff //GETA
  552. RA := lbase + A
  553. B := int(inst & 0x1ff) //GETB
  554. C := int(inst>>9) & 0x1ff //GETC
  555. v := L.getField(reg.Get(lbase+B), L.rkValue(C))
  556. // this section is inlined by go-inline
  557. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  558. {
  559. rg := reg
  560. regi := RA
  561. vali := v
  562. newSize := regi + 1
  563. // this section is inlined by go-inline
  564. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  565. {
  566. requiredSize := newSize
  567. if requiredSize > cap(rg.array) {
  568. rg.resize(requiredSize)
  569. }
  570. }
  571. rg.array[regi] = vali
  572. if regi >= rg.top {
  573. rg.top = regi + 1
  574. }
  575. }
  576. return 0
  577. },
  578. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_GETTABLEKS
  579. reg := L.reg
  580. cf := L.currentFrame
  581. lbase := cf.LocalBase
  582. A := int(inst>>18) & 0xff //GETA
  583. RA := lbase + A
  584. B := int(inst & 0x1ff) //GETB
  585. C := int(inst>>9) & 0x1ff //GETC
  586. v := L.getFieldString(reg.Get(lbase+B), L.rkString(C))
  587. // this section is inlined by go-inline
  588. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  589. {
  590. rg := reg
  591. regi := RA
  592. vali := v
  593. newSize := regi + 1
  594. // this section is inlined by go-inline
  595. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  596. {
  597. requiredSize := newSize
  598. if requiredSize > cap(rg.array) {
  599. rg.resize(requiredSize)
  600. }
  601. }
  602. rg.array[regi] = vali
  603. if regi >= rg.top {
  604. rg.top = regi + 1
  605. }
  606. }
  607. return 0
  608. },
  609. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETGLOBAL
  610. reg := L.reg
  611. cf := L.currentFrame
  612. lbase := cf.LocalBase
  613. A := int(inst>>18) & 0xff //GETA
  614. RA := lbase + A
  615. Bx := int(inst & 0x3ffff) //GETBX
  616. //L.setField(cf.Fn.Env, cf.Fn.Proto.Constants[Bx], reg.Get(RA))
  617. L.setFieldString(cf.Fn.Env, cf.Fn.Proto.stringConstants[Bx], reg.Get(RA))
  618. return 0
  619. },
  620. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETUPVAL
  621. reg := L.reg
  622. cf := L.currentFrame
  623. lbase := cf.LocalBase
  624. A := int(inst>>18) & 0xff //GETA
  625. RA := lbase + A
  626. B := int(inst & 0x1ff) //GETB
  627. cf.Fn.Upvalues[B].SetValue(reg.Get(RA))
  628. return 0
  629. },
  630. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETTABLE
  631. reg := L.reg
  632. cf := L.currentFrame
  633. lbase := cf.LocalBase
  634. A := int(inst>>18) & 0xff //GETA
  635. RA := lbase + A
  636. B := int(inst & 0x1ff) //GETB
  637. C := int(inst>>9) & 0x1ff //GETC
  638. L.setField(reg.Get(RA), L.rkValue(B), L.rkValue(C))
  639. return 0
  640. },
  641. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETTABLEKS
  642. reg := L.reg
  643. cf := L.currentFrame
  644. lbase := cf.LocalBase
  645. A := int(inst>>18) & 0xff //GETA
  646. RA := lbase + A
  647. B := int(inst & 0x1ff) //GETB
  648. C := int(inst>>9) & 0x1ff //GETC
  649. L.setFieldString(reg.Get(RA), L.rkString(B), L.rkValue(C))
  650. return 0
  651. },
  652. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NEWTABLE
  653. reg := L.reg
  654. cf := L.currentFrame
  655. lbase := cf.LocalBase
  656. A := int(inst>>18) & 0xff //GETA
  657. RA := lbase + A
  658. B := int(inst & 0x1ff) //GETB
  659. C := int(inst>>9) & 0x1ff //GETC
  660. v := newLTable(B, C)
  661. // this section is inlined by go-inline
  662. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  663. {
  664. rg := reg
  665. regi := RA
  666. vali := v
  667. newSize := regi + 1
  668. // this section is inlined by go-inline
  669. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  670. {
  671. requiredSize := newSize
  672. if requiredSize > cap(rg.array) {
  673. rg.resize(requiredSize)
  674. }
  675. }
  676. rg.array[regi] = vali
  677. if regi >= rg.top {
  678. rg.top = regi + 1
  679. }
  680. }
  681. return 0
  682. },
  683. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SELF
  684. reg := L.reg
  685. cf := L.currentFrame
  686. lbase := cf.LocalBase
  687. A := int(inst>>18) & 0xff //GETA
  688. RA := lbase + A
  689. B := int(inst & 0x1ff) //GETB
  690. C := int(inst>>9) & 0x1ff //GETC
  691. selfobj := reg.Get(lbase + B)
  692. v := L.getFieldString(selfobj, L.rkString(C))
  693. // this section is inlined by go-inline
  694. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  695. {
  696. rg := reg
  697. regi := RA
  698. vali := v
  699. newSize := regi + 1
  700. // this section is inlined by go-inline
  701. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  702. {
  703. requiredSize := newSize
  704. if requiredSize > cap(rg.array) {
  705. rg.resize(requiredSize)
  706. }
  707. }
  708. rg.array[regi] = vali
  709. if regi >= rg.top {
  710. rg.top = regi + 1
  711. }
  712. }
  713. // this section is inlined by go-inline
  714. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  715. {
  716. rg := reg
  717. regi := RA + 1
  718. vali := selfobj
  719. newSize := regi + 1
  720. // this section is inlined by go-inline
  721. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  722. {
  723. requiredSize := newSize
  724. if requiredSize > cap(rg.array) {
  725. rg.resize(requiredSize)
  726. }
  727. }
  728. rg.array[regi] = vali
  729. if regi >= rg.top {
  730. rg.top = regi + 1
  731. }
  732. }
  733. return 0
  734. },
  735. opArith, // OP_ADD
  736. opArith, // OP_SUB
  737. opArith, // OP_MUL
  738. opArith, // OP_DIV
  739. opArith, // OP_MOD
  740. opArith, // OP_POW
  741. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_UNM
  742. reg := L.reg
  743. cf := L.currentFrame
  744. lbase := cf.LocalBase
  745. A := int(inst>>18) & 0xff //GETA
  746. RA := lbase + A
  747. B := int(inst & 0x1ff) //GETB
  748. unaryv := L.rkValue(B)
  749. if nm, ok := unaryv.(LNumber); ok {
  750. // this section is inlined by go-inline
  751. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  752. {
  753. rg := reg
  754. regi := RA
  755. vali := -nm
  756. newSize := regi + 1
  757. // this section is inlined by go-inline
  758. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  759. {
  760. requiredSize := newSize
  761. if requiredSize > cap(rg.array) {
  762. rg.resize(requiredSize)
  763. }
  764. }
  765. rg.array[regi] = vali
  766. if regi >= rg.top {
  767. rg.top = regi + 1
  768. }
  769. }
  770. } else {
  771. op := L.metaOp1(unaryv, "__unm")
  772. if op.Type() == LTFunction {
  773. reg.Push(op)
  774. reg.Push(unaryv)
  775. L.Call(1, 1)
  776. // this section is inlined by go-inline
  777. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  778. {
  779. rg := reg
  780. regi := RA
  781. vali := reg.Pop()
  782. newSize := regi + 1
  783. // this section is inlined by go-inline
  784. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  785. {
  786. requiredSize := newSize
  787. if requiredSize > cap(rg.array) {
  788. rg.resize(requiredSize)
  789. }
  790. }
  791. rg.array[regi] = vali
  792. if regi >= rg.top {
  793. rg.top = regi + 1
  794. }
  795. }
  796. } else if str, ok1 := unaryv.(LString); ok1 {
  797. if num, err := parseNumber(string(str)); err == nil {
  798. // this section is inlined by go-inline
  799. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  800. {
  801. rg := reg
  802. regi := RA
  803. vali := -num
  804. newSize := regi + 1
  805. // this section is inlined by go-inline
  806. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  807. {
  808. requiredSize := newSize
  809. if requiredSize > cap(rg.array) {
  810. rg.resize(requiredSize)
  811. }
  812. }
  813. rg.array[regi] = vali
  814. if regi >= rg.top {
  815. rg.top = regi + 1
  816. }
  817. }
  818. } else {
  819. L.RaiseError("__unm undefined")
  820. }
  821. } else {
  822. L.RaiseError("__unm undefined")
  823. }
  824. }
  825. return 0
  826. },
  827. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NOT
  828. reg := L.reg
  829. cf := L.currentFrame
  830. lbase := cf.LocalBase
  831. A := int(inst>>18) & 0xff //GETA
  832. RA := lbase + A
  833. B := int(inst & 0x1ff) //GETB
  834. if LVIsFalse(reg.Get(lbase + B)) {
  835. // this section is inlined by go-inline
  836. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  837. {
  838. rg := reg
  839. regi := RA
  840. vali := LTrue
  841. newSize := regi + 1
  842. // this section is inlined by go-inline
  843. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  844. {
  845. requiredSize := newSize
  846. if requiredSize > cap(rg.array) {
  847. rg.resize(requiredSize)
  848. }
  849. }
  850. rg.array[regi] = vali
  851. if regi >= rg.top {
  852. rg.top = regi + 1
  853. }
  854. }
  855. } else {
  856. // this section is inlined by go-inline
  857. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  858. {
  859. rg := reg
  860. regi := RA
  861. vali := LFalse
  862. newSize := regi + 1
  863. // this section is inlined by go-inline
  864. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  865. {
  866. requiredSize := newSize
  867. if requiredSize > cap(rg.array) {
  868. rg.resize(requiredSize)
  869. }
  870. }
  871. rg.array[regi] = vali
  872. if regi >= rg.top {
  873. rg.top = regi + 1
  874. }
  875. }
  876. }
  877. return 0
  878. },
  879. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LEN
  880. reg := L.reg
  881. cf := L.currentFrame
  882. lbase := cf.LocalBase
  883. A := int(inst>>18) & 0xff //GETA
  884. RA := lbase + A
  885. B := int(inst & 0x1ff) //GETB
  886. switch lv := L.rkValue(B).(type) {
  887. case LString:
  888. // this section is inlined by go-inline
  889. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  890. {
  891. rg := reg
  892. regi := RA
  893. vali := LNumber(len(lv))
  894. newSize := regi + 1
  895. // this section is inlined by go-inline
  896. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  897. {
  898. requiredSize := newSize
  899. if requiredSize > cap(rg.array) {
  900. rg.resize(requiredSize)
  901. }
  902. }
  903. rg.array[regi] = rg.alloc.LNumber2I(vali)
  904. if regi >= rg.top {
  905. rg.top = regi + 1
  906. }
  907. }
  908. default:
  909. op := L.metaOp1(lv, "__len")
  910. if op.Type() == LTFunction {
  911. reg.Push(op)
  912. reg.Push(lv)
  913. L.Call(1, 1)
  914. ret := reg.Pop()
  915. if ret.Type() == LTNumber {
  916. v, _ := ret.(LNumber)
  917. // this section is inlined by go-inline
  918. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  919. {
  920. rg := reg
  921. regi := RA
  922. vali := v
  923. newSize := regi + 1
  924. // this section is inlined by go-inline
  925. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  926. {
  927. requiredSize := newSize
  928. if requiredSize > cap(rg.array) {
  929. rg.resize(requiredSize)
  930. }
  931. }
  932. rg.array[regi] = rg.alloc.LNumber2I(vali)
  933. if regi >= rg.top {
  934. rg.top = regi + 1
  935. }
  936. }
  937. } else {
  938. // this section is inlined by go-inline
  939. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  940. {
  941. rg := reg
  942. regi := RA
  943. vali := ret
  944. newSize := regi + 1
  945. // this section is inlined by go-inline
  946. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  947. {
  948. requiredSize := newSize
  949. if requiredSize > cap(rg.array) {
  950. rg.resize(requiredSize)
  951. }
  952. }
  953. rg.array[regi] = vali
  954. if regi >= rg.top {
  955. rg.top = regi + 1
  956. }
  957. }
  958. }
  959. } else if lv.Type() == LTTable {
  960. // this section is inlined by go-inline
  961. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  962. {
  963. rg := reg
  964. regi := RA
  965. vali := LNumber(lv.(*LTable).Len())
  966. newSize := regi + 1
  967. // this section is inlined by go-inline
  968. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  969. {
  970. requiredSize := newSize
  971. if requiredSize > cap(rg.array) {
  972. rg.resize(requiredSize)
  973. }
  974. }
  975. rg.array[regi] = rg.alloc.LNumber2I(vali)
  976. if regi >= rg.top {
  977. rg.top = regi + 1
  978. }
  979. }
  980. } else {
  981. L.RaiseError("__len undefined")
  982. }
  983. }
  984. return 0
  985. },
  986. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CONCAT
  987. reg := L.reg
  988. cf := L.currentFrame
  989. lbase := cf.LocalBase
  990. A := int(inst>>18) & 0xff //GETA
  991. RA := lbase + A
  992. B := int(inst & 0x1ff) //GETB
  993. C := int(inst>>9) & 0x1ff //GETC
  994. RC := lbase + C
  995. RB := lbase + B
  996. v := stringConcat(L, RC-RB+1, RC)
  997. // this section is inlined by go-inline
  998. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  999. {
  1000. rg := reg
  1001. regi := RA
  1002. vali := v
  1003. newSize := regi + 1
  1004. // this section is inlined by go-inline
  1005. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1006. {
  1007. requiredSize := newSize
  1008. if requiredSize > cap(rg.array) {
  1009. rg.resize(requiredSize)
  1010. }
  1011. }
  1012. rg.array[regi] = vali
  1013. if regi >= rg.top {
  1014. rg.top = regi + 1
  1015. }
  1016. }
  1017. return 0
  1018. },
  1019. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_JMP
  1020. cf := L.currentFrame
  1021. Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
  1022. cf.Pc += Sbx
  1023. return 0
  1024. },
  1025. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_EQ
  1026. cf := L.currentFrame
  1027. A := int(inst>>18) & 0xff //GETA
  1028. B := int(inst & 0x1ff) //GETB
  1029. C := int(inst>>9) & 0x1ff //GETC
  1030. ret := equals(L, L.rkValue(B), L.rkValue(C), false)
  1031. v := 1
  1032. if ret {
  1033. v = 0
  1034. }
  1035. if v == A {
  1036. cf.Pc++
  1037. }
  1038. return 0
  1039. },
  1040. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LT
  1041. cf := L.currentFrame
  1042. A := int(inst>>18) & 0xff //GETA
  1043. B := int(inst & 0x1ff) //GETB
  1044. C := int(inst>>9) & 0x1ff //GETC
  1045. ret := lessThan(L, L.rkValue(B), L.rkValue(C))
  1046. v := 1
  1047. if ret {
  1048. v = 0
  1049. }
  1050. if v == A {
  1051. cf.Pc++
  1052. }
  1053. return 0
  1054. },
  1055. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_LE
  1056. cf := L.currentFrame
  1057. A := int(inst>>18) & 0xff //GETA
  1058. B := int(inst & 0x1ff) //GETB
  1059. C := int(inst>>9) & 0x1ff //GETC
  1060. lhs := L.rkValue(B)
  1061. rhs := L.rkValue(C)
  1062. ret := false
  1063. if v1, ok1 := lhs.(LNumber); ok1 {
  1064. if v2, ok2 := rhs.(LNumber); ok2 {
  1065. ret = v1 <= v2
  1066. } else {
  1067. L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
  1068. }
  1069. } else {
  1070. if lhs.Type() != rhs.Type() {
  1071. L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
  1072. }
  1073. switch lhs.Type() {
  1074. case LTString:
  1075. ret = strCmp(string(lhs.(LString)), string(rhs.(LString))) <= 0
  1076. default:
  1077. switch objectRational(L, lhs, rhs, "__le") {
  1078. case 1:
  1079. ret = true
  1080. case 0:
  1081. ret = false
  1082. default:
  1083. ret = !objectRationalWithError(L, rhs, lhs, "__lt")
  1084. }
  1085. }
  1086. }
  1087. v := 1
  1088. if ret {
  1089. v = 0
  1090. }
  1091. if v == A {
  1092. cf.Pc++
  1093. }
  1094. return 0
  1095. },
  1096. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TEST
  1097. reg := L.reg
  1098. cf := L.currentFrame
  1099. lbase := cf.LocalBase
  1100. A := int(inst>>18) & 0xff //GETA
  1101. RA := lbase + A
  1102. C := int(inst>>9) & 0x1ff //GETC
  1103. if LVAsBool(reg.Get(RA)) == (C == 0) {
  1104. cf.Pc++
  1105. }
  1106. return 0
  1107. },
  1108. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TESTSET
  1109. reg := L.reg
  1110. cf := L.currentFrame
  1111. lbase := cf.LocalBase
  1112. A := int(inst>>18) & 0xff //GETA
  1113. RA := lbase + A
  1114. B := int(inst & 0x1ff) //GETB
  1115. C := int(inst>>9) & 0x1ff //GETC
  1116. if value := reg.Get(lbase + B); LVAsBool(value) != (C == 0) {
  1117. // this section is inlined by go-inline
  1118. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  1119. {
  1120. rg := reg
  1121. regi := RA
  1122. vali := value
  1123. newSize := regi + 1
  1124. // this section is inlined by go-inline
  1125. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1126. {
  1127. requiredSize := newSize
  1128. if requiredSize > cap(rg.array) {
  1129. rg.resize(requiredSize)
  1130. }
  1131. }
  1132. rg.array[regi] = vali
  1133. if regi >= rg.top {
  1134. rg.top = regi + 1
  1135. }
  1136. }
  1137. } else {
  1138. cf.Pc++
  1139. }
  1140. return 0
  1141. },
  1142. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CALL
  1143. reg := L.reg
  1144. cf := L.currentFrame
  1145. lbase := cf.LocalBase
  1146. A := int(inst>>18) & 0xff //GETA
  1147. RA := lbase + A
  1148. B := int(inst & 0x1ff) //GETB
  1149. C := int(inst>>9) & 0x1ff //GETC
  1150. nargs := B - 1
  1151. if B == 0 {
  1152. nargs = reg.Top() - (RA + 1)
  1153. }
  1154. lv := reg.Get(RA)
  1155. nret := C - 1
  1156. var callable *LFunction
  1157. var meta bool
  1158. if fn, ok := lv.(*LFunction); ok {
  1159. callable = fn
  1160. meta = false
  1161. } else {
  1162. callable, meta = L.metaCall(lv)
  1163. }
  1164. // this section is inlined by go-inline
  1165. // source function is 'func (ls *LState) pushCallFrame(cf callFrame, fn LValue, meta bool) ' in '_state.go'
  1166. {
  1167. ls := L
  1168. cf := callFrame{Fn: callable, Pc: 0, Base: RA, LocalBase: RA + 1, ReturnBase: RA, NArgs: nargs, NRet: nret, Parent: cf, TailCall: 0}
  1169. fn := lv
  1170. if meta {
  1171. cf.NArgs++
  1172. ls.reg.Insert(fn, cf.LocalBase)
  1173. }
  1174. if cf.Fn == nil {
  1175. ls.RaiseError("attempt to call a non-function object")
  1176. }
  1177. if ls.stack.IsFull() {
  1178. ls.RaiseError("stack overflow")
  1179. }
  1180. ls.stack.Push(cf)
  1181. newcf := ls.stack.Last()
  1182. // this section is inlined by go-inline
  1183. // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go'
  1184. {
  1185. cf := newcf
  1186. if cf.Fn.IsG {
  1187. ls.reg.SetTop(cf.LocalBase + cf.NArgs)
  1188. } else {
  1189. proto := cf.Fn.Proto
  1190. nargs := cf.NArgs
  1191. np := int(proto.NumParameters)
  1192. if nargs < np {
  1193. // default any missing arguments to nil
  1194. newSize := cf.LocalBase + np
  1195. // this section is inlined by go-inline
  1196. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1197. {
  1198. rg := ls.reg
  1199. requiredSize := newSize
  1200. if requiredSize > cap(rg.array) {
  1201. rg.resize(requiredSize)
  1202. }
  1203. }
  1204. for i := nargs; i < np; i++ {
  1205. ls.reg.array[cf.LocalBase+i] = LNil
  1206. }
  1207. nargs = np
  1208. ls.reg.top = newSize
  1209. }
  1210. if (proto.IsVarArg & VarArgIsVarArg) == 0 {
  1211. if nargs < int(proto.NumUsedRegisters) {
  1212. nargs = int(proto.NumUsedRegisters)
  1213. }
  1214. newSize := cf.LocalBase + nargs
  1215. // this section is inlined by go-inline
  1216. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1217. {
  1218. rg := ls.reg
  1219. requiredSize := newSize
  1220. if requiredSize > cap(rg.array) {
  1221. rg.resize(requiredSize)
  1222. }
  1223. }
  1224. for i := np; i < nargs; i++ {
  1225. ls.reg.array[cf.LocalBase+i] = LNil
  1226. }
  1227. ls.reg.top = cf.LocalBase + int(proto.NumUsedRegisters)
  1228. } else {
  1229. /* swap vararg positions:
  1230. closure
  1231. namedparam1 <- lbase
  1232. namedparam2
  1233. vararg1
  1234. vararg2
  1235. TO
  1236. closure
  1237. nil
  1238. nil
  1239. vararg1
  1240. vararg2
  1241. namedparam1 <- lbase
  1242. namedparam2
  1243. */
  1244. nvarargs := nargs - np
  1245. if nvarargs < 0 {
  1246. nvarargs = 0
  1247. }
  1248. ls.reg.SetTop(cf.LocalBase + nargs + np)
  1249. for i := 0; i < np; i++ {
  1250. //ls.reg.Set(cf.LocalBase+nargs+i, ls.reg.Get(cf.LocalBase+i))
  1251. ls.reg.array[cf.LocalBase+nargs+i] = ls.reg.array[cf.LocalBase+i]
  1252. //ls.reg.Set(cf.LocalBase+i, LNil)
  1253. ls.reg.array[cf.LocalBase+i] = LNil
  1254. }
  1255. if CompatVarArg {
  1256. ls.reg.SetTop(cf.LocalBase + nargs + np + 1)
  1257. if (proto.IsVarArg & VarArgNeedsArg) != 0 {
  1258. argtb := newLTable(nvarargs, 0)
  1259. for i := 0; i < nvarargs; i++ {
  1260. argtb.RawSetInt(i+1, ls.reg.Get(cf.LocalBase+np+i))
  1261. }
  1262. argtb.RawSetString("n", LNumber(nvarargs))
  1263. //ls.reg.Set(cf.LocalBase+nargs+np, argtb)
  1264. ls.reg.array[cf.LocalBase+nargs+np] = argtb
  1265. } else {
  1266. ls.reg.array[cf.LocalBase+nargs+np] = LNil
  1267. }
  1268. }
  1269. cf.LocalBase += nargs
  1270. maxreg := cf.LocalBase + int(proto.NumUsedRegisters)
  1271. ls.reg.SetTop(maxreg)
  1272. }
  1273. }
  1274. }
  1275. ls.currentFrame = newcf
  1276. }
  1277. if callable.IsG && callGFunction(L, false) {
  1278. return 1
  1279. }
  1280. return 0
  1281. },
  1282. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TAILCALL
  1283. reg := L.reg
  1284. cf := L.currentFrame
  1285. lbase := cf.LocalBase
  1286. A := int(inst>>18) & 0xff //GETA
  1287. RA := lbase + A
  1288. B := int(inst & 0x1ff) //GETB
  1289. nargs := B - 1
  1290. if B == 0 {
  1291. nargs = reg.Top() - (RA + 1)
  1292. }
  1293. lv := reg.Get(RA)
  1294. var callable *LFunction
  1295. var meta bool
  1296. if fn, ok := lv.(*LFunction); ok {
  1297. callable = fn
  1298. meta = false
  1299. } else {
  1300. callable, meta = L.metaCall(lv)
  1301. }
  1302. if callable == nil {
  1303. L.RaiseError("attempt to call a non-function object")
  1304. }
  1305. // this section is inlined by go-inline
  1306. // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
  1307. {
  1308. ls := L
  1309. idx := lbase
  1310. if ls.uvcache != nil {
  1311. var prev *Upvalue
  1312. for uv := ls.uvcache; uv != nil; uv = uv.next {
  1313. if uv.index >= idx {
  1314. if prev != nil {
  1315. prev.next = nil
  1316. } else {
  1317. ls.uvcache = nil
  1318. }
  1319. uv.Close()
  1320. }
  1321. prev = uv
  1322. }
  1323. }
  1324. }
  1325. if callable.IsG {
  1326. luaframe := cf
  1327. L.pushCallFrame(callFrame{
  1328. Fn: callable,
  1329. Pc: 0,
  1330. Base: RA,
  1331. LocalBase: RA + 1,
  1332. ReturnBase: cf.ReturnBase,
  1333. NArgs: nargs,
  1334. NRet: cf.NRet,
  1335. Parent: cf,
  1336. TailCall: 0,
  1337. }, lv, meta)
  1338. if callGFunction(L, true) {
  1339. return 1
  1340. }
  1341. if L.currentFrame == nil || L.currentFrame.Fn.IsG || luaframe == baseframe {
  1342. return 1
  1343. }
  1344. } else {
  1345. base := cf.Base
  1346. cf.Fn = callable
  1347. cf.Pc = 0
  1348. cf.Base = RA
  1349. cf.LocalBase = RA + 1
  1350. cf.ReturnBase = cf.ReturnBase
  1351. cf.NArgs = nargs
  1352. cf.NRet = cf.NRet
  1353. cf.TailCall++
  1354. lbase := cf.LocalBase
  1355. if meta {
  1356. cf.NArgs++
  1357. L.reg.Insert(lv, cf.LocalBase)
  1358. }
  1359. // this section is inlined by go-inline
  1360. // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go'
  1361. {
  1362. ls := L
  1363. if cf.Fn.IsG {
  1364. ls.reg.SetTop(cf.LocalBase + cf.NArgs)
  1365. } else {
  1366. proto := cf.Fn.Proto
  1367. nargs := cf.NArgs
  1368. np := int(proto.NumParameters)
  1369. if nargs < np {
  1370. // default any missing arguments to nil
  1371. newSize := cf.LocalBase + np
  1372. // this section is inlined by go-inline
  1373. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1374. {
  1375. rg := ls.reg
  1376. requiredSize := newSize
  1377. if requiredSize > cap(rg.array) {
  1378. rg.resize(requiredSize)
  1379. }
  1380. }
  1381. for i := nargs; i < np; i++ {
  1382. ls.reg.array[cf.LocalBase+i] = LNil
  1383. }
  1384. nargs = np
  1385. ls.reg.top = newSize
  1386. }
  1387. if (proto.IsVarArg & VarArgIsVarArg) == 0 {
  1388. if nargs < int(proto.NumUsedRegisters) {
  1389. nargs = int(proto.NumUsedRegisters)
  1390. }
  1391. newSize := cf.LocalBase + nargs
  1392. // this section is inlined by go-inline
  1393. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1394. {
  1395. rg := ls.reg
  1396. requiredSize := newSize
  1397. if requiredSize > cap(rg.array) {
  1398. rg.resize(requiredSize)
  1399. }
  1400. }
  1401. for i := np; i < nargs; i++ {
  1402. ls.reg.array[cf.LocalBase+i] = LNil
  1403. }
  1404. ls.reg.top = cf.LocalBase + int(proto.NumUsedRegisters)
  1405. } else {
  1406. /* swap vararg positions:
  1407. closure
  1408. namedparam1 <- lbase
  1409. namedparam2
  1410. vararg1
  1411. vararg2
  1412. TO
  1413. closure
  1414. nil
  1415. nil
  1416. vararg1
  1417. vararg2
  1418. namedparam1 <- lbase
  1419. namedparam2
  1420. */
  1421. nvarargs := nargs - np
  1422. if nvarargs < 0 {
  1423. nvarargs = 0
  1424. }
  1425. ls.reg.SetTop(cf.LocalBase + nargs + np)
  1426. for i := 0; i < np; i++ {
  1427. //ls.reg.Set(cf.LocalBase+nargs+i, ls.reg.Get(cf.LocalBase+i))
  1428. ls.reg.array[cf.LocalBase+nargs+i] = ls.reg.array[cf.LocalBase+i]
  1429. //ls.reg.Set(cf.LocalBase+i, LNil)
  1430. ls.reg.array[cf.LocalBase+i] = LNil
  1431. }
  1432. if CompatVarArg {
  1433. ls.reg.SetTop(cf.LocalBase + nargs + np + 1)
  1434. if (proto.IsVarArg & VarArgNeedsArg) != 0 {
  1435. argtb := newLTable(nvarargs, 0)
  1436. for i := 0; i < nvarargs; i++ {
  1437. argtb.RawSetInt(i+1, ls.reg.Get(cf.LocalBase+np+i))
  1438. }
  1439. argtb.RawSetString("n", LNumber(nvarargs))
  1440. //ls.reg.Set(cf.LocalBase+nargs+np, argtb)
  1441. ls.reg.array[cf.LocalBase+nargs+np] = argtb
  1442. } else {
  1443. ls.reg.array[cf.LocalBase+nargs+np] = LNil
  1444. }
  1445. }
  1446. cf.LocalBase += nargs
  1447. maxreg := cf.LocalBase + int(proto.NumUsedRegisters)
  1448. ls.reg.SetTop(maxreg)
  1449. }
  1450. }
  1451. }
  1452. // this section is inlined by go-inline
  1453. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  1454. {
  1455. rg := L.reg
  1456. regv := base
  1457. start := RA
  1458. limit := -1
  1459. n := reg.Top() - RA - 1
  1460. newSize := regv + n
  1461. // this section is inlined by go-inline
  1462. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1463. {
  1464. requiredSize := newSize
  1465. if requiredSize > cap(rg.array) {
  1466. rg.resize(requiredSize)
  1467. }
  1468. }
  1469. if limit == -1 || limit > rg.top {
  1470. limit = rg.top
  1471. }
  1472. for i := 0; i < n; i++ {
  1473. srcIdx := start + i
  1474. if srcIdx >= limit || srcIdx < 0 {
  1475. rg.array[regv+i] = LNil
  1476. } else {
  1477. rg.array[regv+i] = rg.array[srcIdx]
  1478. }
  1479. }
  1480. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1481. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1482. oldtop := rg.top
  1483. rg.top = regv + n
  1484. if rg.top < oldtop {
  1485. nilRange := rg.array[rg.top:oldtop]
  1486. for i := range nilRange {
  1487. nilRange[i] = nil
  1488. }
  1489. }
  1490. }
  1491. cf.Base = base
  1492. cf.LocalBase = base + (cf.LocalBase - lbase + 1)
  1493. }
  1494. return 0
  1495. },
  1496. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_RETURN
  1497. reg := L.reg
  1498. cf := L.currentFrame
  1499. lbase := cf.LocalBase
  1500. A := int(inst>>18) & 0xff //GETA
  1501. RA := lbase + A
  1502. B := int(inst & 0x1ff) //GETB
  1503. // this section is inlined by go-inline
  1504. // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
  1505. {
  1506. ls := L
  1507. idx := lbase
  1508. if ls.uvcache != nil {
  1509. var prev *Upvalue
  1510. for uv := ls.uvcache; uv != nil; uv = uv.next {
  1511. if uv.index >= idx {
  1512. if prev != nil {
  1513. prev.next = nil
  1514. } else {
  1515. ls.uvcache = nil
  1516. }
  1517. uv.Close()
  1518. }
  1519. prev = uv
  1520. }
  1521. }
  1522. }
  1523. nret := B - 1
  1524. if B == 0 {
  1525. nret = reg.Top() - RA
  1526. }
  1527. n := cf.NRet
  1528. if cf.NRet == MultRet {
  1529. n = nret
  1530. }
  1531. if L.Parent != nil && L.stack.Sp() == 1 {
  1532. // this section is inlined by go-inline
  1533. // source function is 'func copyReturnValues(L *LState, regv, start, n, b int) ' in '_vm.go'
  1534. {
  1535. regv := reg.Top()
  1536. start := RA
  1537. b := B
  1538. if b == 1 {
  1539. // this section is inlined by go-inline
  1540. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  1541. {
  1542. rg := L.reg
  1543. regm := regv
  1544. newSize := regm + n
  1545. // this section is inlined by go-inline
  1546. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1547. {
  1548. requiredSize := newSize
  1549. if requiredSize > cap(rg.array) {
  1550. rg.resize(requiredSize)
  1551. }
  1552. }
  1553. for i := 0; i < n; i++ {
  1554. rg.array[regm+i] = LNil
  1555. }
  1556. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1557. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1558. oldtop := rg.top
  1559. rg.top = regm + n
  1560. if rg.top < oldtop {
  1561. nilRange := rg.array[rg.top:oldtop]
  1562. for i := range nilRange {
  1563. nilRange[i] = nil
  1564. }
  1565. }
  1566. }
  1567. } else {
  1568. // this section is inlined by go-inline
  1569. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  1570. {
  1571. rg := L.reg
  1572. limit := -1
  1573. newSize := regv + n
  1574. // this section is inlined by go-inline
  1575. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1576. {
  1577. requiredSize := newSize
  1578. if requiredSize > cap(rg.array) {
  1579. rg.resize(requiredSize)
  1580. }
  1581. }
  1582. if limit == -1 || limit > rg.top {
  1583. limit = rg.top
  1584. }
  1585. for i := 0; i < n; i++ {
  1586. srcIdx := start + i
  1587. if srcIdx >= limit || srcIdx < 0 {
  1588. rg.array[regv+i] = LNil
  1589. } else {
  1590. rg.array[regv+i] = rg.array[srcIdx]
  1591. }
  1592. }
  1593. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1594. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1595. oldtop := rg.top
  1596. rg.top = regv + n
  1597. if rg.top < oldtop {
  1598. nilRange := rg.array[rg.top:oldtop]
  1599. for i := range nilRange {
  1600. nilRange[i] = nil
  1601. }
  1602. }
  1603. }
  1604. if b > 1 && n > (b-1) {
  1605. // this section is inlined by go-inline
  1606. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  1607. {
  1608. rg := L.reg
  1609. regm := regv + b - 1
  1610. n := n - (b - 1)
  1611. newSize := regm + n
  1612. // this section is inlined by go-inline
  1613. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1614. {
  1615. requiredSize := newSize
  1616. if requiredSize > cap(rg.array) {
  1617. rg.resize(requiredSize)
  1618. }
  1619. }
  1620. for i := 0; i < n; i++ {
  1621. rg.array[regm+i] = LNil
  1622. }
  1623. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1624. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1625. oldtop := rg.top
  1626. rg.top = regm + n
  1627. if rg.top < oldtop {
  1628. nilRange := rg.array[rg.top:oldtop]
  1629. for i := range nilRange {
  1630. nilRange[i] = nil
  1631. }
  1632. }
  1633. }
  1634. }
  1635. }
  1636. }
  1637. switchToParentThread(L, n, false, true)
  1638. return 1
  1639. }
  1640. islast := baseframe == L.stack.Pop() || L.stack.IsEmpty()
  1641. // this section is inlined by go-inline
  1642. // source function is 'func copyReturnValues(L *LState, regv, start, n, b int) ' in '_vm.go'
  1643. {
  1644. regv := cf.ReturnBase
  1645. start := RA
  1646. b := B
  1647. if b == 1 {
  1648. // this section is inlined by go-inline
  1649. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  1650. {
  1651. rg := L.reg
  1652. regm := regv
  1653. newSize := regm + n
  1654. // this section is inlined by go-inline
  1655. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1656. {
  1657. requiredSize := newSize
  1658. if requiredSize > cap(rg.array) {
  1659. rg.resize(requiredSize)
  1660. }
  1661. }
  1662. for i := 0; i < n; i++ {
  1663. rg.array[regm+i] = LNil
  1664. }
  1665. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1666. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1667. oldtop := rg.top
  1668. rg.top = regm + n
  1669. if rg.top < oldtop {
  1670. nilRange := rg.array[rg.top:oldtop]
  1671. for i := range nilRange {
  1672. nilRange[i] = nil
  1673. }
  1674. }
  1675. }
  1676. } else {
  1677. // this section is inlined by go-inline
  1678. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  1679. {
  1680. rg := L.reg
  1681. limit := -1
  1682. newSize := regv + n
  1683. // this section is inlined by go-inline
  1684. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1685. {
  1686. requiredSize := newSize
  1687. if requiredSize > cap(rg.array) {
  1688. rg.resize(requiredSize)
  1689. }
  1690. }
  1691. if limit == -1 || limit > rg.top {
  1692. limit = rg.top
  1693. }
  1694. for i := 0; i < n; i++ {
  1695. srcIdx := start + i
  1696. if srcIdx >= limit || srcIdx < 0 {
  1697. rg.array[regv+i] = LNil
  1698. } else {
  1699. rg.array[regv+i] = rg.array[srcIdx]
  1700. }
  1701. }
  1702. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1703. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1704. oldtop := rg.top
  1705. rg.top = regv + n
  1706. if rg.top < oldtop {
  1707. nilRange := rg.array[rg.top:oldtop]
  1708. for i := range nilRange {
  1709. nilRange[i] = nil
  1710. }
  1711. }
  1712. }
  1713. if b > 1 && n > (b-1) {
  1714. // this section is inlined by go-inline
  1715. // source function is 'func (rg *registry) FillNil(regm, n int) ' in '_state.go'
  1716. {
  1717. rg := L.reg
  1718. regm := regv + b - 1
  1719. n := n - (b - 1)
  1720. newSize := regm + n
  1721. // this section is inlined by go-inline
  1722. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1723. {
  1724. requiredSize := newSize
  1725. if requiredSize > cap(rg.array) {
  1726. rg.resize(requiredSize)
  1727. }
  1728. }
  1729. for i := 0; i < n; i++ {
  1730. rg.array[regm+i] = LNil
  1731. }
  1732. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1733. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1734. oldtop := rg.top
  1735. rg.top = regm + n
  1736. if rg.top < oldtop {
  1737. nilRange := rg.array[rg.top:oldtop]
  1738. for i := range nilRange {
  1739. nilRange[i] = nil
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. L.currentFrame = L.stack.Last()
  1747. if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG {
  1748. return 1
  1749. }
  1750. return 0
  1751. },
  1752. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_FORLOOP
  1753. reg := L.reg
  1754. cf := L.currentFrame
  1755. lbase := cf.LocalBase
  1756. A := int(inst>>18) & 0xff //GETA
  1757. RA := lbase + A
  1758. if init, ok1 := reg.Get(RA).(LNumber); ok1 {
  1759. if limit, ok2 := reg.Get(RA + 1).(LNumber); ok2 {
  1760. if step, ok3 := reg.Get(RA + 2).(LNumber); ok3 {
  1761. init += step
  1762. v := LNumber(init)
  1763. // this section is inlined by go-inline
  1764. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  1765. {
  1766. rg := reg
  1767. regi := RA
  1768. vali := v
  1769. newSize := regi + 1
  1770. // this section is inlined by go-inline
  1771. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1772. {
  1773. requiredSize := newSize
  1774. if requiredSize > cap(rg.array) {
  1775. rg.resize(requiredSize)
  1776. }
  1777. }
  1778. rg.array[regi] = rg.alloc.LNumber2I(vali)
  1779. if regi >= rg.top {
  1780. rg.top = regi + 1
  1781. }
  1782. }
  1783. if (step > 0 && init <= limit) || (step <= 0 && init >= limit) {
  1784. Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
  1785. cf.Pc += Sbx
  1786. // this section is inlined by go-inline
  1787. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  1788. {
  1789. rg := reg
  1790. regi := RA + 3
  1791. vali := v
  1792. newSize := regi + 1
  1793. // this section is inlined by go-inline
  1794. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1795. {
  1796. requiredSize := newSize
  1797. if requiredSize > cap(rg.array) {
  1798. rg.resize(requiredSize)
  1799. }
  1800. }
  1801. rg.array[regi] = rg.alloc.LNumber2I(vali)
  1802. if regi >= rg.top {
  1803. rg.top = regi + 1
  1804. }
  1805. }
  1806. } else {
  1807. // this section is inlined by go-inline
  1808. // source function is 'func (rg *registry) SetTop(topi int) ' in '_state.go'
  1809. {
  1810. rg := reg
  1811. topi := RA + 1
  1812. // this section is inlined by go-inline
  1813. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1814. {
  1815. requiredSize := topi
  1816. if requiredSize > cap(rg.array) {
  1817. rg.resize(requiredSize)
  1818. }
  1819. }
  1820. oldtopi := rg.top
  1821. rg.top = topi
  1822. for i := oldtopi; i < rg.top; i++ {
  1823. rg.array[i] = LNil
  1824. }
  1825. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1826. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1827. if rg.top < oldtopi {
  1828. nilRange := rg.array[rg.top:oldtopi]
  1829. for i := range nilRange {
  1830. nilRange[i] = nil
  1831. }
  1832. }
  1833. //for i := rg.top; i < oldtop; i++ {
  1834. // rg.array[i] = LNil
  1835. //}
  1836. }
  1837. }
  1838. } else {
  1839. L.RaiseError("for statement step must be a number")
  1840. }
  1841. } else {
  1842. L.RaiseError("for statement limit must be a number")
  1843. }
  1844. } else {
  1845. L.RaiseError("for statement init must be a number")
  1846. }
  1847. return 0
  1848. },
  1849. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_FORPREP
  1850. reg := L.reg
  1851. cf := L.currentFrame
  1852. lbase := cf.LocalBase
  1853. A := int(inst>>18) & 0xff //GETA
  1854. RA := lbase + A
  1855. Sbx := int(inst&0x3ffff) - opMaxArgSbx //GETSBX
  1856. if init, ok1 := reg.Get(RA).(LNumber); ok1 {
  1857. if step, ok2 := reg.Get(RA + 2).(LNumber); ok2 {
  1858. // this section is inlined by go-inline
  1859. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  1860. {
  1861. rg := reg
  1862. regi := RA
  1863. vali := LNumber(init - step)
  1864. newSize := regi + 1
  1865. // this section is inlined by go-inline
  1866. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1867. {
  1868. requiredSize := newSize
  1869. if requiredSize > cap(rg.array) {
  1870. rg.resize(requiredSize)
  1871. }
  1872. }
  1873. rg.array[regi] = rg.alloc.LNumber2I(vali)
  1874. if regi >= rg.top {
  1875. rg.top = regi + 1
  1876. }
  1877. }
  1878. } else {
  1879. L.RaiseError("for statement step must be a number")
  1880. }
  1881. } else {
  1882. L.RaiseError("for statement init must be a number")
  1883. }
  1884. cf.Pc += Sbx
  1885. return 0
  1886. },
  1887. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_TFORLOOP
  1888. reg := L.reg
  1889. cf := L.currentFrame
  1890. lbase := cf.LocalBase
  1891. A := int(inst>>18) & 0xff //GETA
  1892. RA := lbase + A
  1893. C := int(inst>>9) & 0x1ff //GETC
  1894. nret := C
  1895. // this section is inlined by go-inline
  1896. // source function is 'func (rg *registry) SetTop(topi int) ' in '_state.go'
  1897. {
  1898. rg := reg
  1899. topi := RA + 3 + 2
  1900. // this section is inlined by go-inline
  1901. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1902. {
  1903. requiredSize := topi
  1904. if requiredSize > cap(rg.array) {
  1905. rg.resize(requiredSize)
  1906. }
  1907. }
  1908. oldtopi := rg.top
  1909. rg.top = topi
  1910. for i := oldtopi; i < rg.top; i++ {
  1911. rg.array[i] = LNil
  1912. }
  1913. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  1914. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  1915. if rg.top < oldtopi {
  1916. nilRange := rg.array[rg.top:oldtopi]
  1917. for i := range nilRange {
  1918. nilRange[i] = nil
  1919. }
  1920. }
  1921. //for i := rg.top; i < oldtop; i++ {
  1922. // rg.array[i] = LNil
  1923. //}
  1924. }
  1925. // this section is inlined by go-inline
  1926. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  1927. {
  1928. rg := reg
  1929. regi := RA + 3 + 2
  1930. vali := reg.Get(RA + 2)
  1931. newSize := regi + 1
  1932. // this section is inlined by go-inline
  1933. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1934. {
  1935. requiredSize := newSize
  1936. if requiredSize > cap(rg.array) {
  1937. rg.resize(requiredSize)
  1938. }
  1939. }
  1940. rg.array[regi] = vali
  1941. if regi >= rg.top {
  1942. rg.top = regi + 1
  1943. }
  1944. }
  1945. // this section is inlined by go-inline
  1946. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  1947. {
  1948. rg := reg
  1949. regi := RA + 3 + 1
  1950. vali := reg.Get(RA + 1)
  1951. newSize := regi + 1
  1952. // this section is inlined by go-inline
  1953. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1954. {
  1955. requiredSize := newSize
  1956. if requiredSize > cap(rg.array) {
  1957. rg.resize(requiredSize)
  1958. }
  1959. }
  1960. rg.array[regi] = vali
  1961. if regi >= rg.top {
  1962. rg.top = regi + 1
  1963. }
  1964. }
  1965. // this section is inlined by go-inline
  1966. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  1967. {
  1968. rg := reg
  1969. regi := RA + 3
  1970. vali := reg.Get(RA)
  1971. newSize := regi + 1
  1972. // this section is inlined by go-inline
  1973. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1974. {
  1975. requiredSize := newSize
  1976. if requiredSize > cap(rg.array) {
  1977. rg.resize(requiredSize)
  1978. }
  1979. }
  1980. rg.array[regi] = vali
  1981. if regi >= rg.top {
  1982. rg.top = regi + 1
  1983. }
  1984. }
  1985. L.callR(2, nret, RA+3)
  1986. if value := reg.Get(RA + 3); value != LNil {
  1987. // this section is inlined by go-inline
  1988. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  1989. {
  1990. rg := reg
  1991. regi := RA + 2
  1992. vali := value
  1993. newSize := regi + 1
  1994. // this section is inlined by go-inline
  1995. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  1996. {
  1997. requiredSize := newSize
  1998. if requiredSize > cap(rg.array) {
  1999. rg.resize(requiredSize)
  2000. }
  2001. }
  2002. rg.array[regi] = vali
  2003. if regi >= rg.top {
  2004. rg.top = regi + 1
  2005. }
  2006. }
  2007. pc := cf.Fn.Proto.Code[cf.Pc]
  2008. cf.Pc += int(pc&0x3ffff) - opMaxArgSbx
  2009. }
  2010. cf.Pc++
  2011. return 0
  2012. },
  2013. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_SETLIST
  2014. reg := L.reg
  2015. cf := L.currentFrame
  2016. lbase := cf.LocalBase
  2017. A := int(inst>>18) & 0xff //GETA
  2018. RA := lbase + A
  2019. B := int(inst & 0x1ff) //GETB
  2020. C := int(inst>>9) & 0x1ff //GETC
  2021. if C == 0 {
  2022. C = int(cf.Fn.Proto.Code[cf.Pc])
  2023. cf.Pc++
  2024. }
  2025. offset := (C - 1) * FieldsPerFlush
  2026. table := reg.Get(RA).(*LTable)
  2027. nelem := B
  2028. if B == 0 {
  2029. nelem = reg.Top() - RA - 1
  2030. }
  2031. for i := 1; i <= nelem; i++ {
  2032. table.RawSetInt(offset+i, reg.Get(RA+i))
  2033. }
  2034. return 0
  2035. },
  2036. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CLOSE
  2037. cf := L.currentFrame
  2038. lbase := cf.LocalBase
  2039. A := int(inst>>18) & 0xff //GETA
  2040. RA := lbase + A
  2041. // this section is inlined by go-inline
  2042. // source function is 'func (ls *LState) closeUpvalues(idx int) ' in '_state.go'
  2043. {
  2044. ls := L
  2045. idx := RA
  2046. if ls.uvcache != nil {
  2047. var prev *Upvalue
  2048. for uv := ls.uvcache; uv != nil; uv = uv.next {
  2049. if uv.index >= idx {
  2050. if prev != nil {
  2051. prev.next = nil
  2052. } else {
  2053. ls.uvcache = nil
  2054. }
  2055. uv.Close()
  2056. }
  2057. prev = uv
  2058. }
  2059. }
  2060. }
  2061. return 0
  2062. },
  2063. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_CLOSURE
  2064. reg := L.reg
  2065. cf := L.currentFrame
  2066. lbase := cf.LocalBase
  2067. A := int(inst>>18) & 0xff //GETA
  2068. RA := lbase + A
  2069. Bx := int(inst & 0x3ffff) //GETBX
  2070. proto := cf.Fn.Proto.FunctionPrototypes[Bx]
  2071. closure := newLFunctionL(proto, cf.Fn.Env, int(proto.NumUpvalues))
  2072. // this section is inlined by go-inline
  2073. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  2074. {
  2075. rg := reg
  2076. regi := RA
  2077. vali := closure
  2078. newSize := regi + 1
  2079. // this section is inlined by go-inline
  2080. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  2081. {
  2082. requiredSize := newSize
  2083. if requiredSize > cap(rg.array) {
  2084. rg.resize(requiredSize)
  2085. }
  2086. }
  2087. rg.array[regi] = vali
  2088. if regi >= rg.top {
  2089. rg.top = regi + 1
  2090. }
  2091. }
  2092. for i := 0; i < int(proto.NumUpvalues); i++ {
  2093. inst = cf.Fn.Proto.Code[cf.Pc]
  2094. cf.Pc++
  2095. B := opGetArgB(inst)
  2096. switch opGetOpCode(inst) {
  2097. case OP_MOVE:
  2098. closure.Upvalues[i] = L.findUpvalue(lbase + B)
  2099. case OP_GETUPVAL:
  2100. closure.Upvalues[i] = cf.Fn.Upvalues[B]
  2101. }
  2102. }
  2103. return 0
  2104. },
  2105. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_VARARG
  2106. reg := L.reg
  2107. cf := L.currentFrame
  2108. lbase := cf.LocalBase
  2109. A := int(inst>>18) & 0xff //GETA
  2110. RA := lbase + A
  2111. B := int(inst & 0x1ff) //GETB
  2112. nparams := int(cf.Fn.Proto.NumParameters)
  2113. nvarargs := cf.NArgs - nparams
  2114. if nvarargs < 0 {
  2115. nvarargs = 0
  2116. }
  2117. nwant := B - 1
  2118. if B == 0 {
  2119. nwant = nvarargs
  2120. }
  2121. // this section is inlined by go-inline
  2122. // source function is 'func (rg *registry) CopyRange(regv, start, limit, n int) ' in '_state.go'
  2123. {
  2124. rg := reg
  2125. regv := RA
  2126. start := cf.Base + nparams + 1
  2127. limit := cf.LocalBase
  2128. n := nwant
  2129. newSize := regv + n
  2130. // this section is inlined by go-inline
  2131. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  2132. {
  2133. requiredSize := newSize
  2134. if requiredSize > cap(rg.array) {
  2135. rg.resize(requiredSize)
  2136. }
  2137. }
  2138. if limit == -1 || limit > rg.top {
  2139. limit = rg.top
  2140. }
  2141. for i := 0; i < n; i++ {
  2142. srcIdx := start + i
  2143. if srcIdx >= limit || srcIdx < 0 {
  2144. rg.array[regv+i] = LNil
  2145. } else {
  2146. rg.array[regv+i] = rg.array[srcIdx]
  2147. }
  2148. }
  2149. // values beyond top don't need to be valid LValues, so setting them to nil is fine
  2150. // setting them to nil rather than LNil lets us invoke the golang memclr opto
  2151. oldtop := rg.top
  2152. rg.top = regv + n
  2153. if rg.top < oldtop {
  2154. nilRange := rg.array[rg.top:oldtop]
  2155. for i := range nilRange {
  2156. nilRange[i] = nil
  2157. }
  2158. }
  2159. }
  2160. return 0
  2161. },
  2162. func(L *LState, inst uint32, baseframe *callFrame) int { //OP_NOP
  2163. return 0
  2164. },
  2165. }
  2166. }
  2167. func opArith(L *LState, inst uint32, baseframe *callFrame) int { //OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW
  2168. reg := L.reg
  2169. cf := L.currentFrame
  2170. lbase := cf.LocalBase
  2171. A := int(inst>>18) & 0xff //GETA
  2172. RA := lbase + A
  2173. opcode := int(inst >> 26) //GETOPCODE
  2174. B := int(inst & 0x1ff) //GETB
  2175. C := int(inst>>9) & 0x1ff //GETC
  2176. lhs := L.rkValue(B)
  2177. rhs := L.rkValue(C)
  2178. v1, ok1 := lhs.(LNumber)
  2179. v2, ok2 := rhs.(LNumber)
  2180. if ok1 && ok2 {
  2181. v := numberArith(L, opcode, LNumber(v1), LNumber(v2))
  2182. // this section is inlined by go-inline
  2183. // source function is 'func (rg *registry) SetNumber(regi int, vali LNumber) ' in '_state.go'
  2184. {
  2185. rg := reg
  2186. regi := RA
  2187. vali := v
  2188. newSize := regi + 1
  2189. // this section is inlined by go-inline
  2190. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  2191. {
  2192. requiredSize := newSize
  2193. if requiredSize > cap(rg.array) {
  2194. rg.resize(requiredSize)
  2195. }
  2196. }
  2197. rg.array[regi] = rg.alloc.LNumber2I(vali)
  2198. if regi >= rg.top {
  2199. rg.top = regi + 1
  2200. }
  2201. }
  2202. } else {
  2203. v := objectArith(L, opcode, lhs, rhs)
  2204. // this section is inlined by go-inline
  2205. // source function is 'func (rg *registry) Set(regi int, vali LValue) ' in '_state.go'
  2206. {
  2207. rg := reg
  2208. regi := RA
  2209. vali := v
  2210. newSize := regi + 1
  2211. // this section is inlined by go-inline
  2212. // source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
  2213. {
  2214. requiredSize := newSize
  2215. if requiredSize > cap(rg.array) {
  2216. rg.resize(requiredSize)
  2217. }
  2218. }
  2219. rg.array[regi] = vali
  2220. if regi >= rg.top {
  2221. rg.top = regi + 1
  2222. }
  2223. }
  2224. }
  2225. return 0
  2226. }
  2227. func luaModulo(lhs, rhs LNumber) LNumber {
  2228. flhs := float64(lhs)
  2229. frhs := float64(rhs)
  2230. v := math.Mod(flhs, frhs)
  2231. if frhs > 0 && v < 0 || frhs < 0 && v > 0 {
  2232. v += frhs
  2233. }
  2234. return LNumber(v)
  2235. }
  2236. func numberArith(L *LState, opcode int, lhs, rhs LNumber) LNumber {
  2237. switch opcode {
  2238. case OP_ADD:
  2239. return lhs + rhs
  2240. case OP_SUB:
  2241. return lhs - rhs
  2242. case OP_MUL:
  2243. return lhs * rhs
  2244. case OP_DIV:
  2245. return lhs / rhs
  2246. case OP_MOD:
  2247. return luaModulo(lhs, rhs)
  2248. case OP_POW:
  2249. flhs := float64(lhs)
  2250. frhs := float64(rhs)
  2251. return LNumber(math.Pow(flhs, frhs))
  2252. }
  2253. panic("should not reach here")
  2254. return LNumber(0)
  2255. }
  2256. func objectArith(L *LState, opcode int, lhs, rhs LValue) LValue {
  2257. event := ""
  2258. switch opcode {
  2259. case OP_ADD:
  2260. event = "__add"
  2261. case OP_SUB:
  2262. event = "__sub"
  2263. case OP_MUL:
  2264. event = "__mul"
  2265. case OP_DIV:
  2266. event = "__div"
  2267. case OP_MOD:
  2268. event = "__mod"
  2269. case OP_POW:
  2270. event = "__pow"
  2271. }
  2272. op := L.metaOp2(lhs, rhs, event)
  2273. if _, ok := op.(*LFunction); ok {
  2274. L.reg.Push(op)
  2275. L.reg.Push(lhs)
  2276. L.reg.Push(rhs)
  2277. L.Call(2, 1)
  2278. return L.reg.Pop()
  2279. }
  2280. if str, ok := lhs.(LString); ok {
  2281. if lnum, err := parseNumber(string(str)); err == nil {
  2282. lhs = lnum
  2283. }
  2284. }
  2285. if str, ok := rhs.(LString); ok {
  2286. if rnum, err := parseNumber(string(str)); err == nil {
  2287. rhs = rnum
  2288. }
  2289. }
  2290. if v1, ok1 := lhs.(LNumber); ok1 {
  2291. if v2, ok2 := rhs.(LNumber); ok2 {
  2292. return numberArith(L, opcode, LNumber(v1), LNumber(v2))
  2293. }
  2294. }
  2295. L.RaiseError(fmt.Sprintf("cannot perform %v operation between %v and %v",
  2296. strings.TrimLeft(event, "_"), lhs.Type().String(), rhs.Type().String()))
  2297. return LNil
  2298. }
  2299. func stringConcat(L *LState, total, last int) LValue {
  2300. rhs := L.reg.Get(last)
  2301. total--
  2302. for i := last - 1; total > 0; {
  2303. lhs := L.reg.Get(i)
  2304. if !(LVCanConvToString(lhs) && LVCanConvToString(rhs)) {
  2305. op := L.metaOp2(lhs, rhs, "__concat")
  2306. if op.Type() == LTFunction {
  2307. L.reg.Push(op)
  2308. L.reg.Push(lhs)
  2309. L.reg.Push(rhs)
  2310. L.Call(2, 1)
  2311. rhs = L.reg.Pop()
  2312. total--
  2313. i--
  2314. } else {
  2315. L.RaiseError("cannot perform concat operation between %v and %v", lhs.Type().String(), rhs.Type().String())
  2316. return LNil
  2317. }
  2318. } else {
  2319. buf := make([]string, total+1)
  2320. buf[total] = LVAsString(rhs)
  2321. for total > 0 {
  2322. lhs = L.reg.Get(i)
  2323. if !LVCanConvToString(lhs) {
  2324. break
  2325. }
  2326. buf[total-1] = LVAsString(lhs)
  2327. i--
  2328. total--
  2329. }
  2330. rhs = LString(strings.Join(buf, ""))
  2331. }
  2332. }
  2333. return rhs
  2334. }
  2335. func lessThan(L *LState, lhs, rhs LValue) bool {
  2336. // optimization for numbers
  2337. if v1, ok1 := lhs.(LNumber); ok1 {
  2338. if v2, ok2 := rhs.(LNumber); ok2 {
  2339. return v1 < v2
  2340. }
  2341. L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
  2342. }
  2343. if lhs.Type() != rhs.Type() {
  2344. L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
  2345. return false
  2346. }
  2347. ret := false
  2348. switch lhs.Type() {
  2349. case LTString:
  2350. ret = strCmp(string(lhs.(LString)), string(rhs.(LString))) < 0
  2351. default:
  2352. ret = objectRationalWithError(L, lhs, rhs, "__lt")
  2353. }
  2354. return ret
  2355. }
  2356. func equals(L *LState, lhs, rhs LValue, raw bool) bool {
  2357. lt := lhs.Type()
  2358. if lt != rhs.Type() {
  2359. return false
  2360. }
  2361. ret := false
  2362. switch lt {
  2363. case LTNil:
  2364. ret = true
  2365. case LTNumber:
  2366. v1, _ := lhs.(LNumber)
  2367. v2, _ := rhs.(LNumber)
  2368. ret = v1 == v2
  2369. case LTBool:
  2370. ret = bool(lhs.(LBool)) == bool(rhs.(LBool))
  2371. case LTString:
  2372. ret = string(lhs.(LString)) == string(rhs.(LString))
  2373. case LTUserData, LTTable:
  2374. if lhs == rhs {
  2375. ret = true
  2376. } else if !raw {
  2377. switch objectRational(L, lhs, rhs, "__eq") {
  2378. case 1:
  2379. ret = true
  2380. default:
  2381. ret = false
  2382. }
  2383. }
  2384. default:
  2385. ret = lhs == rhs
  2386. }
  2387. return ret
  2388. }
  2389. func objectRationalWithError(L *LState, lhs, rhs LValue, event string) bool {
  2390. switch objectRational(L, lhs, rhs, event) {
  2391. case 1:
  2392. return true
  2393. case 0:
  2394. return false
  2395. }
  2396. L.RaiseError("attempt to compare %v with %v", lhs.Type().String(), rhs.Type().String())
  2397. return false
  2398. }
  2399. func objectRational(L *LState, lhs, rhs LValue, event string) int {
  2400. m1 := L.metaOp1(lhs, event)
  2401. m2 := L.metaOp1(rhs, event)
  2402. if m1.Type() == LTFunction && m1 == m2 {
  2403. L.reg.Push(m1)
  2404. L.reg.Push(lhs)
  2405. L.reg.Push(rhs)
  2406. L.Call(2, 1)
  2407. if LVAsBool(L.reg.Pop()) {
  2408. return 1
  2409. }
  2410. return 0
  2411. }
  2412. return -1
  2413. }