AA122294

SERVERSIDE🤑🤑🤑

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