Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 213.23 KB | None | 0 0
  1. --[[
  2. Gui to Lua Converter
  3. -- Revamped by:HoIyScript
  4. --]]
  5.  
  6.  
  7.  
  8. -- Instances:
  9.  
  10. local SS = Instance.new("ScreenGui")
  11. local Frame = Instance.new("Frame")
  12. local Properties = Instance.new("ScrollingFrame")
  13. local TextButton4 = Instance.new("TextButton")
  14. local TextButton2 = Instance.new("TextButton")
  15. local TextButton3 = Instance.new("TextButton")
  16. local TextButton5 = Instance.new("TextButton")
  17. local TextButton1 = Instance.new("TextButton")
  18. local TextButton6 = Instance.new("TextButton")
  19. local TextLabel = Instance.new("TextLabel")
  20. local TextButton7 = Instance.new("TextButton")
  21. local TextButton8 = Instance.new("TextButton")
  22. local TextButton9 = Instance.new("TextButton")
  23. local TextButton10 = Instance.new("TextButton")
  24. local TextButton11 = Instance.new("TextButton")
  25. local TextButton12 = Instance.new("TextButton")
  26. local TextButton13 = Instance.new("TextButton")
  27. local TextButton14 = Instance.new("TextButton")
  28. local TextButton15 = Instance.new("TextButton")
  29. local TextButton16 = Instance.new("TextButton")
  30. local TextButton17 = Instance.new("TextButton")
  31. local TextButton18 = Instance.new("TextButton")
  32. local TextButton19 = Instance.new("TextButton")
  33. local TextButton20 = Instance.new("TextButton")
  34. local TextButton21 = Instance.new("TextButton")
  35. local TextButton22 = Instance.new("TextButton")
  36. local TextButton23 = Instance.new("TextButton")
  37. local TextButton24 = Instance.new("TextButton")
  38. local TextButton25 = Instance.new("TextButton")
  39. local EEEEE = Instance.new("Frame")
  40. local Execute = Instance.new("TextButton")
  41. local TextBox = Instance.new("TextBox")
  42. local TextButton = Instance.new("TextButton")
  43. local Framedodo = Instance.new("Frame")
  44. local Frame_2 = Instance.new("Frame")
  45. local TextButton_2 = Instance.new("TextButton")
  46. local LocalScript = Instance.new("LocalScript")
  47. local MSFunction = Instance.new("RemoteEvent")
  48. local Script = Instance.new("Script")
  49. local Loadstring = Instance.new("ModuleScript")
  50. local LuaK = Instance.new("ModuleScript")
  51. local LuaP = Instance.new("ModuleScript")
  52. local LuaU = Instance.new("ModuleScript")
  53. local LuaX = Instance.new("ModuleScript")
  54. local LuaY = Instance.new("ModuleScript")
  55. local LuaZ = Instance.new("ModuleScript")
  56. local Rerubi = Instance.new("ModuleScript")
  57. --[[
  58. Properties:
  59. --]]
  60.  
  61. SS.Name = "SS"
  62. SS.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  63. SS.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  64.  
  65. Frame.Parent = SS
  66. Frame.Active = true
  67. Frame.BackgroundColor3 = Color3.new(1, 1, 1)
  68. Frame.BackgroundTransparency = 1
  69. Frame.Selectable = true
  70. Frame.Size = UDim2.new(0, 646, 0, 419)
  71.  
  72. Properties.Name = "Properties"
  73. Properties.Parent = Frame
  74. Properties.BackgroundColor3 = Color3.new(1, 1, 0)
  75. Properties.BackgroundTransparency = 0.10000000149012
  76. Properties.Position = UDim2.new(0.111916594, 0, 0.121442124, 0)
  77. Properties.Size = UDim2.new(0, 266, 0, 355)
  78.  
  79. TextButton4.Name = "TextButton4"
  80. TextButton4.Parent = Properties
  81. TextButton4.BackgroundColor3 = Color3.new(1, 1, 0)
  82. TextButton4.Position = UDim2.new(-0.0349922925, 0, 0.125925601, 0)
  83. TextButton4.Size = UDim2.new(0, 271, 0, 26)
  84. TextButton4.Font = Enum.Font.SourceSans
  85. TextButton4.Text = "ZephMidnight's Doggo GUI"
  86. TextButton4.TextColor3 = Color3.new(0, 0, 0)
  87. TextButton4.TextScaled = true
  88. TextButton4.TextSize = 14
  89. TextButton4.TextWrapped = true
  90.  
  91. TextButton2.Name = "TextButton2"
  92. TextButton2.Parent = Properties
  93. TextButton2.BackgroundColor3 = Color3.new(1, 1, 0)
  94. TextButton2.Position = UDim2.new(-0.0610094443, 0, 0.0701576695, 0)
  95. TextButton2.Size = UDim2.new(0, 279, 0, 25)
  96. TextButton2.Font = Enum.Font.SourceSans
  97. TextButton2.Text = "Xester"
  98. TextButton2.TextColor3 = Color3.new(0, 0, 0)
  99. TextButton2.TextScaled = true
  100. TextButton2.TextSize = 14
  101. TextButton2.TextWrapped = true
  102.  
  103. TextButton3.Name = "TextButton3"
  104. TextButton3.Parent = Properties
  105. TextButton3.BackgroundColor3 = Color3.new(1, 1, 0)
  106. TextButton3.Position = UDim2.new(-0.0351415277, 0, 0.0996287316, 0)
  107. TextButton3.Size = UDim2.new(0, 271, 0, 22)
  108. TextButton3.Font = Enum.Font.SourceSans
  109. TextButton3.Text = "Bad"
  110. TextButton3.TextColor3 = Color3.new(0, 0, 0)
  111. TextButton3.TextScaled = true
  112. TextButton3.TextSize = 14
  113. TextButton3.TextWrapped = true
  114.  
  115. TextButton5.Name = "TextButton5"
  116. TextButton5.Parent = Properties
  117. TextButton5.BackgroundColor3 = Color3.new(1, 1, 0)
  118. TextButton5.Position = UDim2.new(-0.0318299979, 0, 0.158103436, 0)
  119. TextButton5.Size = UDim2.new(0, 271, 0, 22)
  120. TextButton5.Font = Enum.Font.SourceSans
  121. TextButton5.Text = "Fallen Anger"
  122. TextButton5.TextColor3 = Color3.new(0, 0, 0)
  123. TextButton5.TextScaled = true
  124. TextButton5.TextSize = 14
  125. TextButton5.TextWrapped = true
  126.  
  127. TextButton1.Name = "TextButton1"
  128. TextButton1.Parent = Properties
  129. TextButton1.BackgroundColor3 = Color3.new(1, 1, 0)
  130. TextButton1.Position = UDim2.new(-0.0940410644, 0, 0.036961548, 0)
  131. TextButton1.Size = UDim2.new(0, 288, 0, 27)
  132. TextButton1.Font = Enum.Font.SourceSans
  133. TextButton1.Text = "Noot Noot"
  134. TextButton1.TextColor3 = Color3.new(0, 0, 0)
  135. TextButton1.TextScaled = true
  136. TextButton1.TextSize = 14
  137. TextButton1.TextWrapped = true
  138.  
  139. TextButton6.Name = "TextButton6"
  140. TextButton6.Parent = Properties
  141. TextButton6.BackgroundColor3 = Color3.new(1, 1, 0)
  142. TextButton6.Position = UDim2.new(-0.0258679222, 0, 0.185488552, 0)
  143. TextButton6.Size = UDim2.new(0, 268, 0, 25)
  144. TextButton6.Font = Enum.Font.SourceSans
  145. TextButton6.Text = "Joshua_Dent's Spare Kick"
  146. TextButton6.TextColor3 = Color3.new(0, 0, 0)
  147. TextButton6.TextScaled = true
  148. TextButton6.TextSize = 14
  149. TextButton6.TextWrapped = true
  150.  
  151. TextLabel.Parent = Properties
  152. TextLabel.BackgroundColor3 = Color3.new(1, 0.294118, 0.294118)
  153. TextLabel.BackgroundTransparency = 0.20000000298023
  154. TextLabel.Position = UDim2.new(-0.00716845877, 0, -0.227270052, 0)
  155. TextLabel.Size = UDim2.new(0, 278, 0, 50)
  156. TextLabel.Font = Enum.Font.Cartoon
  157. TextLabel.Text = "LeEpicMegaTrollingGUI V2.10"
  158. TextLabel.TextColor3 = Color3.new(0, 0, 0)
  159. TextLabel.TextScaled = true
  160. TextLabel.TextSize = 14
  161. TextLabel.TextWrapped = true
  162.  
  163. TextButton7.Name = "TextButton7"
  164. TextButton7.Parent = Properties
  165. TextButton7.BackgroundColor3 = Color3.new(1, 1, 0)
  166. TextButton7.Position = UDim2.new(-0.0202532783, 0, 0.215961039, 0)
  167. TextButton7.Size = UDim2.new(0, 271, 0, 26)
  168. TextButton7.Font = Enum.Font.SourceSans
  169. TextButton7.Text = "Anti Filter"
  170. TextButton7.TextColor3 = Color3.new(0, 0, 0)
  171. TextButton7.TextScaled = true
  172. TextButton7.TextSize = 14
  173. TextButton7.TextWrapped = true
  174.  
  175. TextButton8.Name = "TextButton8"
  176. TextButton8.Parent = Properties
  177. TextButton8.BackgroundColor3 = Color3.new(1, 1, 0)
  178. TextButton8.Position = UDim2.new(-0.0166431703, 0, 0.247788876, 0)
  179. TextButton8.Size = UDim2.new(0, 271, 0, 26)
  180. TextButton8.Font = Enum.Font.SourceSans
  181. TextButton8.Text = "Force Chat"
  182. TextButton8.TextColor3 = Color3.new(0, 0, 0)
  183. TextButton8.TextScaled = true
  184. TextButton8.TextSize = 14
  185. TextButton8.TextWrapped = true
  186.  
  187. TextButton9.Name = "TextButton9"
  188. TextButton9.Parent = Properties
  189. TextButton9.BackgroundColor3 = Color3.new(1, 1, 0)
  190. TextButton9.Position = UDim2.new(-0.0279213656, 0, 0.279518783, 0)
  191. TextButton9.Size = UDim2.new(0, 271, 0, 26)
  192. TextButton9.Font = Enum.Font.SourceSans
  193. TextButton9.Text = "Plauge Doctor"
  194. TextButton9.TextColor3 = Color3.new(0, 0, 0)
  195. TextButton9.TextScaled = true
  196. TextButton9.TextSize = 14
  197. TextButton9.TextWrapped = true
  198.  
  199. TextButton10.Name = "TextButton10"
  200. TextButton10.Parent = Properties
  201. TextButton10.BackgroundColor3 = Color3.new(1, 1, 0)
  202. TextButton10.Position = UDim2.new(-0.0389009789, 0, 0.31134665, 0)
  203. TextButton10.Size = UDim2.new(0, 271, 0, 26)
  204. TextButton10.Font = Enum.Font.SourceSans
  205. TextButton10.Text = "Star Glitcher"
  206. TextButton10.TextColor3 = Color3.new(0, 0, 0)
  207. TextButton10.TextScaled = true
  208. TextButton10.TextSize = 14
  209. TextButton10.TextWrapped = true
  210.  
  211. TextButton11.Name = "TextButton11"
  212. TextButton11.Parent = Properties
  213. TextButton11.BackgroundColor3 = Color3.new(1, 1, 0)
  214. TextButton11.Position = UDim2.new(-0.0238633864, 0, 0.341981173, 0)
  215. TextButton11.Size = UDim2.new(0, 271, 0, 26)
  216. TextButton11.Font = Enum.Font.SourceSans
  217. TextButton11.Text = "Nebula Star Glitcher"
  218. TextButton11.TextColor3 = Color3.new(0, 0, 0)
  219. TextButton11.TextScaled = true
  220. TextButton11.TextSize = 14
  221. TextButton11.TextWrapped = true
  222.  
  223. TextButton12.Name = "TextButton12"
  224. TextButton12.Parent = Properties
  225. TextButton12.BackgroundColor3 = Color3.new(1, 1, 0)
  226. TextButton12.Position = UDim2.new(-0.0237140972, 0, 0.37380898, 0)
  227. TextButton12.Size = UDim2.new(0, 271, 0, 26)
  228. TextButton12.Font = Enum.Font.SourceSans
  229. TextButton12.Text = "Cop"
  230. TextButton12.TextColor3 = Color3.new(0, 0, 0)
  231. TextButton12.TextScaled = true
  232. TextButton12.TextSize = 14
  233. TextButton12.TextWrapped = true
  234.  
  235. TextButton13.Name = "TextButton13"
  236. TextButton13.Parent = Properties
  237. TextButton13.BackgroundColor3 = Color3.new(1, 1, 0)
  238. TextButton13.Position = UDim2.new(-0.0199546982, 0, 0.405636817, 0)
  239. TextButton13.Size = UDim2.new(0, 271, 0, 26)
  240. TextButton13.Font = Enum.Font.SourceSans
  241. TextButton13.Text = "Joseph & Elementals Killbot"
  242. TextButton13.TextColor3 = Color3.new(0, 0, 0)
  243. TextButton13.TextScaled = true
  244. TextButton13.TextSize = 14
  245. TextButton13.TextWrapped = true
  246.  
  247. TextButton14.Name = "TextButton14"
  248. TextButton14.Parent = Properties
  249. TextButton14.BackgroundColor3 = Color3.new(1, 1, 0)
  250. TextButton14.Position = UDim2.new(-0.0199546982, 0, 0.437464654, 0)
  251. TextButton14.Size = UDim2.new(0, 271, 0, 26)
  252. TextButton14.Font = Enum.Font.SourceSans
  253. TextButton14.Text = "Joshua_Dent's John Doe"
  254. TextButton14.TextColor3 = Color3.new(0, 0, 0)
  255. TextButton14.TextScaled = true
  256. TextButton14.TextSize = 14
  257. TextButton14.TextWrapped = true
  258.  
  259. TextButton15.Name = "TextButton15"
  260. TextButton15.Parent = Properties
  261. TextButton15.BackgroundColor3 = Color3.new(1, 1, 0)
  262. TextButton15.Position = UDim2.new(-0.0348430015, 0, 0.469047934, 0)
  263. TextButton15.Size = UDim2.new(0, 271, 0, 26)
  264. TextButton15.Font = Enum.Font.SourceSans
  265. TextButton15.Text = "Karacius' Kitchen Gun"
  266. TextButton15.TextColor3 = Color3.new(0, 0, 0)
  267. TextButton15.TextScaled = true
  268. TextButton15.TextSize = 14
  269. TextButton15.TextWrapped = true
  270.  
  271. TextButton16.Name = "TextButton16"
  272. TextButton16.Parent = Properties
  273. TextButton16.BackgroundColor3 = Color3.new(1, 1, 0)
  274. TextButton16.Position = UDim2.new(-0.0348430015, 0, 0.500875771, 0)
  275. TextButton16.Size = UDim2.new(0, 271, 0, 26)
  276. TextButton16.Font = Enum.Font.SourceSans
  277. TextButton16.Text = "Pan"
  278. TextButton16.TextColor3 = Color3.new(0, 0, 0)
  279. TextButton16.TextScaled = true
  280. TextButton16.TextSize = 14
  281. TextButton16.TextWrapped = true
  282.  
  283. TextButton17.Name = "TextButton17"
  284. TextButton17.Parent = Properties
  285. TextButton17.BackgroundColor3 = Color3.new(1, 1, 0)
  286. TextButton17.Position = UDim2.new(-0.0386024006, 0, 0.532703578, 0)
  287. TextButton17.Size = UDim2.new(0, 271, 0, 26)
  288. TextButton17.Font = Enum.Font.SourceSans
  289. TextButton17.Text = "Joshua's Cloud"
  290. TextButton17.TextColor3 = Color3.new(0, 0, 0)
  291. TextButton17.TextScaled = true
  292. TextButton17.TextSize = 14
  293. TextButton17.TextWrapped = true
  294.  
  295. TextButton18.Name = "TextButton18"
  296. TextButton18.Parent = Properties
  297. TextButton18.BackgroundColor3 = Color3.new(1, 1, 0)
  298. TextButton18.Position = UDim2.new(-0.0235648062, 0, 0.564531446, 0)
  299. TextButton18.Size = UDim2.new(0, 271, 0, 26)
  300. TextButton18.Font = Enum.Font.SourceSans
  301. TextButton18.Text = "Chara X"
  302. TextButton18.TextColor3 = Color3.new(0, 0, 0)
  303. TextButton18.TextScaled = true
  304. TextButton18.TextSize = 14
  305. TextButton18.TextWrapped = true
  306.  
  307. TextButton19.Name = "TextButton19"
  308. TextButton19.Parent = Properties
  309. TextButton19.BackgroundColor3 = Color3.new(1, 1, 0)
  310. TextButton19.Position = UDim2.new(-0.0277720746, 0, 0.596785605, 0)
  311. TextButton19.Size = UDim2.new(0, 271, 0, 26)
  312. TextButton19.Font = Enum.Font.SourceSans
  313. TextButton19.Text = "Doritos"
  314. TextButton19.TextColor3 = Color3.new(0, 0, 0)
  315. TextButton19.TextScaled = true
  316. TextButton19.TextSize = 14
  317. TextButton19.TextWrapped = true
  318.  
  319. TextButton20.Name = "TextButton20"
  320. TextButton20.Parent = Properties
  321. TextButton20.BackgroundColor3 = Color3.new(1, 1, 0)
  322. TextButton20.Position = UDim2.new(-0.0277720746, 0, 0.628613412, 0)
  323. TextButton20.Size = UDim2.new(0, 271, 0, 26)
  324. TextButton20.Font = Enum.Font.SourceSans
  325. TextButton20.Text = "Suicide"
  326. TextButton20.TextColor3 = Color3.new(0, 0, 0)
  327. TextButton20.TextScaled = true
  328. TextButton20.TextSize = 14
  329. TextButton20.TextWrapped = true
  330.  
  331. TextButton21.Name = "TextButton21"
  332. TextButton21.Parent = Properties
  333. TextButton21.BackgroundColor3 = Color3.new(1, 1, 0)
  334. TextButton21.Position = UDim2.new(-0.0352908708, 0, 0.660441279, 0)
  335. TextButton21.Size = UDim2.new(0, 271, 0, 26)
  336. TextButton21.Font = Enum.Font.SourceSans
  337. TextButton21.Text = "Calamity"
  338. TextButton21.TextColor3 = Color3.new(0, 0, 0)
  339. TextButton21.TextScaled = true
  340. TextButton21.TextSize = 14
  341. TextButton21.TextWrapped = true
  342.  
  343. TextButton22.Name = "TextButton22"
  344. TextButton22.Parent = Properties
  345. TextButton22.BackgroundColor3 = Color3.new(1, 1, 0)
  346. TextButton22.Position = UDim2.new(-0.0277720764, 0, 0.691780031, 0)
  347. TextButton22.Size = UDim2.new(0, 271, 0, 26)
  348. TextButton22.Font = Enum.Font.SourceSans
  349. TextButton22.Text = "Joshua_Dent's Black Demon"
  350. TextButton22.TextColor3 = Color3.new(0, 0, 0)
  351. TextButton22.TextScaled = true
  352. TextButton22.TextSize = 14
  353. TextButton22.TextWrapped = true
  354.  
  355. TextButton23.Name = "TextButton23"
  356. TextButton23.Parent = Properties
  357. TextButton23.BackgroundColor3 = Color3.new(1, 1, 0)
  358. TextButton23.Position = UDim2.new(-0.0315314718, 0, 0.723607838, 0)
  359. TextButton23.Size = UDim2.new(0, 271, 0, 26)
  360. TextButton23.Font = Enum.Font.SourceSans
  361. TextButton23.Text = "Karacius' Server Admin"
  362. TextButton23.TextColor3 = Color3.new(0, 0, 0)
  363. TextButton23.TextScaled = true
  364. TextButton23.TextSize = 14
  365. TextButton23.TextWrapped = true
  366.  
  367. TextButton24.Name = "TextButton24"
  368. TextButton24.Parent = Properties
  369. TextButton24.BackgroundColor3 = Color3.new(1, 1, 0)
  370. TextButton24.Position = UDim2.new(-0.0277720746, 0, 0.755435705, 0)
  371. TextButton24.Size = UDim2.new(0, 271, 0, 26)
  372. TextButton24.Font = Enum.Font.SourceSans
  373. TextButton24.Text = "Big Ban"
  374. TextButton24.TextColor3 = Color3.new(1, 0, 0)
  375. TextButton24.TextScaled = true
  376. TextButton24.TextSize = 14
  377. TextButton24.TextWrapped = true
  378.  
  379. TextButton25.Name = "TextButton25"
  380. TextButton25.Parent = Properties
  381. TextButton25.BackgroundColor3 = Color3.new(1, 1, 0)
  382. TextButton25.Position = UDim2.new(-0.0352908708, 0, 0.787263513, 0)
  383. TextButton25.Size = UDim2.new(0, 271, 0, 26)
  384. TextButton25.Font = Enum.Font.SourceSans
  385. TextButton25.Text = "Dex"
  386. TextButton25.TextColor3 = Color3.new(0, 0, 0)
  387. TextButton25.TextScaled = true
  388. TextButton25.TextSize = 14
  389. TextButton25.TextWrapped = true
  390.  
  391. EEEEE.Name = "EEEEE"
  392. EEEEE.Parent = Frame
  393. EEEEE.BackgroundColor3 = Color3.new(1, 1, 0)
  394. EEEEE.Position = UDim2.new(0.522484779, 0, 0.118964285, 0)
  395. EEEEE.Selectable = true
  396. EEEEE.Size = UDim2.new(0, 319, 0, 356)
  397.  
  398. Execute.Name = "Execute"
  399. Execute.Parent = EEEEE
  400. Execute.BackgroundColor3 = Color3.new(1, 0.294118, 0.294118)
  401. Execute.Position = UDim2.new(0.183322221, 0, 0.516644001, 0)
  402. Execute.Size = UDim2.new(0, 200, 0, 50)
  403. Execute.Font = Enum.Font.SourceSans
  404. Execute.Text = "Execute"
  405. Execute.TextColor3 = Color3.new(0, 0, 0)
  406. Execute.TextScaled = true
  407. Execute.TextSize = 14
  408. Execute.TextWrapped = true
  409.  
  410. TextBox.Parent = EEEEE
  411. TextBox.BackgroundColor3 = Color3.new(1, 1, 0)
  412. TextBox.Position = UDim2.new(-7.72027779e-05, 0, 0.00105612457, 0)
  413. TextBox.Size = UDim2.new(0, 319, 0, 107)
  414. TextBox.ClearTextOnFocus = false
  415. TextBox.Font = Enum.Font.SourceSans
  416. TextBox.Text = "Place Text Here"
  417. TextBox.TextColor3 = Color3.new(0, 0, 0)
  418. TextBox.TextScaled = true
  419. TextBox.TextSize = 14
  420. TextBox.TextWrapped = true
  421.  
  422. TextButton.Parent = EEEEE
  423. TextButton.BackgroundColor3 = Color3.new(1, 0.294118, 0.294118)
  424. TextButton.Position = UDim2.new(0.18295145, 0, 0.686538577, 0)
  425. TextButton.Size = UDim2.new(0, 200, 0, 50)
  426. TextButton.Font = Enum.Font.SourceSans
  427. TextButton.Text = "Clear"
  428. TextButton.TextColor3 = Color3.new(0, 0, 0)
  429. TextButton.TextScaled = true
  430. TextButton.TextSize = 14
  431. TextButton.TextWrapped = true
  432.  
  433. Framedodo.Name = "Framedodo"
  434. Framedodo.Parent = SS
  435. Framedodo.BackgroundColor3 = Color3.new(1, 1, 1)
  436. Framedodo.Position = UDim2.new(0.836146951, 0, 0.33141908, 0)
  437. Framedodo.Size = UDim2.new(0, 100, 0, 99)
  438.  
  439. Frame_2.Parent = Framedodo
  440. Frame_2.BackgroundColor3 = Color3.new(1, 1, 1)
  441. Frame_2.Size = UDim2.new(0, 100, 0, 100)
  442.  
  443. TextButton_2.Parent = Frame_2
  444. TextButton_2.BackgroundColor3 = Color3.new(1, 1, 1)
  445. TextButton_2.Size = UDim2.new(0, 100, 0, 100)
  446. TextButton_2.Font = Enum.Font.SourceSans
  447. TextButton_2.Text = "GUI"
  448. TextButton_2.TextColor3 = Color3.new(0, 0, 0)
  449. TextButton_2.TextScaled = true
  450. TextButton_2.TextSize = 14
  451. TextButton_2.TextWrapped = true
  452.  
  453. LuaK.Parent = Loadstring
  454.  
  455. Script.Parent = Execute
  456.  
  457. Loadstring.Parent = Script
  458.  
  459. LuaP.Parent = Loadstring
  460. LuaU.Parent = Loadstring
  461. LuaX.Parent = Loadstring
  462. LuaY.Parent = Loadstring
  463. LuaZ.Parent = Loadstring
  464. Rerubi.Parent = Loadstring
  465. LocalScript.Parent = Execute
  466. MSFunction.Parent = Execute
  467.  
  468. --[[
  469. Scripts:
  470. --]]
  471. local function yeet()
  472. local script = LuaK
  473. --[[--------------------------------------------------------------------
  474.  
  475. lcode.lua
  476. Lua 5 code generator in Lua
  477. This file is part of Yueliang.
  478.  
  479. Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
  480. The COPYRIGHT file describes the conditions
  481. under which this software may be distributed.
  482.  
  483. See the ChangeLog for more information.
  484.  
  485. ----------------------------------------------------------------------]]
  486.  
  487. --[[--------------------------------------------------------------------
  488. -- Notes:
  489. -- * one function manipulate a pointer argument with a simple data type
  490. -- (can't be emulated by a table, ambiguous), now returns that value:
  491. -- luaK:concat(fs, l1, l2)
  492. -- * luaM_growvector uses the faux luaY:growvector, for limit checking
  493. -- * some function parameters changed to boolean, additional code
  494. -- translates boolean back to 1/0 for instruction fields
  495. --
  496. -- Not implemented:
  497. -- * NOTE there is a failed assert in luaK:addk, a porting problem
  498. --
  499. -- Added:
  500. -- * constant MAXSTACK from llimits.h
  501. -- * luaK:ttisnumber(o) (from lobject.h)
  502. -- * luaK:nvalue(o) (from lobject.h)
  503. -- * luaK:setnilvalue(o) (from lobject.h)
  504. -- * luaK:setnvalue(o, x) (from lobject.h)
  505. -- * luaK:setbvalue(o, x) (from lobject.h)
  506. -- * luaK:sethvalue(o, x) (from lobject.h), parameter L deleted
  507. -- * luaK:setsvalue(o, x) (from lobject.h), parameter L deleted
  508. -- * luaK:numadd, luaK:numsub, luaK:nummul, luaK:numdiv, luaK:nummod,
  509. -- luaK:numpow, luaK:numunm, luaK:numisnan (from luaconf.h)
  510. -- * copyexp(e1, e2) added in luaK:posfix to copy expdesc struct
  511. --
  512. -- Changed in 5.1.x:
  513. -- * enum BinOpr has a new entry, OPR_MOD
  514. -- * enum UnOpr has a new entry, OPR_LEN
  515. -- * binopistest, unused in 5.0.x, has been deleted
  516. -- * macro setmultret is new
  517. -- * functions isnumeral, luaK_ret, boolK are new
  518. -- * funcion nilK was named nil_constant in 5.0.x
  519. -- * function interface changed: need_value, patchtestreg, concat
  520. -- * TObject now a TValue
  521. -- * functions luaK_setreturns, luaK_setoneret are new
  522. -- * function luaK:setcallreturns deleted, to be replaced by:
  523. -- luaK:setmultret, luaK:ret, luaK:setreturns, luaK:setoneret
  524. -- * functions constfolding, codearith, codecomp are new
  525. -- * luaK:codebinop has been deleted
  526. -- * function luaK_setlist is new
  527. -- * OPR_MULT renamed to OPR_MUL
  528. ----------------------------------------------------------------------]]
  529.  
  530. -- requires luaP, luaX, luaY
  531. local luaK = {}
  532. local luaP = require(script.Parent.LuaP)
  533. local luaX = require(script.Parent.LuaX)
  534.  
  535. ------------------------------------------------------------------------
  536. -- constants used by code generator
  537. ------------------------------------------------------------------------
  538. -- maximum stack for a Lua function
  539. luaK.MAXSTACK = 250 -- (from llimits.h)
  540.  
  541. --[[--------------------------------------------------------------------
  542. -- other functions
  543. ----------------------------------------------------------------------]]
  544.  
  545. ------------------------------------------------------------------------
  546. -- emulation of TValue macros (these are from lobject.h)
  547. -- * TValue is a table since lcode passes references around
  548. -- * tt member field removed, using Lua's type() instead
  549. -- * for setsvalue, sethvalue, parameter L (deleted here) in lobject.h
  550. -- is used in an assert for testing, see checkliveness(g,obj)
  551. ------------------------------------------------------------------------
  552. function luaK:ttisnumber(o)
  553. if o then return type(o.value) == "number" else return false end
  554. end
  555. function luaK:nvalue(o) return o.value end
  556. function luaK:setnilvalue(o) o.value = nil end
  557. function luaK:setsvalue(o, x) o.value = x end
  558. luaK.setnvalue = luaK.setsvalue
  559. luaK.sethvalue = luaK.setsvalue
  560. luaK.setbvalue = luaK.setsvalue
  561.  
  562. ------------------------------------------------------------------------
  563. -- The luai_num* macros define the primitive operations over numbers.
  564. -- * this is not the entire set of primitive operations from luaconf.h
  565. -- * used in luaK:constfolding()
  566. ------------------------------------------------------------------------
  567. function luaK:numadd(a, b) return a + b end
  568. function luaK:numsub(a, b) return a - b end
  569. function luaK:nummul(a, b) return a * b end
  570. function luaK:numdiv(a, b) return a / b end
  571. function luaK:nummod(a, b) return a % b end
  572. -- ((a) - floor((a)/(b))*(b)) /* actual, for reference */
  573. function luaK:numpow(a, b) return a ^ b end
  574. function luaK:numunm(a) return -a end
  575. function luaK:numisnan(a) return not a == a end
  576. -- a NaN cannot equal another NaN
  577.  
  578. --[[--------------------------------------------------------------------
  579. -- code generator functions
  580. ----------------------------------------------------------------------]]
  581.  
  582. ------------------------------------------------------------------------
  583. -- Marks the end of a patch list. It is an invalid value both as an absolute
  584. -- address, and as a list link (would link an element to itself).
  585. ------------------------------------------------------------------------
  586. luaK.NO_JUMP = -1
  587.  
  588. ------------------------------------------------------------------------
  589. -- grep "ORDER OPR" if you change these enums
  590. ------------------------------------------------------------------------
  591. luaK.BinOpr = {
  592. OPR_ADD = 0, OPR_SUB = 1, OPR_MUL = 2, OPR_DIV = 3, OPR_MOD = 4, OPR_POW = 5,
  593. OPR_CONCAT = 6,
  594. OPR_NE = 7, OPR_EQ = 8,
  595. OPR_LT = 9, OPR_LE = 10, OPR_GT = 11, OPR_GE = 12,
  596. OPR_AND = 13, OPR_OR = 14,
  597. OPR_NOBINOPR = 15,
  598. }
  599.  
  600. -- * UnOpr is used by luaK:prefix's op argument, but not directly used
  601. -- because the function receives the symbols as strings, e.g. "OPR_NOT"
  602. luaK.UnOpr = {
  603. OPR_MINUS = 0, OPR_NOT = 1, OPR_LEN = 2, OPR_NOUNOPR = 3
  604. }
  605.  
  606. ------------------------------------------------------------------------
  607. -- returns the instruction object for given e (expdesc), was a macro
  608. ------------------------------------------------------------------------
  609. function luaK:getcode(fs, e)
  610. return fs.f.code[e.info]
  611. end
  612.  
  613. ------------------------------------------------------------------------
  614. -- codes an instruction with a signed Bx (sBx) field, was a macro
  615. -- * used in luaK:jump(), (lparser) luaY:forbody()
  616. ------------------------------------------------------------------------
  617. function luaK:codeAsBx(fs, o, A, sBx)
  618. return self:codeABx(fs, o, A, sBx + luaP.MAXARG_sBx)
  619. end
  620.  
  621. ------------------------------------------------------------------------
  622. -- set the expdesc e instruction for multiple returns, was a macro
  623. ------------------------------------------------------------------------
  624. function luaK:setmultret(fs, e)
  625. self:setreturns(fs, e, luaY.LUA_MULTRET)
  626. end
  627.  
  628. ------------------------------------------------------------------------
  629. -- there is a jump if patch lists are not identical, was a macro
  630. -- * used in luaK:exp2reg(), luaK:exp2anyreg(), luaK:exp2val()
  631. ------------------------------------------------------------------------
  632. function luaK:hasjumps(e)
  633. return e.t ~= e.f
  634. end
  635.  
  636. ------------------------------------------------------------------------
  637. -- true if the expression is a constant number (for constant folding)
  638. -- * used in constfolding(), infix()
  639. ------------------------------------------------------------------------
  640. function luaK:isnumeral(e)
  641. return e.k == "VKNUM" and e.t == self.NO_JUMP and e.f == self.NO_JUMP
  642. end
  643.  
  644. ------------------------------------------------------------------------
  645. -- codes loading of nil, optimization done if consecutive locations
  646. -- * used in luaK:discharge2reg(), (lparser) luaY:adjust_assign()
  647. ------------------------------------------------------------------------
  648. function luaK:_nil(fs, from, n)
  649. if fs.pc > fs.lasttarget then -- no jumps to current position?
  650. if fs.pc == 0 then -- function start?
  651. if from >= fs.nactvar then
  652. return -- positions are already clean
  653. end
  654. else
  655. local previous = fs.f.code[fs.pc - 1]
  656. if luaP:GET_OPCODE(previous) == "OP_LOADNIL" then
  657. local pfrom = luaP:GETARG_A(previous)
  658. local pto = luaP:GETARG_B(previous)
  659. if pfrom <= from and from <= pto + 1 then -- can connect both?
  660. if from + n - 1 > pto then
  661. luaP:SETARG_B(previous, from + n - 1)
  662. end
  663. return
  664. end
  665. end
  666. end
  667. end
  668. self:codeABC(fs, "OP_LOADNIL", from, from + n - 1, 0) -- else no optimization
  669. end
  670.  
  671. ------------------------------------------------------------------------
  672. --
  673. -- * used in multiple locations
  674. ------------------------------------------------------------------------
  675. function luaK:jump(fs)
  676. local jpc = fs.jpc -- save list of jumps to here
  677. fs.jpc = self.NO_JUMP
  678. local j = self:codeAsBx(fs, "OP_JMP", 0, self.NO_JUMP)
  679. j = self:concat(fs, j, jpc) -- keep them on hold
  680. return j
  681. end
  682.  
  683. ------------------------------------------------------------------------
  684. -- codes a RETURN instruction
  685. -- * used in luaY:close_func(), luaY:retstat()
  686. ------------------------------------------------------------------------
  687. function luaK:ret(fs, first, nret)
  688. self:codeABC(fs, "OP_RETURN", first, nret + 1, 0)
  689. end
  690.  
  691. ------------------------------------------------------------------------
  692. --
  693. -- * used in luaK:jumponcond(), luaK:codecomp()
  694. ------------------------------------------------------------------------
  695. function luaK:condjump(fs, op, A, B, C)
  696. self:codeABC(fs, op, A, B, C)
  697. return self:jump(fs)
  698. end
  699.  
  700. ------------------------------------------------------------------------
  701. --
  702. -- * used in luaK:patchlistaux(), luaK:concat()
  703. ------------------------------------------------------------------------
  704. function luaK:fixjump(fs, pc, dest)
  705. local jmp = fs.f.code[pc]
  706. local offset = dest - (pc + 1)
  707. assert(dest ~= self.NO_JUMP)
  708. if math.abs(offset) > luaP.MAXARG_sBx then
  709. luaX:syntaxerror(fs.ls, "control structure too long")
  710. end
  711. luaP:SETARG_sBx(jmp, offset)
  712. end
  713.  
  714. ------------------------------------------------------------------------
  715. -- returns current 'pc' and marks it as a jump target (to avoid wrong
  716. -- optimizations with consecutive instructions not in the same basic block).
  717. -- * used in multiple locations
  718. -- * fs.lasttarget tested only by luaK:_nil() when optimizing OP_LOADNIL
  719. ------------------------------------------------------------------------
  720. function luaK:getlabel(fs)
  721. fs.lasttarget = fs.pc
  722. return fs.pc
  723. end
  724.  
  725. ------------------------------------------------------------------------
  726. --
  727. -- * used in luaK:need_value(), luaK:removevalues(), luaK:patchlistaux(),
  728. -- luaK:concat()
  729. ------------------------------------------------------------------------
  730. function luaK:getjump(fs, pc)
  731. local offset = luaP:GETARG_sBx(fs.f.code[pc])
  732. if offset == self.NO_JUMP then -- point to itself represents end of list
  733. return self.NO_JUMP -- end of list
  734. else
  735. return (pc + 1) + offset -- turn offset into absolute position
  736. end
  737. end
  738.  
  739. ------------------------------------------------------------------------
  740. --
  741. -- * used in luaK:need_value(), luaK:patchtestreg(), luaK:invertjump()
  742. ------------------------------------------------------------------------
  743. function luaK:getjumpcontrol(fs, pc)
  744. local pi = fs.f.code[pc]
  745. local ppi = fs.f.code[pc - 1]
  746. if pc >= 1 and luaP:testTMode(luaP:GET_OPCODE(ppi)) ~= 0 then
  747. return ppi
  748. else
  749. return pi
  750. end
  751. end
  752.  
  753. ------------------------------------------------------------------------
  754. -- check whether list has any jump that do not produce a value
  755. -- (or produce an inverted value)
  756. -- * return value changed to boolean
  757. -- * used only in luaK:exp2reg()
  758. ------------------------------------------------------------------------
  759. function luaK:need_value(fs, list)
  760. while list ~= self.NO_JUMP do
  761. local i = self:getjumpcontrol(fs, list)
  762. if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then return true end
  763. list = self:getjump(fs, list)
  764. end
  765. return false -- not found
  766. end
  767.  
  768. ------------------------------------------------------------------------
  769. --
  770. -- * used in luaK:removevalues(), luaK:patchlistaux()
  771. ------------------------------------------------------------------------
  772. function luaK:patchtestreg(fs, node, reg)
  773. local i = self:getjumpcontrol(fs, node)
  774. if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then
  775. return false -- cannot patch other instructions
  776. end
  777. if reg ~= luaP.NO_REG and reg ~= luaP:GETARG_B(i) then
  778. luaP:SETARG_A(i, reg)
  779. else -- no register to put value or register already has the value
  780. -- due to use of a table as i, i cannot be replaced by another table
  781. -- so the following is required; there is no change to ARG_C
  782. luaP:SET_OPCODE(i, "OP_TEST")
  783. local b = luaP:GETARG_B(i)
  784. luaP:SETARG_A(i, b)
  785. luaP:SETARG_B(i, 0)
  786. -- *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); /* C */
  787. end
  788. return true
  789. end
  790.  
  791. ------------------------------------------------------------------------
  792. --
  793. -- * used only in luaK:codenot()
  794. ------------------------------------------------------------------------
  795. function luaK:removevalues(fs, list)
  796. while list ~= self.NO_JUMP do
  797. self:patchtestreg(fs, list, luaP.NO_REG)
  798. list = self:getjump(fs, list)
  799. end
  800. end
  801.  
  802. ------------------------------------------------------------------------
  803. --
  804. -- * used in luaK:dischargejpc(), luaK:patchlist(), luaK:exp2reg()
  805. ------------------------------------------------------------------------
  806. function luaK:patchlistaux(fs, list, vtarget, reg, dtarget)
  807. while list ~= self.NO_JUMP do
  808. local _next = self:getjump(fs, list)
  809. if self:patchtestreg(fs, list, reg) then
  810. self:fixjump(fs, list, vtarget)
  811. else
  812. self:fixjump(fs, list, dtarget) -- jump to default target
  813. end
  814. list = _next
  815. end
  816. end
  817.  
  818. ------------------------------------------------------------------------
  819. --
  820. -- * used only in luaK:code()
  821. ------------------------------------------------------------------------
  822. function luaK:dischargejpc(fs)
  823. self:patchlistaux(fs, fs.jpc, fs.pc, luaP.NO_REG, fs.pc)
  824. fs.jpc = self.NO_JUMP
  825. end
  826.  
  827. ------------------------------------------------------------------------
  828. --
  829. -- * used in (lparser) luaY:whilestat(), luaY:repeatstat(), luaY:forbody()
  830. ------------------------------------------------------------------------
  831. function luaK:patchlist(fs, list, target)
  832. if target == fs.pc then
  833. self:patchtohere(fs, list)
  834. else
  835. assert(target < fs.pc)
  836. self:patchlistaux(fs, list, target, luaP.NO_REG, target)
  837. end
  838. end
  839.  
  840. ------------------------------------------------------------------------
  841. --
  842. -- * used in multiple locations
  843. ------------------------------------------------------------------------
  844. function luaK:patchtohere(fs, list)
  845. self:getlabel(fs)
  846. fs.jpc = self:concat(fs, fs.jpc, list)
  847. end
  848.  
  849. ------------------------------------------------------------------------
  850. -- * l1 was a pointer, now l1 is returned and callee assigns the value
  851. -- * used in multiple locations
  852. ------------------------------------------------------------------------
  853. function luaK:concat(fs, l1, l2)
  854. if l2 == self.NO_JUMP then return l1
  855. elseif l1 == self.NO_JUMP then
  856. return l2
  857. else
  858. local list = l1
  859. local _next = self:getjump(fs, list)
  860. while _next ~= self.NO_JUMP do -- find last element
  861. list = _next
  862. _next = self:getjump(fs, list)
  863. end
  864. self:fixjump(fs, list, l2)
  865. end
  866. return l1
  867. end
  868.  
  869. ------------------------------------------------------------------------
  870. --
  871. -- * used in luaK:reserveregs(), (lparser) luaY:forlist()
  872. ------------------------------------------------------------------------
  873. function luaK:checkstack(fs, n)
  874. local newstack = fs.freereg + n
  875. if newstack > fs.f.maxstacksize then
  876. if newstack >= self.MAXSTACK then
  877. luaX:syntaxerror(fs.ls, "function or expression too complex")
  878. end
  879. fs.f.maxstacksize = newstack
  880. end
  881. end
  882.  
  883. ------------------------------------------------------------------------
  884. --
  885. -- * used in multiple locations
  886. ------------------------------------------------------------------------
  887. function luaK:reserveregs(fs, n)
  888. self:checkstack(fs, n)
  889. fs.freereg = fs.freereg + n
  890. end
  891.  
  892. ------------------------------------------------------------------------
  893. --
  894. -- * used in luaK:freeexp(), luaK:dischargevars()
  895. ------------------------------------------------------------------------
  896. function luaK:freereg(fs, reg)
  897. if not luaP:ISK(reg) and reg >= fs.nactvar then
  898. fs.freereg = fs.freereg - 1
  899. assert(reg == fs.freereg)
  900. end
  901. end
  902.  
  903. ------------------------------------------------------------------------
  904. --
  905. -- * used in multiple locations
  906. ------------------------------------------------------------------------
  907. function luaK:freeexp(fs, e)
  908. if e.k == "VNONRELOC" then
  909. self:freereg(fs, e.info)
  910. end
  911. end
  912.  
  913. ------------------------------------------------------------------------
  914. -- * TODO NOTE implementation is not 100% correct, since the assert fails
  915. -- * luaH_set, setobj deleted; direct table access used instead
  916. -- * used in luaK:stringK(), luaK:numberK(), luaK:boolK(), luaK:nilK()
  917. ------------------------------------------------------------------------
  918. function luaK:addk(fs, k, v)
  919. local L = fs.L
  920. local idx = fs.h[k.value]
  921. --TValue *idx = luaH_set(L, fs->h, k); /* C */
  922. local f = fs.f
  923. if self:ttisnumber(idx) then
  924. --TODO this assert currently FAILS (last tested for 5.0.2)
  925. --assert(fs.f.k[self:nvalue(idx)] == v)
  926. --assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); /* C */
  927. return self:nvalue(idx)
  928. else -- constant not found; create a new entry
  929. idx = {}
  930. self:setnvalue(idx, fs.nk)
  931. fs.h[k.value] = idx
  932. -- setnvalue(idx, cast_num(fs->nk)); /* C */
  933. luaY:growvector(L, f.k, fs.nk, f.sizek, nil,
  934. luaP.MAXARG_Bx, "constant table overflow")
  935. -- loop to initialize empty f.k positions not required
  936. f.k[fs.nk] = v
  937. -- setobj(L, &f->k[fs->nk], v); /* C */
  938. -- luaC_barrier(L, f, v); /* GC */
  939. local nk = fs.nk
  940. fs.nk = fs.nk + 1
  941. return nk
  942. end
  943.  
  944. end
  945.  
  946. ------------------------------------------------------------------------
  947. -- creates and sets a string object
  948. -- * used in (lparser) luaY:codestring(), luaY:singlevar()
  949. ------------------------------------------------------------------------
  950. function luaK:stringK(fs, s)
  951. local o = {} -- TValue
  952. self:setsvalue(o, s)
  953. return self:addk(fs, o, o)
  954. end
  955.  
  956. ------------------------------------------------------------------------
  957. -- creates and sets a number object
  958. -- * used in luaK:prefix() for negative (or negation of) numbers
  959. -- * used in (lparser) luaY:simpleexp(), luaY:fornum()
  960. ------------------------------------------------------------------------
  961. function luaK:numberK(fs, r)
  962. local o = {} -- TValue
  963. self:setnvalue(o, r)
  964. return self:addk(fs, o, o)
  965. end
  966.  
  967. ------------------------------------------------------------------------
  968. -- creates and sets a boolean object
  969. -- * used only in luaK:exp2RK()
  970. ------------------------------------------------------------------------
  971. function luaK:boolK(fs, b)
  972. local o = {} -- TValue
  973. self:setbvalue(o, b)
  974. return self:addk(fs, o, o)
  975. end
  976.  
  977. ------------------------------------------------------------------------
  978. -- creates and sets a nil object
  979. -- * used only in luaK:exp2RK()
  980. ------------------------------------------------------------------------
  981. function luaK:nilK(fs)
  982. local k, v = {}, {} -- TValue
  983. self:setnilvalue(v)
  984. -- cannot use nil as key; instead use table itself to represent nil
  985. self:sethvalue(k, fs.h)
  986. return self:addk(fs, k, v)
  987. end
  988.  
  989. ------------------------------------------------------------------------
  990. --
  991. -- * used in luaK:setmultret(), (lparser) luaY:adjust_assign()
  992. ------------------------------------------------------------------------
  993. function luaK:setreturns(fs, e, nresults)
  994. if e.k == "VCALL" then -- expression is an open function call?
  995. luaP:SETARG_C(self:getcode(fs, e), nresults + 1)
  996. elseif e.k == "VVARARG" then
  997. luaP:SETARG_B(self:getcode(fs, e), nresults + 1);
  998. luaP:SETARG_A(self:getcode(fs, e), fs.freereg);
  999. luaK:reserveregs(fs, 1)
  1000. end
  1001. end
  1002.  
  1003. ------------------------------------------------------------------------
  1004. --
  1005. -- * used in luaK:dischargevars(), (lparser) luaY:assignment()
  1006. ------------------------------------------------------------------------
  1007. function luaK:setoneret(fs, e)
  1008. if e.k == "VCALL" then -- expression is an open function call?
  1009. e.k = "VNONRELOC"
  1010. e.info = luaP:GETARG_A(self:getcode(fs, e))
  1011. elseif e.k == "VVARARG" then
  1012. luaP:SETARG_B(self:getcode(fs, e), 2)
  1013. e.k = "VRELOCABLE" -- can relocate its simple result
  1014. end
  1015. end
  1016.  
  1017. ------------------------------------------------------------------------
  1018. --
  1019. -- * used in multiple locations
  1020. ------------------------------------------------------------------------
  1021. function luaK:dischargevars(fs, e)
  1022. local k = e.k
  1023. if k == "VLOCAL" then
  1024. e.k = "VNONRELOC"
  1025. elseif k == "VUPVAL" then
  1026. e.info = self:codeABC(fs, "OP_GETUPVAL", 0, e.info, 0)
  1027. e.k = "VRELOCABLE"
  1028. elseif k == "VGLOBAL" then
  1029. e.info = self:codeABx(fs, "OP_GETGLOBAL", 0, e.info)
  1030. e.k = "VRELOCABLE"
  1031. elseif k == "VINDEXED" then
  1032. self:freereg(fs, e.aux)
  1033. self:freereg(fs, e.info)
  1034. e.info = self:codeABC(fs, "OP_GETTABLE", 0, e.info, e.aux)
  1035. e.k = "VRELOCABLE"
  1036. elseif k == "VVARARG" or k == "VCALL" then
  1037. self:setoneret(fs, e)
  1038. else
  1039. -- there is one value available (somewhere)
  1040. end
  1041. end
  1042.  
  1043. ------------------------------------------------------------------------
  1044. --
  1045. -- * used only in luaK:exp2reg()
  1046. ------------------------------------------------------------------------
  1047. function luaK:code_label(fs, A, b, jump)
  1048. self:getlabel(fs) -- those instructions may be jump targets
  1049. return self:codeABC(fs, "OP_LOADBOOL", A, b, jump)
  1050. end
  1051.  
  1052. ------------------------------------------------------------------------
  1053. --
  1054. -- * used in luaK:discharge2anyreg(), luaK:exp2reg()
  1055. ------------------------------------------------------------------------
  1056. function luaK:discharge2reg(fs, e, reg)
  1057. self:dischargevars(fs, e)
  1058. local k = e.k
  1059. if k == "VNIL" then
  1060. self:_nil(fs, reg, 1)
  1061. elseif k == "VFALSE" or k == "VTRUE" then
  1062. self:codeABC(fs, "OP_LOADBOOL", reg, (e.k == "VTRUE") and 1 or 0, 0)
  1063. elseif k == "VK" then
  1064. self:codeABx(fs, "OP_LOADK", reg, e.info)
  1065. elseif k == "VKNUM" then
  1066. self:codeABx(fs, "OP_LOADK", reg, self:numberK(fs, e.nval))
  1067. elseif k == "VRELOCABLE" then
  1068. local pc = self:getcode(fs, e)
  1069. luaP:SETARG_A(pc, reg)
  1070. elseif k == "VNONRELOC" then
  1071. if reg ~= e.info then
  1072. self:codeABC(fs, "OP_MOVE", reg, e.info, 0)
  1073. end
  1074. else
  1075. assert(e.k == "VVOID" or e.k == "VJMP")
  1076. return -- nothing to do...
  1077. end
  1078. e.info = reg
  1079. e.k = "VNONRELOC"
  1080. end
  1081.  
  1082. ------------------------------------------------------------------------
  1083. --
  1084. -- * used in luaK:jumponcond(), luaK:codenot()
  1085. ------------------------------------------------------------------------
  1086. function luaK:discharge2anyreg(fs, e)
  1087. if e.k ~= "VNONRELOC" then
  1088. self:reserveregs(fs, 1)
  1089. self:discharge2reg(fs, e, fs.freereg - 1)
  1090. end
  1091. end
  1092.  
  1093. ------------------------------------------------------------------------
  1094. --
  1095. -- * used in luaK:exp2nextreg(), luaK:exp2anyreg(), luaK:storevar()
  1096. ------------------------------------------------------------------------
  1097. function luaK:exp2reg(fs, e, reg)
  1098. self:discharge2reg(fs, e, reg)
  1099. if e.k == "VJMP" then
  1100. e.t = self:concat(fs, e.t, e.info) -- put this jump in 't' list
  1101. end
  1102. if self:hasjumps(e) then
  1103. local final -- position after whole expression
  1104. local p_f = self.NO_JUMP -- position of an eventual LOAD false
  1105. local p_t = self.NO_JUMP -- position of an eventual LOAD true
  1106. if self:need_value(fs, e.t) or self:need_value(fs, e.f) then
  1107. local fj = (e.k == "VJMP") and self.NO_JUMP or self:jump(fs)
  1108. p_f = self:code_label(fs, reg, 0, 1)
  1109. p_t = self:code_label(fs, reg, 1, 0)
  1110. self:patchtohere(fs, fj)
  1111. end
  1112. final = self:getlabel(fs)
  1113. self:patchlistaux(fs, e.f, final, reg, p_f)
  1114. self:patchlistaux(fs, e.t, final, reg, p_t)
  1115. end
  1116. e.f, e.t = self.NO_JUMP, self.NO_JUMP
  1117. e.info = reg
  1118. e.k = "VNONRELOC"
  1119. end
  1120.  
  1121. ------------------------------------------------------------------------
  1122. --
  1123. -- * used in multiple locations
  1124. ------------------------------------------------------------------------
  1125. function luaK:exp2nextreg(fs, e)
  1126. self:dischargevars(fs, e)
  1127. self:freeexp(fs, e)
  1128. self:reserveregs(fs, 1)
  1129. self:exp2reg(fs, e, fs.freereg - 1)
  1130. end
  1131.  
  1132. ------------------------------------------------------------------------
  1133. --
  1134. -- * used in multiple locations
  1135. ------------------------------------------------------------------------
  1136. function luaK:exp2anyreg(fs, e)
  1137. self:dischargevars(fs, e)
  1138. if e.k == "VNONRELOC" then
  1139. if not self:hasjumps(e) then -- exp is already in a register
  1140. return e.info
  1141. end
  1142. if e.info >= fs.nactvar then -- reg. is not a local?
  1143. self:exp2reg(fs, e, e.info) -- put value on it
  1144. return e.info
  1145. end
  1146. end
  1147. self:exp2nextreg(fs, e) -- default
  1148. return e.info
  1149. end
  1150.  
  1151. ------------------------------------------------------------------------
  1152. --
  1153. -- * used in luaK:exp2RK(), luaK:prefix(), luaK:posfix()
  1154. -- * used in (lparser) luaY:yindex()
  1155. ------------------------------------------------------------------------
  1156. function luaK:exp2val(fs, e)
  1157. if self:hasjumps(e) then
  1158. self:exp2anyreg(fs, e)
  1159. else
  1160. self:dischargevars(fs, e)
  1161. end
  1162. end
  1163.  
  1164. ------------------------------------------------------------------------
  1165. --
  1166. -- * used in multiple locations
  1167. ------------------------------------------------------------------------
  1168. function luaK:exp2RK(fs, e)
  1169. self:exp2val(fs, e)
  1170. local k = e.k
  1171. if k == "VKNUM" or k == "VTRUE" or k == "VFALSE" or k == "VNIL" then
  1172. if fs.nk <= luaP.MAXINDEXRK then -- constant fit in RK operand?
  1173. -- converted from a 2-deep ternary operator expression
  1174. if e.k == "VNIL" then
  1175. e.info = self:nilK(fs)
  1176. else
  1177. e.info = (e.k == "VKNUM") and self:numberK(fs, e.nval)
  1178. or self:boolK(fs, e.k == "VTRUE")
  1179. end
  1180. e.k = "VK"
  1181. return luaP:RKASK(e.info)
  1182. end
  1183. elseif k == "VK" then
  1184. if e.info <= luaP.MAXINDEXRK then -- constant fit in argC?
  1185. return luaP:RKASK(e.info)
  1186. end
  1187. else
  1188. -- default
  1189. end
  1190. -- not a constant in the right range: put it in a register
  1191. return self:exp2anyreg(fs, e)
  1192. end
  1193.  
  1194. ------------------------------------------------------------------------
  1195. --
  1196. -- * used in (lparser) luaY:assignment(), luaY:localfunc(), luaY:funcstat()
  1197. ------------------------------------------------------------------------
  1198. function luaK:storevar(fs, var, ex)
  1199. local k = var.k
  1200. if k == "VLOCAL" then
  1201. self:freeexp(fs, ex)
  1202. self:exp2reg(fs, ex, var.info)
  1203. return
  1204. elseif k == "VUPVAL" then
  1205. local e = self:exp2anyreg(fs, ex)
  1206. self:codeABC(fs, "OP_SETUPVAL", e, var.info, 0)
  1207. elseif k == "VGLOBAL" then
  1208. local e = self:exp2anyreg(fs, ex)
  1209. self:codeABx(fs, "OP_SETGLOBAL", e, var.info)
  1210. elseif k == "VINDEXED" then
  1211. local e = self:exp2RK(fs, ex)
  1212. self:codeABC(fs, "OP_SETTABLE", var.info, var.aux, e)
  1213. else
  1214. assert(0) -- invalid var kind to store
  1215. end
  1216. self:freeexp(fs, ex)
  1217. end
  1218.  
  1219. ------------------------------------------------------------------------
  1220. --
  1221. -- * used only in (lparser) luaY:primaryexp()
  1222. ------------------------------------------------------------------------
  1223. function luaK:_self(fs, e, key)
  1224. self:exp2anyreg(fs, e)
  1225. self:freeexp(fs, e)
  1226. local func = fs.freereg
  1227. self:reserveregs(fs, 2)
  1228. self:codeABC(fs, "OP_SELF", func, e.info, self:exp2RK(fs, key))
  1229. self:freeexp(fs, key)
  1230. e.info = func
  1231. e.k = "VNONRELOC"
  1232. end
  1233.  
  1234. ------------------------------------------------------------------------
  1235. --
  1236. -- * used in luaK:goiftrue(), luaK:codenot()
  1237. ------------------------------------------------------------------------
  1238. function luaK:invertjump(fs, e)
  1239. local pc = self:getjumpcontrol(fs, e.info)
  1240. assert(luaP:testTMode(luaP:GET_OPCODE(pc)) ~= 0 and
  1241. luaP:GET_OPCODE(pc) ~= "OP_TESTSET" and
  1242. luaP:GET_OPCODE(pc) ~= "OP_TEST")
  1243. luaP:SETARG_A(pc, (luaP:GETARG_A(pc) == 0) and 1 or 0)
  1244. end
  1245.  
  1246. ------------------------------------------------------------------------
  1247. --
  1248. -- * used in luaK:goiftrue(), luaK:goiffalse()
  1249. ------------------------------------------------------------------------
  1250. function luaK:jumponcond(fs, e, cond)
  1251. if e.k == "VRELOCABLE" then
  1252. local ie = self:getcode(fs, e)
  1253. if luaP:GET_OPCODE(ie) == "OP_NOT" then
  1254. fs.pc = fs.pc - 1 -- remove previous OP_NOT
  1255. return self:condjump(fs, "OP_TEST", luaP:GETARG_B(ie), 0, cond and 0 or 1)
  1256. end
  1257. -- else go through
  1258. end
  1259. self:discharge2anyreg(fs, e)
  1260. self:freeexp(fs, e)
  1261. return self:condjump(fs, "OP_TESTSET", luaP.NO_REG, e.info, cond and 1 or 0)
  1262. end
  1263.  
  1264. ------------------------------------------------------------------------
  1265. --
  1266. -- * used in luaK:infix(), (lparser) luaY:cond()
  1267. ------------------------------------------------------------------------
  1268. function luaK:goiftrue(fs, e)
  1269. local pc -- pc of last jump
  1270. self:dischargevars(fs, e)
  1271. local k = e.k
  1272. if k == "VK" or k == "VKNUM" or k == "VTRUE" then
  1273. pc = self.NO_JUMP -- always true; do nothing
  1274. elseif k == "VFALSE" then
  1275. pc = self:jump(fs) -- always jump
  1276. elseif k == "VJMP" then
  1277. self:invertjump(fs, e)
  1278. pc = e.info
  1279. else
  1280. pc = self:jumponcond(fs, e, false)
  1281. end
  1282. e.f = self:concat(fs, e.f, pc) -- insert last jump in `f' list
  1283. self:patchtohere(fs, e.t)
  1284. e.t = self.NO_JUMP
  1285. end
  1286.  
  1287. ------------------------------------------------------------------------
  1288. --
  1289. -- * used in luaK:infix()
  1290. ------------------------------------------------------------------------
  1291. function luaK:goiffalse(fs, e)
  1292. local pc -- pc of last jump
  1293. self:dischargevars(fs, e)
  1294. local k = e.k
  1295. if k == "VNIL" or k == "VFALSE"then
  1296. pc = self.NO_JUMP -- always false; do nothing
  1297. elseif k == "VTRUE" then
  1298. pc = self:jump(fs) -- always jump
  1299. elseif k == "VJMP" then
  1300. pc = e.info
  1301. else
  1302. pc = self:jumponcond(fs, e, true)
  1303. end
  1304. e.t = self:concat(fs, e.t, pc) -- insert last jump in `t' list
  1305. self:patchtohere(fs, e.f)
  1306. e.f = self.NO_JUMP
  1307. end
  1308.  
  1309. ------------------------------------------------------------------------
  1310. --
  1311. -- * used only in luaK:prefix()
  1312. ------------------------------------------------------------------------
  1313. function luaK:codenot(fs, e)
  1314. self:dischargevars(fs, e)
  1315. local k = e.k
  1316. if k == "VNIL" or k == "VFALSE" then
  1317. e.k = "VTRUE"
  1318. elseif k == "VK" or k == "VKNUM" or k == "VTRUE" then
  1319. e.k = "VFALSE"
  1320. elseif k == "VJMP" then
  1321. self:invertjump(fs, e)
  1322. elseif k == "VRELOCABLE" or k == "VNONRELOC" then
  1323. self:discharge2anyreg(fs, e)
  1324. self:freeexp(fs, e)
  1325. e.info = self:codeABC(fs, "OP_NOT", 0, e.info, 0)
  1326. e.k = "VRELOCABLE"
  1327. else
  1328. assert(0) -- cannot happen
  1329. end
  1330. -- interchange true and false lists
  1331. e.f, e.t = e.t, e.f
  1332. self:removevalues(fs, e.f)
  1333. self:removevalues(fs, e.t)
  1334. end
  1335.  
  1336. ------------------------------------------------------------------------
  1337. --
  1338. -- * used in (lparser) luaY:field(), luaY:primaryexp()
  1339. ------------------------------------------------------------------------
  1340. function luaK:indexed(fs, t, k)
  1341. t.aux = self:exp2RK(fs, k)
  1342. t.k = "VINDEXED"
  1343. end
  1344.  
  1345. ------------------------------------------------------------------------
  1346. --
  1347. -- * used only in luaK:codearith()
  1348. ------------------------------------------------------------------------
  1349. function luaK:constfolding(op, e1, e2)
  1350. local r
  1351. if not self:isnumeral(e1) or not self:isnumeral(e2) then return false end
  1352. local v1 = e1.nval
  1353. local v2 = e2.nval
  1354. if op == "OP_ADD" then
  1355. r = self:numadd(v1, v2)
  1356. elseif op == "OP_SUB" then
  1357. r = self:numsub(v1, v2)
  1358. elseif op == "OP_MUL" then
  1359. r = self:nummul(v1, v2)
  1360. elseif op == "OP_DIV" then
  1361. if v2 == 0 then return false end -- do not attempt to divide by 0
  1362. r = self:numdiv(v1, v2)
  1363. elseif op == "OP_MOD" then
  1364. if v2 == 0 then return false end -- do not attempt to divide by 0
  1365. r = self:nummod(v1, v2)
  1366. elseif op == "OP_POW" then
  1367. r = self:numpow(v1, v2)
  1368. elseif op == "OP_UNM" then
  1369. r = self:numunm(v1)
  1370. elseif op == "OP_LEN" then
  1371. return false -- no constant folding for 'len'
  1372. else
  1373. assert(0)
  1374. r = 0
  1375. end
  1376. if self:numisnan(r) then return false end -- do not attempt to produce NaN
  1377. e1.nval = r
  1378. return true
  1379. end
  1380.  
  1381. ------------------------------------------------------------------------
  1382. --
  1383. -- * used in luaK:prefix(), luaK:posfix()
  1384. ------------------------------------------------------------------------
  1385. function luaK:codearith(fs, op, e1, e2)
  1386. if self:constfolding(op, e1, e2) then
  1387. return
  1388. else
  1389. local o2 = (op ~= "OP_UNM" and op ~= "OP_LEN") and self:exp2RK(fs, e2) or 0
  1390. local o1 = self:exp2RK(fs, e1)
  1391. if o1 > o2 then
  1392. self:freeexp(fs, e1)
  1393. self:freeexp(fs, e2)
  1394. else
  1395. self:freeexp(fs, e2)
  1396. self:freeexp(fs, e1)
  1397. end
  1398. e1.info = self:codeABC(fs, op, 0, o1, o2)
  1399. e1.k = "VRELOCABLE"
  1400. end
  1401. end
  1402.  
  1403. ------------------------------------------------------------------------
  1404. --
  1405. -- * used only in luaK:posfix()
  1406. ------------------------------------------------------------------------
  1407. function luaK:codecomp(fs, op, cond, e1, e2)
  1408. local o1 = self:exp2RK(fs, e1)
  1409. local o2 = self:exp2RK(fs, e2)
  1410. self:freeexp(fs, e2)
  1411. self:freeexp(fs, e1)
  1412. if cond == 0 and op ~= "OP_EQ" then
  1413. -- exchange args to replace by `<' or `<='
  1414. o1, o2 = o2, o1 -- o1 <==> o2
  1415. cond = 1
  1416. end
  1417. e1.info = self:condjump(fs, op, cond, o1, o2)
  1418. e1.k = "VJMP"
  1419. end
  1420.  
  1421. ------------------------------------------------------------------------
  1422. --
  1423. -- * used only in (lparser) luaY:subexpr()
  1424. ------------------------------------------------------------------------
  1425. function luaK:prefix(fs, op, e)
  1426. local e2 = {} -- expdesc
  1427. e2.t, e2.f = self.NO_JUMP, self.NO_JUMP
  1428. e2.k = "VKNUM"
  1429. e2.nval = 0
  1430. if op == "OPR_MINUS" then
  1431. if not self:isnumeral(e) then
  1432. self:exp2anyreg(fs, e) -- cannot operate on non-numeric constants
  1433. end
  1434. self:codearith(fs, "OP_UNM", e, e2)
  1435. elseif op == "OPR_NOT" then
  1436. self:codenot(fs, e)
  1437. elseif op == "OPR_LEN" then
  1438. self:exp2anyreg(fs, e) -- cannot operate on constants
  1439. self:codearith(fs, "OP_LEN", e, e2)
  1440. else
  1441. assert(0)
  1442. end
  1443. end
  1444.  
  1445. ------------------------------------------------------------------------
  1446. --
  1447. -- * used only in (lparser) luaY:subexpr()
  1448. ------------------------------------------------------------------------
  1449. function luaK:infix(fs, op, v)
  1450. if op == "OPR_AND" then
  1451. self:goiftrue(fs, v)
  1452. elseif op == "OPR_OR" then
  1453. self:goiffalse(fs, v)
  1454. elseif op == "OPR_CONCAT" then
  1455. self:exp2nextreg(fs, v) -- operand must be on the 'stack'
  1456. elseif op == "OPR_ADD" or op == "OPR_SUB" or
  1457. op == "OPR_MUL" or op == "OPR_DIV" or
  1458. op == "OPR_MOD" or op == "OPR_POW" then
  1459. if not self:isnumeral(v) then self:exp2RK(fs, v) end
  1460. else
  1461. self:exp2RK(fs, v)
  1462. end
  1463. end
  1464.  
  1465. ------------------------------------------------------------------------
  1466. --
  1467. -- * used only in (lparser) luaY:subexpr()
  1468. ------------------------------------------------------------------------
  1469. -- table lookups to simplify testing
  1470. luaK.arith_op = {
  1471. OPR_ADD = "OP_ADD", OPR_SUB = "OP_SUB", OPR_MUL = "OP_MUL",
  1472. OPR_DIV = "OP_DIV", OPR_MOD = "OP_MOD", OPR_POW = "OP_POW",
  1473. }
  1474. luaK.comp_op = {
  1475. OPR_EQ = "OP_EQ", OPR_NE = "OP_EQ", OPR_LT = "OP_LT",
  1476. OPR_LE = "OP_LE", OPR_GT = "OP_LT", OPR_GE = "OP_LE",
  1477. }
  1478. luaK.comp_cond = {
  1479. OPR_EQ = 1, OPR_NE = 0, OPR_LT = 1,
  1480. OPR_LE = 1, OPR_GT = 0, OPR_GE = 0,
  1481. }
  1482. function luaK:posfix(fs, op, e1, e2)
  1483. -- needed because e1 = e2 doesn't copy values...
  1484. -- * in 5.0.x, only k/info/aux/t/f copied, t for AND, f for OR
  1485. -- but here, all elements are copied for completeness' sake
  1486. local function copyexp(e1, e2)
  1487. e1.k = e2.k
  1488. e1.info = e2.info; e1.aux = e2.aux
  1489. e1.nval = e2.nval
  1490. e1.t = e2.t; e1.f = e2.f
  1491. end
  1492. if op == "OPR_AND" then
  1493. assert(e1.t == self.NO_JUMP) -- list must be closed
  1494. self:dischargevars(fs, e2)
  1495. e2.f = self:concat(fs, e2.f, e1.f)
  1496. copyexp(e1, e2)
  1497. elseif op == "OPR_OR" then
  1498. assert(e1.f == self.NO_JUMP) -- list must be closed
  1499. self:dischargevars(fs, e2)
  1500. e2.t = self:concat(fs, e2.t, e1.t)
  1501. copyexp(e1, e2)
  1502. elseif op == "OPR_CONCAT" then
  1503. self:exp2val(fs, e2)
  1504. if e2.k == "VRELOCABLE" and luaP:GET_OPCODE(self:getcode(fs, e2)) == "OP_CONCAT" then
  1505. assert(e1.info == luaP:GETARG_B(self:getcode(fs, e2)) - 1)
  1506. self:freeexp(fs, e1)
  1507. luaP:SETARG_B(self:getcode(fs, e2), e1.info)
  1508. e1.k = "VRELOCABLE"
  1509. e1.info = e2.info
  1510. else
  1511. self:exp2nextreg(fs, e2) -- operand must be on the 'stack'
  1512. self:codearith(fs, "OP_CONCAT", e1, e2)
  1513. end
  1514. else
  1515. -- the following uses a table lookup in place of conditionals
  1516. local arith = self.arith_op[op]
  1517. if arith then
  1518. self:codearith(fs, arith, e1, e2)
  1519. else
  1520. local comp = self.comp_op[op]
  1521. if comp then
  1522. self:codecomp(fs, comp, self.comp_cond[op], e1, e2)
  1523. else
  1524. assert(0)
  1525. end
  1526. end--if arith
  1527. end--if op
  1528. end
  1529.  
  1530. ------------------------------------------------------------------------
  1531. -- adjusts debug information for last instruction written, in order to
  1532. -- change the line where item comes into existence
  1533. -- * used in (lparser) luaY:funcargs(), luaY:forbody(), luaY:funcstat()
  1534. ------------------------------------------------------------------------
  1535. function luaK:fixline(fs, line)
  1536. fs.f.lineinfo[fs.pc - 1] = line
  1537. end
  1538.  
  1539. ------------------------------------------------------------------------
  1540. -- general function to write an instruction into the instruction buffer,
  1541. -- sets debug information too
  1542. -- * used in luaK:codeABC(), luaK:codeABx()
  1543. -- * called directly by (lparser) luaY:whilestat()
  1544. ------------------------------------------------------------------------
  1545. function luaK:code(fs, i, line)
  1546. local f = fs.f
  1547. self:dischargejpc(fs) -- 'pc' will change
  1548. -- put new instruction in code array
  1549. luaY:growvector(fs.L, f.code, fs.pc, f.sizecode, nil,
  1550. luaY.MAX_INT, "code size overflow")
  1551. f.code[fs.pc] = i
  1552. -- save corresponding line information
  1553. luaY:growvector(fs.L, f.lineinfo, fs.pc, f.sizelineinfo, nil,
  1554. luaY.MAX_INT, "code size overflow")
  1555. f.lineinfo[fs.pc] = line
  1556. local pc = fs.pc
  1557. fs.pc = fs.pc + 1
  1558. return pc
  1559. end
  1560.  
  1561. ------------------------------------------------------------------------
  1562. -- writes an instruction of type ABC
  1563. -- * calls luaK:code()
  1564. ------------------------------------------------------------------------
  1565. function luaK:codeABC(fs, o, a, b, c)
  1566. assert(luaP:getOpMode(o) == luaP.OpMode.iABC)
  1567. assert(luaP:getBMode(o) ~= luaP.OpArgMask.OpArgN or b == 0)
  1568. assert(luaP:getCMode(o) ~= luaP.OpArgMask.OpArgN or c == 0)
  1569. return self:code(fs, luaP:CREATE_ABC(o, a, b, c), fs.ls.lastline)
  1570. end
  1571.  
  1572. ------------------------------------------------------------------------
  1573. -- writes an instruction of type ABx
  1574. -- * calls luaK:code(), called by luaK:codeAsBx()
  1575. ------------------------------------------------------------------------
  1576. function luaK:codeABx(fs, o, a, bc)
  1577. assert(luaP:getOpMode(o) == luaP.OpMode.iABx or
  1578. luaP:getOpMode(o) == luaP.OpMode.iAsBx)
  1579. assert(luaP:getCMode(o) == luaP.OpArgMask.OpArgN)
  1580. return self:code(fs, luaP:CREATE_ABx(o, a, bc), fs.ls.lastline)
  1581. end
  1582.  
  1583. ------------------------------------------------------------------------
  1584. --
  1585. -- * used in (lparser) luaY:closelistfield(), luaY:lastlistfield()
  1586. ------------------------------------------------------------------------
  1587. function luaK:setlist(fs, base, nelems, tostore)
  1588. local c = math.floor((nelems - 1)/luaP.LFIELDS_PER_FLUSH) + 1
  1589. local b = (tostore == luaY.LUA_MULTRET) and 0 or tostore
  1590. assert(tostore ~= 0)
  1591. if c <= luaP.MAXARG_C then
  1592. self:codeABC(fs, "OP_SETLIST", base, b, c)
  1593. else
  1594. self:codeABC(fs, "OP_SETLIST", base, b, 0)
  1595. self:code(fs, luaP:CREATE_Inst(c), fs.ls.lastline)
  1596. end
  1597. fs.freereg = base + 1 -- free registers with list values
  1598. end
  1599.  
  1600. return function(a) luaY = a return luaK end
  1601. end
  1602. coroutine.wrap(yeet)
  1603.  
  1604. local function YEAOT()
  1605. local script = LuaP
  1606. --[[--------------------------------------------------------------------
  1607.  
  1608. lopcodes.lua
  1609. Lua 5 virtual machine opcodes in Lua
  1610. This file is part of Yueliang.
  1611.  
  1612. Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
  1613. The COPYRIGHT file describes the conditions
  1614. under which this software may be distributed.
  1615.  
  1616. See the ChangeLog for more information.
  1617.  
  1618. ----------------------------------------------------------------------]]
  1619.  
  1620. --[[--------------------------------------------------------------------
  1621. -- Notes:
  1622. -- * an Instruction is a table with OP, A, B, C, Bx elements; this
  1623. -- makes the code easy to follow and should allow instruction handling
  1624. -- to work with doubles and ints
  1625. -- * WARNING luaP:Instruction outputs instructions encoded in little-
  1626. -- endian form and field size and positions are hard-coded
  1627. --
  1628. -- Not implemented:
  1629. -- *
  1630. --
  1631. -- Added:
  1632. -- * luaP:CREATE_Inst(c): create an inst from a number (for OP_SETLIST)
  1633. -- * luaP:Instruction(i): convert field elements to a 4-char string
  1634. -- * luaP:DecodeInst(x): convert 4-char string into field elements
  1635. --
  1636. -- Changed in 5.1.x:
  1637. -- * POS_OP added, instruction field positions changed
  1638. -- * some symbol names may have changed, e.g. LUAI_BITSINT
  1639. -- * new operators for RK indices: BITRK, ISK(x), INDEXK(r), RKASK(x)
  1640. -- * OP_MOD, OP_LEN is new
  1641. -- * OP_TEST is now OP_TESTSET, OP_TEST is new
  1642. -- * OP_FORLOOP, OP_TFORLOOP adjusted, OP_FORPREP is new
  1643. -- * OP_TFORPREP deleted
  1644. -- * OP_SETLIST and OP_SETLISTO merged and extended
  1645. -- * OP_VARARG is new
  1646. -- * many changes to implementation of OpMode data
  1647. ----------------------------------------------------------------------]]
  1648.  
  1649. local luaP = {}
  1650.  
  1651. --[[
  1652. ===========================================================================
  1653. We assume that instructions are unsigned numbers.
  1654. All instructions have an opcode in the first 6 bits.
  1655. Instructions can have the following fields:
  1656. 'A' : 8 bits
  1657. 'B' : 9 bits
  1658. 'C' : 9 bits
  1659. 'Bx' : 18 bits ('B' and 'C' together)
  1660. 'sBx' : signed Bx
  1661.  
  1662. A signed argument is represented in excess K; that is, the number
  1663. value is the unsigned value minus K. K is exactly the maximum value
  1664. for that argument (so that -max is represented by 0, and +max is
  1665. represented by 2*max), which is half the maximum for the corresponding
  1666. unsigned argument.
  1667. ===========================================================================
  1668. --]]
  1669.  
  1670. luaP.OpMode = { iABC = 0, iABx = 1, iAsBx = 2 } -- basic instruction format
  1671.  
  1672. ------------------------------------------------------------------------
  1673. -- size and position of opcode arguments.
  1674. -- * WARNING size and position is hard-coded elsewhere in this script
  1675. ------------------------------------------------------------------------
  1676. luaP.SIZE_C = 9
  1677. luaP.SIZE_B = 9
  1678. luaP.SIZE_Bx = luaP.SIZE_C + luaP.SIZE_B
  1679. luaP.SIZE_A = 8
  1680.  
  1681. luaP.SIZE_OP = 6
  1682.  
  1683. luaP.POS_OP = 0
  1684. luaP.POS_A = luaP.POS_OP + luaP.SIZE_OP
  1685. luaP.POS_C = luaP.POS_A + luaP.SIZE_A
  1686. luaP.POS_B = luaP.POS_C + luaP.SIZE_C
  1687. luaP.POS_Bx = luaP.POS_C
  1688.  
  1689. ------------------------------------------------------------------------
  1690. -- limits for opcode arguments.
  1691. -- we use (signed) int to manipulate most arguments,
  1692. -- so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
  1693. ------------------------------------------------------------------------
  1694. -- removed "#if SIZE_Bx < BITS_INT-1" test, assume this script is
  1695. -- running on a Lua VM with double or int as LUA_NUMBER
  1696.  
  1697. luaP.MAXARG_Bx = math.ldexp(1, luaP.SIZE_Bx) - 1
  1698. luaP.MAXARG_sBx = math.floor(luaP.MAXARG_Bx / 2) -- 'sBx' is signed
  1699.  
  1700. luaP.MAXARG_A = math.ldexp(1, luaP.SIZE_A) - 1
  1701. luaP.MAXARG_B = math.ldexp(1, luaP.SIZE_B) - 1
  1702. luaP.MAXARG_C = math.ldexp(1, luaP.SIZE_C) - 1
  1703.  
  1704. -- creates a mask with 'n' 1 bits at position 'p'
  1705. -- MASK1(n,p) deleted, not required
  1706. -- creates a mask with 'n' 0 bits at position 'p'
  1707. -- MASK0(n,p) deleted, not required
  1708.  
  1709. --[[--------------------------------------------------------------------
  1710. Visual representation for reference:
  1711.  
  1712. 31 | | | 0 bit position
  1713. +-----+-----+-----+----------+
  1714. | B | C | A | Opcode | iABC format
  1715. +-----+-----+-----+----------+
  1716. - 9 - 9 - 8 - 6 - field sizes
  1717. +-----+-----+-----+----------+
  1718. | [s]Bx | A | Opcode | iABx | iAsBx format
  1719. +-----+-----+-----+----------+
  1720.  
  1721. ----------------------------------------------------------------------]]
  1722.  
  1723. ------------------------------------------------------------------------
  1724. -- the following macros help to manipulate instructions
  1725. -- * changed to a table object representation, very clean compared to
  1726. -- the [nightmare] alternatives of using a number or a string
  1727. -- * Bx is a separate element from B and C, since there is never a need
  1728. -- to split Bx in the parser or code generator
  1729. ------------------------------------------------------------------------
  1730.  
  1731. -- these accept or return opcodes in the form of string names
  1732. function luaP:GET_OPCODE(i) return self.ROpCode[i.OP] end
  1733. function luaP:SET_OPCODE(i, o) i.OP = self.OpCode[o] end
  1734.  
  1735. function luaP:GETARG_A(i) return i.A end
  1736. function luaP:SETARG_A(i, u) i.A = u end
  1737.  
  1738. function luaP:GETARG_B(i) return i.B end
  1739. function luaP:SETARG_B(i, b) i.B = b end
  1740.  
  1741. function luaP:GETARG_C(i) return i.C end
  1742. function luaP:SETARG_C(i, b) i.C = b end
  1743.  
  1744. function luaP:GETARG_Bx(i) return i.Bx end
  1745. function luaP:SETARG_Bx(i, b) i.Bx = b end
  1746.  
  1747. function luaP:GETARG_sBx(i) return i.Bx - self.MAXARG_sBx end
  1748. function luaP:SETARG_sBx(i, b) i.Bx = b + self.MAXARG_sBx end
  1749.  
  1750. function luaP:CREATE_ABC(o,a,b,c)
  1751. return {OP = self.OpCode[o], A = a, B = b, C = c}
  1752. end
  1753.  
  1754. function luaP:CREATE_ABx(o,a,bc)
  1755. return {OP = self.OpCode[o], A = a, Bx = bc}
  1756. end
  1757.  
  1758. ------------------------------------------------------------------------
  1759. -- create an instruction from a number (for OP_SETLIST)
  1760. ------------------------------------------------------------------------
  1761. function luaP:CREATE_Inst(c)
  1762. local o = c % 64
  1763. c = (c - o) / 64
  1764. local a = c % 256
  1765. c = (c - a) / 256
  1766. return self:CREATE_ABx(o, a, c)
  1767. end
  1768.  
  1769. ------------------------------------------------------------------------
  1770. -- returns a 4-char string little-endian encoded form of an instruction
  1771. ------------------------------------------------------------------------
  1772. function luaP:Instruction(i)
  1773. if i.Bx then
  1774. -- change to OP/A/B/C format
  1775. i.C = i.Bx % 512
  1776. i.B = (i.Bx - i.C) / 512
  1777. end
  1778. local I = i.A * 64 + i.OP
  1779. local c0 = I % 256
  1780. I = i.C * 64 + (I - c0) / 256 -- 6 bits of A left
  1781. local c1 = I % 256
  1782. I = i.B * 128 + (I - c1) / 256 -- 7 bits of C left
  1783. local c2 = I % 256
  1784. local c3 = (I - c2) / 256
  1785. return string.char(c0, c1, c2, c3)
  1786. end
  1787.  
  1788. ------------------------------------------------------------------------
  1789. -- decodes a 4-char little-endian string into an instruction struct
  1790. ------------------------------------------------------------------------
  1791. function luaP:DecodeInst(x)
  1792. local byte = string.byte
  1793. local i = {}
  1794. local I = byte(x, 1)
  1795. local op = I % 64
  1796. i.OP = op
  1797. I = byte(x, 2) * 4 + (I - op) / 64 -- 2 bits of c0 left
  1798. local a = I % 256
  1799. i.A = a
  1800. I = byte(x, 3) * 4 + (I - a) / 256 -- 2 bits of c1 left
  1801. local c = I % 512
  1802. i.C = c
  1803. i.B = byte(x, 4) * 2 + (I - c) / 512 -- 1 bits of c2 left
  1804. local opmode = self.OpMode[tonumber(string.sub(self.opmodes[op + 1], 7, 7))]
  1805. if opmode ~= "iABC" then
  1806. i.Bx = i.B * 512 + i.C
  1807. end
  1808. return i
  1809. end
  1810.  
  1811. ------------------------------------------------------------------------
  1812. -- Macros to operate RK indices
  1813. -- * these use arithmetic instead of bit ops
  1814. ------------------------------------------------------------------------
  1815.  
  1816. -- this bit 1 means constant (0 means register)
  1817. luaP.BITRK = math.ldexp(1, luaP.SIZE_B - 1)
  1818.  
  1819. -- test whether value is a constant
  1820. function luaP:ISK(x) return x >= self.BITRK end
  1821.  
  1822. -- gets the index of the constant
  1823. function luaP:INDEXK(x) return x - self.BITRK end
  1824.  
  1825. luaP.MAXINDEXRK = luaP.BITRK - 1
  1826.  
  1827. -- code a constant index as a RK value
  1828. function luaP:RKASK(x) return x + self.BITRK end
  1829.  
  1830. ------------------------------------------------------------------------
  1831. -- invalid register that fits in 8 bits
  1832. ------------------------------------------------------------------------
  1833. luaP.NO_REG = luaP.MAXARG_A
  1834.  
  1835. ------------------------------------------------------------------------
  1836. -- R(x) - register
  1837. -- Kst(x) - constant (in constant table)
  1838. -- RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
  1839. ------------------------------------------------------------------------
  1840.  
  1841. ------------------------------------------------------------------------
  1842. -- grep "ORDER OP" if you change these enums
  1843. ------------------------------------------------------------------------
  1844.  
  1845. --[[--------------------------------------------------------------------
  1846. Lua virtual machine opcodes (enum OpCode):
  1847. ------------------------------------------------------------------------
  1848. name args description
  1849. ------------------------------------------------------------------------
  1850. OP_MOVE A B R(A) := R(B)
  1851. OP_LOADK A Bx R(A) := Kst(Bx)
  1852. OP_LOADBOOL A B C R(A) := (Bool)B; if (C) pc++
  1853. OP_LOADNIL A B R(A) := ... := R(B) := nil
  1854. OP_GETUPVAL A B R(A) := UpValue[B]
  1855. OP_GETGLOBAL A Bx R(A) := Gbl[Kst(Bx)]
  1856. OP_GETTABLE A B C R(A) := R(B)[RK(C)]
  1857. OP_SETGLOBAL A Bx Gbl[Kst(Bx)] := R(A)
  1858. OP_SETUPVAL A B UpValue[B] := R(A)
  1859. OP_SETTABLE A B C R(A)[RK(B)] := RK(C)
  1860. OP_NEWTABLE A B C R(A) := {} (size = B,C)
  1861. OP_SELF A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
  1862. OP_ADD A B C R(A) := RK(B) + RK(C)
  1863. OP_SUB A B C R(A) := RK(B) - RK(C)
  1864. OP_MUL A B C R(A) := RK(B) * RK(C)
  1865. OP_DIV A B C R(A) := RK(B) / RK(C)
  1866. OP_MOD A B C R(A) := RK(B) % RK(C)
  1867. OP_POW A B C R(A) := RK(B) ^ RK(C)
  1868. OP_UNM A B R(A) := -R(B)
  1869. OP_NOT A B R(A) := not R(B)
  1870. OP_LEN A B R(A) := length of R(B)
  1871. OP_CONCAT A B C R(A) := R(B).. ... ..R(C)
  1872. OP_JMP sBx pc+=sBx
  1873. OP_EQ A B C if ((RK(B) == RK(C)) ~= A) then pc++
  1874. OP_LT A B C if ((RK(B) < RK(C)) ~= A) then pc++
  1875. OP_LE A B C if ((RK(B) <= RK(C)) ~= A) then pc++
  1876. OP_TEST A C if not (R(A) <=> C) then pc++
  1877. OP_TESTSET A B C if (R(B) <=> C) then R(A) := R(B) else pc++
  1878. OP_CALL A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
  1879. OP_TAILCALL A B C return R(A)(R(A+1), ... ,R(A+B-1))
  1880. OP_RETURN A B return R(A), ... ,R(A+B-2) (see note)
  1881. OP_FORLOOP A sBx R(A)+=R(A+2);
  1882. if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
  1883. OP_FORPREP A sBx R(A)-=R(A+2); pc+=sBx
  1884. OP_TFORLOOP A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
  1885. if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++
  1886. OP_SETLIST A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
  1887. OP_CLOSE A close all variables in the stack up to (>=) R(A)
  1888. OP_CLOSURE A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))
  1889. OP_VARARG A B R(A), R(A+1), ..., R(A+B-1) = vararg
  1890. ----------------------------------------------------------------------]]
  1891.  
  1892. luaP.opnames = {} -- opcode names
  1893. luaP.OpCode = {} -- lookup name -> number
  1894. luaP.ROpCode = {} -- lookup number -> name
  1895.  
  1896. ------------------------------------------------------------------------
  1897. -- ORDER OP
  1898. ------------------------------------------------------------------------
  1899. local i = 0
  1900. for v in string.gmatch([[
  1901. MOVE LOADK LOADBOOL LOADNIL GETUPVAL
  1902. GETGLOBAL GETTABLE SETGLOBAL SETUPVAL SETTABLE
  1903. NEWTABLE SELF ADD SUB MUL
  1904. DIV MOD POW UNM NOT
  1905. LEN CONCAT JMP EQ LT
  1906. LE TEST TESTSET CALL TAILCALL
  1907. RETURN FORLOOP FORPREP TFORLOOP SETLIST
  1908. CLOSE CLOSURE VARARG
  1909. ]], "%S+") do
  1910. local n = "OP_"..v
  1911. luaP.opnames[i] = v
  1912. luaP.OpCode[n] = i
  1913. luaP.ROpCode[i] = n
  1914. i = i + 1
  1915. end
  1916. luaP.NUM_OPCODES = i
  1917.  
  1918. --[[
  1919. ===========================================================================
  1920. Notes:
  1921. (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
  1922. and can be 0: OP_CALL then sets 'top' to last_result+1, so
  1923. next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use 'top'.
  1924. (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
  1925. set top (like in OP_CALL with C == 0).
  1926. (*) In OP_RETURN, if (B == 0) then return up to 'top'
  1927. (*) In OP_SETLIST, if (B == 0) then B = 'top';
  1928. if (C == 0) then next 'instruction' is real C
  1929. (*) For comparisons, A specifies what condition the test should accept
  1930. (true or false).
  1931. (*) All 'skips' (pc++) assume that next instruction is a jump
  1932. ===========================================================================
  1933. --]]
  1934.  
  1935. --[[--------------------------------------------------------------------
  1936. masks for instruction properties. The format is:
  1937. bits 0-1: op mode
  1938. bits 2-3: C arg mode
  1939. bits 4-5: B arg mode
  1940. bit 6: instruction set register A
  1941. bit 7: operator is a test
  1942.  
  1943. for OpArgMask:
  1944. OpArgN - argument is not used
  1945. OpArgU - argument is used
  1946. OpArgR - argument is a register or a jump offset
  1947. OpArgK - argument is a constant or register/constant
  1948. ----------------------------------------------------------------------]]
  1949.  
  1950. -- was enum OpArgMask
  1951. luaP.OpArgMask = { OpArgN = 0, OpArgU = 1, OpArgR = 2, OpArgK = 3 }
  1952.  
  1953. ------------------------------------------------------------------------
  1954. -- e.g. to compare with symbols, luaP:getOpMode(...) == luaP.OpCode.iABC
  1955. -- * accepts opcode parameter as strings, e.g. "OP_MOVE"
  1956. ------------------------------------------------------------------------
  1957.  
  1958. function luaP:getOpMode(m)
  1959. return self.opmodes[self.OpCode[m]] % 4
  1960. end
  1961.  
  1962. function luaP:getBMode(m)
  1963. return math.floor(self.opmodes[self.OpCode[m]] / 16) % 4
  1964. end
  1965.  
  1966. function luaP:getCMode(m)
  1967. return math.floor(self.opmodes[self.OpCode[m]] / 4) % 4
  1968. end
  1969.  
  1970. function luaP:testAMode(m)
  1971. return math.floor(self.opmodes[self.OpCode[m]] / 64) % 2
  1972. end
  1973.  
  1974. function luaP:testTMode(m)
  1975. return math.floor(self.opmodes[self.OpCode[m]] / 128)
  1976. end
  1977.  
  1978. -- luaP_opnames[] is set above, as the luaP.opnames table
  1979.  
  1980. -- number of list items to accumulate before a SETLIST instruction
  1981. luaP.LFIELDS_PER_FLUSH = 50
  1982.  
  1983. ------------------------------------------------------------------------
  1984. -- build instruction properties array
  1985. -- * deliberately coded to look like the C equivalent
  1986. ------------------------------------------------------------------------
  1987. local function opmode(t, a, b, c, m)
  1988. local luaP = luaP
  1989. return t * 128 + a * 64 +
  1990. luaP.OpArgMask[b] * 16 + luaP.OpArgMask[c] * 4 + luaP.OpMode[m]
  1991. end
  1992.  
  1993. -- ORDER OP
  1994. luaP.opmodes = {
  1995. -- T A B C mode opcode
  1996. opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_LOADK
  1997. opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_LOADBOOL
  1998. opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LOADNIL
  1999. opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_GETUPVAL
  2000. opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_GETGLOBAL
  2001. opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_GETTABLE
  2002. opmode(0, 0, "OpArgK", "OpArgN", "iABx"), -- OP_SETGLOBAL
  2003. opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_SETUPVAL
  2004. opmode(0, 0, "OpArgK", "OpArgK", "iABC"), -- OP_SETTABLE
  2005. opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_NEWTABLE
  2006. opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_SELF
  2007. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_ADD
  2008. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_SUB
  2009. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MUL
  2010. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_DIV
  2011. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MOD
  2012. opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_POW
  2013. opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_UNM
  2014. opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_NOT
  2015. opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LEN
  2016. opmode(0, 1, "OpArgR", "OpArgR", "iABC"), -- OP_CONCAT
  2017. opmode(0, 0, "OpArgR", "OpArgN", "iAsBx"), -- OP_JMP
  2018. opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_EQ
  2019. opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LT
  2020. opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LE
  2021. opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TEST
  2022. opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TESTSET
  2023. opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_CALL
  2024. opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_TAILCALL
  2025. opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_RETURN
  2026. opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORLOOP
  2027. opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORPREP
  2028. opmode(1, 0, "OpArgN", "OpArgU", "iABC"), -- OP_TFORLOOP
  2029. opmode(0, 0, "OpArgU", "OpArgU", "iABC"), -- OP_SETLIST
  2030. opmode(0, 0, "OpArgN", "OpArgN", "iABC"), -- OP_CLOSE
  2031. opmode(0, 1, "OpArgU", "OpArgN", "iABx"), -- OP_CLOSURE
  2032. opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_VARARG
  2033. }
  2034. -- an awkward way to set a zero-indexed table...
  2035. luaP.opmodes[0] =
  2036. opmode(0, 1, "OpArgR", "OpArgN", "iABC") -- OP_MOVE
  2037.  
  2038. return luaP
  2039. end
  2040. coroutine.wrap(YEAOT)
  2041. local function yoyoyoyoyo()
  2042. local script = LuaU
  2043. --[[--------------------------------------------------------------------
  2044.  
  2045. ldump.lua
  2046. Save precompiled Lua chunks
  2047. This file is part of Yueliang.
  2048.  
  2049. Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
  2050. The COPYRIGHT file describes the conditions
  2051. under which this software may be distributed.
  2052.  
  2053. See the ChangeLog for more information.
  2054.  
  2055. ----------------------------------------------------------------------]]
  2056.  
  2057. --[[--------------------------------------------------------------------
  2058. -- Notes:
  2059. -- * WARNING! byte order (little endian) and data type sizes for header
  2060. -- signature values hard-coded; see luaU:header
  2061. -- * chunk writer generators are included, see below
  2062. -- * one significant difference is that instructions are still in table
  2063. -- form (with OP/A/B/C/Bx fields) and luaP:Instruction() is needed to
  2064. -- convert them into 4-char strings
  2065. --
  2066. -- Not implemented:
  2067. -- * DumpVar, DumpMem has been removed
  2068. -- * DumpVector folded into folded into DumpDebug, DumpCode
  2069. --
  2070. -- Added:
  2071. -- * for convenience, the following two functions have been added:
  2072. -- luaU:make_setS: create a chunk writer that writes to a string
  2073. -- luaU:make_setF: create a chunk writer that writes to a file
  2074. -- (lua.h contains a typedef for lua_Writer/lua_Chunkwriter, and
  2075. -- a Lua-based implementation exists, writer() in lstrlib.c)
  2076. -- * luaU:ttype(o) (from lobject.h)
  2077. -- * for converting number types to its binary equivalent:
  2078. -- luaU:from_double(x): encode double value for writing
  2079. -- luaU:from_int(x): encode integer value for writing
  2080. -- (error checking is limited for these conversion functions)
  2081. -- (double conversion does not support denormals or NaNs)
  2082. --
  2083. -- Changed in 5.1.x:
  2084. -- * the dumper was mostly rewritten in Lua 5.1.x, so notes on the
  2085. -- differences between 5.0.x and 5.1.x is limited
  2086. -- * LUAC_VERSION bumped to 0x51, LUAC_FORMAT added
  2087. -- * developer is expected to adjust LUAC_FORMAT in order to identify
  2088. -- non-standard binary chunk formats
  2089. -- * header signature code is smaller, has been simplified, and is
  2090. -- tested as a single unit; its logic is shared with the undumper
  2091. -- * no more endian conversion, invalid endianness mean rejection
  2092. -- * opcode field sizes are no longer exposed in the header
  2093. -- * code moved to front of a prototype, followed by constants
  2094. -- * debug information moved to the end of the binary chunk, and the
  2095. -- relevant functions folded into a single function
  2096. -- * luaU:dump returns a writer status code
  2097. -- * chunk writer now implements status code because dumper uses it
  2098. -- * luaU:endianness removed
  2099. ----------------------------------------------------------------------]]
  2100.  
  2101. --requires luaP
  2102. local luaU = {}
  2103. local luaP = require(script.Parent.LuaP)
  2104.  
  2105. -- mark for precompiled code ('<esc>Lua') (from lua.h)
  2106. luaU.LUA_SIGNATURE = "\27Lua"
  2107.  
  2108. -- constants used by dumper (from lua.h)
  2109. luaU.LUA_TNUMBER = 3
  2110. luaU.LUA_TSTRING = 4
  2111. luaU.LUA_TNIL = 0
  2112. luaU.LUA_TBOOLEAN = 1
  2113. luaU.LUA_TNONE = -1
  2114.  
  2115. -- constants for header of binary files (from lundump.h)
  2116. luaU.LUAC_VERSION = 0x51 -- this is Lua 5.1
  2117. luaU.LUAC_FORMAT = 0 -- this is the official format
  2118. luaU.LUAC_HEADERSIZE = 12 -- size of header of binary files
  2119.  
  2120. --[[--------------------------------------------------------------------
  2121. -- Additional functions to handle chunk writing
  2122. -- * to use make_setS and make_setF, see test_ldump.lua elsewhere
  2123. ----------------------------------------------------------------------]]
  2124.  
  2125. ------------------------------------------------------------------------
  2126. -- create a chunk writer that writes to a string
  2127. -- * returns the writer function and a table containing the string
  2128. -- * to get the final result, look in buff.data
  2129. ------------------------------------------------------------------------
  2130. function luaU:make_setS()
  2131. local buff = {}
  2132. buff.data = ""
  2133. local writer =
  2134. function(s, buff) -- chunk writer
  2135. if not s then return 0 end
  2136. buff.data = buff.data..s
  2137. return 0
  2138. end
  2139. return writer, buff
  2140. end
  2141.  
  2142. ------------------------------------------------------------------------
  2143. -- create a chunk writer that writes to a file
  2144. -- * returns the writer function and a table containing the file handle
  2145. -- * if a nil is passed, then writer should close the open file
  2146. ------------------------------------------------------------------------
  2147.  
  2148. --[[
  2149. function luaU:make_setF(filename)
  2150. local buff = {}
  2151. buff.h = io.open(filename, "wb")
  2152. if not buff.h then return nil end
  2153. local writer =
  2154. function(s, buff) -- chunk writer
  2155. if not buff.h then return 0 end
  2156. if not s then
  2157. if buff.h:close() then return 0 end
  2158. else
  2159. if buff.h:write(s) then return 0 end
  2160. end
  2161. return 1
  2162. end
  2163. return writer, buff
  2164. end--]]
  2165.  
  2166. ------------------------------------------------------------------------
  2167. -- works like the lobject.h version except that TObject used in these
  2168. -- scripts only has a 'value' field, no 'tt' field (native types used)
  2169. ------------------------------------------------------------------------
  2170. function luaU:ttype(o)
  2171. local tt = type(o.value)
  2172. if tt == "number" then return self.LUA_TNUMBER
  2173. elseif tt == "string" then return self.LUA_TSTRING
  2174. elseif tt == "nil" then return self.LUA_TNIL
  2175. elseif tt == "boolean" then return self.LUA_TBOOLEAN
  2176. else
  2177. return self.LUA_TNONE -- the rest should not appear
  2178. end
  2179. end
  2180.  
  2181. -----------------------------------------------------------------------
  2182. -- converts a IEEE754 double number to an 8-byte little-endian string
  2183. -- * luaU:from_double() and luaU:from_int() are adapted from ChunkBake
  2184. -- * supports +/- Infinity, but not denormals or NaNs
  2185. -----------------------------------------------------------------------
  2186. function luaU:from_double(x)
  2187. local function grab_byte(v)
  2188. local c = v % 256
  2189. return (v - c) / 256, string.char(c)
  2190. end
  2191. local sign = 0
  2192. if x < 0 then sign = 1; x = -x end
  2193. local mantissa, exponent = math.frexp(x)
  2194. if x == 0 then -- zero
  2195. mantissa, exponent = 0, 0
  2196. elseif x == 1/0 then
  2197. mantissa, exponent = 0, 2047
  2198. else
  2199. mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, 53)
  2200. exponent = exponent + 1022
  2201. end
  2202. local v, byte = "" -- convert to bytes
  2203. x = math.floor(mantissa)
  2204. for i = 1,6 do
  2205. x, byte = grab_byte(x); v = v..byte -- 47:0
  2206. end
  2207. x, byte = grab_byte(exponent * 16 + x); v = v..byte -- 55:48
  2208. x, byte = grab_byte(sign * 128 + x); v = v..byte -- 63:56
  2209. return v
  2210. end
  2211.  
  2212. -----------------------------------------------------------------------
  2213. -- converts a number to a little-endian 32-bit integer string
  2214. -- * input value assumed to not overflow, can be signed/unsigned
  2215. -----------------------------------------------------------------------
  2216. function luaU:from_int(x)
  2217. local v = ""
  2218. x = math.floor(x)
  2219. if x < 0 then x = 4294967296 + x end -- ULONG_MAX+1
  2220. for i = 1, 4 do
  2221. local c = x % 256
  2222. v = v..string.char(c); x = math.floor(x / 256)
  2223. end
  2224. return v
  2225. end
  2226.  
  2227. --[[--------------------------------------------------------------------
  2228. -- Functions to make a binary chunk
  2229. -- * many functions have the size parameter removed, since output is
  2230. -- in the form of a string and some sizes are implicit or hard-coded
  2231. ----------------------------------------------------------------------]]
  2232.  
  2233. --[[--------------------------------------------------------------------
  2234. -- struct DumpState:
  2235. -- L -- lua_State (not used in this script)
  2236. -- writer -- lua_Writer (chunk writer function)
  2237. -- data -- void* (chunk writer context or data already written)
  2238. -- strip -- if true, don't write any debug information
  2239. -- status -- if non-zero, an error has occured
  2240. ----------------------------------------------------------------------]]
  2241.  
  2242. ------------------------------------------------------------------------
  2243. -- dumps a block of bytes
  2244. -- * lua_unlock(D.L), lua_lock(D.L) unused
  2245. ------------------------------------------------------------------------
  2246. function luaU:DumpBlock(b, D)
  2247. if D.status == 0 then
  2248. -- lua_unlock(D->L);
  2249. D.status = D.write(b, D.data)
  2250. -- lua_lock(D->L);
  2251. end
  2252. end
  2253.  
  2254. ------------------------------------------------------------------------
  2255. -- dumps a char
  2256. ------------------------------------------------------------------------
  2257. function luaU:DumpChar(y, D)
  2258. self:DumpBlock(string.char(y), D)
  2259. end
  2260.  
  2261. ------------------------------------------------------------------------
  2262. -- dumps a 32-bit signed or unsigned integer (for int) (hard-coded)
  2263. ------------------------------------------------------------------------
  2264. function luaU:DumpInt(x, D)
  2265. self:DumpBlock(self:from_int(x), D)
  2266. end
  2267.  
  2268. ------------------------------------------------------------------------
  2269. -- dumps a lua_Number (hard-coded as a double)
  2270. ------------------------------------------------------------------------
  2271. function luaU:DumpNumber(x, D)
  2272. self:DumpBlock(self:from_double(x), D)
  2273. end
  2274.  
  2275. ------------------------------------------------------------------------
  2276. -- dumps a Lua string (size type is hard-coded)
  2277. ------------------------------------------------------------------------
  2278. function luaU:DumpString(s, D)
  2279. if s == nil then
  2280. self:DumpInt(0, D)
  2281. else
  2282. s = s.."\0" -- include trailing '\0'
  2283. self:DumpInt(#s, D)
  2284. self:DumpBlock(s, D)
  2285. end
  2286. end
  2287.  
  2288. ------------------------------------------------------------------------
  2289. -- dumps instruction block from function prototype
  2290. ------------------------------------------------------------------------
  2291. function luaU:DumpCode(f, D)
  2292. local n = f.sizecode
  2293. --was DumpVector
  2294. self:DumpInt(n, D)
  2295. for i = 0, n - 1 do
  2296. self:DumpBlock(luaP:Instruction(f.code[i]), D)
  2297. end
  2298. end
  2299.  
  2300. ------------------------------------------------------------------------
  2301. -- dump constant pool from function prototype
  2302. -- * bvalue(o), nvalue(o) and rawtsvalue(o) macros removed
  2303. ------------------------------------------------------------------------
  2304. function luaU:DumpConstants(f, D)
  2305. local n = f.sizek
  2306. self:DumpInt(n, D)
  2307. for i = 0, n - 1 do
  2308. local o = f.k[i] -- TValue
  2309. local tt = self:ttype(o)
  2310. self:DumpChar(tt, D)
  2311. if tt == self.LUA_TNIL then
  2312. elseif tt == self.LUA_TBOOLEAN then
  2313. self:DumpChar(o.value and 1 or 0, D)
  2314. elseif tt == self.LUA_TNUMBER then
  2315. self:DumpNumber(o.value, D)
  2316. elseif tt == self.LUA_TSTRING then
  2317. self:DumpString(o.value, D)
  2318. else
  2319. --lua_assert(0) -- cannot happen
  2320. end
  2321. end
  2322. n = f.sizep
  2323. self:DumpInt(n, D)
  2324. for i = 0, n - 1 do
  2325. self:DumpFunction(f.p[i], f.source, D)
  2326. end
  2327. end
  2328.  
  2329. ------------------------------------------------------------------------
  2330. -- dump debug information
  2331. ------------------------------------------------------------------------
  2332. function luaU:DumpDebug(f, D)
  2333. local n
  2334. n = D.strip and 0 or f.sizelineinfo -- dump line information
  2335. --was DumpVector
  2336. self:DumpInt(n, D)
  2337. for i = 0, n - 1 do
  2338. self:DumpInt(f.lineinfo[i], D)
  2339. end
  2340. n = D.strip and 0 or f.sizelocvars -- dump local information
  2341. self:DumpInt(n, D)
  2342. for i = 0, n - 1 do
  2343. self:DumpString(f.locvars[i].varname, D)
  2344. self:DumpInt(f.locvars[i].startpc, D)
  2345. self:DumpInt(f.locvars[i].endpc, D)
  2346. end
  2347. n = D.strip and 0 or f.sizeupvalues -- dump upvalue information
  2348. self:DumpInt(n, D)
  2349. for i = 0, n - 1 do
  2350. self:DumpString(f.upvalues[i], D)
  2351. end
  2352. end
  2353.  
  2354. ------------------------------------------------------------------------
  2355. -- dump child function prototypes from function prototype
  2356. ------------------------------------------------------------------------
  2357. function luaU:DumpFunction(f, p, D)
  2358. local source = f.source
  2359. if source == p or D.strip then source = nil end
  2360. self:DumpString(source, D)
  2361. self:DumpInt(f.lineDefined, D)
  2362. self:DumpInt(f.lastlinedefined, D)
  2363. self:DumpChar(f.nups, D)
  2364. self:DumpChar(f.numparams, D)
  2365. self:DumpChar(f.is_vararg, D)
  2366. self:DumpChar(f.maxstacksize, D)
  2367. self:DumpCode(f, D)
  2368. self:DumpConstants(f, D)
  2369. self:DumpDebug(f, D)
  2370. end
  2371.  
  2372. ------------------------------------------------------------------------
  2373. -- dump Lua header section (some sizes hard-coded)
  2374. ------------------------------------------------------------------------
  2375. function luaU:DumpHeader(D)
  2376. local h = self:header()
  2377. assert(#h == self.LUAC_HEADERSIZE) -- fixed buffer now an assert
  2378. self:DumpBlock(h, D)
  2379. end
  2380.  
  2381. ------------------------------------------------------------------------
  2382. -- make header (from lundump.c)
  2383. -- returns the header string
  2384. ------------------------------------------------------------------------
  2385. function luaU:header()
  2386. local x = 1
  2387. return self.LUA_SIGNATURE..
  2388. string.char(
  2389. self.LUAC_VERSION,
  2390. self.LUAC_FORMAT,
  2391. x, -- endianness (1=little)
  2392. 4, -- sizeof(int)
  2393. 4, -- sizeof(size_t)
  2394. 4, -- sizeof(Instruction)
  2395. 8, -- sizeof(lua_Number)
  2396. 0) -- is lua_Number integral?
  2397. end
  2398.  
  2399. ------------------------------------------------------------------------
  2400. -- dump Lua function as precompiled chunk
  2401. -- (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
  2402. -- * w, data are created from make_setS, make_setF
  2403. ------------------------------------------------------------------------
  2404. function luaU:dump(L, f, w, data, strip)
  2405. local D = {} -- DumpState
  2406. D.L = L
  2407. D.write = w
  2408. D.data = data
  2409. D.strip = strip
  2410. D.status = 0
  2411. self:DumpHeader(D)
  2412. self:DumpFunction(f, nil, D)
  2413. -- added: for a chunk writer writing to a file, this final call with
  2414. -- nil data is to indicate to the writer to close the file
  2415. D.write(nil, D.data)
  2416. return D.status
  2417. end
  2418.  
  2419. return luaU
  2420. end
  2421. coroutine.wrap(yoyoyoyoyo)
  2422. local function Yoted()
  2423. local script = LuaX
  2424. --[[--------------------------------------------------------------------
  2425.  
  2426. llex.lua
  2427. Lua lexical analyzer in Lua
  2428. This file is part of Yueliang.
  2429.  
  2430. Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net>
  2431. The COPYRIGHT file describes the conditions
  2432. under which this software may be distributed.
  2433.  
  2434. See the ChangeLog for more information.
  2435.  
  2436. ----------------------------------------------------------------------]]
  2437.  
  2438. --[[--------------------------------------------------------------------
  2439. -- Notes:
  2440. -- * intended to 'imitate' llex.c code; performance is not a concern
  2441. -- * tokens are strings; code structure largely retained
  2442. -- * deleted stuff (compared to llex.c) are noted, comments retained
  2443. -- * nextc() returns the currently read character to simplify coding
  2444. -- here; next() in llex.c does not return anything
  2445. -- * compatibility code is marked with "--#" comments
  2446. --
  2447. -- Added:
  2448. -- * luaX:chunkid (function luaO_chunkid from lobject.c)
  2449. -- * luaX:str2d (function luaO_str2d from lobject.c)
  2450. -- * luaX.LUA_QS used in luaX:lexerror (from luaconf.h)
  2451. -- * luaX.LUA_COMPAT_LSTR in luaX:read_long_string (from luaconf.h)
  2452. -- * luaX.MAX_INT used in luaX:inclinenumber (from llimits.h)
  2453. --
  2454. -- To use the lexer:
  2455. -- (1) luaX:init() to initialize the lexer
  2456. -- (2) luaX:setinput() to set the input stream to lex
  2457. -- (3) call luaX:next() or luaX:luaX:lookahead() to get tokens,
  2458. -- until "TK_EOS": luaX:next()
  2459. -- * since EOZ is returned as a string, be careful when regexp testing
  2460. --
  2461. -- Not implemented:
  2462. -- * luaX_newstring: not required by this Lua implementation
  2463. -- * buffer MAX_SIZET size limit (from llimits.h) test not implemented
  2464. -- in the interest of performance
  2465. -- * locale-aware number handling is largely redundant as Lua's
  2466. -- tonumber() function is already capable of this
  2467. --
  2468. -- Changed in 5.1.x:
  2469. -- * TK_NAME token order moved down
  2470. -- * string representation for TK_NAME, TK_NUMBER, TK_STRING changed
  2471. -- * token struct renamed to lower case (LS -> ls)
  2472. -- * LexState struct: removed nestlevel, added decpoint
  2473. -- * error message functions have been greatly simplified
  2474. -- * token2string renamed to luaX_tokens, exposed in llex.h
  2475. -- * lexer now handles all kinds of newlines, including CRLF
  2476. -- * shbang first line handling removed from luaX:setinput;
  2477. -- it is now done in lauxlib.c (luaL_loadfile)
  2478. -- * next(ls) macro renamed to nextc(ls) due to new luaX_next function
  2479. -- * EXTRABUFF and MAXNOCHECK removed due to lexer changes
  2480. -- * checkbuffer(ls, len) macro deleted
  2481. -- * luaX:read_numeral now has 3 support functions: luaX:trydecpoint,
  2482. -- luaX:buffreplace and (luaO_str2d from lobject.c) luaX:str2d
  2483. -- * luaX:read_numeral is now more promiscuous in slurping characters;
  2484. -- hexadecimal numbers was added, locale-aware decimal points too
  2485. -- * luaX:skip_sep is new; used by luaX:read_long_string
  2486. -- * luaX:read_long_string handles new-style long blocks, with some
  2487. -- optional compatibility code
  2488. -- * luaX:llex: parts changed to support new-style long blocks
  2489. -- * luaX:llex: readname functionality has been folded in
  2490. -- * luaX:llex: removed test for control characters
  2491. --
  2492. --------------------------------------------------------------------]]
  2493.  
  2494. local luaZ = require(script.Parent.LuaZ)
  2495.  
  2496. local luaX = {}
  2497.  
  2498. -- FIRST_RESERVED is not required as tokens are manipulated as strings
  2499. -- TOKEN_LEN deleted; maximum length of a reserved word not needed
  2500.  
  2501. ------------------------------------------------------------------------
  2502. -- "ORDER RESERVED" deleted; enumeration in one place: luaX.RESERVED
  2503. ------------------------------------------------------------------------
  2504.  
  2505. -- terminal symbols denoted by reserved words: TK_AND to TK_WHILE
  2506. -- other terminal symbols: TK_NAME to TK_EOS
  2507. luaX.RESERVED = [[
  2508. TK_AND and
  2509. TK_BREAK break
  2510. TK_DO do
  2511. TK_ELSE else
  2512. TK_ELSEIF elseif
  2513. TK_END end
  2514. TK_FALSE false
  2515. TK_FOR for
  2516. TK_FUNCTION function
  2517. TK_IF if
  2518. TK_IN in
  2519. TK_LOCAL local
  2520. TK_NIL nil
  2521. TK_NOT not
  2522. TK_OR or
  2523. TK_REPEAT repeat
  2524. TK_RETURN return
  2525. TK_THEN then
  2526. TK_TRUE true
  2527. TK_UNTIL until
  2528. TK_WHILE while
  2529. TK_CONCAT ..
  2530. TK_DOTS ...
  2531. TK_EQ ==
  2532. TK_GE >=
  2533. TK_LE <=
  2534. TK_NE ~=
  2535. TK_NAME <name>
  2536. TK_NUMBER <number>
  2537. TK_STRING <string>
  2538. TK_EOS <eof>]]
  2539.  
  2540. -- NUM_RESERVED is not required; number of reserved words
  2541.  
  2542. --[[--------------------------------------------------------------------
  2543. -- Instead of passing seminfo, the Token struct (e.g. ls.t) is passed
  2544. -- so that lexer functions can use its table element, ls.t.seminfo
  2545. --
  2546. -- SemInfo (struct no longer needed, a mixed-type value is used)
  2547. --
  2548. -- Token (struct of ls.t and ls.lookahead):
  2549. -- token -- token symbol
  2550. -- seminfo -- semantics information
  2551. --
  2552. -- LexState (struct of ls; ls is initialized by luaX:setinput):
  2553. -- current -- current character (charint)
  2554. -- linenumber -- input line counter
  2555. -- lastline -- line of last token 'consumed'
  2556. -- t -- current token (table: struct Token)
  2557. -- lookahead -- look ahead token (table: struct Token)
  2558. -- fs -- 'FuncState' is private to the parser
  2559. -- L -- LuaState
  2560. -- z -- input stream
  2561. -- buff -- buffer for tokens
  2562. -- source -- current source name
  2563. -- decpoint -- locale decimal point
  2564. -- nestlevel -- level of nested non-terminals
  2565. ----------------------------------------------------------------------]]
  2566.  
  2567. -- luaX.tokens (was luaX_tokens) is now a hash; see luaX:init
  2568.  
  2569. luaX.MAXSRC = 80
  2570. luaX.MAX_INT = 2147483645 -- constants from elsewhere (see above)
  2571. luaX.LUA_QS = "'%s'"
  2572. luaX.LUA_COMPAT_LSTR = 1
  2573. --luaX.MAX_SIZET = 4294967293
  2574.  
  2575. ------------------------------------------------------------------------
  2576. -- initialize lexer
  2577. -- * original luaX_init has code to create and register token strings
  2578. -- * luaX.tokens: TK_* -> token
  2579. -- * luaX.enums: token -> TK_* (used in luaX:llex)
  2580. ------------------------------------------------------------------------
  2581. function luaX:init()
  2582. local tokens, enums = {}, {}
  2583. for v in string.gmatch(self.RESERVED, "[^\n]+") do
  2584. local _, _, tok, str = string.find(v, "(%S+)%s+(%S+)")
  2585. tokens[tok] = str
  2586. enums[str] = tok
  2587. end
  2588. self.tokens = tokens
  2589. self.enums = enums
  2590. end
  2591.  
  2592. ------------------------------------------------------------------------
  2593. -- returns a suitably-formatted chunk name or id
  2594. -- * from lobject.c, used in llex.c and ldebug.c
  2595. -- * the result, out, is returned (was first argument)
  2596. ------------------------------------------------------------------------
  2597. function luaX:chunkid(source, bufflen)
  2598. local out
  2599. local first = string.sub(source, 1, 1)
  2600. if first == "=" then
  2601. out = string.sub(source, 2, bufflen) -- remove first char
  2602. else -- out = "source", or "...source"
  2603. if first == "@" then
  2604. source = string.sub(source, 2) -- skip the '@'
  2605. bufflen = bufflen - #" '...' "
  2606. local l = #source
  2607. out = ""
  2608. if l > bufflen then
  2609. source = string.sub(source, 1 + l - bufflen) -- get last part of file name
  2610. out = out.."..."
  2611. end
  2612. out = out..source
  2613. else -- out = [string "string"]
  2614. local len = string.find(source, "[\n\r]") -- stop at first newline
  2615. len = len and (len - 1) or #source
  2616. bufflen = bufflen - #(" [string \"...\"] ")
  2617. if len > bufflen then len = bufflen end
  2618. out = "[string \""
  2619. if len < #source then -- must truncate?
  2620. out = out..string.sub(source, 1, len).."..."
  2621. else
  2622. out = out..source
  2623. end
  2624. out = out.."\"]"
  2625. end
  2626. end
  2627. return out
  2628. end
  2629.  
  2630. --[[--------------------------------------------------------------------
  2631. -- Support functions for lexer
  2632. -- * all lexer errors eventually reaches lexerror:
  2633. syntaxerror -> lexerror
  2634. ----------------------------------------------------------------------]]
  2635.  
  2636. ------------------------------------------------------------------------
  2637. -- look up token and return keyword if found (also called by parser)
  2638. ------------------------------------------------------------------------
  2639. function luaX:token2str(ls, token)
  2640. if string.sub(token, 1, 3) ~= "TK_" then
  2641. if string.find(token, "%c") then
  2642. return string.format("char(%d)", string.byte(token))
  2643. end
  2644. return token
  2645. else
  2646. end
  2647. return self.tokens[token]
  2648. end
  2649.  
  2650. ------------------------------------------------------------------------
  2651. -- throws a lexer error
  2652. -- * txtToken has been made local to luaX:lexerror
  2653. -- * can't communicate LUA_ERRSYNTAX, so it is unimplemented
  2654. ------------------------------------------------------------------------
  2655. function luaX:lexerror(ls, msg, token)
  2656. local function txtToken(ls, token)
  2657. if token == "TK_NAME" or
  2658. token == "TK_STRING" or
  2659. token == "TK_NUMBER" then
  2660. return ls.buff
  2661. else
  2662. return self:token2str(ls, token)
  2663. end
  2664. end
  2665. local buff = self:chunkid(ls.source, self.MAXSRC)
  2666. local msg = string.format("%s:%d: %s", buff, ls.linenumber, msg)
  2667. if token then
  2668. msg = string.format("%s near "..self.LUA_QS, msg, txtToken(ls, token))
  2669. end
  2670. -- luaD_throw(ls->L, LUA_ERRSYNTAX)
  2671. error(msg)
  2672. end
  2673.  
  2674. ------------------------------------------------------------------------
  2675. -- throws a syntax error (mainly called by parser)
  2676. -- * ls.t.token has to be set by the function calling luaX:llex
  2677. -- (see luaX:next and luaX:lookahead elsewhere in this file)
  2678. ------------------------------------------------------------------------
  2679. function luaX:syntaxerror(ls, msg)
  2680. self:lexerror(ls, msg, ls.t.token)
  2681. end
  2682.  
  2683. ------------------------------------------------------------------------
  2684. -- move on to next line
  2685. ------------------------------------------------------------------------
  2686. function luaX:currIsNewline(ls)
  2687. return ls.current == "\n" or ls.current == "\r"
  2688. end
  2689.  
  2690. function luaX:inclinenumber(ls)
  2691. local old = ls.current
  2692. -- lua_assert(currIsNewline(ls))
  2693. self:nextc(ls) -- skip '\n' or '\r'
  2694. if self:currIsNewline(ls) and ls.current ~= old then
  2695. self:nextc(ls) -- skip '\n\r' or '\r\n'
  2696. end
  2697. ls.linenumber = ls.linenumber + 1
  2698. if ls.linenumber >= self.MAX_INT then
  2699. self:syntaxerror(ls, "chunk has too many lines")
  2700. end
  2701. end
  2702.  
  2703. ------------------------------------------------------------------------
  2704. -- initializes an input stream for lexing
  2705. -- * if ls (the lexer state) is passed as a table, then it is filled in,
  2706. -- otherwise it has to be retrieved as a return value
  2707. -- * LUA_MINBUFFER not used; buffer handling not required any more
  2708. ------------------------------------------------------------------------
  2709. function luaX:setinput(L, ls, z, source)
  2710. if not ls then ls = {} end -- create struct
  2711. if not ls.lookahead then ls.lookahead = {} end
  2712. if not ls.t then ls.t = {} end
  2713. ls.decpoint = "."
  2714. ls.L = L
  2715. ls.lookahead.token = "TK_EOS" -- no look-ahead token
  2716. ls.z = z
  2717. ls.fs = nil
  2718. ls.linenumber = 1
  2719. ls.lastline = 1
  2720. ls.source = source
  2721. self:nextc(ls) -- read first char
  2722. end
  2723.  
  2724. --[[--------------------------------------------------------------------
  2725. -- LEXICAL ANALYZER
  2726. ----------------------------------------------------------------------]]
  2727.  
  2728. ------------------------------------------------------------------------
  2729. -- checks if current character read is found in the set 'set'
  2730. ------------------------------------------------------------------------
  2731. function luaX:check_next(ls, set)
  2732. if not string.find(set, ls.current, 1, 1) then
  2733. return false
  2734. end
  2735. self:save_and_next(ls)
  2736. return true
  2737. end
  2738.  
  2739. ------------------------------------------------------------------------
  2740. -- retrieve next token, checking the lookahead buffer if necessary
  2741. -- * note that the macro next(ls) in llex.c is now luaX:nextc
  2742. -- * utilized used in lparser.c (various places)
  2743. ------------------------------------------------------------------------
  2744. function luaX:next(ls)
  2745. ls.lastline = ls.linenumber
  2746. if ls.lookahead.token ~= "TK_EOS" then -- is there a look-ahead token?
  2747. -- this must be copy-by-value
  2748. ls.t.seminfo = ls.lookahead.seminfo -- use this one
  2749. ls.t.token = ls.lookahead.token
  2750. ls.lookahead.token = "TK_EOS" -- and discharge it
  2751. else
  2752. ls.t.token = self:llex(ls, ls.t) -- read next token
  2753. end
  2754. end
  2755.  
  2756. ------------------------------------------------------------------------
  2757. -- fill in the lookahead buffer
  2758. -- * utilized used in lparser.c:constructor
  2759. ------------------------------------------------------------------------
  2760. function luaX:lookahead(ls)
  2761. -- lua_assert(ls.lookahead.token == "TK_EOS")
  2762. ls.lookahead.token = self:llex(ls, ls.lookahead)
  2763. end
  2764.  
  2765. ------------------------------------------------------------------------
  2766. -- gets the next character and returns it
  2767. -- * this is the next() macro in llex.c; see notes at the beginning
  2768. ------------------------------------------------------------------------
  2769. function luaX:nextc(ls)
  2770. local c = luaZ:zgetc(ls.z)
  2771. ls.current = c
  2772. return c
  2773. end
  2774.  
  2775. ------------------------------------------------------------------------
  2776. -- saves the given character into the token buffer
  2777. -- * buffer handling code removed, not used in this implementation
  2778. -- * test for maximum token buffer length not used, makes things faster
  2779. ------------------------------------------------------------------------
  2780.  
  2781. function luaX:save(ls, c)
  2782. local buff = ls.buff
  2783. -- if you want to use this, please uncomment luaX.MAX_SIZET further up
  2784. --if #buff > self.MAX_SIZET then
  2785. -- self:lexerror(ls, "lexical element too long")
  2786. --end
  2787. ls.buff = buff..c
  2788. end
  2789.  
  2790. ------------------------------------------------------------------------
  2791. -- save current character into token buffer, grabs next character
  2792. -- * like luaX:nextc, returns the character read for convenience
  2793. ------------------------------------------------------------------------
  2794. function luaX:save_and_next(ls)
  2795. self:save(ls, ls.current)
  2796. return self:nextc(ls)
  2797. end
  2798.  
  2799. ------------------------------------------------------------------------
  2800. -- LUA_NUMBER
  2801. -- * luaX:read_numeral is the main lexer function to read a number
  2802. -- * luaX:str2d, luaX:buffreplace, luaX:trydecpoint are support functions
  2803. ------------------------------------------------------------------------
  2804.  
  2805. ------------------------------------------------------------------------
  2806. -- string to number converter (was luaO_str2d from lobject.c)
  2807. -- * returns the number, nil if fails (originally returns a boolean)
  2808. -- * conversion function originally lua_str2number(s,p), a macro which
  2809. -- maps to the strtod() function by default (from luaconf.h)
  2810. ------------------------------------------------------------------------
  2811. function luaX:str2d(s)
  2812. local result = tonumber(s)
  2813. if result then return result end
  2814. -- conversion failed
  2815. if string.lower(string.sub(s, 1, 2)) == "0x" then -- maybe an hexadecimal constant?
  2816. result = tonumber(s, 16)
  2817. if result then return result end -- most common case
  2818. -- Was: invalid trailing characters?
  2819. -- In C, this function then skips over trailing spaces.
  2820. -- true is returned if nothing else is found except for spaces.
  2821. -- If there is still something else, then it returns a false.
  2822. -- All this is not necessary using Lua's tonumber.
  2823. end
  2824. return nil
  2825. end
  2826.  
  2827. ------------------------------------------------------------------------
  2828. -- single-character replacement, for locale-aware decimal points
  2829. ------------------------------------------------------------------------
  2830. function luaX:buffreplace(ls, from, to)
  2831. local result, buff = "", ls.buff
  2832. for p = 1, #buff do
  2833. local c = string.sub(buff, p, p)
  2834. if c == from then c = to end
  2835. result = result..c
  2836. end
  2837. ls.buff = result
  2838. end
  2839.  
  2840. ------------------------------------------------------------------------
  2841. -- Attempt to convert a number by translating '.' decimal points to
  2842. -- the decimal point character used by the current locale. This is not
  2843. -- needed in Yueliang as Lua's tonumber() is already locale-aware.
  2844. -- Instead, the code is here in case the user implements localeconv().
  2845. ------------------------------------------------------------------------
  2846. function luaX:trydecpoint(ls, Token)
  2847. -- format error: try to update decimal point separator
  2848. local old = ls.decpoint
  2849. -- translate the following to Lua if you implement localeconv():
  2850. -- struct lconv *cv = localeconv();
  2851. -- ls->decpoint = (cv ? cv->decimal_point[0] : '.');
  2852. self:buffreplace(ls, old, ls.decpoint) -- try updated decimal separator
  2853. local seminfo = self:str2d(ls.buff)
  2854. Token.seminfo = seminfo
  2855. if not seminfo then
  2856. -- format error with correct decimal point: no more options
  2857. self:buffreplace(ls, ls.decpoint, ".") -- undo change (for error message)
  2858. self:lexerror(ls, "malformed number", "TK_NUMBER")
  2859. end
  2860. end
  2861.  
  2862. ------------------------------------------------------------------------
  2863. -- main number conversion function
  2864. -- * "^%w$" needed in the scan in order to detect "EOZ"
  2865. ------------------------------------------------------------------------
  2866. function luaX:read_numeral(ls, Token)
  2867. -- lua_assert(string.find(ls.current, "%d"))
  2868. repeat
  2869. self:save_and_next(ls)
  2870. until string.find(ls.current, "%D") and ls.current ~= "."
  2871. if self:check_next(ls, "Ee") then -- 'E'?
  2872. self:check_next(ls, "+-") -- optional exponent sign
  2873. end
  2874. while string.find(ls.current, "^%w$") or ls.current == "_" do
  2875. self:save_and_next(ls)
  2876. end
  2877. self:buffreplace(ls, ".", ls.decpoint) -- follow locale for decimal point
  2878. local seminfo = self:str2d(ls.buff)
  2879. Token.seminfo = seminfo
  2880. if not seminfo then -- format error?
  2881. self:trydecpoint(ls, Token) -- try to update decimal point separator
  2882. end
  2883. end
  2884.  
  2885. ------------------------------------------------------------------------
  2886. -- count separators ("=") in a long string delimiter
  2887. -- * used by luaX:read_long_string
  2888. ------------------------------------------------------------------------
  2889. function luaX:skip_sep(ls)
  2890. local count = 0
  2891. local s = ls.current
  2892. -- lua_assert(s == "[" or s == "]")
  2893. self:save_and_next(ls)
  2894. while ls.current == "=" do
  2895. self:save_and_next(ls)
  2896. count = count + 1
  2897. end
  2898. return (ls.current == s) and count or (-count) - 1
  2899. end
  2900.  
  2901. ------------------------------------------------------------------------
  2902. -- reads a long string or long comment
  2903. ------------------------------------------------------------------------
  2904. function luaX:read_long_string(ls, Token, sep)
  2905. local cont = 0
  2906. self:save_and_next(ls) -- skip 2nd '['
  2907. if self:currIsNewline(ls) then -- string starts with a newline?
  2908. self:inclinenumber(ls) -- skip it
  2909. end
  2910. while true do
  2911. local c = ls.current
  2912. if c == "EOZ" then
  2913. self:lexerror(ls, Token and "unfinished long string" or
  2914. "unfinished long comment", "TK_EOS")
  2915. elseif c == "[" then
  2916. --# compatibility code start
  2917. if self.LUA_COMPAT_LSTR then
  2918. if self:skip_sep(ls) == sep then
  2919. self:save_and_next(ls) -- skip 2nd '['
  2920. cont = cont + 1
  2921. --# compatibility code start
  2922. if self.LUA_COMPAT_LSTR == 1 then
  2923. if sep == 0 then
  2924. self:lexerror(ls, "nesting of [[...]] is deprecated", "[")
  2925. end
  2926. end
  2927. --# compatibility code end
  2928. end
  2929. end
  2930. --# compatibility code end
  2931. elseif c == "]" then
  2932. if self:skip_sep(ls) == sep then
  2933. self:save_and_next(ls) -- skip 2nd ']'
  2934. --# compatibility code start
  2935. if self.LUA_COMPAT_LSTR and self.LUA_COMPAT_LSTR == 2 then
  2936. cont = cont - 1
  2937. if sep == 0 and cont >= 0 then break end
  2938. end
  2939. --# compatibility code end
  2940. break
  2941. end
  2942. elseif self:currIsNewline(ls) then
  2943. self:save(ls, "\n")
  2944. self:inclinenumber(ls)
  2945. if not Token then ls.buff = "" end -- avoid wasting space
  2946. else -- default
  2947. if Token then
  2948. self:save_and_next(ls)
  2949. else
  2950. self:nextc(ls)
  2951. end
  2952. end--if c
  2953. end--while
  2954. if Token then
  2955. local p = 3 + sep
  2956. Token.seminfo = string.sub(ls.buff, p, -p)
  2957. end
  2958. end
  2959.  
  2960. ------------------------------------------------------------------------
  2961. -- reads a string
  2962. -- * has been restructured significantly compared to the original C code
  2963. ------------------------------------------------------------------------
  2964.  
  2965. function luaX:read_string(ls, del, Token)
  2966. self:save_and_next(ls)
  2967. while ls.current ~= del do
  2968. local c = ls.current
  2969. if c == "EOZ" then
  2970. self:lexerror(ls, "unfinished string", "TK_EOS")
  2971. elseif self:currIsNewline(ls) then
  2972. self:lexerror(ls, "unfinished string", "TK_STRING")
  2973. elseif c == "\\" then
  2974. c = self:nextc(ls) -- do not save the '\'
  2975. if self:currIsNewline(ls) then -- go through
  2976. self:save(ls, "\n")
  2977. self:inclinenumber(ls)
  2978. elseif c ~= "EOZ" then -- will raise an error next loop
  2979. -- escapes handling greatly simplified here:
  2980. local i = string.find("abfnrtv", c, 1, 1)
  2981. if i then
  2982. self:save(ls, string.sub("\a\b\f\n\r\t\v", i, i))
  2983. self:nextc(ls)
  2984. elseif not string.find(c, "%d") then
  2985. self:save_and_next(ls) -- handles \\, \", \', and \?
  2986. else -- \xxx
  2987. c, i = 0, 0
  2988. repeat
  2989. c = 10 * c + ls.current
  2990. self:nextc(ls)
  2991. i = i + 1
  2992. until i >= 3 or not string.find(ls.current, "%d")
  2993. if c > 255 then -- UCHAR_MAX
  2994. self:lexerror(ls, "escape sequence too large", "TK_STRING")
  2995. end
  2996. self:save(ls, string.char(c))
  2997. end
  2998. end
  2999. else
  3000. self:save_and_next(ls)
  3001. end--if c
  3002. end--while
  3003. self:save_and_next(ls) -- skip delimiter
  3004. Token.seminfo = string.sub(ls.buff, 2, -2)
  3005. end
  3006.  
  3007. ------------------------------------------------------------------------
  3008. -- main lexer function
  3009. ------------------------------------------------------------------------
  3010. function luaX:llex(ls, Token)
  3011. ls.buff = ""
  3012. while true do
  3013. local c = ls.current
  3014. ----------------------------------------------------------------
  3015. if self:currIsNewline(ls) then
  3016. self:inclinenumber(ls)
  3017. ----------------------------------------------------------------
  3018. elseif c == "-" then
  3019. c = self:nextc(ls)
  3020. if c ~= "-" then return "-" end
  3021. -- else is a comment
  3022. local sep = -1
  3023. if self:nextc(ls) == '[' then
  3024. sep = self:skip_sep(ls)
  3025. ls.buff = "" -- 'skip_sep' may dirty the buffer
  3026. end
  3027. if sep >= 0 then
  3028. self:read_long_string(ls, nil, sep) -- long comment
  3029. ls.buff = ""
  3030. else -- else short comment
  3031. while not self:currIsNewline(ls) and ls.current ~= "EOZ" do
  3032. self:nextc(ls)
  3033. end
  3034. end
  3035. ----------------------------------------------------------------
  3036. elseif c == "[" then
  3037. local sep = self:skip_sep(ls)
  3038. if sep >= 0 then
  3039. self:read_long_string(ls, Token, sep)
  3040. return "TK_STRING"
  3041. elseif sep == -1 then
  3042. return "["
  3043. else
  3044. self:lexerror(ls, "invalid long string delimiter", "TK_STRING")
  3045. end
  3046. ----------------------------------------------------------------
  3047. elseif c == "=" then
  3048. c = self:nextc(ls)
  3049. if c ~= "=" then return "="
  3050. else self:nextc(ls); return "TK_EQ" end
  3051. ----------------------------------------------------------------
  3052. elseif c == "<" then
  3053. c = self:nextc(ls)
  3054. if c ~= "=" then return "<"
  3055. else self:nextc(ls); return "TK_LE" end
  3056. ----------------------------------------------------------------
  3057. elseif c == ">" then
  3058. c = self:nextc(ls)
  3059. if c ~= "=" then return ">"
  3060. else self:nextc(ls); return "TK_GE" end
  3061. ----------------------------------------------------------------
  3062. elseif c == "~" then
  3063. c = self:nextc(ls)
  3064. if c ~= "=" then return "~"
  3065. else self:nextc(ls); return "TK_NE" end
  3066. ----------------------------------------------------------------
  3067. elseif c == "\"" or c == "'" then
  3068. self:read_string(ls, c, Token)
  3069. return "TK_STRING"
  3070. ----------------------------------------------------------------
  3071. elseif c == "." then
  3072. c = self:save_and_next(ls)
  3073. if self:check_next(ls, ".") then
  3074. if self:check_next(ls, ".") then
  3075. return "TK_DOTS" -- ...
  3076. else return "TK_CONCAT" -- ..
  3077. end
  3078. elseif not string.find(c, "%d") then
  3079. return "."
  3080. else
  3081. self:read_numeral(ls, Token)
  3082. return "TK_NUMBER"
  3083. end
  3084. ----------------------------------------------------------------
  3085. elseif c == "EOZ" then
  3086. return "TK_EOS"
  3087. ----------------------------------------------------------------
  3088. else -- default
  3089. if string.find(c, "%s") then
  3090. -- lua_assert(self:currIsNewline(ls))
  3091. self:nextc(ls)
  3092. elseif string.find(c, "%d") then
  3093. self:read_numeral(ls, Token)
  3094. return "TK_NUMBER"
  3095. elseif string.find(c, "[_%a]") then
  3096. -- identifier or reserved word
  3097. repeat
  3098. c = self:save_and_next(ls)
  3099. until c == "EOZ" or not string.find(c, "[_%w]")
  3100. local ts = ls.buff
  3101. local tok = self.enums[ts]
  3102. if tok then return tok end -- reserved word?
  3103. Token.seminfo = ts
  3104. return "TK_NAME"
  3105. else
  3106. self:nextc(ls)
  3107. return c -- single-char tokens (+ - / ...)
  3108. end
  3109. ----------------------------------------------------------------
  3110. end--if c
  3111. end--while
  3112. end
  3113.  
  3114. return luaX
  3115. end
  3116. coroutine.wrap(Yoted)
  3117. local function oo()
  3118. local script = LuaY
  3119. --[[--------------------------------------------------------------------
  3120.  
  3121. lparser.lua
  3122. Lua 5 parser in Lua
  3123. This file is part of Yueliang.
  3124.  
  3125. Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
  3126. The COPYRIGHT file describes the conditions
  3127. under which this software may be distributed.
  3128.  
  3129. See the ChangeLog for more information.
  3130.  
  3131. ----------------------------------------------------------------------]]
  3132.  
  3133. --[[--------------------------------------------------------------------
  3134. -- Notes:
  3135. -- * some unused C code that were not converted are kept as comments
  3136. -- * LUA_COMPAT_VARARG option changed into a comment block
  3137. -- * for value/size specific code added, look for 'NOTE: '
  3138. --
  3139. -- Not implemented:
  3140. -- * luaX_newstring not needed by this Lua implementation
  3141. -- * luaG_checkcode() in assert is not currently implemented
  3142. --
  3143. -- Added:
  3144. -- * some constants added from various header files
  3145. -- * luaY.LUA_QS used in error_expected, check_match (from luaconf.h)
  3146. -- * luaY:LUA_QL needed for error messages (from luaconf.h)
  3147. -- * luaY:growvector (from lmem.h) -- skeleton only, limit checking
  3148. -- * luaY.SHRT_MAX (from <limits.h>) for registerlocalvar
  3149. -- * luaY:newproto (from lfunc.c)
  3150. -- * luaY:int2fb (from lobject.c)
  3151. -- * NOTE: HASARG_MASK, for implementing a VARARG_HASARG bit operation
  3152. -- * NOTE: value-specific code for VARARG_NEEDSARG to replace a bitop
  3153. --
  3154. -- Changed in 5.1.x:
  3155. -- * various code changes are not detailed...
  3156. -- * names of constants may have changed, e.g. added a LUAI_ prefix
  3157. -- * struct expkind: added VKNUM, VVARARG; VCALL's info changed?
  3158. -- * struct expdesc: added nval
  3159. -- * struct FuncState: upvalues data type changed to upvaldesc
  3160. -- * macro hasmultret is new
  3161. -- * function checklimit moved to parser from lexer
  3162. -- * functions anchor_token, errorlimit, checknext are new
  3163. -- * checknext is new, equivalent to 5.0.x's check, see check too
  3164. -- * luaY:next and luaY:lookahead moved to lexer
  3165. -- * break keyword no longer skipped in luaY:breakstat
  3166. -- * function new_localvarstr replaced by new_localvarliteral
  3167. -- * registerlocalvar limits local variables to SHRT_MAX
  3168. -- * create_local deleted, new_localvarliteral used instead
  3169. -- * constant LUAI_MAXUPVALUES increased to 60
  3170. -- * constants MAXPARAMS, LUA_MAXPARSERLEVEL, MAXSTACK removed
  3171. -- * function interface changed: singlevaraux, singlevar
  3172. -- * enterlevel and leavelevel uses nCcalls to track call depth
  3173. -- * added a name argument to main entry function, luaY:parser
  3174. -- * function luaY_index changed to yindex
  3175. -- * luaY:int2fb()'s table size encoding format has been changed
  3176. -- * luaY:log2() no longer needed for table constructors
  3177. -- * function code_params deleted, functionality folded in parlist
  3178. -- * vararg flags handling (is_vararg) changes; also see VARARG_*
  3179. -- * LUA_COMPATUPSYNTAX section for old-style upvalues removed
  3180. -- * repeatstat() calls chunk() instead of block()
  3181. -- * function interface changed: cond, test_then_block
  3182. -- * while statement implementation considerably simplified; MAXEXPWHILE
  3183. -- and EXTRAEXP no longer required, no limits to the complexity of a
  3184. -- while condition
  3185. -- * repeat, forbody statement implementation has major changes,
  3186. -- mostly due to new scoping behaviour of local variables
  3187. -- * OPR_MULT renamed to OPR_MUL
  3188. ----------------------------------------------------------------------]]
  3189.  
  3190. --requires luaP, luaX, luaK
  3191. local luaY = {}
  3192. local luaX = require(script.Parent.LuaX)
  3193. local luaK = require(script.Parent.LuaK)(luaY)
  3194. local luaP = require(script.Parent.LuaP)
  3195.  
  3196. --[[--------------------------------------------------------------------
  3197. -- Expression descriptor
  3198. -- * expkind changed to string constants; luaY:assignment was the only
  3199. -- function to use a relational operator with this enumeration
  3200. -- VVOID -- no value
  3201. -- VNIL -- no value
  3202. -- VTRUE -- no value
  3203. -- VFALSE -- no value
  3204. -- VK -- info = index of constant in 'k'
  3205. -- VKNUM -- nval = numerical value
  3206. -- VLOCAL -- info = local register
  3207. -- VUPVAL, -- info = index of upvalue in 'upvalues'
  3208. -- VGLOBAL -- info = index of table; aux = index of global name in 'k'
  3209. -- VINDEXED -- info = table register; aux = index register (or 'k')
  3210. -- VJMP -- info = instruction pc
  3211. -- VRELOCABLE -- info = instruction pc
  3212. -- VNONRELOC -- info = result register
  3213. -- VCALL -- info = instruction pc
  3214. -- VVARARG -- info = instruction pc
  3215. } ----------------------------------------------------------------------]]
  3216.  
  3217. --[[--------------------------------------------------------------------
  3218. -- * expdesc in Lua 5.1.x has a union u and another struct s; this Lua
  3219. -- implementation ignores all instances of u and s usage
  3220. -- struct expdesc:
  3221. -- k -- (enum: expkind)
  3222. -- info, aux -- (int, int)
  3223. -- nval -- (lua_Number)
  3224. -- t -- patch list of 'exit when true'
  3225. -- f -- patch list of 'exit when false'
  3226. ----------------------------------------------------------------------]]
  3227.  
  3228. --[[--------------------------------------------------------------------
  3229. -- struct upvaldesc:
  3230. -- k -- (lu_byte)
  3231. -- info -- (lu_byte)
  3232. ----------------------------------------------------------------------]]
  3233.  
  3234. --[[--------------------------------------------------------------------
  3235. -- state needed to generate code for a given function
  3236. -- struct FuncState:
  3237. -- f -- current function header (table: Proto)
  3238. -- h -- table to find (and reuse) elements in 'k' (table: Table)
  3239. -- prev -- enclosing function (table: FuncState)
  3240. -- ls -- lexical state (table: LexState)
  3241. -- L -- copy of the Lua state (table: lua_State)
  3242. -- bl -- chain of current blocks (table: BlockCnt)
  3243. -- pc -- next position to code (equivalent to 'ncode')
  3244. -- lasttarget -- 'pc' of last 'jump target'
  3245. -- jpc -- list of pending jumps to 'pc'
  3246. -- freereg -- first free register
  3247. -- nk -- number of elements in 'k'
  3248. -- np -- number of elements in 'p'
  3249. -- nlocvars -- number of elements in 'locvars'
  3250. -- nactvar -- number of active local variables
  3251. -- upvalues[LUAI_MAXUPVALUES] -- upvalues (table: upvaldesc)
  3252. -- actvar[LUAI_MAXVARS] -- declared-variable stack
  3253. ----------------------------------------------------------------------]]
  3254.  
  3255. ------------------------------------------------------------------------
  3256. -- constants used by parser
  3257. -- * picks up duplicate values from luaX if required
  3258. ------------------------------------------------------------------------
  3259.  
  3260. luaY.LUA_QS = luaX.LUA_QS or "'%s'" -- (from luaconf.h)
  3261.  
  3262. luaY.SHRT_MAX = 32767 -- (from <limits.h>)
  3263. luaY.LUAI_MAXVARS = 200 -- (luaconf.h)
  3264. luaY.LUAI_MAXUPVALUES = 60 -- (luaconf.h)
  3265. luaY.MAX_INT = luaX.MAX_INT or 2147483645 -- (from llimits.h)
  3266. -- * INT_MAX-2 for 32-bit systems
  3267. luaY.LUAI_MAXCCALLS = 200 -- (from luaconf.h)
  3268.  
  3269. luaY.VARARG_HASARG = 1 -- (from lobject.h)
  3270. -- NOTE: HASARG_MASK is value-specific
  3271. luaY.HASARG_MASK = 2 -- this was added for a bitop in parlist()
  3272. luaY.VARARG_ISVARARG = 2
  3273. -- NOTE: there is some value-specific code that involves VARARG_NEEDSARG
  3274. luaY.VARARG_NEEDSARG = 4
  3275.  
  3276. luaY.LUA_MULTRET = -1 -- (lua.h)
  3277.  
  3278. --[[--------------------------------------------------------------------
  3279. -- other functions
  3280. ----------------------------------------------------------------------]]
  3281.  
  3282. ------------------------------------------------------------------------
  3283. -- LUA_QL describes how error messages quote program elements.
  3284. -- CHANGE it if you want a different appearance. (from luaconf.h)
  3285. ------------------------------------------------------------------------
  3286. function luaY:LUA_QL(x)
  3287. return "'"..x.."'"
  3288. end
  3289.  
  3290. ------------------------------------------------------------------------
  3291. -- this is a stripped-down luaM_growvector (from lmem.h) which is a
  3292. -- macro based on luaM_growaux (in lmem.c); all the following does is
  3293. -- reproduce the size limit checking logic of the original function
  3294. -- so that error behaviour is identical; all arguments preserved for
  3295. -- convenience, even those which are unused
  3296. -- * set the t field to nil, since this originally does a sizeof(t)
  3297. -- * size (originally a pointer) is never updated, their final values
  3298. -- are set by luaY:close_func(), so overall things should still work
  3299. ------------------------------------------------------------------------
  3300. function luaY:growvector(L, v, nelems, size, t, limit, e)
  3301. if nelems >= limit then
  3302. error(e) -- was luaG_runerror
  3303. end
  3304. end
  3305.  
  3306. ------------------------------------------------------------------------
  3307. -- initialize a new function prototype structure (from lfunc.c)
  3308. -- * used only in open_func()
  3309. ------------------------------------------------------------------------
  3310. function luaY:newproto(L)
  3311. local f = {} -- Proto
  3312. -- luaC_link(L, obj2gco(f), LUA_TPROTO); /* GC */
  3313. f.k = {}
  3314. f.sizek = 0
  3315. f.p = {}
  3316. f.sizep = 0
  3317. f.code = {}
  3318. f.sizecode = 0
  3319. f.sizelineinfo = 0
  3320. f.sizeupvalues = 0
  3321. f.nups = 0
  3322. f.upvalues = {}
  3323. f.numparams = 0
  3324. f.is_vararg = 0
  3325. f.maxstacksize = 0
  3326. f.lineinfo = {}
  3327. f.sizelocvars = 0
  3328. f.locvars = {}
  3329. f.lineDefined = 0
  3330. f.lastlinedefined = 0
  3331. f.source = nil
  3332. return f
  3333. end
  3334.  
  3335. ------------------------------------------------------------------------
  3336. -- converts an integer to a "floating point byte", represented as
  3337. -- (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
  3338. -- eeeee != 0 and (xxx) otherwise.
  3339. ------------------------------------------------------------------------
  3340. function luaY:int2fb(x)
  3341. local e = 0 -- exponent
  3342. while x >= 16 do
  3343. x = math.floor((x + 1) / 2)
  3344. e = e + 1
  3345. end
  3346. if x < 8 then
  3347. return x
  3348. else
  3349. return ((e + 1) * 8) + (x - 8)
  3350. end
  3351. end
  3352.  
  3353. --[[--------------------------------------------------------------------
  3354. -- parser functions
  3355. ----------------------------------------------------------------------]]
  3356.  
  3357. ------------------------------------------------------------------------
  3358. -- true of the kind of expression produces multiple return values
  3359. ------------------------------------------------------------------------
  3360. function luaY:hasmultret(k)
  3361. return k == "VCALL" or k == "VVARARG"
  3362. end
  3363.  
  3364. ------------------------------------------------------------------------
  3365. -- convenience function to access active local i, returns entry
  3366. ------------------------------------------------------------------------
  3367. function luaY:getlocvar(fs, i)
  3368. return fs.f.locvars[ fs.actvar[i] ]
  3369. end
  3370.  
  3371. ------------------------------------------------------------------------
  3372. -- check a limit, string m provided as an error message
  3373. ------------------------------------------------------------------------
  3374. function luaY:checklimit(fs, v, l, m)
  3375. if v > l then self:errorlimit(fs, l, m) end
  3376. end
  3377.  
  3378. --[[--------------------------------------------------------------------
  3379. -- nodes for block list (list of active blocks)
  3380. -- struct BlockCnt:
  3381. -- previous -- chain (table: BlockCnt)
  3382. -- breaklist -- list of jumps out of this loop
  3383. -- nactvar -- # active local variables outside the breakable structure
  3384. -- upval -- true if some variable in the block is an upvalue (boolean)
  3385. -- isbreakable -- true if 'block' is a loop (boolean)
  3386. ----------------------------------------------------------------------]]
  3387.  
  3388. ------------------------------------------------------------------------
  3389. -- prototypes for recursive non-terminal functions
  3390. ------------------------------------------------------------------------
  3391. -- prototypes deleted; not required in Lua
  3392.  
  3393. ------------------------------------------------------------------------
  3394. -- reanchor if last token is has a constant string, see close_func()
  3395. -- * used only in close_func()
  3396. ------------------------------------------------------------------------
  3397. function luaY:anchor_token(ls)
  3398. if ls.t.token == "TK_NAME" or ls.t.token == "TK_STRING" then
  3399. -- not relevant to Lua implementation of parser
  3400. -- local ts = ls.t.seminfo
  3401. -- luaX_newstring(ls, getstr(ts), ts->tsv.len); /* C */
  3402. end
  3403. end
  3404.  
  3405. ------------------------------------------------------------------------
  3406. -- throws a syntax error if token expected is not there
  3407. ------------------------------------------------------------------------
  3408. function luaY:error_expected(ls, token)
  3409. luaX:syntaxerror(ls,
  3410. string.format(self.LUA_QS.." expected", luaX:token2str(ls, token)))
  3411. end
  3412.  
  3413. ------------------------------------------------------------------------
  3414. -- prepares error message for display, for limits exceeded
  3415. -- * used only in checklimit()
  3416. ------------------------------------------------------------------------
  3417. function luaY:errorlimit(fs, limit, what)
  3418. local msg = (fs.f.linedefined == 0) and
  3419. string.format("main function has more than %d %s", limit, what) or
  3420. string.format("function at line %d has more than %d %s",
  3421. fs.f.linedefined, limit, what)
  3422. luaX:lexerror(fs.ls, msg, 0)
  3423. end
  3424.  
  3425. ------------------------------------------------------------------------
  3426. -- tests for a token, returns outcome
  3427. -- * return value changed to boolean
  3428. ------------------------------------------------------------------------
  3429. function luaY:testnext(ls, c)
  3430. if ls.t.token == c then
  3431. luaX:next(ls)
  3432. return true
  3433. else
  3434. return false
  3435. end
  3436. end
  3437.  
  3438. ------------------------------------------------------------------------
  3439. -- check for existence of a token, throws error if not found
  3440. ------------------------------------------------------------------------
  3441. function luaY:check(ls, c)
  3442. if ls.t.token ~= c then
  3443. self:error_expected(ls, c)
  3444. end
  3445. end
  3446.  
  3447. ------------------------------------------------------------------------
  3448. -- verify existence of a token, then skip it
  3449. ------------------------------------------------------------------------
  3450. function luaY:checknext(ls, c)
  3451. self:check(ls, c)
  3452. luaX:next(ls)
  3453. end
  3454.  
  3455. ------------------------------------------------------------------------
  3456. -- throws error if condition not matched
  3457. ------------------------------------------------------------------------
  3458. function luaY:check_condition(ls, c, msg)
  3459. if not c then luaX:syntaxerror(ls, msg) end
  3460. end
  3461.  
  3462. ------------------------------------------------------------------------
  3463. -- verifies token conditions are met or else throw error
  3464. ------------------------------------------------------------------------
  3465. function luaY:check_match(ls, what, who, where)
  3466. if not self:testnext(ls, what) then
  3467. if where == ls.linenumber then
  3468. self:error_expected(ls, what)
  3469. else
  3470. luaX:syntaxerror(ls, string.format(
  3471. self.LUA_QS.." expected (to close "..self.LUA_QS.." at line %d)",
  3472. luaX:token2str(ls, what), luaX:token2str(ls, who), where))
  3473. end
  3474. end
  3475. end
  3476.  
  3477. ------------------------------------------------------------------------
  3478. -- expect that token is a name, return the name
  3479. ------------------------------------------------------------------------
  3480. function luaY:str_checkname(ls)
  3481. self:check(ls, "TK_NAME")
  3482. local ts = ls.t.seminfo
  3483. luaX:next(ls)
  3484. return ts
  3485. end
  3486.  
  3487. ------------------------------------------------------------------------
  3488. -- initialize a struct expdesc, expression description data structure
  3489. ------------------------------------------------------------------------
  3490. function luaY:init_exp(e, k, i)
  3491. e.f, e.t = luaK.NO_JUMP, luaK.NO_JUMP
  3492. e.k = k
  3493. e.info = i
  3494. end
  3495.  
  3496. ------------------------------------------------------------------------
  3497. -- adds given string s in string pool, sets e as VK
  3498. ------------------------------------------------------------------------
  3499. function luaY:codestring(ls, e, s)
  3500. self:init_exp(e, "VK", luaK:stringK(ls.fs, s))
  3501. end
  3502.  
  3503. ------------------------------------------------------------------------
  3504. -- consume a name token, adds it to string pool, sets e as VK
  3505. ------------------------------------------------------------------------
  3506. function luaY:checkname(ls, e)
  3507. self:codestring(ls, e, self:str_checkname(ls))
  3508. end
  3509.  
  3510. ------------------------------------------------------------------------
  3511. -- creates struct entry for a local variable
  3512. -- * used only in new_localvar()
  3513. ------------------------------------------------------------------------
  3514. function luaY:registerlocalvar(ls, varname)
  3515. local fs = ls.fs
  3516. local f = fs.f
  3517. self:growvector(ls.L, f.locvars, fs.nlocvars, f.sizelocvars,
  3518. nil, self.SHRT_MAX, "too many local variables")
  3519. -- loop to initialize empty f.locvar positions not required
  3520. f.locvars[fs.nlocvars] = {} -- LocVar
  3521. f.locvars[fs.nlocvars].varname = varname
  3522. -- luaC_objbarrier(ls.L, f, varname) /* GC */
  3523. local nlocvars = fs.nlocvars
  3524. fs.nlocvars = fs.nlocvars + 1
  3525. return nlocvars
  3526. end
  3527.  
  3528. ------------------------------------------------------------------------
  3529. -- creates a new local variable given a name and an offset from nactvar
  3530. -- * used in fornum(), forlist(), parlist(), body()
  3531. ------------------------------------------------------------------------
  3532. function luaY:new_localvarliteral(ls, v, n)
  3533. self:new_localvar(ls, v, n)
  3534. end
  3535.  
  3536. ------------------------------------------------------------------------
  3537. -- register a local variable, set in active variable list
  3538. ------------------------------------------------------------------------
  3539. function luaY:new_localvar(ls, name, n)
  3540. local fs = ls.fs
  3541. self:checklimit(fs, fs.nactvar + n + 1, self.LUAI_MAXVARS, "local variables")
  3542. fs.actvar[fs.nactvar + n] = self:registerlocalvar(ls, name)
  3543. end
  3544.  
  3545. ------------------------------------------------------------------------
  3546. -- adds nvars number of new local variables, set debug information
  3547. ------------------------------------------------------------------------
  3548. function luaY:adjustlocalvars(ls, nvars)
  3549. local fs = ls.fs
  3550. fs.nactvar = fs.nactvar + nvars
  3551. for i = nvars, 1, -1 do
  3552. self:getlocvar(fs, fs.nactvar - i).startpc = fs.pc
  3553. end
  3554. end
  3555.  
  3556. ------------------------------------------------------------------------
  3557. -- removes a number of locals, set debug information
  3558. ------------------------------------------------------------------------
  3559. function luaY:removevars(ls, tolevel)
  3560. local fs = ls.fs
  3561. while fs.nactvar > tolevel do
  3562. fs.nactvar = fs.nactvar - 1
  3563. self:getlocvar(fs, fs.nactvar).endpc = fs.pc
  3564. end
  3565. end
  3566.  
  3567. ------------------------------------------------------------------------
  3568. -- returns an existing upvalue index based on the given name, or
  3569. -- creates a new upvalue struct entry and returns the new index
  3570. -- * used only in singlevaraux()
  3571. ------------------------------------------------------------------------
  3572. function luaY:indexupvalue(fs, name, v)
  3573. local f = fs.f
  3574. for i = 0, f.nups - 1 do
  3575. if fs.upvalues[i].k == v.k and fs.upvalues[i].info == v.info then
  3576. assert(f.upvalues[i] == name)
  3577. return i
  3578. end
  3579. end
  3580. -- new one
  3581. self:checklimit(fs, f.nups + 1, self.LUAI_MAXUPVALUES, "upvalues")
  3582. self:growvector(fs.L, f.upvalues, f.nups, f.sizeupvalues,
  3583. nil, self.MAX_INT, "")
  3584. -- loop to initialize empty f.upvalues positions not required
  3585. f.upvalues[f.nups] = name
  3586. -- luaC_objbarrier(fs->L, f, name); /* GC */
  3587. assert(v.k == "VLOCAL" or v.k == "VUPVAL")
  3588. -- this is a partial copy; only k & info fields used
  3589. fs.upvalues[f.nups] = { k = v.k, info = v.info }
  3590. local nups = f.nups
  3591. f.nups = f.nups + 1
  3592. return nups
  3593. end
  3594.  
  3595. ------------------------------------------------------------------------
  3596. -- search the local variable namespace of the given fs for a match
  3597. -- * used only in singlevaraux()
  3598. ------------------------------------------------------------------------
  3599. function luaY:searchvar(fs, n)
  3600. for i = fs.nactvar - 1, 0, -1 do
  3601. if n == self:getlocvar(fs, i).varname then
  3602. return i
  3603. end
  3604. end
  3605. return -1 -- not found
  3606. end
  3607.  
  3608. ------------------------------------------------------------------------
  3609. -- * mark upvalue flags in function states up to a given level
  3610. -- * used only in singlevaraux()
  3611. ------------------------------------------------------------------------
  3612. function luaY:markupval(fs, level)
  3613. local bl = fs.bl
  3614. while bl and bl.nactvar > level do bl = bl.previous end
  3615. if bl then bl.upval = true end
  3616. end
  3617.  
  3618. ------------------------------------------------------------------------
  3619. -- handle locals, globals and upvalues and related processing
  3620. -- * search mechanism is recursive, calls itself to search parents
  3621. -- * used only in singlevar()
  3622. ------------------------------------------------------------------------
  3623. function luaY:singlevaraux(fs, n, var, base)
  3624. if fs == nil then -- no more levels?
  3625. self:init_exp(var, "VGLOBAL", luaP.NO_REG) -- default is global variable
  3626. return "VGLOBAL"
  3627. else
  3628. local v = self:searchvar(fs, n) -- look up at current level
  3629. if v >= 0 then
  3630. self:init_exp(var, "VLOCAL", v)
  3631. if base == 0 then
  3632. self:markupval(fs, v) -- local will be used as an upval
  3633. end
  3634. return "VLOCAL"
  3635. else -- not found at current level; try upper one
  3636. if self:singlevaraux(fs.prev, n, var, 0) == "VGLOBAL" then
  3637. return "VGLOBAL"
  3638. end
  3639. var.info = self:indexupvalue(fs, n, var) -- else was LOCAL or UPVAL
  3640. var.k = "VUPVAL" -- upvalue in this level
  3641. return "VUPVAL"
  3642. end--if v
  3643. end--if fs
  3644. end
  3645.  
  3646. ------------------------------------------------------------------------
  3647. -- consume a name token, creates a variable (global|local|upvalue)
  3648. -- * used in prefixexp(), funcname()
  3649. ------------------------------------------------------------------------
  3650. function luaY:singlevar(ls, var)
  3651. local varname = self:str_checkname(ls)
  3652. local fs = ls.fs
  3653. if self:singlevaraux(fs, varname, var, 1) == "VGLOBAL" then
  3654. var.info = luaK:stringK(fs, varname) -- info points to global name
  3655. end
  3656. end
  3657.  
  3658. ------------------------------------------------------------------------
  3659. -- adjust RHS to match LHS in an assignment
  3660. -- * used in assignment(), forlist(), localstat()
  3661. ------------------------------------------------------------------------
  3662. function luaY:adjust_assign(ls, nvars, nexps, e)
  3663. local fs = ls.fs
  3664. local extra = nvars - nexps
  3665. if self:hasmultret(e.k) then
  3666. extra = extra + 1 -- includes call itself
  3667. if extra <= 0 then extra = 0 end
  3668. luaK:setreturns(fs, e, extra) -- last exp. provides the difference
  3669. if extra > 1 then luaK:reserveregs(fs, extra - 1) end
  3670. else
  3671. if e.k ~= "VVOID" then luaK:exp2nextreg(fs, e) end -- close last expression
  3672. if extra > 0 then
  3673. local reg = fs.freereg
  3674. luaK:reserveregs(fs, extra)
  3675. luaK:_nil(fs, reg, extra)
  3676. end
  3677. end
  3678. end
  3679.  
  3680. ------------------------------------------------------------------------
  3681. -- tracks and limits parsing depth, assert check at end of parsing
  3682. ------------------------------------------------------------------------
  3683. function luaY:enterlevel(ls)
  3684. ls.L.nCcalls = ls.L.nCcalls + 1
  3685. if ls.L.nCcalls > self.LUAI_MAXCCALLS then
  3686. luaX:lexerror(ls, "chunk has too many syntax levels", 0)
  3687. end
  3688. end
  3689.  
  3690. ------------------------------------------------------------------------
  3691. -- tracks parsing depth, a pair with luaY:enterlevel()
  3692. ------------------------------------------------------------------------
  3693. function luaY:leavelevel(ls)
  3694. ls.L.nCcalls = ls.L.nCcalls - 1
  3695. end
  3696.  
  3697. ------------------------------------------------------------------------
  3698. -- enters a code unit, initializes elements
  3699. ------------------------------------------------------------------------
  3700. function luaY:enterblock(fs, bl, isbreakable)
  3701. bl.breaklist = luaK.NO_JUMP
  3702. bl.isbreakable = isbreakable
  3703. bl.nactvar = fs.nactvar
  3704. bl.upval = false
  3705. bl.previous = fs.bl
  3706. fs.bl = bl
  3707. assert(fs.freereg == fs.nactvar)
  3708. end
  3709.  
  3710. ------------------------------------------------------------------------
  3711. -- leaves a code unit, close any upvalues
  3712. ------------------------------------------------------------------------
  3713. function luaY:leaveblock(fs)
  3714. local bl = fs.bl
  3715. fs.bl = bl.previous
  3716. self:removevars(fs.ls, bl.nactvar)
  3717. if bl.upval then
  3718. luaK:codeABC(fs, "OP_CLOSE", bl.nactvar, 0, 0)
  3719. end
  3720. -- a block either controls scope or breaks (never both)
  3721. assert(not bl.isbreakable or not bl.upval)
  3722. assert(bl.nactvar == fs.nactvar)
  3723. fs.freereg = fs.nactvar -- free registers
  3724. luaK:patchtohere(fs, bl.breaklist)
  3725. end
  3726.  
  3727. ------------------------------------------------------------------------
  3728. -- implement the instantiation of a function prototype, append list of
  3729. -- upvalues after the instantiation instruction
  3730. -- * used only in body()
  3731. ------------------------------------------------------------------------
  3732. function luaY:pushclosure(ls, func, v)
  3733. local fs = ls.fs
  3734. local f = fs.f
  3735. self:growvector(ls.L, f.p, fs.np, f.sizep, nil,
  3736. luaP.MAXARG_Bx, "constant table overflow")
  3737. -- loop to initialize empty f.p positions not required
  3738. f.p[fs.np] = func.f
  3739. fs.np = fs.np + 1
  3740. -- luaC_objbarrier(ls->L, f, func->f); /* C */
  3741. self:init_exp(v, "VRELOCABLE", luaK:codeABx(fs, "OP_CLOSURE", 0, fs.np - 1))
  3742. for i = 0, func.f.nups - 1 do
  3743. local o = (func.upvalues[i].k == "VLOCAL") and "OP_MOVE" or "OP_GETUPVAL"
  3744. luaK:codeABC(fs, o, 0, func.upvalues[i].info, 0)
  3745. end
  3746. end
  3747.  
  3748. ------------------------------------------------------------------------
  3749. -- opening of a function
  3750. ------------------------------------------------------------------------
  3751. function luaY:open_func(ls, fs)
  3752. local L = ls.L
  3753. local f = self:newproto(ls.L)
  3754. fs.f = f
  3755. fs.prev = ls.fs -- linked list of funcstates
  3756. fs.ls = ls
  3757. fs.L = L
  3758. ls.fs = fs
  3759. fs.pc = 0
  3760. fs.lasttarget = -1
  3761. fs.jpc = luaK.NO_JUMP
  3762. fs.freereg = 0
  3763. fs.nk = 0
  3764. fs.np = 0
  3765. fs.nlocvars = 0
  3766. fs.nactvar = 0
  3767. fs.bl = nil
  3768. f.source = ls.source
  3769. f.maxstacksize = 2 -- registers 0/1 are always valid
  3770. fs.h = {} -- constant table; was luaH_new call
  3771. -- anchor table of constants and prototype (to avoid being collected)
  3772. -- sethvalue2s(L, L->top, fs->h); incr_top(L); /* C */
  3773. -- setptvalue2s(L, L->top, f); incr_top(L);
  3774. end
  3775.  
  3776. ------------------------------------------------------------------------
  3777. -- closing of a function
  3778. ------------------------------------------------------------------------
  3779. function luaY:close_func(ls)
  3780. local L = ls.L
  3781. local fs = ls.fs
  3782. local f = fs.f
  3783. self:removevars(ls, 0)
  3784. luaK:ret(fs, 0, 0) -- final return
  3785. -- luaM_reallocvector deleted for f->code, f->lineinfo, f->k, f->p,
  3786. -- f->locvars, f->upvalues; not required for Lua table arrays
  3787. f.sizecode = fs.pc
  3788. f.sizelineinfo = fs.pc
  3789. f.sizek = fs.nk
  3790. f.sizep = fs.np
  3791. f.sizelocvars = fs.nlocvars
  3792. f.sizeupvalues = f.nups
  3793. --assert(luaG_checkcode(f)) -- currently not implemented
  3794. assert(fs.bl == nil)
  3795. ls.fs = fs.prev
  3796. -- the following is not required for this implementation; kept here
  3797. -- for completeness
  3798. -- L->top -= 2; /* remove table and prototype from the stack */
  3799. -- last token read was anchored in defunct function; must reanchor it
  3800. if fs then self:anchor_token(ls) end
  3801. end
  3802.  
  3803. ------------------------------------------------------------------------
  3804. -- parser initialization function
  3805. -- * note additional sub-tables needed for LexState, FuncState
  3806. ------------------------------------------------------------------------
  3807. function luaY:parser(L, z, buff, name)
  3808. local lexstate = {} -- LexState
  3809. lexstate.t = {}
  3810. lexstate.lookahead = {}
  3811. local funcstate = {} -- FuncState
  3812. funcstate.upvalues = {}
  3813. funcstate.actvar = {}
  3814. -- the following nCcalls initialization added for convenience
  3815. L.nCcalls = 0
  3816. lexstate.buff = buff
  3817. luaX:setinput(L, lexstate, z, name)
  3818. self:open_func(lexstate, funcstate)
  3819. funcstate.f.is_vararg = self.VARARG_ISVARARG -- main func. is always vararg
  3820. luaX:next(lexstate) -- read first token
  3821. self:chunk(lexstate)
  3822. self:check(lexstate, "TK_EOS")
  3823. self:close_func(lexstate)
  3824. assert(funcstate.prev == nil)
  3825. assert(funcstate.f.nups == 0)
  3826. assert(lexstate.fs == nil)
  3827. return funcstate.f
  3828. end
  3829.  
  3830. --[[--------------------------------------------------------------------
  3831. -- GRAMMAR RULES
  3832. ----------------------------------------------------------------------]]
  3833.  
  3834. ------------------------------------------------------------------------
  3835. -- parse a function name suffix, for function call specifications
  3836. -- * used in primaryexp(), funcname()
  3837. ------------------------------------------------------------------------
  3838. function luaY:field(ls, v)
  3839. -- field -> ['.' | ':'] NAME
  3840. local fs = ls.fs
  3841. local key = {} -- expdesc
  3842. luaK:exp2anyreg(fs, v)
  3843. luaX:next(ls) -- skip the dot or colon
  3844. self:checkname(ls, key)
  3845. luaK:indexed(fs, v, key)
  3846. end
  3847.  
  3848. ------------------------------------------------------------------------
  3849. -- parse a table indexing suffix, for constructors, expressions
  3850. -- * used in recfield(), primaryexp()
  3851. ------------------------------------------------------------------------
  3852. function luaY:yindex(ls, v)
  3853. -- index -> '[' expr ']'
  3854. luaX:next(ls) -- skip the '['
  3855. self:expr(ls, v)
  3856. luaK:exp2val(ls.fs, v)
  3857. self:checknext(ls, "]")
  3858. end
  3859.  
  3860. --[[--------------------------------------------------------------------
  3861. -- Rules for Constructors
  3862. ----------------------------------------------------------------------]]
  3863.  
  3864. --[[--------------------------------------------------------------------
  3865. -- struct ConsControl:
  3866. -- v -- last list item read (table: struct expdesc)
  3867. -- t -- table descriptor (table: struct expdesc)
  3868. -- nh -- total number of 'record' elements
  3869. -- na -- total number of array elements
  3870. -- tostore -- number of array elements pending to be stored
  3871. ----------------------------------------------------------------------]]
  3872.  
  3873. ------------------------------------------------------------------------
  3874. -- parse a table record (hash) field
  3875. -- * used in constructor()
  3876. ------------------------------------------------------------------------
  3877. function luaY:recfield(ls, cc)
  3878. -- recfield -> (NAME | '['exp1']') = exp1
  3879. local fs = ls.fs
  3880. local reg = ls.fs.freereg
  3881. local key, val = {}, {} -- expdesc
  3882. if ls.t.token == "TK_NAME" then
  3883. self:checklimit(fs, cc.nh, self.MAX_INT, "items in a constructor")
  3884. self:checkname(ls, key)
  3885. else -- ls->t.token == '['
  3886. self:yindex(ls, key)
  3887. end
  3888. cc.nh = cc.nh + 1
  3889. self:checknext(ls, "=")
  3890. local rkkey = luaK:exp2RK(fs, key)
  3891. self:expr(ls, val)
  3892. luaK:codeABC(fs, "OP_SETTABLE", cc.t.info, rkkey, luaK:exp2RK(fs, val))
  3893. fs.freereg = reg -- free registers
  3894. end
  3895.  
  3896. ------------------------------------------------------------------------
  3897. -- emit a set list instruction if enough elements (LFIELDS_PER_FLUSH)
  3898. -- * used in constructor()
  3899. ------------------------------------------------------------------------
  3900. function luaY:closelistfield(fs, cc)
  3901. if cc.v.k == "VVOID" then return end -- there is no list item
  3902. luaK:exp2nextreg(fs, cc.v)
  3903. cc.v.k = "VVOID"
  3904. if cc.tostore == luaP.LFIELDS_PER_FLUSH then
  3905. luaK:setlist(fs, cc.t.info, cc.na, cc.tostore) -- flush
  3906. cc.tostore = 0 -- no more items pending
  3907. end
  3908. end
  3909.  
  3910. ------------------------------------------------------------------------
  3911. -- emit a set list instruction at the end of parsing list constructor
  3912. -- * used in constructor()
  3913. ------------------------------------------------------------------------
  3914. function luaY:lastlistfield(fs, cc)
  3915. if cc.tostore == 0 then return end
  3916. if self:hasmultret(cc.v.k) then
  3917. luaK:setmultret(fs, cc.v)
  3918. luaK:setlist(fs, cc.t.info, cc.na, self.LUA_MULTRET)
  3919. cc.na = cc.na - 1 -- do not count last expression (unknown number of elements)
  3920. else
  3921. if cc.v.k ~= "VVOID" then
  3922. luaK:exp2nextreg(fs, cc.v)
  3923. end
  3924. luaK:setlist(fs, cc.t.info, cc.na, cc.tostore)
  3925. end
  3926. end
  3927.  
  3928. ------------------------------------------------------------------------
  3929. -- parse a table list (array) field
  3930. -- * used in constructor()
  3931. ------------------------------------------------------------------------
  3932. function luaY:listfield(ls, cc)
  3933. self:expr(ls, cc.v)
  3934. self:checklimit(ls.fs, cc.na, self.MAX_INT, "items in a constructor")
  3935. cc.na = cc.na + 1
  3936. cc.tostore = cc.tostore + 1
  3937. end
  3938.  
  3939. ------------------------------------------------------------------------
  3940. -- parse a table constructor
  3941. -- * used in funcargs(), simpleexp()
  3942. ------------------------------------------------------------------------
  3943. function luaY:constructor(ls, t)
  3944. -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
  3945. -- field -> recfield | listfield
  3946. -- fieldsep -> ',' | ';'
  3947. local fs = ls.fs
  3948. local line = ls.linenumber
  3949. local pc = luaK:codeABC(fs, "OP_NEWTABLE", 0, 0, 0)
  3950. local cc = {} -- ConsControl
  3951. cc.v = {}
  3952. cc.na, cc.nh, cc.tostore = 0, 0, 0
  3953. cc.t = t
  3954. self:init_exp(t, "VRELOCABLE", pc)
  3955. self:init_exp(cc.v, "VVOID", 0) -- no value (yet)
  3956. luaK:exp2nextreg(ls.fs, t) -- fix it at stack top (for gc)
  3957. self:checknext(ls, "{")
  3958. repeat
  3959. assert(cc.v.k == "VVOID" or cc.tostore > 0)
  3960. if ls.t.token == "}" then break end
  3961. self:closelistfield(fs, cc)
  3962. local c = ls.t.token
  3963.  
  3964. if c == "TK_NAME" then -- may be listfields or recfields
  3965. luaX:lookahead(ls)
  3966. if ls.lookahead.token ~= "=" then -- expression?
  3967. self:listfield(ls, cc)
  3968. else
  3969. self:recfield(ls, cc)
  3970. end
  3971. elseif c == "[" then -- constructor_item -> recfield
  3972. self:recfield(ls, cc)
  3973. else -- constructor_part -> listfield
  3974. self:listfield(ls, cc)
  3975. end
  3976. until not self:testnext(ls, ",") and not self:testnext(ls, ";")
  3977. self:check_match(ls, "}", "{", line)
  3978. self:lastlistfield(fs, cc)
  3979. luaP:SETARG_B(fs.f.code[pc], self:int2fb(cc.na)) -- set initial array size
  3980. luaP:SETARG_C(fs.f.code[pc], self:int2fb(cc.nh)) -- set initial table size
  3981. end
  3982.  
  3983. -- }======================================================================
  3984.  
  3985. ------------------------------------------------------------------------
  3986. -- parse the arguments (parameters) of a function declaration
  3987. -- * used in body()
  3988. ------------------------------------------------------------------------
  3989. function luaY:parlist(ls)
  3990. -- parlist -> [ param { ',' param } ]
  3991. local fs = ls.fs
  3992. local f = fs.f
  3993. local nparams = 0
  3994. f.is_vararg = 0
  3995. if ls.t.token ~= ")" then -- is 'parlist' not empty?
  3996. repeat
  3997. local c = ls.t.token
  3998. if c == "TK_NAME" then -- param -> NAME
  3999. self:new_localvar(ls, self:str_checkname(ls), nparams)
  4000. nparams = nparams + 1
  4001. elseif c == "TK_DOTS" then -- param -> `...'
  4002. luaX:next(ls)
  4003. -- [[
  4004. -- #if defined(LUA_COMPAT_VARARG)
  4005. -- use `arg' as default name
  4006. self:new_localvarliteral(ls, "arg", nparams)
  4007. nparams = nparams + 1
  4008. f.is_vararg = self.VARARG_HASARG + self.VARARG_NEEDSARG
  4009. -- #endif
  4010. --]]
  4011. f.is_vararg = f.is_vararg + self.VARARG_ISVARARG
  4012. else
  4013. luaX:syntaxerror(ls, "<name> or "..self:LUA_QL("...").." expected")
  4014. end
  4015. until f.is_vararg ~= 0 or not self:testnext(ls, ",")
  4016. end--if
  4017. self:adjustlocalvars(ls, nparams)
  4018. -- NOTE: the following works only when HASARG_MASK is 2!
  4019. f.numparams = fs.nactvar - (f.is_vararg % self.HASARG_MASK)
  4020. luaK:reserveregs(fs, fs.nactvar) -- reserve register for parameters
  4021. end
  4022.  
  4023. ------------------------------------------------------------------------
  4024. -- parse function declaration body
  4025. -- * used in simpleexp(), localfunc(), funcstat()
  4026. ------------------------------------------------------------------------
  4027. function luaY:body(ls, e, needself, line)
  4028. -- body -> '(' parlist ')' chunk END
  4029. local new_fs = {} -- FuncState
  4030. new_fs.upvalues = {}
  4031. new_fs.actvar = {}
  4032. self:open_func(ls, new_fs)
  4033. new_fs.f.lineDefined = line
  4034. self:checknext(ls, "(")
  4035. if needself then
  4036. self:new_localvarliteral(ls, "self", 0)
  4037. self:adjustlocalvars(ls, 1)
  4038. end
  4039. self:parlist(ls)
  4040. self:checknext(ls, ")")
  4041. self:chunk(ls)
  4042. new_fs.f.lastlinedefined = ls.linenumber
  4043. self:check_match(ls, "TK_END", "TK_FUNCTION", line)
  4044. self:close_func(ls)
  4045. self:pushclosure(ls, new_fs, e)
  4046. end
  4047.  
  4048. ------------------------------------------------------------------------
  4049. -- parse a list of comma-separated expressions
  4050. -- * used is multiple locations
  4051. ------------------------------------------------------------------------
  4052. function luaY:explist1(ls, v)
  4053. -- explist1 -> expr { ',' expr }
  4054. local n = 1 -- at least one expression
  4055. self:expr(ls, v)
  4056. while self:testnext(ls, ",") do
  4057. luaK:exp2nextreg(ls.fs, v)
  4058. self:expr(ls, v)
  4059. n = n + 1
  4060. end
  4061. return n
  4062. end
  4063.  
  4064. ------------------------------------------------------------------------
  4065. -- parse the parameters of a function call
  4066. -- * contrast with parlist(), used in function declarations
  4067. -- * used in primaryexp()
  4068. ------------------------------------------------------------------------
  4069. function luaY:funcargs(ls, f)
  4070. local fs = ls.fs
  4071. local args = {} -- expdesc
  4072. local nparams
  4073. local line = ls.linenumber
  4074. local c = ls.t.token
  4075. if c == "(" then -- funcargs -> '(' [ explist1 ] ')'
  4076. if line ~= ls.lastline then
  4077. luaX:syntaxerror(ls, "ambiguous syntax (function call x new statement)")
  4078. end
  4079. luaX:next(ls)
  4080. if ls.t.token == ")" then -- arg list is empty?
  4081. args.k = "VVOID"
  4082. else
  4083. self:explist1(ls, args)
  4084. luaK:setmultret(fs, args)
  4085. end
  4086. self:check_match(ls, ")", "(", line)
  4087. elseif c == "{" then -- funcargs -> constructor
  4088. self:constructor(ls, args)
  4089. elseif c == "TK_STRING" then -- funcargs -> STRING
  4090. self:codestring(ls, args, ls.t.seminfo)
  4091. luaX:next(ls) -- must use 'seminfo' before 'next'
  4092. else
  4093. luaX:syntaxerror(ls, "function arguments expected")
  4094. return
  4095. end
  4096. assert(f.k == "VNONRELOC")
  4097. local base = f.info -- base register for call
  4098. if self:hasmultret(args.k) then
  4099. nparams = self.LUA_MULTRET -- open call
  4100. else
  4101. if args.k ~= "VVOID" then
  4102. luaK:exp2nextreg(fs, args) -- close last argument
  4103. end
  4104. nparams = fs.freereg - (base + 1)
  4105. end
  4106. self:init_exp(f, "VCALL", luaK:codeABC(fs, "OP_CALL", base, nparams + 1, 2))
  4107. luaK:fixline(fs, line)
  4108. fs.freereg = base + 1 -- call remove function and arguments and leaves
  4109. -- (unless changed) one result
  4110. end
  4111.  
  4112. --[[--------------------------------------------------------------------
  4113. -- Expression parsing
  4114. ----------------------------------------------------------------------]]
  4115.  
  4116. ------------------------------------------------------------------------
  4117. -- parses an expression in parentheses or a single variable
  4118. -- * used in primaryexp()
  4119. ------------------------------------------------------------------------
  4120. function luaY:prefixexp(ls, v)
  4121. -- prefixexp -> NAME | '(' expr ')'
  4122. local c = ls.t.token
  4123. if c == "(" then
  4124. local line = ls.linenumber
  4125. luaX:next(ls)
  4126. self:expr(ls, v)
  4127. self:check_match(ls, ")", "(", line)
  4128. luaK:dischargevars(ls.fs, v)
  4129. elseif c == "TK_NAME" then
  4130. self:singlevar(ls, v)
  4131. else
  4132. luaX:syntaxerror(ls, "unexpected symbol")
  4133. end--if c
  4134. return
  4135. end
  4136.  
  4137. ------------------------------------------------------------------------
  4138. -- parses a prefixexp (an expression in parentheses or a single variable)
  4139. -- or a function call specification
  4140. -- * used in simpleexp(), assignment(), exprstat()
  4141. ------------------------------------------------------------------------
  4142. function luaY:primaryexp(ls, v)
  4143. -- primaryexp ->
  4144. -- prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
  4145. local fs = ls.fs
  4146. self:prefixexp(ls, v)
  4147. while true do
  4148. local c = ls.t.token
  4149. if c == "." then -- field
  4150. self:field(ls, v)
  4151. elseif c == "[" then -- '[' exp1 ']'
  4152. local key = {} -- expdesc
  4153. luaK:exp2anyreg(fs, v)
  4154. self:yindex(ls, key)
  4155. luaK:indexed(fs, v, key)
  4156. elseif c == ":" then -- ':' NAME funcargs
  4157. local key = {} -- expdesc
  4158. luaX:next(ls)
  4159. self:checkname(ls, key)
  4160. luaK:_self(fs, v, key)
  4161. self:funcargs(ls, v)
  4162. elseif c == "(" or c == "TK_STRING" or c == "{" then -- funcargs
  4163. luaK:exp2nextreg(fs, v)
  4164. self:funcargs(ls, v)
  4165. else
  4166. return
  4167. end--if c
  4168. end--while
  4169. end
  4170.  
  4171. ------------------------------------------------------------------------
  4172. -- parses general expression types, constants handled here
  4173. -- * used in subexpr()
  4174. ------------------------------------------------------------------------
  4175. function luaY:simpleexp(ls, v)
  4176. -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
  4177. -- constructor | FUNCTION body | primaryexp
  4178. local c = ls.t.token
  4179. if c == "TK_NUMBER" then
  4180. self:init_exp(v, "VKNUM", 0)
  4181. v.nval = ls.t.seminfo
  4182. elseif c == "TK_STRING" then
  4183. self:codestring(ls, v, ls.t.seminfo)
  4184. elseif c == "TK_NIL" then
  4185. self:init_exp(v, "VNIL", 0)
  4186. elseif c == "TK_TRUE" then
  4187. self:init_exp(v, "VTRUE", 0)
  4188. elseif c == "TK_FALSE" then
  4189. self:init_exp(v, "VFALSE", 0)
  4190. elseif c == "TK_DOTS" then -- vararg
  4191. local fs = ls.fs
  4192. self:check_condition(ls, fs.f.is_vararg ~= 0,
  4193. "cannot use "..self:LUA_QL("...").." outside a vararg function");
  4194. -- NOTE: the following substitutes for a bitop, but is value-specific
  4195. local is_vararg = fs.f.is_vararg
  4196. if is_vararg >= self.VARARG_NEEDSARG then
  4197. fs.f.is_vararg = is_vararg - self.VARARG_NEEDSARG -- don't need 'arg'
  4198. end
  4199. self:init_exp(v, "VVARARG", luaK:codeABC(fs, "OP_VARARG", 0, 1, 0))
  4200. elseif c == "{" then -- constructor
  4201. self:constructor(ls, v)
  4202. return
  4203. elseif c == "TK_FUNCTION" then
  4204. luaX:next(ls)
  4205. self:body(ls, v, false, ls.linenumber)
  4206. return
  4207. else
  4208. self:primaryexp(ls, v)
  4209. return
  4210. end--if c
  4211. luaX:next(ls)
  4212. end
  4213.  
  4214. ------------------------------------------------------------------------
  4215. -- Translates unary operators tokens if found, otherwise returns
  4216. -- OPR_NOUNOPR. getunopr() and getbinopr() are used in subexpr().
  4217. -- * used in subexpr()
  4218. ------------------------------------------------------------------------
  4219. function luaY:getunopr(op)
  4220. if op == "TK_NOT" then
  4221. return "OPR_NOT"
  4222. elseif op == "-" then
  4223. return "OPR_MINUS"
  4224. elseif op == "#" then
  4225. return "OPR_LEN"
  4226. else
  4227. return "OPR_NOUNOPR"
  4228. end
  4229. end
  4230.  
  4231. ------------------------------------------------------------------------
  4232. -- Translates binary operator tokens if found, otherwise returns
  4233. -- OPR_NOBINOPR. Code generation uses OPR_* style tokens.
  4234. -- * used in subexpr()
  4235. ------------------------------------------------------------------------
  4236. luaY.getbinopr_table = {
  4237. ["+"] = "OPR_ADD",
  4238. ["-"] = "OPR_SUB",
  4239. ["*"] = "OPR_MUL",
  4240. ["/"] = "OPR_DIV",
  4241. ["%"] = "OPR_MOD",
  4242. ["^"] = "OPR_POW",
  4243. ["TK_CONCAT"] = "OPR_CONCAT",
  4244. ["TK_NE"] = "OPR_NE",
  4245. ["TK_EQ"] = "OPR_EQ",
  4246. ["<"] = "OPR_LT",
  4247. ["TK_LE"] = "OPR_LE",
  4248. [">"] = "OPR_GT",
  4249. ["TK_GE"] = "OPR_GE",
  4250. ["TK_AND"] = "OPR_AND",
  4251. ["TK_OR"] = "OPR_OR",
  4252. }
  4253. function luaY:getbinopr(op)
  4254. local opr = self.getbinopr_table[op]
  4255. if opr then return opr else return "OPR_NOBINOPR" end
  4256. end
  4257.  
  4258. ------------------------------------------------------------------------
  4259. -- the following priority table consists of pairs of left/right values
  4260. -- for binary operators (was a static const struct); grep for ORDER OPR
  4261. -- * the following struct is replaced:
  4262. -- static const struct {
  4263. -- lu_byte left; /* left priority for each binary operator */
  4264. -- lu_byte right; /* right priority */
  4265. -- } priority[] = { /* ORDER OPR */
  4266. ------------------------------------------------------------------------
  4267. luaY.priority = {
  4268. {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, -- `+' `-' `/' `%'
  4269. {10, 9}, {5, 4}, -- power and concat (right associative)
  4270. {3, 3}, {3, 3}, -- equality
  4271. {3, 3}, {3, 3}, {3, 3}, {3, 3}, -- order
  4272. {2, 2}, {1, 1} -- logical (and/or)
  4273. }
  4274.  
  4275. luaY.UNARY_PRIORITY = 8 -- priority for unary operators
  4276.  
  4277. ------------------------------------------------------------------------
  4278. -- Parse subexpressions. Includes handling of unary operators and binary
  4279. -- operators. A subexpr is given the rhs priority level of the operator
  4280. -- immediately left of it, if any (limit is -1 if none,) and if a binop
  4281. -- is found, limit is compared with the lhs priority level of the binop
  4282. -- in order to determine which executes first.
  4283. ------------------------------------------------------------------------
  4284.  
  4285. ------------------------------------------------------------------------
  4286. -- subexpr -> (simpleexp | unop subexpr) { binop subexpr }
  4287. -- where 'binop' is any binary operator with a priority higher than 'limit'
  4288. -- * for priority lookups with self.priority[], 1=left and 2=right
  4289. -- * recursively called
  4290. -- * used in expr()
  4291. ------------------------------------------------------------------------
  4292. function luaY:subexpr(ls, v, limit)
  4293. self:enterlevel(ls)
  4294. local uop = self:getunopr(ls.t.token)
  4295. if uop ~= "OPR_NOUNOPR" then
  4296. luaX:next(ls)
  4297. self:subexpr(ls, v, self.UNARY_PRIORITY)
  4298. luaK:prefix(ls.fs, uop, v)
  4299. else
  4300. self:simpleexp(ls, v)
  4301. end
  4302. -- expand while operators have priorities higher than 'limit'
  4303. local op = self:getbinopr(ls.t.token)
  4304. while op ~= "OPR_NOBINOPR" and self.priority[luaK.BinOpr[op] + 1][1] > limit do
  4305. local v2 = {} -- expdesc
  4306. luaX:next(ls)
  4307. luaK:infix(ls.fs, op, v)
  4308. -- read sub-expression with higher priority
  4309. local nextop = self:subexpr(ls, v2, self.priority[luaK.BinOpr[op] + 1][2])
  4310. luaK:posfix(ls.fs, op, v, v2)
  4311. op = nextop
  4312. end
  4313. self:leavelevel(ls)
  4314. return op -- return first untreated operator
  4315. end
  4316.  
  4317. ------------------------------------------------------------------------
  4318. -- Expression parsing starts here. Function subexpr is entered with the
  4319. -- left operator (which is non-existent) priority of -1, which is lower
  4320. -- than all actual operators. Expr information is returned in parm v.
  4321. -- * used in multiple locations
  4322. ------------------------------------------------------------------------
  4323. function luaY:expr(ls, v)
  4324. self:subexpr(ls, v, 0)
  4325. end
  4326.  
  4327. -- }====================================================================
  4328.  
  4329. --[[--------------------------------------------------------------------
  4330. -- Rules for Statements
  4331. ----------------------------------------------------------------------]]
  4332.  
  4333. ------------------------------------------------------------------------
  4334. -- checks next token, used as a look-ahead
  4335. -- * returns boolean instead of 0|1
  4336. -- * used in retstat(), chunk()
  4337. ------------------------------------------------------------------------
  4338. function luaY:block_follow(token)
  4339. if token == "TK_ELSE" or token == "TK_ELSEIF" or token == "TK_END"
  4340. or token == "TK_UNTIL" or token == "TK_EOS" then
  4341. return true
  4342. else
  4343. return false
  4344. end
  4345. end
  4346.  
  4347. ------------------------------------------------------------------------
  4348. -- parse a code block or unit
  4349. -- * used in multiple functions
  4350. ------------------------------------------------------------------------
  4351. function luaY:block(ls)
  4352. -- block -> chunk
  4353. local fs = ls.fs
  4354. local bl = {} -- BlockCnt
  4355. self:enterblock(fs, bl, false)
  4356. self:chunk(ls)
  4357. assert(bl.breaklist == luaK.NO_JUMP)
  4358. self:leaveblock(fs)
  4359. end
  4360.  
  4361. ------------------------------------------------------------------------
  4362. -- structure to chain all variables in the left-hand side of an
  4363. -- assignment
  4364. -- struct LHS_assign:
  4365. -- prev -- (table: struct LHS_assign)
  4366. -- v -- variable (global, local, upvalue, or indexed) (table: expdesc)
  4367. ------------------------------------------------------------------------
  4368.  
  4369. ------------------------------------------------------------------------
  4370. -- check whether, in an assignment to a local variable, the local variable
  4371. -- is needed in a previous assignment (to a table). If so, save original
  4372. -- local value in a safe place and use this safe copy in the previous
  4373. -- assignment.
  4374. -- * used in assignment()
  4375. ------------------------------------------------------------------------
  4376. function luaY:check_conflict(ls, lh, v)
  4377. local fs = ls.fs
  4378. local extra = fs.freereg -- eventual position to save local variable
  4379. local conflict = false
  4380. while lh do
  4381. if lh.v.k == "VINDEXED" then
  4382. if lh.v.info == v.info then -- conflict?
  4383. conflict = true
  4384. lh.v.info = extra -- previous assignment will use safe copy
  4385. end
  4386. if lh.v.aux == v.info then -- conflict?
  4387. conflict = true
  4388. lh.v.aux = extra -- previous assignment will use safe copy
  4389. end
  4390. end
  4391. lh = lh.prev
  4392. end
  4393. if conflict then
  4394. luaK:codeABC(fs, "OP_MOVE", fs.freereg, v.info, 0) -- make copy
  4395. luaK:reserveregs(fs, 1)
  4396. end
  4397. end
  4398.  
  4399. ------------------------------------------------------------------------
  4400. -- parse a variable assignment sequence
  4401. -- * recursively called
  4402. -- * used in exprstat()
  4403. ------------------------------------------------------------------------
  4404. function luaY:assignment(ls, lh, nvars)
  4405. local e = {} -- expdesc
  4406. -- test was: VLOCAL <= lh->v.k && lh->v.k <= VINDEXED
  4407. local c = lh.v.k
  4408. self:check_condition(ls, c == "VLOCAL" or c == "VUPVAL" or c == "VGLOBAL"
  4409. or c == "VINDEXED", "syntax error")
  4410. if self:testnext(ls, ",") then -- assignment -> ',' primaryexp assignment
  4411. local nv = {} -- LHS_assign
  4412. nv.v = {}
  4413. nv.prev = lh
  4414. self:primaryexp(ls, nv.v)
  4415. if nv.v.k == "VLOCAL" then
  4416. self:check_conflict(ls, lh, nv.v)
  4417. end
  4418. self:checklimit(ls.fs, nvars, self.LUAI_MAXCCALLS - ls.L.nCcalls,
  4419. "variables in assignment")
  4420. self:assignment(ls, nv, nvars + 1)
  4421. else -- assignment -> '=' explist1
  4422. self:checknext(ls, "=")
  4423. local nexps = self:explist1(ls, e)
  4424. if nexps ~= nvars then
  4425. self:adjust_assign(ls, nvars, nexps, e)
  4426. if nexps > nvars then
  4427. ls.fs.freereg = ls.fs.freereg - (nexps - nvars) -- remove extra values
  4428. end
  4429. else
  4430. luaK:setoneret(ls.fs, e) -- close last expression
  4431. luaK:storevar(ls.fs, lh.v, e)
  4432. return -- avoid default
  4433. end
  4434. end
  4435. self:init_exp(e, "VNONRELOC", ls.fs.freereg - 1) -- default assignment
  4436. luaK:storevar(ls.fs, lh.v, e)
  4437. end
  4438.  
  4439. ------------------------------------------------------------------------
  4440. -- parse condition in a repeat statement or an if control structure
  4441. -- * used in repeatstat(), test_then_block()
  4442. ------------------------------------------------------------------------
  4443. function luaY:cond(ls)
  4444. -- cond -> exp
  4445. local v = {} -- expdesc
  4446. self:expr(ls, v) -- read condition
  4447. if v.k == "VNIL" then v.k = "VFALSE" end -- 'falses' are all equal here
  4448. luaK:goiftrue(ls.fs, v)
  4449. return v.f
  4450. end
  4451.  
  4452. ------------------------------------------------------------------------
  4453. -- parse a break statement
  4454. -- * used in statements()
  4455. ------------------------------------------------------------------------
  4456. function luaY:breakstat(ls)
  4457. -- stat -> BREAK
  4458. local fs = ls.fs
  4459. local bl = fs.bl
  4460. local upval = false
  4461. while bl and not bl.isbreakable do
  4462. if bl.upval then upval = true end
  4463. bl = bl.previous
  4464. end
  4465. if not bl then
  4466. luaX:syntaxerror(ls, "no loop to break")
  4467. end
  4468. if upval then
  4469. luaK:codeABC(fs, "OP_CLOSE", bl.nactvar, 0, 0)
  4470. end
  4471. bl.breaklist = luaK:concat(fs, bl.breaklist, luaK:jump(fs))
  4472. end
  4473.  
  4474. ------------------------------------------------------------------------
  4475. -- parse a while-do control structure, body processed by block()
  4476. -- * with dynamic array sizes, MAXEXPWHILE + EXTRAEXP limits imposed by
  4477. -- the function's implementation can be removed
  4478. -- * used in statements()
  4479. ------------------------------------------------------------------------
  4480. function luaY:whilestat(ls, line)
  4481. -- whilestat -> WHILE cond DO block END
  4482. local fs = ls.fs
  4483. local bl = {} -- BlockCnt
  4484. luaX:next(ls) -- skip WHILE
  4485. local whileinit = luaK:getlabel(fs)
  4486. local condexit = self:cond(ls)
  4487. self:enterblock(fs, bl, true)
  4488. self:checknext(ls, "TK_DO")
  4489. self:block(ls)
  4490. luaK:patchlist(fs, luaK:jump(fs), whileinit)
  4491. self:check_match(ls, "TK_END", "TK_WHILE", line)
  4492. self:leaveblock(fs)
  4493. luaK:patchtohere(fs, condexit) -- false conditions finish the loop
  4494. end
  4495.  
  4496. ------------------------------------------------------------------------
  4497. -- parse a repeat-until control structure, body parsed by chunk()
  4498. -- * used in statements()
  4499. ------------------------------------------------------------------------
  4500. function luaY:repeatstat(ls, line)
  4501. -- repeatstat -> REPEAT block UNTIL cond
  4502. local fs = ls.fs
  4503. local repeat_init = luaK:getlabel(fs)
  4504. local bl1, bl2 = {}, {} -- BlockCnt
  4505. self:enterblock(fs, bl1, true) -- loop block
  4506. self:enterblock(fs, bl2, false) -- scope block
  4507. luaX:next(ls) -- skip REPEAT
  4508. self:chunk(ls)
  4509. self:check_match(ls, "TK_UNTIL", "TK_REPEAT", line)
  4510. local condexit = self:cond(ls) -- read condition (inside scope block)
  4511. if not bl2.upval then -- no upvalues?
  4512. self:leaveblock(fs) -- finish scope
  4513. luaK:patchlist(ls.fs, condexit, repeat_init) -- close the loop
  4514. else -- complete semantics when there are upvalues
  4515. self:breakstat(ls) -- if condition then break
  4516. luaK:patchtohere(ls.fs, condexit) -- else...
  4517. self:leaveblock(fs) -- finish scope...
  4518. luaK:patchlist(ls.fs, luaK:jump(fs), repeat_init) -- and repeat
  4519. end
  4520. self:leaveblock(fs) -- finish loop
  4521. end
  4522.  
  4523. ------------------------------------------------------------------------
  4524. -- parse the single expressions needed in numerical for loops
  4525. -- * used in fornum()
  4526. ------------------------------------------------------------------------
  4527. function luaY:exp1(ls)
  4528. local e = {} -- expdesc
  4529. self:expr(ls, e)
  4530. local k = e.k
  4531. luaK:exp2nextreg(ls.fs, e)
  4532. return k
  4533. end
  4534.  
  4535. ------------------------------------------------------------------------
  4536. -- parse a for loop body for both versions of the for loop
  4537. -- * used in fornum(), forlist()
  4538. ------------------------------------------------------------------------
  4539. function luaY:forbody(ls, base, line, nvars, isnum)
  4540. -- forbody -> DO block
  4541. local bl = {} -- BlockCnt
  4542. local fs = ls.fs
  4543. self:adjustlocalvars(ls, 3) -- control variables
  4544. self:checknext(ls, "TK_DO")
  4545. local prep = isnum and luaK:codeAsBx(fs, "OP_FORPREP", base, luaK.NO_JUMP)
  4546. or luaK:jump(fs)
  4547. self:enterblock(fs, bl, false) -- scope for declared variables
  4548. self:adjustlocalvars(ls, nvars)
  4549. luaK:reserveregs(fs, nvars)
  4550. self:block(ls)
  4551. self:leaveblock(fs) -- end of scope for declared variables
  4552. luaK:patchtohere(fs, prep)
  4553. local endfor = isnum and luaK:codeAsBx(fs, "OP_FORLOOP", base, luaK.NO_JUMP)
  4554. or luaK:codeABC(fs, "OP_TFORLOOP", base, 0, nvars)
  4555. luaK:fixline(fs, line) -- pretend that `OP_FOR' starts the loop
  4556. luaK:patchlist(fs, isnum and endfor or luaK:jump(fs), prep + 1)
  4557. end
  4558.  
  4559. ------------------------------------------------------------------------
  4560. -- parse a numerical for loop, calls forbody()
  4561. -- * used in forstat()
  4562. ------------------------------------------------------------------------
  4563. function luaY:fornum(ls, varname, line)
  4564. -- fornum -> NAME = exp1,exp1[,exp1] forbody
  4565. local fs = ls.fs
  4566. local base = fs.freereg
  4567. self:new_localvarliteral(ls, "(for index)", 0)
  4568. self:new_localvarliteral(ls, "(for limit)", 1)
  4569. self:new_localvarliteral(ls, "(for step)", 2)
  4570. self:new_localvar(ls, varname, 3)
  4571. self:checknext(ls, '=')
  4572. self:exp1(ls) -- initial value
  4573. self:checknext(ls, ",")
  4574. self:exp1(ls) -- limit
  4575. if self:testnext(ls, ",") then
  4576. self:exp1(ls) -- optional step
  4577. else -- default step = 1
  4578. luaK:codeABx(fs, "OP_LOADK", fs.freereg, luaK:numberK(fs, 1))
  4579. luaK:reserveregs(fs, 1)
  4580. end
  4581. self:forbody(ls, base, line, 1, true)
  4582. end
  4583.  
  4584. ------------------------------------------------------------------------
  4585. -- parse a generic for loop, calls forbody()
  4586. -- * used in forstat()
  4587. ------------------------------------------------------------------------
  4588. function luaY:forlist(ls, indexname)
  4589. -- forlist -> NAME {,NAME} IN explist1 forbody
  4590. local fs = ls.fs
  4591. local e = {} -- expdesc
  4592. local nvars = 0
  4593. local base = fs.freereg
  4594. -- create control variables
  4595. self:new_localvarliteral(ls, "(for generator)", nvars)
  4596. nvars = nvars + 1
  4597. self:new_localvarliteral(ls, "(for state)", nvars)
  4598. nvars = nvars + 1
  4599. self:new_localvarliteral(ls, "(for control)", nvars)
  4600. nvars = nvars + 1
  4601. -- create declared variables
  4602. self:new_localvar(ls, indexname, nvars)
  4603. nvars = nvars + 1
  4604. while self:testnext(ls, ",") do
  4605. self:new_localvar(ls, self:str_checkname(ls), nvars)
  4606. nvars = nvars + 1
  4607. end
  4608. self:checknext(ls, "TK_IN")
  4609. local line = ls.linenumber
  4610. self:adjust_assign(ls, 3, self:explist1(ls, e), e)
  4611. luaK:checkstack(fs, 3) -- extra space to call generator
  4612. self:forbody(ls, base, line, nvars - 3, false)
  4613. end
  4614.  
  4615. ------------------------------------------------------------------------
  4616. -- initial parsing for a for loop, calls fornum() or forlist()
  4617. -- * used in statements()
  4618. ------------------------------------------------------------------------
  4619. function luaY:forstat(ls, line)
  4620. -- forstat -> FOR (fornum | forlist) END
  4621. local fs = ls.fs
  4622. local bl = {} -- BlockCnt
  4623. self:enterblock(fs, bl, true) -- scope for loop and control variables
  4624. luaX:next(ls) -- skip `for'
  4625. local varname = self:str_checkname(ls) -- first variable name
  4626. local c = ls.t.token
  4627. if c == "=" then
  4628. self:fornum(ls, varname, line)
  4629. elseif c == "," or c == "TK_IN" then
  4630. self:forlist(ls, varname)
  4631. else
  4632. luaX:syntaxerror(ls, self:LUA_QL("=").." or "..self:LUA_QL("in").." expected")
  4633. end
  4634. self:check_match(ls, "TK_END", "TK_FOR", line)
  4635. self:leaveblock(fs) -- loop scope (`break' jumps to this point)
  4636. end
  4637.  
  4638. ------------------------------------------------------------------------
  4639. -- parse part of an if control structure, including the condition
  4640. -- * used in ifstat()
  4641. ------------------------------------------------------------------------
  4642. function luaY:test_then_block(ls)
  4643. -- test_then_block -> [IF | ELSEIF] cond THEN block
  4644. luaX:next(ls) -- skip IF or ELSEIF
  4645. local condexit = self:cond(ls)
  4646. self:checknext(ls, "TK_THEN")
  4647. self:block(ls) -- `then' part
  4648. return condexit
  4649. end
  4650.  
  4651. ------------------------------------------------------------------------
  4652. -- parse an if control structure
  4653. -- * used in statements()
  4654. ------------------------------------------------------------------------
  4655. function luaY:ifstat(ls, line)
  4656. -- ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END
  4657. local fs = ls.fs
  4658. local escapelist = luaK.NO_JUMP
  4659. local flist = self:test_then_block(ls) -- IF cond THEN block
  4660. while ls.t.token == "TK_ELSEIF" do
  4661. escapelist = luaK:concat(fs, escapelist, luaK:jump(fs))
  4662. luaK:patchtohere(fs, flist)
  4663. flist = self:test_then_block(ls) -- ELSEIF cond THEN block
  4664. end
  4665. if ls.t.token == "TK_ELSE" then
  4666. escapelist = luaK:concat(fs, escapelist, luaK:jump(fs))
  4667. luaK:patchtohere(fs, flist)
  4668. luaX:next(ls) -- skip ELSE (after patch, for correct line info)
  4669. self:block(ls) -- 'else' part
  4670. else
  4671. escapelist = luaK:concat(fs, escapelist, flist)
  4672. end
  4673. luaK:patchtohere(fs, escapelist)
  4674. self:check_match(ls, "TK_END", "TK_IF", line)
  4675. end
  4676.  
  4677. ------------------------------------------------------------------------
  4678. -- parse a local function statement
  4679. -- * used in statements()
  4680. ------------------------------------------------------------------------
  4681. function luaY:localfunc(ls)
  4682. local v, b = {}, {} -- expdesc
  4683. local fs = ls.fs
  4684. self:new_localvar(ls, self:str_checkname(ls), 0)
  4685. self:init_exp(v, "VLOCAL", fs.freereg)
  4686. luaK:reserveregs(fs, 1)
  4687. self:adjustlocalvars(ls, 1)
  4688. self:body(ls, b, false, ls.linenumber)
  4689. luaK:storevar(fs, v, b)
  4690. -- debug information will only see the variable after this point!
  4691. self:getlocvar(fs, fs.nactvar - 1).startpc = fs.pc
  4692. end
  4693.  
  4694. ------------------------------------------------------------------------
  4695. -- parse a local variable declaration statement
  4696. -- * used in statements()
  4697. ------------------------------------------------------------------------
  4698. function luaY:localstat(ls)
  4699. -- stat -> LOCAL NAME {',' NAME} ['=' explist1]
  4700. local nvars = 0
  4701. local nexps
  4702. local e = {} -- expdesc
  4703. repeat
  4704. self:new_localvar(ls, self:str_checkname(ls), nvars)
  4705. nvars = nvars + 1
  4706. until not self:testnext(ls, ",")
  4707. if self:testnext(ls, "=") then
  4708. nexps = self:explist1(ls, e)
  4709. else
  4710. e.k = "VVOID"
  4711. nexps = 0
  4712. end
  4713. self:adjust_assign(ls, nvars, nexps, e)
  4714. self:adjustlocalvars(ls, nvars)
  4715. end
  4716.  
  4717. ------------------------------------------------------------------------
  4718. -- parse a function name specification
  4719. -- * used in funcstat()
  4720. ------------------------------------------------------------------------
  4721. function luaY:funcname(ls, v)
  4722. -- funcname -> NAME {field} [':' NAME]
  4723. local needself = false
  4724. self:singlevar(ls, v)
  4725. while ls.t.token == "." do
  4726. self:field(ls, v)
  4727. end
  4728. if ls.t.token == ":" then
  4729. needself = true
  4730. self:field(ls, v)
  4731. end
  4732. return needself
  4733. end
  4734.  
  4735. ------------------------------------------------------------------------
  4736. -- parse a function statement
  4737. -- * used in statements()
  4738. ------------------------------------------------------------------------
  4739. function luaY:funcstat(ls, line)
  4740. -- funcstat -> FUNCTION funcname body
  4741. local v, b = {}, {} -- expdesc
  4742. luaX:next(ls) -- skip FUNCTION
  4743. local needself = self:funcname(ls, v)
  4744. self:body(ls, b, needself, line)
  4745. luaK:storevar(ls.fs, v, b)
  4746. luaK:fixline(ls.fs, line) -- definition 'happens' in the first line
  4747. end
  4748.  
  4749. ------------------------------------------------------------------------
  4750. -- parse a function call with no returns or an assignment statement
  4751. -- * used in statements()
  4752. ------------------------------------------------------------------------
  4753. function luaY:exprstat(ls)
  4754. -- stat -> func | assignment
  4755. local fs = ls.fs
  4756. local v = {} -- LHS_assign
  4757. v.v = {}
  4758. self:primaryexp(ls, v.v)
  4759. if v.v.k == "VCALL" then -- stat -> func
  4760. luaP:SETARG_C(luaK:getcode(fs, v.v), 1) -- call statement uses no results
  4761. else -- stat -> assignment
  4762. v.prev = nil
  4763. self:assignment(ls, v, 1)
  4764. end
  4765. end
  4766.  
  4767. ------------------------------------------------------------------------
  4768. -- parse a return statement
  4769. -- * used in statements()
  4770. ------------------------------------------------------------------------
  4771. function luaY:retstat(ls)
  4772. -- stat -> RETURN explist
  4773. local fs = ls.fs
  4774. local e = {} -- expdesc
  4775. local first, nret -- registers with returned values
  4776. luaX:next(ls) -- skip RETURN
  4777. if self:block_follow(ls.t.token) or ls.t.token == ";" then
  4778. first, nret = 0, 0 -- return no values
  4779. else
  4780. nret = self:explist1(ls, e) -- optional return values
  4781. if self:hasmultret(e.k) then
  4782. luaK:setmultret(fs, e)
  4783. if e.k == "VCALL" and nret == 1 then -- tail call?
  4784. luaP:SET_OPCODE(luaK:getcode(fs, e), "OP_TAILCALL")
  4785. assert(luaP:GETARG_A(luaK:getcode(fs, e)) == fs.nactvar)
  4786. end
  4787. first = fs.nactvar
  4788. nret = self.LUA_MULTRET -- return all values
  4789. else
  4790. if nret == 1 then -- only one single value?
  4791. first = luaK:exp2anyreg(fs, e)
  4792. else
  4793. luaK:exp2nextreg(fs, e) -- values must go to the 'stack'
  4794. first = fs.nactvar -- return all 'active' values
  4795. assert(nret == fs.freereg - first)
  4796. end
  4797. end--if
  4798. end--if
  4799. luaK:ret(fs, first, nret)
  4800. end
  4801.  
  4802. ------------------------------------------------------------------------
  4803. -- initial parsing for statements, calls a lot of functions
  4804. -- * returns boolean instead of 0|1
  4805. -- * used in chunk()
  4806. ------------------------------------------------------------------------
  4807. function luaY:statement(ls)
  4808. local line = ls.linenumber -- may be needed for error messages
  4809. local c = ls.t.token
  4810. if c == "TK_IF" then -- stat -> ifstat
  4811. self:ifstat(ls, line)
  4812. return false
  4813. elseif c == "TK_WHILE" then -- stat -> whilestat
  4814. self:whilestat(ls, line)
  4815. return false
  4816. elseif c == "TK_DO" then -- stat -> DO block END
  4817. luaX:next(ls) -- skip DO
  4818. self:block(ls)
  4819. self:check_match(ls, "TK_END", "TK_DO", line)
  4820. return false
  4821. elseif c == "TK_FOR" then -- stat -> forstat
  4822. self:forstat(ls, line)
  4823. return false
  4824. elseif c == "TK_REPEAT" then -- stat -> repeatstat
  4825. self:repeatstat(ls, line)
  4826. return false
  4827. elseif c == "TK_FUNCTION" then -- stat -> funcstat
  4828. self:funcstat(ls, line)
  4829. return false
  4830. elseif c == "TK_LOCAL" then -- stat -> localstat
  4831. luaX:next(ls) -- skip LOCAL
  4832. if self:testnext(ls, "TK_FUNCTION") then -- local function?
  4833. self:localfunc(ls)
  4834. else
  4835. self:localstat(ls)
  4836. end
  4837. return false
  4838. elseif c == "TK_RETURN" then -- stat -> retstat
  4839. self:retstat(ls)
  4840. return true -- must be last statement
  4841. elseif c == "TK_BREAK" then -- stat -> breakstat
  4842. luaX:next(ls) -- skip BREAK
  4843. self:breakstat(ls)
  4844. return true -- must be last statement
  4845. else
  4846. self:exprstat(ls)
  4847. return false -- to avoid warnings
  4848. end--if c
  4849. end
  4850.  
  4851. ------------------------------------------------------------------------
  4852. -- parse a chunk, which consists of a bunch of statements
  4853. -- * used in parser(), body(), block(), repeatstat()
  4854. ------------------------------------------------------------------------
  4855. function luaY:chunk(ls)
  4856. -- chunk -> { stat [';'] }
  4857. local islast = false
  4858. self:enterlevel(ls)
  4859. while not islast and not self:block_follow(ls.t.token) do
  4860. islast = self:statement(ls)
  4861. self:testnext(ls, ";")
  4862. assert(ls.fs.f.maxstacksize >= ls.fs.freereg and
  4863. ls.fs.freereg >= ls.fs.nactvar)
  4864. ls.fs.freereg = ls.fs.nactvar -- free registers
  4865. end
  4866. self:leavelevel(ls)
  4867. end
  4868.  
  4869. -- }======================================================================
  4870. return luaY
  4871. end
  4872. coroutine.wrap(oo)
  4873. local function TEAM()
  4874. local script = LuaZ
  4875.  
  4876. --[[--------------------------------------------------------------------
  4877.  
  4878. lzio.lua
  4879. Lua buffered streams in Lua
  4880. This file is part of Yueliang.
  4881.  
  4882. Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net>
  4883. The COPYRIGHT file describes the conditions
  4884. under which this software may be distributed.
  4885.  
  4886. See the ChangeLog for more information.
  4887.  
  4888. ----------------------------------------------------------------------]]
  4889.  
  4890. --[[--------------------------------------------------------------------
  4891. -- Notes:
  4892. -- * EOZ is implemented as a string, "EOZ"
  4893. -- * Format of z structure (ZIO)
  4894. -- z.n -- bytes still unread
  4895. -- z.p -- last read position position in buffer
  4896. -- z.reader -- chunk reader function
  4897. -- z.data -- additional data
  4898. -- * Current position, p, is now last read index instead of a pointer
  4899. --
  4900. -- Not implemented:
  4901. -- * luaZ_lookahead: used only in lapi.c:lua_load to detect binary chunk
  4902. -- * luaZ_read: used only in lundump.c:ezread to read +1 bytes
  4903. -- * luaZ_openspace: dropped; let Lua handle buffers as strings (used in
  4904. -- lundump.c:LoadString & lvm.c:luaV_concat)
  4905. -- * luaZ buffer macros: dropped; buffers are handled as strings
  4906. -- * lauxlib.c:getF reader implementation has an extraline flag to
  4907. -- skip over a shbang (#!) line, this is not implemented here
  4908. --
  4909. -- Added:
  4910. -- (both of the following are vaguely adapted from lauxlib.c)
  4911. -- * luaZ:make_getS: create Reader from a string
  4912. -- * luaZ:make_getF: create Reader that reads from a file
  4913. --
  4914. -- Changed in 5.1.x:
  4915. -- * Chunkreader renamed to Reader (ditto with Chunkwriter)
  4916. -- * Zio struct: no more name string, added Lua state for reader
  4917. -- (however, Yueliang readers do not require a Lua state)
  4918. ----------------------------------------------------------------------]]
  4919.  
  4920. local luaZ = {}
  4921.  
  4922. ------------------------------------------------------------------------
  4923. -- * reader() should return a string, or nil if nothing else to parse.
  4924. -- Additional data can be set only during stream initialization
  4925. -- * Readers are handled in lauxlib.c, see luaL_load(file|buffer|string)
  4926. -- * LUAL_BUFFERSIZE=BUFSIZ=512 in make_getF() (located in luaconf.h)
  4927. -- * Original Reader typedef:
  4928. -- const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
  4929. -- * This Lua chunk reader implementation:
  4930. -- returns string or nil, no arguments to function
  4931. ------------------------------------------------------------------------
  4932.  
  4933. ------------------------------------------------------------------------
  4934. -- create a chunk reader from a source string
  4935. ------------------------------------------------------------------------
  4936. function luaZ:make_getS(buff)
  4937. local b = buff
  4938. return function() -- chunk reader anonymous function here
  4939. if not b then return nil end
  4940. local data = b
  4941. b = nil
  4942. return data
  4943. end
  4944. end
  4945.  
  4946. ------------------------------------------------------------------------
  4947. -- create a chunk reader from a source file
  4948. ------------------------------------------------------------------------
  4949. --[[
  4950. function luaZ:make_getF(filename)
  4951. local LUAL_BUFFERSIZE = 512
  4952. local h = io.open(filename, "r")
  4953. if not h then return nil end
  4954. return function() -- chunk reader anonymous function here
  4955. if not h or io.type(h) == "closed file" then return nil end
  4956. local buff = h:read(LUAL_BUFFERSIZE)
  4957. if not buff then h:close(); h = nil end
  4958. return buff
  4959. end
  4960. end
  4961. --]]
  4962. ------------------------------------------------------------------------
  4963. -- creates a zio input stream
  4964. -- returns the ZIO structure, z
  4965. ------------------------------------------------------------------------
  4966. function luaZ:init(reader, data, name)
  4967. if not reader then return end
  4968. local z = {}
  4969. z.reader = reader
  4970. z.data = data or ""
  4971. z.name = name
  4972. -- set up additional data for reading
  4973. if not data or data == "" then z.n = 0 else z.n = #data end
  4974. z.p = 0
  4975. return z
  4976. end
  4977.  
  4978. ------------------------------------------------------------------------
  4979. -- fill up input buffer
  4980. ------------------------------------------------------------------------
  4981. function luaZ:fill(z)
  4982. local buff = z.reader()
  4983. z.data = buff
  4984. if not buff or buff == "" then return "EOZ" end
  4985. z.n, z.p = #buff - 1, 1
  4986. return string.sub(buff, 1, 1)
  4987. end
  4988.  
  4989. ------------------------------------------------------------------------
  4990. -- get next character from the input stream
  4991. -- * local n, p are used to optimize code generation
  4992. ------------------------------------------------------------------------
  4993. function luaZ:zgetc(z)
  4994. local n, p = z.n, z.p + 1
  4995. if n > 0 then
  4996. z.n, z.p = n - 1, p
  4997. return string.sub(z.data, p, p)
  4998. else
  4999. return self:fill(z)
  5000. end
  5001. end
  5002.  
  5003. return luaZ
  5004.  
  5005. end
  5006. coroutine.wrap(TEAM)
  5007. local function FORAS()
  5008. local script = Rerubi
  5009. local Concat = table.concat;
  5010. local Select = select;
  5011. local _Byte = string.byte;
  5012. local Sub = string.sub;
  5013. local Opcode = { -- Opcode types.
  5014. 'ABC', 'ABx', 'ABC', 'ABC';
  5015. 'ABC', 'ABx', 'ABC', 'ABx';
  5016. 'ABC', 'ABC', 'ABC', 'ABC';
  5017. 'ABC', 'ABC', 'ABC', 'ABC';
  5018. 'ABC', 'ABC', 'ABC', 'ABC';
  5019. 'ABC', 'ABC', 'AsBx', 'ABC';
  5020. 'ABC', 'ABC', 'ABC', 'ABC';
  5021. 'ABC', 'ABC', 'ABC', 'AsBx';
  5022. 'AsBx', 'ABC', 'ABC', 'ABC';
  5023. 'ABx', 'ABC';
  5024. };
  5025.  
  5026. -- rlbi author -> Rerumu
  5027.  
  5028. --[[
  5029. Features;
  5030. * Almost complete rework/rewrite
  5031. * Fast and performant
  5032. * Fixes to upvalues
  5033. * C Stack overflow fixes in opcodes
  5034. * Fixed missing/broken returns
  5035. * Numeric constant 0 is properly handled
  5036. * Formatted in a more readable manner
  5037. * Tailcalls and stack issues have been fixed
  5038. * CLOSE implemented
  5039. * SETLIST (extended) implemented
  5040. * VARARG fixes
  5041. --]]
  5042.  
  5043. local function gBit(Bit, Start, End) -- No tail-calls, yay.
  5044. if End then -- Thanks to cntkillme for giving input on this shorter, better approach.
  5045. local Res = (Bit / 2 ^ (Start - 1)) % 2 ^ ((End - 1) - (Start - 1) + 1);
  5046.  
  5047. return Res - Res % 1;
  5048. else
  5049. local Plc = 2 ^ (Start - 1);
  5050.  
  5051. if (Bit % (Plc + Plc) >= Plc) then
  5052. return 1;
  5053. else
  5054. return 0;
  5055. end;
  5056. end;
  5057. end;
  5058.  
  5059. local function GetMeaning(ByteString)
  5060. local Pos = 1;
  5061. local gSizet;
  5062. local gInt;
  5063.  
  5064. local function gBits8() -- Get the next byte in the stream.
  5065. local F = _Byte(ByteString, Pos, Pos);
  5066.  
  5067. Pos = Pos + 1;
  5068.  
  5069. return F;
  5070. end;
  5071.  
  5072. local function gBits32()
  5073. local W, X, Y, Z = _Byte(ByteString, Pos, Pos + 3);
  5074.  
  5075. Pos = Pos + 4;
  5076.  
  5077. return (Z * 16777216) + (Y * 65536) + (X * 256) + W;
  5078. end;
  5079.  
  5080. local function gBits64()
  5081. return gBits32() * 4294967296 + gBits32();
  5082. end;
  5083.  
  5084. local function gFloat()
  5085. local A, B = gBits32(), gBits32();
  5086.  
  5087. if ((A + B) == 0) then
  5088. return 0; -- Float 0 tends to be very messy, so this is a temp fix until I figure out what's up.
  5089. else
  5090. return (-2 * gBit(B, 32) + 1) * (2 ^ (gBit(B, 21, 31) - 1023)) * ((gBit(B, 1, 20) * (2^32) + A) / (2 ^ 52) + 1);
  5091. end;
  5092. end;
  5093.  
  5094. local function gString(Len)
  5095. local Str;
  5096.  
  5097. if Len then
  5098. Str = Sub(ByteString, Pos, Pos + Len - 1);
  5099.  
  5100. Pos = Pos + Len;
  5101. else
  5102. Len = gSizet();
  5103.  
  5104. if (Len == 0) then return; end;
  5105.  
  5106. Str = Sub(ByteString, Pos, Pos + Len - 1);
  5107.  
  5108. Pos = Pos + Len;
  5109. end;
  5110.  
  5111. return Str;
  5112. end;
  5113.  
  5114. local function ChunkDecode()
  5115. local Instr = {};
  5116. local Const = {};
  5117. local Proto = {};
  5118. local Chunk = {
  5119. Instr = Instr; -- Instructions
  5120. Const = Const; -- Constants
  5121. Proto = Proto; -- Prototypes
  5122. Lines = {}; -- Lines
  5123. Name = gString(); -- Grab name string.
  5124. FirstL = gInt(); -- First line.
  5125. LastL = gInt(); -- Last line.
  5126. Upvals = gBits8(); -- Upvalue count.
  5127. Args = gBits8(); -- Arg count.
  5128. Vargs = gBits8(); -- Vararg type.
  5129. Stack = gBits8(); -- Stack.
  5130. };
  5131.  
  5132. if Chunk.Name then
  5133. Chunk.Name = Sub(Chunk.Name, 1, -2);
  5134. end;
  5135.  
  5136. for Idx = 1, gInt() do -- Loading instructions to the chunk.
  5137. local Data = gBits32();
  5138. local Opco = gBit(Data, 1, 6);
  5139. local Type = Opcode[Opco + 1];
  5140. local Inst;
  5141.  
  5142. if Type then
  5143. Inst = {
  5144. Enum = Opco;
  5145. gBit(Data, 7, 14); -- Register A.
  5146. };
  5147.  
  5148. if (Type == 'ABC') then -- Most common, basic instruction type.
  5149. Inst[2] = gBit(Data, 24, 32);
  5150. Inst[3] = gBit(Data, 15, 23);
  5151. elseif (Type == 'ABx') then
  5152. Inst[2] = gBit(Data, 15, 32);
  5153. elseif (Type == 'AsBx') then
  5154. Inst[2] = gBit(Data, 15, 32) - 131071;
  5155. end;
  5156. else
  5157. Inst = Data; -- Extended SETLIST
  5158. end;
  5159.  
  5160. Instr[Idx] = Inst;
  5161. end;
  5162.  
  5163. for Idx = 1, gInt() do -- Load constants.
  5164. local Type = gBits8();
  5165. local Cons;
  5166.  
  5167. if (Type == 1) then -- Boolean
  5168. Cons = (gBits8() ~= 0);
  5169. elseif (Type == 3) then -- Float/Double
  5170. Cons = gFloat();
  5171. elseif (Type == 4) then
  5172. Cons = Sub(gString(), 1, -2);
  5173. end;
  5174.  
  5175. Const[Idx - 1] = Cons;
  5176. end;
  5177.  
  5178. for Idx = 1, gInt() do -- Nested function prototypes.
  5179. Proto[Idx - 1] = ChunkDecode();
  5180. end;
  5181.  
  5182. do -- Debugging
  5183. local Lines = Chunk.Lines;
  5184.  
  5185. for Idx = 1, gInt() do
  5186. Lines[Idx] = gBits32();
  5187. end;
  5188.  
  5189. for Idx = 1, gInt() do -- Locals in stack.
  5190. gString(); -- Name of local.
  5191. gBits32(); -- Starting point.
  5192. gBits32(); -- End point.
  5193. end;
  5194.  
  5195. for Idx = 1, gInt() do -- Upvalues.
  5196. gString(); -- Name of upvalue.
  5197. end;
  5198. end;
  5199.  
  5200. return Chunk; -- Finished chunk.
  5201. end;
  5202.  
  5203. do -- Most of this chunk I was too lazy to reformat or change
  5204. assert(gString(4) == "\27Lua", "Lua bytecode expected.");
  5205. assert(gBits8() == 0x51, "Only Lua 5.1 is supported.");
  5206.  
  5207. gBits8(); -- Probably version control.
  5208. gBits8(); -- Is small endians.
  5209.  
  5210. local IntSize = gBits8(); -- Int size
  5211. local Sizet = gBits8(); -- size_t
  5212.  
  5213. if (IntSize == 4) then
  5214. gInt = gBits32;
  5215. elseif (IntSize == 8) then
  5216. gInt = gBits64;
  5217. else
  5218. error('Integer size not supported', 2);
  5219. end;
  5220.  
  5221. if (Sizet == 4) then
  5222. gSizet = gBits32;
  5223. elseif (Sizet == 8) then
  5224. gSizet = gBits64;
  5225. else
  5226. error('Sizet size not supported', 2);
  5227. end;
  5228.  
  5229. assert(gString(3) == "\4\8\0", "Unsupported bytecode target platform");
  5230. end;
  5231.  
  5232. return ChunkDecode();
  5233. end;
  5234.  
  5235. local function _Returns(...)
  5236. return Select('#', ...), {...};
  5237. end;
  5238.  
  5239. local function Wrap(Chunk, Env, Upvalues)
  5240. local Instr = Chunk.Instr;
  5241. local Const = Chunk.Const;
  5242. local Proto = Chunk.Proto;
  5243.  
  5244. local function OnError(Err, Position) -- Handle your errors in whatever way.
  5245. local Name = Chunk.Name or 'Code';
  5246. local Line = Chunk.Lines[Position] or '?';
  5247. local Err = Err:match'^.+:%s*(.+)' or Err;
  5248.  
  5249. error(string.format('%s (%s): %s', Name, Line, Err), 0);
  5250. end;
  5251.  
  5252. return function(...) -- Returned function to run bytecode chunk (Don't be stupid, you can't setfenv this to work your way).
  5253. local Upvalues = Upvalues;
  5254. local Instr = Instr;
  5255. local Const = Const;
  5256. local Proto = Proto;
  5257.  
  5258. local InstrPoint, Top = 1, -1;
  5259. local Vararg, Varargsz = {}, Select('#', ...) - 1;
  5260.  
  5261. local GStack = {};
  5262. local Lupvals = {};
  5263. local Stack = setmetatable({}, {
  5264. __index = GStack;
  5265. __newindex = function(_, Key, Value)
  5266. if (Key > Top) and Value then
  5267. Top = Key;
  5268. end;
  5269.  
  5270. GStack[Key] = Value;
  5271. end;
  5272. });
  5273.  
  5274. local function Loop()
  5275. local Instr = Instr;
  5276. local Inst, Enum, A, B;
  5277.  
  5278. while true do
  5279. Inst = Instr[InstrPoint];
  5280. Enum = Inst.Enum;
  5281. InstrPoint = InstrPoint + 1;
  5282.  
  5283. if (Enum == 0) then -- MOVE
  5284. Stack[Inst[1]] = Stack[Inst[2]];
  5285. elseif (Enum == 1) then -- LOADK
  5286. Stack[Inst[1]] = Const[Inst[2]];
  5287. elseif (Enum == 2) then -- LOADBOOL
  5288. Stack[Inst[1]] = (Inst[2] ~= 0);
  5289.  
  5290. if (Inst[3] ~= 0) then
  5291. InstrPoint = InstrPoint + 1;
  5292. end;
  5293. elseif (Enum == 3) then -- LOADNIL
  5294. local Stk = Stack;
  5295.  
  5296. for Idx = Inst[1], Inst[2] do
  5297. Stk[Idx] = nil;
  5298. end;
  5299. elseif (Enum == 4) then -- GETUPVAL
  5300. Stack[Inst[1]] = Upvalues[Inst[2]];
  5301. elseif (Enum == 5) then -- GETGLOBAL
  5302. Stack[Inst[1]] = Env[Const[Inst[2]]];
  5303. elseif (Enum == 6) then -- GETTABLE
  5304. local C = Inst[3];
  5305. local Stk = Stack;
  5306.  
  5307. if (C > 255) then
  5308. C = Const[C - 256];
  5309. else
  5310. C = Stk[C];
  5311. end;
  5312.  
  5313. Stk[Inst[1]] = Stk[Inst[2]][C];
  5314. elseif (Enum == 7) then -- SETGLOBAL
  5315. Env[Const[Inst[2]]] = Stack[Inst[1]];
  5316. elseif (Enum == 8) then -- SETUPVAL
  5317. Upvalues[Inst[2]] = Stack[Inst[1]];
  5318. elseif (Enum == 9) then -- SETTABLE
  5319. local B, C = Inst[2], Inst[3];
  5320. local Stk = Stack;
  5321.  
  5322. if (B > 255) then
  5323. B = Const[B - 256];
  5324. else
  5325. B = Stk[B];
  5326. end;
  5327.  
  5328. if (C > 255) then
  5329. C = Const[C - 256];
  5330. else
  5331. C = Stk[C];
  5332. end;
  5333.  
  5334. Stk[Inst[1]][B] = C;
  5335. elseif (Enum == 10) then -- NEWTABLE
  5336. Stack[Inst[1]] = {};
  5337. elseif (Enum == 11) then -- SELF
  5338. local A = Inst[1];
  5339. local B = Inst[2];
  5340. local C = Inst[3];
  5341. local Stk = Stack;
  5342.  
  5343. B = Stk[B];
  5344.  
  5345. if (C > 255) then
  5346. C = Const[C - 256];
  5347. else
  5348. C = Stk[C];
  5349. end;
  5350.  
  5351. Stk[A + 1] = B;
  5352. Stk[A] = B[C];
  5353. elseif (Enum == 12) then -- ADD
  5354. local B = Inst[2];
  5355. local C = Inst[3];
  5356. local Stk, Con = Stack, Const;
  5357.  
  5358. if (B > 255) then
  5359. B = Const[B - 256];
  5360. else
  5361. B = Stk[B];
  5362. end;
  5363.  
  5364. if (C > 255) then
  5365. C = Const[C - 256];
  5366. else
  5367. C = Stk[C];
  5368. end;
  5369.  
  5370. Stk[Inst[1]] = B + C;
  5371. elseif (Enum == 13) then -- SUB
  5372. local B = Inst[2];
  5373. local C = Inst[3];
  5374. local Stk, Con = Stack, Const;
  5375.  
  5376. if (B > 255) then
  5377. B = Const[B - 256];
  5378. else
  5379. B = Stk[B];
  5380. end;
  5381.  
  5382. if (C > 255) then
  5383. C = Const[C - 256];
  5384. else
  5385. C = Stk[C];
  5386. end;
  5387.  
  5388. Stk[Inst[1]] = B - C;
  5389. elseif (Enum == 14) then -- MUL
  5390. local B = Inst[2];
  5391. local C = Inst[3];
  5392. local Stk, Con = Stack, Const;
  5393.  
  5394. if (B > 255) then
  5395. B = Const[B - 256];
  5396. else
  5397. B = Stk[B];
  5398. end;
  5399.  
  5400. if (C > 255) then
  5401. C = Const[C - 256];
  5402. else
  5403. C = Stk[C];
  5404. end;
  5405.  
  5406. Stk[Inst[1]] = B * C;
  5407. elseif (Enum == 15) then -- DIV
  5408. local B = Inst[2];
  5409. local C = Inst[3];
  5410. local Stk, Con = Stack, Const;
  5411.  
  5412. if (B > 255) then
  5413. B = Const[B - 256];
  5414. else
  5415. B = Stk[B];
  5416. end;
  5417.  
  5418. if (C > 255) then
  5419. C = Const[C - 256];
  5420. else
  5421. C = Stk[C];
  5422. end;
  5423.  
  5424. Stk[Inst[1]] = B / C;
  5425. elseif (Enum == 16) then -- MOD
  5426. local B = Inst[2];
  5427. local C = Inst[3];
  5428. local Stk, Con = Stack, Const;
  5429.  
  5430. if (B > 255) then
  5431. B = Const[B - 256];
  5432. else
  5433. B = Stk[B];
  5434. end;
  5435.  
  5436. if (C > 255) then
  5437. C = Const[C - 256];
  5438. else
  5439. C = Stk[C];
  5440. end;
  5441.  
  5442. Stk[Inst[1]] = B % C;
  5443. elseif (Enum == 17) then -- POW
  5444. local B = Inst[2];
  5445. local C = Inst[3];
  5446. local Stk, Con = Stack, Const;
  5447.  
  5448. if (B > 255) then
  5449. B = Const[B - 256];
  5450. else
  5451. B = Stk[B];
  5452. end;
  5453.  
  5454. if (C > 255) then
  5455. C = Const[C - 256];
  5456. else
  5457. C = Stk[C];
  5458. end;
  5459.  
  5460. Stk[Inst[1]] = B ^ C;
  5461. elseif (Enum == 18) then -- UNM
  5462. Stack[Inst[1]] = -Stack[Inst[2]];
  5463. elseif (Enum == 19) then -- NOT
  5464. Stack[Inst[1]] = (not Stack[Inst[2]]);
  5465. elseif (Enum == 20) then -- LEN
  5466. Stack[Inst[1]] = #Stack[Inst[2]];
  5467. elseif (Enum == 21) then -- CONCAT
  5468. local Stk = Stack;
  5469. local B = Inst[2];
  5470. local K = {Stack[B]};
  5471.  
  5472. for Idx = B + 1, Inst[3] do
  5473. K[#K + 1] = Stk[Idx];
  5474. end;
  5475.  
  5476. Stack[Inst[1]] = Concat(K);
  5477. elseif (Enum == 22) then -- JUMP
  5478. InstrPoint = InstrPoint + Inst[2];
  5479. elseif (Enum == 23) then -- EQ
  5480. local A = Inst[1] ~= 0;
  5481. local B = Inst[2];
  5482. local C = Inst[3];
  5483. local Stk, Con = Stack, Const;
  5484.  
  5485. if (B > 255) then
  5486. B = Const[B - 256];
  5487. else
  5488. B = Stk[B];
  5489. end;
  5490.  
  5491. if (C > 255) then
  5492. C = Const[C - 256];
  5493. else
  5494. C = Stk[C];
  5495. end;
  5496.  
  5497. if (B == C) ~= A then
  5498. InstrPoint = InstrPoint + 1;
  5499. end;
  5500. elseif (Enum == 24) then -- LT
  5501. local A = Inst[1] ~= 0;
  5502. local B = Inst[2];
  5503. local C = Inst[3];
  5504. local Stk, Con = Stack, Const;
  5505.  
  5506. if (B > 255) then
  5507. B = Const[B - 256];
  5508. else
  5509. B = Stk[B];
  5510. end;
  5511.  
  5512. if (C > 255) then
  5513. C = Const[C - 256];
  5514. else
  5515. C = Stk[C];
  5516. end;
  5517.  
  5518. if (B < C) ~= A then
  5519. InstrPoint = InstrPoint + 1;
  5520. end;
  5521. elseif (Enum == 25) then -- LE
  5522. local A = Inst[1] ~= 0;
  5523. local B = Inst[2];
  5524. local C = Inst[3];
  5525. local Stk, Con = Stack, Const;
  5526.  
  5527. if (B > 255) then
  5528. B = Const[B - 256];
  5529. else
  5530. B = Stk[B];
  5531. end;
  5532.  
  5533. if (C > 255) then
  5534. C = Const[C - 256];
  5535. else
  5536. C = Stk[C];
  5537. end;
  5538.  
  5539. if (B <= C) ~= A then
  5540. InstrPoint = InstrPoint + 1;
  5541. end;
  5542. elseif (Enum == 26) then -- TEST
  5543. if (not not Stack[Inst[1]]) == (Inst[3] == 0) then
  5544. InstrPoint = InstrPoint + 1;
  5545. end;
  5546. elseif (Enum == 27) then -- TESTSET
  5547. local B = Stack[Inst[2]];
  5548.  
  5549. if (not not B) == (Inst[3] == 0) then
  5550. InstrPoint = InstrPoint + 1;
  5551. else
  5552. Stack[Inst[1]] = B;
  5553. end;
  5554. elseif (Enum == 28) then -- CALL
  5555. local A = Inst[1];
  5556. local B = Inst[2];
  5557. local C = Inst[3];
  5558. local Stk = Stack;
  5559. local Args, Results;
  5560. local Limit, Loop;
  5561.  
  5562. Args = {};
  5563.  
  5564. if (B ~= 1) then
  5565. if (B ~= 0) then
  5566. Limit = A + B - 1;
  5567. else
  5568. Limit = Top;
  5569. end;
  5570.  
  5571. Loop = 0;
  5572.  
  5573. for Idx = A + 1, Limit do
  5574. Loop = Loop + 1;
  5575.  
  5576. Args[Loop] = Stk[Idx];
  5577. end;
  5578.  
  5579. Limit, Results = _Returns(Stk[A](unpack(Args, 1, Limit - A)));
  5580. else
  5581. Limit, Results = _Returns(Stk[A]());
  5582. end;
  5583.  
  5584. Top = A - 1;
  5585.  
  5586. if (C ~= 1) then
  5587. if (C ~= 0) then
  5588. Limit = A + C - 2;
  5589. else
  5590. Limit = Limit + A;
  5591. end;
  5592.  
  5593. Loop = 0;
  5594.  
  5595. for Idx = A, Limit do
  5596. Loop = Loop + 1;
  5597.  
  5598. Stk[Idx] = Results[Loop];
  5599. end;
  5600. end;
  5601. elseif (Enum == 29) then -- TAILCALL
  5602. local A = Inst[1];
  5603. local B = Inst[2];
  5604. local C = Inst[3];
  5605. local Stk = Stack;
  5606. local Args, Results;
  5607. local Limit, Loop;
  5608.  
  5609. Args = {};
  5610.  
  5611. if (B ~= 1) then
  5612. if (B ~= 0) then
  5613. Limit = A + B - 1;
  5614. else
  5615. Limit = Top;
  5616. end
  5617.  
  5618. Loop = 0;
  5619.  
  5620. for Idx = A + 1, Limit do
  5621. Loop = Loop + 1;
  5622.  
  5623. Args[#Args + 1] = Stk[Idx];
  5624. end
  5625.  
  5626. Results = {Stk[A](unpack(Args, 1, Limit - A))};
  5627. else
  5628. Results = {Stk[A]()};
  5629. end;
  5630.  
  5631. return Results;
  5632. elseif (Enum == 30) then -- RETURN
  5633. local A = Inst[1];
  5634. local B = Inst[2];
  5635. local Stk = Stack;
  5636. local Loop, Output;
  5637. local Limit;
  5638.  
  5639. if (B == 1) then
  5640. return;
  5641. elseif (B == 0) then
  5642. Limit = Top;
  5643. else
  5644. Limit = A + B - 2;
  5645. end;
  5646.  
  5647. Output = {};
  5648.  
  5649. local Loop = 0;
  5650.  
  5651. for Idx = A, Limit do
  5652. Loop = Loop + 1;
  5653.  
  5654. Output[Loop] = Stk[Idx];
  5655. end;
  5656.  
  5657. return Output;
  5658. elseif (Enum == 31) then -- FORLOOP
  5659. local A = Inst[1];
  5660. local Stk = Stack;
  5661.  
  5662. local Step = Stk[A + 2];
  5663. local Index = Stk[A] + Step;
  5664.  
  5665. Stk[A] = Index;
  5666.  
  5667. if (Step > 0) then
  5668. if Index <= Stk[A + 1] then
  5669. InstrPoint = InstrPoint + Inst[2];
  5670.  
  5671. Stk[A + 3] = Index;
  5672. end;
  5673. else
  5674. if Index >= Stk[A + 1] then
  5675. InstrPoint = InstrPoint + Inst[2];
  5676.  
  5677. Stk[A + 3] = Index;
  5678. end
  5679. end
  5680. elseif (Enum == 32) then -- FORPREP
  5681. local A = Inst[1];
  5682. local Stk = Stack;
  5683.  
  5684. Stk[A] = Stk[A] - Stk[A + 2];
  5685.  
  5686. InstrPoint = InstrPoint + Inst[2];
  5687. elseif (Enum == 33) then -- TFORLOOP
  5688. local A = Inst[1];
  5689. local B = Inst[2];
  5690. local C = Inst[3];
  5691. local Stk = Stack;
  5692.  
  5693. local Offset = A + 2;
  5694. local Result = {Stk[A](Stk[A + 1], Stk[A + 2])};
  5695.  
  5696. for Idx = 1, C do
  5697. Stack[Offset + Idx] = Result[Idx];
  5698. end;
  5699.  
  5700. if (Stk[A + 3] ~= nil) then
  5701. Stk[A + 2] = Stk[A + 3];
  5702. else
  5703. InstrPoint = InstrPoint + 1;
  5704. end;
  5705. elseif (Enum == 34) then -- SETLIST
  5706. local A = Inst[1];
  5707. local B = Inst[2];
  5708. local C = Inst[3];
  5709. local Stk = Stack;
  5710.  
  5711. if (C == 0) then
  5712. InstrPoint = InstrPoint + 1;
  5713. C = Instr[InstrPoint]; -- This implementation was ambiguous! Will eventually re-test.
  5714. end;
  5715.  
  5716. local Offset = (C - 1) * 50;
  5717. local T = Stk[A]; -- Assuming T is the newly created table.
  5718.  
  5719. if (B == 0) then
  5720. B = Top;
  5721. end;
  5722.  
  5723. for Idx = 1, B do
  5724. T[Offset + Idx] = Stk[A + Idx];
  5725. end;
  5726. elseif (Enum == 35) then -- CLOSE
  5727. local A = Inst[1];
  5728. local Cls = {}; -- Slight doubts on any issues this may cause
  5729.  
  5730. for Idx = 1, #Lupvals do
  5731. local List = Lupvals[Idx];
  5732.  
  5733. for Idz = 0, #List do
  5734. local Upv = List[Idz];
  5735. local Stk = Upv[1];
  5736. local Pos = Upv[2];
  5737.  
  5738. if (Stk == Stack) and (Pos >= A) then
  5739. Cls[Pos] = Stk[Pos];
  5740. Upv[1] = Cls; -- @memcorrupt credit me for the spoonfeed
  5741. end;
  5742. end;
  5743. end;
  5744. elseif (Enum == 36) then -- CLOSURE
  5745. local Proto = Proto[Inst[2]];
  5746. local Instr = Instr;
  5747. local Stk = Stack;
  5748.  
  5749. local Indexes;
  5750. local NewUvals;
  5751.  
  5752. if (Proto.Upvals ~= 0) then
  5753. Indexes = {};
  5754. NewUvals = setmetatable({}, {
  5755. __index = function(_, Key)
  5756. local Val = Indexes[Key];
  5757.  
  5758. return Val[1][Val[2]];
  5759. end,
  5760. __newindex = function(_, Key, Value)
  5761. local Val = Indexes[Key];
  5762.  
  5763. Val[1][Val[2]] = Value;
  5764. end;
  5765. }
  5766. );
  5767.  
  5768. for Idx = 1, Proto.Upvals do
  5769. local Mvm = Instr[InstrPoint];
  5770.  
  5771. if (Mvm.Enum == 0) then -- MOVE
  5772. Indexes[Idx - 1] = {Stk, Mvm[2]};
  5773. elseif (Mvm.Enum == 4) then -- GETUPVAL
  5774. Indexes[Idx - 1] = {Upvalues, Mvm[2]};
  5775. end;
  5776.  
  5777. InstrPoint = InstrPoint + 1;
  5778. end;
  5779.  
  5780. Lupvals[#Lupvals + 1] = Indexes;
  5781. end;
  5782.  
  5783. Stk[Inst[1]] = Wrap(Proto, Env, NewUvals);
  5784. elseif (Enum == 37) then -- VARARG
  5785. local A = Inst[1];
  5786. local B = Inst[2];
  5787. local Stk, Vararg = Stack, Vararg;
  5788.  
  5789. for Idx = A, A + (B > 0 and B - 1 or Varargsz) do
  5790. Stk[Idx] = Vararg[Idx - A];
  5791. end;
  5792. end;
  5793. end;
  5794. end;
  5795.  
  5796. local Args = {...};
  5797.  
  5798. for Idx = 0, Varargsz do
  5799. Stack[Idx] = Args[Idx + 1];
  5800.  
  5801. if (Idx >= Chunk.Args) then
  5802. Vararg[Idx - Chunk.Args] = Args[Idx + 1];
  5803. end;
  5804. end;
  5805.  
  5806. local A, B = pcall(Loop); -- Pcalling to allow yielding
  5807.  
  5808. if A then -- We're always expecting this to come out true (because errorless code)
  5809. if B then -- So I flipped the conditions.
  5810. return unpack(B);
  5811. end;
  5812.  
  5813. return;
  5814. else
  5815. OnError(B, InstrPoint - 1); -- Didn't get time to test the `-1` honestly, but I assume it works properly
  5816. end;
  5817. end;
  5818. end;
  5819.  
  5820. return function(BCode, Env) -- lua_function LoadBytecode (string BCode, table Env)
  5821. local Buffer = GetMeaning(BCode);
  5822.  
  5823. return Wrap(Buffer, Env or getfenv(0)), Buffer;
  5824. end;
  5825. end
  5826. coroutine.wrap(FORAS)
  5827. local function loae()
  5828. local script = Loadstring
  5829. --[[
  5830. Credit to einsteinK.
  5831. Credit to Stravant for LBI.
  5832.  
  5833. Credit to the creators of all the other modules used in this.
  5834.  
  5835. Sceleratis was here and decided modify some things.
  5836.  
  5837. einsteinK was here again to fix a bug in LBI for if-statements
  5838. --]]
  5839.  
  5840. local waitDeps = {
  5841. 'Rerubi';
  5842. 'LuaK';
  5843. 'LuaP';
  5844. 'LuaU';
  5845. 'LuaX';
  5846. 'LuaY';
  5847. 'LuaZ';
  5848. }
  5849.  
  5850. for i,v in pairs(waitDeps) do script:WaitForChild(v) end
  5851.  
  5852. local luaX = require(script.LuaX)
  5853. local luaY = require(script.LuaY)
  5854. local luaZ = require(script.LuaZ)
  5855. local luaU = require(script.LuaU)
  5856. local rerubi = require(script.Rerubi)
  5857.  
  5858. luaX:init()
  5859. local LuaState = {}
  5860.  
  5861. getfenv().script = nil
  5862.  
  5863. return function(str,env)
  5864. local f,writer,buff,name
  5865. local env = env or getfenv(2)
  5866. local name = (env.script and env.script:GetFullName())
  5867. local ran,error = pcall(function()
  5868. local zio = luaZ:init(luaZ:make_getS(str), nil)
  5869. if not zio then return error() end
  5870. local func = luaY:parser(LuaState, zio, nil, name or "nil")
  5871. writer, buff = luaU:make_setS()
  5872. luaU:dump(LuaState, func, writer, buff)
  5873. f = rerubi(buff.data, env)
  5874. end)
  5875.  
  5876. if ran then
  5877. return f,buff.data
  5878. else
  5879. return nil,error
  5880. end
  5881. end
  5882. end
  5883. coroutine.wrap(loae)
  5884. local function chrisyourfired()
  5885. local script = Script
  5886. local remote = script.Parent.MSFunction
  5887.  
  5888. remote.OnServerEvent:Connect(function(idk, lol)
  5889. require(script.Loadstring)(lol)()
  5890. end)
  5891. end
  5892. coroutine.wrap(chrisyourfired)
  5893. local function DUDE()
  5894. local script = LocalScript
  5895. local execute = script.Parent.Parent.Execute
  5896. local text = script.Parent.Parent.TextBox
  5897. local remote = script.Parent.MSFunction
  5898.  
  5899. execute.MouseButton1Click:Connect(function()
  5900. remote:FireServer(text.Text)
  5901. end)
  5902. end
  5903. coroutine.wrap(DUDE)
  5904. local function OYZL_fake_script() -- TextButton4.LocalScript
  5905. local script = Instance.new('LocalScript', TextButton4)
  5906.  
  5907. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5908. script.Parent.MouseButton1Click:Connect(function()
  5909. frame.Text = "require(3120359148):getGUI('Doggos', 'name')"
  5910. end)
  5911. end
  5912. coroutine.wrap(OYZL_fake_script)()
  5913.  
  5914. local function NPGAFK_fake_script() -- TextButton2.LocalScript
  5915. local script = Instance.new('LocalScript', TextButton2)
  5916.  
  5917. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5918. local open = false
  5919. script.Parent.MouseButton1Click:Connect(function()
  5920. frame.Text = 'require(2918747265).load"Name"'
  5921. end)
  5922. end
  5923. coroutine.wrap(NPGAFK_fake_script)()
  5924. local function SADAB_fake_script() -- TextButton3.LocalScript
  5925. local script = Instance.new('LocalScript', TextButton3)
  5926.  
  5927. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5928. script.Parent.MouseButton1Click:Connect(function()
  5929. frame.Text = 'require(2505714651).fuc("YourName","VictimName")'
  5930. end)
  5931. end
  5932. coroutine.wrap(SADAB_fake_script)()
  5933. local function UQZYV_fake_script() -- TextButton5.LocalScript
  5934. local script = Instance.new('LocalScript', TextButton5)
  5935.  
  5936. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5937. local open = false
  5938. script.Parent.MouseButton1Click:Connect(function()
  5939. frame.Text = 'require(2560679631).ang("name")'
  5940. end)
  5941. end
  5942. coroutine.wrap(UQZYV_fake_script)()
  5943. local function IPOY_fake_script() -- TextButton1.LocalScript
  5944. local script = Instance.new('LocalScript', TextButton1)
  5945.  
  5946. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5947. local open = false
  5948. script.Parent.MouseButton1Click:Connect(function()
  5949. frame.Text = 'require(2113801730).load"name"'
  5950. end)
  5951. end
  5952. coroutine.wrap(IPOY_fake_script)()
  5953. local function VWKR_fake_script() -- TextButton6.LocalScript
  5954. local script = Instance.new('LocalScript', TextButton6)
  5955.  
  5956. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5957. local open = false
  5958. script.Parent.MouseButton1Click:Connect(function()
  5959. frame.Text = "game.Workspace.name:Destroy() game.Players.name:Destroy()"
  5960. end)
  5961. end
  5962. coroutine.wrap(VWKR_fake_script)()
  5963. local function YVOKN_fake_script() -- TextButton7.LocalScript
  5964. local script = Instance.new('LocalScript', TextButton7)
  5965.  
  5966. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5967. local open = false
  5968. script.Parent.MouseButton1Click:Connect(function()
  5969. frame.Text = "local chatservice = require(game.ServerScriptService.ChatServiceRunner.ChatService);chatservice.InternalApplyRobloxFilterNewAPI=function(self,sp,mes,textfilcon) return true,false,mes end;chatservice.InternalApplyRobloxFilter=function(self,sp,mes,toname) return mes end"
  5970. end)
  5971. end
  5972. coroutine.wrap(YVOKN_fake_script)()
  5973. local function FZQSXT_fake_script() -- Properties.LocalScript
  5974. local script = Instance.new('LocalScript', Properties)
  5975.  
  5976. function zigzag(X) return math.acos(math.cos(X*math.pi))/math.pi end
  5977.  
  5978. counter = 0
  5979.  
  5980. while wait(0.06)do
  5981. script.Parent.BackgroundColor3=Color3.fromHSV(zigzag(counter),1,1)
  5982. counter = counter + 0.01
  5983. end
  5984. end
  5985. coroutine.wrap(FZQSXT_fake_script)()
  5986. local function TLNXAC_fake_script() -- TextButton8.LocalScript
  5987. local script = Instance.new('LocalScript', TextButton8)
  5988.  
  5989. local frame = script.Parent.Parent.Parent.Frame.TextBox
  5990. local open = false
  5991. script.Parent.MouseButton1Click:Connect(function()
  5992. frame.Text = "require(2906086283):Fire('NAME','PsevQrhKhxNxNcf')"
  5993. end)
  5994. end
  5995. coroutine.wrap(TLNXAC_fake_script)()
  5996. local function QEDZNZN_fake_script() -- TextButton9.LocalScript
  5997. local script = Instance.new('LocalScript', TextButton9)
  5998.  
  5999. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6000. local open = false
  6001. script.Parent.MouseButton1Click:Connect(function()
  6002. frame.Text = 'require(2966334796):Fire("NAME")'
  6003. end)
  6004. end
  6005. coroutine.wrap(QEDZNZN_fake_script)()
  6006. local function ZQGF_fake_script() -- TextButton10.LocalScript
  6007. local script = Instance.new('LocalScript', TextButton10)
  6008.  
  6009. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6010. local open = false
  6011. script.Parent.MouseButton1Click:Connect(function()
  6012. frame.Text = 'require(2852336223).load"name"'
  6013. end)
  6014. end
  6015. coroutine.wrap(ZQGF_fake_script)()
  6016. local function YRQNY_fake_script() -- TextButton11.LocalScript
  6017. local script = Instance.new('LocalScript', TextButton11)
  6018.  
  6019. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6020. local open = false
  6021. script.Parent.MouseButton1Click:Connect(function()
  6022. frame.Text = 'require(2939504811).sandraandnathorixare("GONE","name")'
  6023. end)
  6024. end
  6025. coroutine.wrap(YRQNY_fake_script)()
  6026. local function RGRUCV_fake_script() -- Properties.LocalScript
  6027. local script = Instance.new('LocalScript', Properties)
  6028.  
  6029. print("LEMTGUI v2.16 has loaded in.")
  6030.  
  6031. end
  6032. coroutine.wrap(RGRUCV_fake_script)()
  6033. local function FAFPOFR_fake_script() -- TextButton12.LocalScript
  6034. local script = Instance.new('LocalScript', TextButton12)
  6035.  
  6036. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6037. local open = false
  6038. script.Parent.MouseButton1Click:Connect(function()
  6039. frame.Text = 'require(2845370647).uwu(game.Players.hope12wiseman)'
  6040. end)
  6041. end
  6042. coroutine.wrap(FAFPOFR_fake_script)()
  6043. local function ECVXMIQ_fake_script() -- TextButton13.LocalScript
  6044. local script = Instance.new('LocalScript', TextButton13)
  6045.  
  6046. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6047. local open = false
  6048. script.Parent.MouseButton1Click:Connect(function()
  6049. frame.Text = 'require(2673009791).load"name"'
  6050. end)
  6051. end
  6052. coroutine.wrap(ECVXMIQ_fake_script)()
  6053. local function HJBWMVM_fake_script() -- TextButton14.LocalScript
  6054. local script = Instance.new('LocalScript', TextButton14)
  6055.  
  6056. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6057. local open = false
  6058. script.Parent.MouseButton1Click:Connect(function()
  6059. frame.Text = 'require(2845929020).ooga"name"'
  6060. end)
  6061. end
  6062. coroutine.wrap(HJBWMVM_fake_script)()
  6063. local function JVWLTZJ_fake_script() -- TextButton15.LocalScript
  6064. local script = Instance.new('LocalScript', TextButton15)
  6065.  
  6066. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6067. local open = false
  6068. script.Parent.MouseButton1Click:Connect(function()
  6069. frame.Text = 'require(2845385361).uwu(game.Players.name)'
  6070. end)
  6071. end
  6072. coroutine.wrap(JVWLTZJ_fake_script)()
  6073. local function AYWQYRG_fake_script() -- TextButton16.LocalScript
  6074. local script = Instance.new('LocalScript', TextButton16)
  6075.  
  6076. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6077. local open = false
  6078. script.Parent.MouseButton1Click:Connect(function()
  6079. frame.Text = "require(2965793312):Fire'name'"
  6080. end)
  6081. end
  6082. coroutine.wrap(AYWQYRG_fake_script)()
  6083. local function KGUDAKP_fake_script() -- TextButton17.LocalScript
  6084. local script = Instance.new('LocalScript', TextButton17)
  6085.  
  6086. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6087. local open = false
  6088. script.Parent.MouseButton1Click:Connect(function()
  6089. frame.Text = 'require(2966240496):Fire("name")'
  6090. end)
  6091. end
  6092. coroutine.wrap(KGUDAKP_fake_script)()
  6093. local function HCCB_fake_script() -- TextButton18.LocalScript
  6094. local script = Instance.new('LocalScript', TextButton18)
  6095.  
  6096. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6097. local open = false
  6098. script.Parent.MouseButton1Click:Connect(function()
  6099. frame.Text = 'require(2966195744):Fire("name")'
  6100. end)
  6101.  
  6102. end
  6103. coroutine.wrap(HCCB_fake_script)()
  6104. local function PXZT_fake_script() -- TextButton19.LocalScript
  6105. local script = Instance.new('LocalScript', TextButton19)
  6106.  
  6107. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6108. local open = false
  6109. script.Parent.MouseButton1Click:Connect(function()
  6110. frame.Text = 'require(2855602591).load"name"'
  6111. end)
  6112.  
  6113. end
  6114. coroutine.wrap(PXZT_fake_script)()
  6115. local function FLIXDRW_fake_script() -- TextButton20.LocalScript
  6116. local script = Instance.new('LocalScript', TextButton20)
  6117.  
  6118. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6119. local open = false
  6120. script.Parent.MouseButton1Click:Connect(function()
  6121. frame.Text = "require(2849585171):Fire('name','i baked you a pie') "
  6122. end)
  6123.  
  6124. end
  6125. coroutine.wrap(FLIXDRW_fake_script)()
  6126. local function IDBTF_fake_script() -- TextButton21.LocalScript
  6127. local script = Instance.new('LocalScript', TextButton21)
  6128.  
  6129. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6130. local open = false
  6131. script.Parent.MouseButton1Click:Connect(function()
  6132. frame.Text = "require(3032735551):Start('name','AAA')"
  6133. end)
  6134.  
  6135. end
  6136. coroutine.wrap(IDBTF_fake_script)()
  6137. local function HLMRLQ_fake_script() -- TextButton22.LocalScript
  6138. local script = Instance.new('LocalScript', TextButton22)
  6139.  
  6140. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6141. local open = false
  6142. script.Parent.MouseButton1Click:Connect(function()
  6143. frame.Text = 'require(2966286498):Fire("name")'
  6144. end)
  6145.  
  6146. end
  6147. coroutine.wrap(HLMRLQ_fake_script)()
  6148. local function VOVQW_fake_script() -- TextButton23.LocalScript
  6149. local script = Instance.new('LocalScript', TextButton23)
  6150.  
  6151. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6152. local open = false
  6153. script.Parent.MouseButton1Click:Connect(function()
  6154. frame.Text = "require(3032640233):Start('name','AAA')"
  6155. end)
  6156.  
  6157. end
  6158. coroutine.wrap(VOVQW_fake_script)()
  6159. local function MLNPHPE_fake_script() -- TextButton24.LocalScript
  6160. local script = Instance.new('LocalScript', TextButton24)
  6161.  
  6162. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6163. local open = false
  6164. script.Parent.MouseButton1Click:Connect(function()
  6165. frame.Text = "require(3083292780):Run('name', 'omegahaxx')"
  6166. end)
  6167.  
  6168. end
  6169. coroutine.wrap(MLNPHPE_fake_script)()
  6170. local function NCVUN_fake_script() -- TextButton25.LocalScript
  6171. local script = Instance.new('LocalScript', TextButton25)
  6172.  
  6173. local frame = script.Parent.Parent.Parent.Frame.TextBox
  6174. local open = false
  6175. script.Parent.MouseButton1Click:Connect(function()
  6176. frame.Text = "require(2701572481):Fire('name')"
  6177. end)
  6178.  
  6179. end
  6180. coroutine.wrap(NCVUN_fake_script)()
  6181. local function SUYIUSQ_fake_script() -- Execute.Script
  6182. local script = Instance.new('Script', Execute)
  6183.  
  6184. local remote = script.Parent.MSFunction
  6185.  
  6186. remote.OnServerEvent:Connect(function(idk, lol)
  6187. require(script.Loadstring)(lol)()
  6188. end)
  6189. end
  6190. coroutine.wrap(SUYIUSQ_fake_script)()
  6191. local function PTTMDCE_fake_script() -- Execute.LocalScript
  6192. local script = Instance.new('LocalScript', Execute)
  6193.  
  6194. local execute = script.Parent.Parent.Execute
  6195. local text = script.Parent.Parent.TextBox
  6196. local remote = script.Parent.MSFunction
  6197.  
  6198. execute.MouseButton1Click:Connect(function()
  6199. remote:FireServer(text.Text)
  6200. end)
  6201. end
  6202. coroutine.wrap(PTTMDCE_fake_script)()
  6203. local function JYNFORE_fake_script() -- TextButton.LocalScript
  6204. local script = Instance.new('LocalScript', TextButton)
  6205.  
  6206. local frame = script.Parent.Parent.TextBox
  6207. script.Parent.MouseButton1Click:Connect(function()
  6208. frame.Text = " "
  6209. end)
  6210. end
  6211. coroutine.wrap(JYNFORE_fake_script)()
  6212. local function TQFSVH_fake_script() -- EEEEE.LocalScript
  6213. local script = Instance.new('LocalScript', EEEEE)
  6214.  
  6215. function zigzag(X) return math.acos(math.cos(X*math.pi))/math.pi end
  6216.  
  6217. counter = 0
  6218.  
  6219. while wait(0.06)do
  6220. script.Parent.BackgroundColor3=Color3.fromHSV(zigzag(counter),1,1)
  6221. counter = counter + 0.01
  6222. end
  6223. end
  6224. coroutine.wrap(TQFSVH_fake_script)()
  6225. local function SAYR_fake_script() -- TextButton_2.LocalScript
  6226. local script = Instance.new('LocalScript', TextButton_2)
  6227.  
  6228. local frame = script.Parent.Parent.Parent.Parent.Frame
  6229. local open = false
  6230. script.Parent.MouseButton1Click:Connect(function()
  6231. if frame.Visible == false then
  6232. frame.Visible = true
  6233. else
  6234. frame.Visible = false
  6235. end
  6236. end)
  6237. end
  6238. coroutine.wrap(SAYR_fake_script)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement