This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
source.lua
6125 lines (5543 loc) · 218 KB
/
source.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--!nocheck
--! Nanocore Internal UI
--! Release 3.9
--! Author: ttwiz_z (ttwizz)
--! License: MIT
--! GitHub: https://github.com/ttwizz/Nanocore
--! Issues: https://github.com/ttwizz/Nanocore/issues
--! Pull requests: https://github.com/ttwizz/Nanocore/pulls
--! Discussions: https://github.com/ttwizz/Nanocore/discussions
--! twix.cyou/pix
--? Script Hider
pcall(function()
local _script_ = script
if _script_ then
script = nil
_script_.Parent = nil
_script_ = nil
getfenv().script = nil
end
end)
--? Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local CoreGui = game:GetService("CoreGui")
--? Constants
local Player = Players.LocalPlayer
local ExecutorTweenInfo = TweenInfo.new(0.075)
local StrokeTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local ButtonHover = Color3.fromRGB(120, 120, 120)
local ButtonDown = Color3.fromRGB(170, 170, 170)
--? Instances
local Executor = Instance.new("CanvasGroup")
local UICorner = Instance.new("UICorner")
local Title = Instance.new("TextLabel")
local UICorner_2 = Instance.new("UICorner")
local Editor = Instance.new("Frame")
local Code = Instance.new("ScrollingFrame")
local Content = Instance.new("TextBox")
local UIPadding = Instance.new("UIPadding")
local Buttons = Instance.new("Frame")
local UIListLayout = Instance.new("UIListLayout")
local Execute = Instance.new("TextButton")
local UIStroke = Instance.new("UIStroke")
local UICorner_3 = Instance.new("UICorner")
local Clear = Instance.new("TextButton")
local UIStroke_2 = Instance.new("UIStroke")
local UICorner_4 = Instance.new("UICorner")
local UIStroke_3 = Instance.new("UIStroke")
--? Functions
local function RandomString()
local Length = math.random(11, 22)
local Array = {}
for Index = 1, Length do
Array[Index] = string.char(math.random(35, 91))
end
return table.concat(Array)
end
local function AutoRename(Object)
while task.wait() do
if typeof(Object) == "Instance" and Object.Parent then
Object.Name = RandomString()
else
break
end
end
end
local function Tween(Object, TweenInfo, Properties)
if typeof(Object) == "Instance" and typeof(TweenInfo) == "TweenInfo" and type(Properties) == "table" then
TweenService:Create(Object, TweenInfo, Properties):Play()
end
end
local function SmoothDrag(Object)
if type(Object) == "userdata" then
local Toggle, Input, Start, StartPosition
local function Update(Key)
local Delta = Key.Position - Start
local NewPosition = UDim2.new(StartPosition.X.Scale, StartPosition.X.Offset + Delta.X, StartPosition.Y.Scale, StartPosition.Y.Offset + Delta.Y)
Tween(Object, ExecutorTweenInfo, {Position = NewPosition})
end
Object.InputBegan:Connect(function(NewInput)
if (NewInput.UserInputType == Enum.UserInputType.MouseButton1 or NewInput.UserInputType == Enum.UserInputType.Touch) and not UserInputService:GetFocusedTextBox() then
Toggle = true
Start = NewInput.Position
StartPosition = Object.Position
NewInput.Changed:Connect(function()
if NewInput.UserInputState == Enum.UserInputState.End then
Toggle = false
end
end)
end
end)
Object.InputChanged:Connect(function(NewInput)
if NewInput.UserInputType == Enum.UserInputType.MouseMovement or NewInput.UserInputType == Enum.UserInputType.Touch then
Input = NewInput
end
end)
UserInputService.InputChanged:Connect(function(NewInput)
if NewInput == Input and Toggle then
Update(NewInput)
end
end)
end
end
--? NanocoreVM
--# selene: allow(incorrect_standard_library_use, multiple_statements, shadowing, unused_variable, empty_if, divide_by_zero, unbalanced_assignments)
--[[
lopcodes.lua
Lua 5 virtual machine opcodes in Lua
This file is part of Yueliang.
Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
See the ChangeLog for more information.
]]
--[[
-- Notes:
-- * an Instruction is a table with OP, A, B, C, Bx elements; this
-- makes the code easy to follow and should allow instruction handling
-- to work with doubles and ints
-- * WARNING luaP:Instruction outputs instructions encoded in little-
-- endian form and field size and positions are hard-coded
--
-- Not implemented:
-- *
--
-- Added:
-- * luaP:CREATE_Inst(c): create an inst from a number (for OP_SETLIST)
-- * luaP:Instruction(i): convert field elements to a 4-char string
-- * luaP:DecodeInst(x): convert 4-char string into field elements
--
-- Changed in 5.1.x:
-- * POS_OP added, instruction field positions changed
-- * some symbol names may have changed, e.g. LUAI_BITSINT
-- * new operators for RK indices: BITRK, ISK(x), INDEXK(r), RKASK(x)
-- * OP_MOD, OP_LEN is new
-- * OP_TEST is now OP_TESTSET, OP_TEST is new
-- * OP_FORLOOP, OP_TFORLOOP adjusted, OP_FORPREP is new
-- * OP_TFORPREP deleted
-- * OP_SETLIST and OP_SETLISTO merged and extended
-- * OP_VARARG is new
-- * many changes to implementation of OpMode data
]]
local luaP = {}
--[[
===========================================================================
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
'A' : 8 bits
'B' : 9 bits
'C' : 9 bits
'Bx' : 18 bits ('B' and 'C' together)
'sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
for that argument (so that -max is represented by 0, and +max is
represented by 2*max), which is half the maximum for the corresponding
unsigned argument.
===========================================================================
]]
luaP.OpMode = { iABC = 0, iABx = 1, iAsBx = 2 } -- basic instruction format
------------------------------------------------------------------------
-- size and position of opcode arguments.
-- * WARNING size and position is hard-coded elsewhere in this script
------------------------------------------------------------------------
luaP.SIZE_C = 9
luaP.SIZE_B = 9
luaP.SIZE_Bx = luaP.SIZE_C + luaP.SIZE_B
luaP.SIZE_A = 8
luaP.SIZE_OP = 6
luaP.POS_OP = 0
luaP.POS_A = luaP.POS_OP + luaP.SIZE_OP
luaP.POS_C = luaP.POS_A + luaP.SIZE_A
luaP.POS_B = luaP.POS_C + luaP.SIZE_C
luaP.POS_Bx = luaP.POS_C
------------------------------------------------------------------------
-- limits for opcode arguments.
-- we use (signed) int to manipulate most arguments,
-- so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
------------------------------------------------------------------------
-- removed "#if SIZE_Bx < BITS_INT-1" test, assume this script is
-- running on a Lua VM with double or int as LUA_NUMBER
luaP.MAXARG_Bx = math.ldexp(1, luaP.SIZE_Bx) - 1
luaP.MAXARG_sBx = math.floor(luaP.MAXARG_Bx / 2) -- 'sBx' is signed
luaP.MAXARG_A = math.ldexp(1, luaP.SIZE_A) - 1
luaP.MAXARG_B = math.ldexp(1, luaP.SIZE_B) - 1
luaP.MAXARG_C = math.ldexp(1, luaP.SIZE_C) - 1
-- creates a mask with 'n' 1 bits at position 'p'
-- MASK1(n,p) deleted, not required
-- creates a mask with 'n' 0 bits at position 'p'
-- MASK0(n,p) deleted, not required
--[[
Visual representation for reference:
31 | | | 0 bit position
+-----+-----+-----+----------+
| B | C | A | Opcode | iABC format
+-----+-----+-----+----------+
- 9 - 9 - 8 - 6 - field sizes
+-----+-----+-----+----------+
| [s]Bx | A | Opcode | iABx | iAsBx format
+-----+-----+-----+----------+
]]
------------------------------------------------------------------------
-- the following macros help to manipulate instructions
-- * changed to a table object representation, very clean compared to
-- the [nightmare] alternatives of using a number or a string
-- * Bx is a separate element from B and C, since there is never a need
-- to split Bx in the parser or code generator
------------------------------------------------------------------------
-- these accept or return opcodes in the form of string names
function luaP:GET_OPCODE(i) return self.ROpCode[i.OP] end
function luaP:SET_OPCODE(i, o) i.OP = self.OpCode[o] end
function luaP:GETARG_A(i) return i.A end
function luaP:SETARG_A(i, u) i.A = u end
function luaP:GETARG_B(i) return i.B end
function luaP:SETARG_B(i, b) i.B = b end
function luaP:GETARG_C(i) return i.C end
function luaP:SETARG_C(i, b) i.C = b end
function luaP:GETARG_Bx(i) return i.Bx end
function luaP:SETARG_Bx(i, b) i.Bx = b end
function luaP:GETARG_sBx(i) return i.Bx - self.MAXARG_sBx end
function luaP:SETARG_sBx(i, b) i.Bx = b + self.MAXARG_sBx end
function luaP:CREATE_ABC(o,a,b,c)
return {OP = self.OpCode[o], A = a, B = b, C = c}
end
function luaP:CREATE_ABx(o,a,bc)
return {OP = self.OpCode[o], A = a, Bx = bc}
end
------------------------------------------------------------------------
-- create an instruction from a number (for OP_SETLIST)
------------------------------------------------------------------------
function luaP:CREATE_Inst(c)
local o = c % 64
c = (c - o) / 64
local a = c % 256
c = (c - a) / 256
return self:CREATE_ABx(o, a, c)
end
------------------------------------------------------------------------
-- returns a 4-char string little-endian encoded form of an instruction
------------------------------------------------------------------------
function luaP:Instruction(i)
if i.Bx then
-- change to OP/A/B/C format
i.C = i.Bx % 512
i.B = (i.Bx - i.C) / 512
end
local I = i.A * 64 + i.OP
local c0 = I % 256
I = i.C * 64 + (I - c0) / 256 -- 6 bits of A left
local c1 = I % 256
I = i.B * 128 + (I - c1) / 256 -- 7 bits of C left
local c2 = I % 256
local c3 = (I - c2) / 256
return string.char(c0, c1, c2, c3)
end
------------------------------------------------------------------------
-- decodes a 4-char little-endian string into an instruction struct
------------------------------------------------------------------------
function luaP:DecodeInst(x)
local byte = string.byte
local i = {}
local I = byte(x, 1)
local op = I % 64
i.OP = op
I = byte(x, 2) * 4 + (I - op) / 64 -- 2 bits of c0 left
local a = I % 256
i.A = a
I = byte(x, 3) * 4 + (I - a) / 256 -- 2 bits of c1 left
local c = I % 512
i.C = c
i.B = byte(x, 4) * 2 + (I - c) / 512 -- 1 bits of c2 left
local opmode = self.OpMode[tonumber(string.sub(self.opmodes[op + 1], 7, 7))]
if opmode ~= "iABC" then
i.Bx = i.B * 512 + i.C
end
return i
end
------------------------------------------------------------------------
-- Macros to operate RK indices
-- * these use arithmetic instead of bit ops
------------------------------------------------------------------------
-- this bit 1 means constant (0 means register)
luaP.BITRK = math.ldexp(1, luaP.SIZE_B - 1)
-- test whether value is a constant
function luaP:ISK(x) return x >= self.BITRK end
-- gets the index of the constant
function luaP:INDEXK(x) return x - self.BITRK end
luaP.MAXINDEXRK = luaP.BITRK - 1
-- code a constant index as a RK value
function luaP:RKASK(x) return x + self.BITRK end
------------------------------------------------------------------------
-- invalid register that fits in 8 bits
------------------------------------------------------------------------
luaP.NO_REG = luaP.MAXARG_A
------------------------------------------------------------------------
-- R(x) - register
-- Kst(x) - constant (in constant table)
-- RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
------------------------------------------------------------------------
------------------------------------------------------------------------
-- grep "ORDER OP" if you change these enums
------------------------------------------------------------------------
--[[
Lua virtual machine opcodes (enum OpCode):
------------------------------------------------------------------------
name args description
------------------------------------------------------------------------
OP_MOVE A B R(A) := R(B)
OP_LOADK A Bx R(A) := Kst(Bx)
OP_LOADBOOL A B C R(A) := (Bool)B; if (C) pc++
OP_LOADNIL A B R(A) := ... := R(B) := nil
OP_GETUPVAL A B R(A) := UpValue[B]
OP_GETGLOBAL A Bx R(A) := Gbl[Kst(Bx)]
OP_GETTABLE A B C R(A) := R(B)[RK(C)]
OP_SETGLOBAL A Bx Gbl[Kst(Bx)] := R(A)
OP_SETUPVAL A B UpValue[B] := R(A)
OP_SETTABLE A B C R(A)[RK(B)] := RK(C)
OP_NEWTABLE A B C R(A) := {} (size = B,C)
OP_SELF A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
OP_ADD A B C R(A) := RK(B) + RK(C)
OP_SUB A B C R(A) := RK(B) - RK(C)
OP_MUL A B C R(A) := RK(B) * RK(C)
OP_DIV A B C R(A) := RK(B) / RK(C)
OP_MOD A B C R(A) := RK(B) % RK(C)
OP_POW A B C R(A) := RK(B) ^ RK(C)
OP_UNM A B R(A) := -R(B)
OP_NOT A B R(A) := not R(B)
OP_LEN A B R(A) := length of R(B)
OP_CONCAT A B C R(A) := R(B).. ... ..R(C)
OP_JMP sBx pc+=sBx
OP_EQ A B C if ((RK(B) == RK(C)) ~= A) then pc++
OP_LT A B C if ((RK(B) < RK(C)) ~= A) then pc++
OP_LE A B C if ((RK(B) <= RK(C)) ~= A) then pc++
OP_TEST A C if not (R(A) <=> C) then pc++
OP_TESTSET A B C if (R(B) <=> C) then R(A) := R(B) else pc++
OP_CALL A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
OP_TAILCALL A B C return R(A)(R(A+1), ... ,R(A+B-1))
OP_RETURN A B return R(A), ... ,R(A+B-2) (see note)
OP_FORLOOP A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
OP_FORPREP A sBx R(A)-=R(A+2); pc+=sBx
OP_TFORLOOP A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++
OP_SETLIST A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
OP_CLOSE A close all variables in the stack up to (>=) R(A)
OP_CLOSURE A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))
OP_VARARG A B R(A), R(A+1), ..., R(A+B-1) = vararg
]]
luaP.opnames = {} -- opcode names
luaP.OpCode = {} -- lookup name -> number
luaP.ROpCode = {} -- lookup number -> name
------------------------------------------------------------------------
-- ORDER OP
------------------------------------------------------------------------
local i = 0
for v in string.gmatch([[
MOVE LOADK LOADBOOL LOADNIL GETUPVAL
GETGLOBAL GETTABLE SETGLOBAL SETUPVAL SETTABLE
NEWTABLE SELF ADD SUB MUL
DIV MOD POW UNM NOT
LEN CONCAT JMP EQ LT
LE TEST TESTSET CALL TAILCALL
RETURN FORLOOP FORPREP TFORLOOP SETLIST
CLOSE CLOSURE VARARG
]], "%S+") do
local n = "OP_"..v
luaP.opnames[i] = v
luaP.OpCode[n] = i
luaP.ROpCode[i] = n
i = i + 1
end
luaP.NUM_OPCODES = i
--[[
===========================================================================
Notes:
(*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
and can be 0: OP_CALL then sets 'top' to last_result+1, so
next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use 'top'.
(*) In OP_VARARG, if (B == 0) then use actual number of varargs and
set top (like in OP_CALL with C == 0).
(*) In OP_RETURN, if (B == 0) then return up to 'top'
(*) In OP_SETLIST, if (B == 0) then B = 'top';
if (C == 0) then next 'instruction' is real C
(*) For comparisons, A specifies what condition the test should accept
(true or false).
(*) All 'skips' (pc++) assume that next instruction is a jump
===========================================================================
]]
--[[
masks for instruction properties. The format is:
bits 0-1: op mode
bits 2-3: C arg mode
bits 4-5: B arg mode
bit 6: instruction set register A
bit 7: operator is a test
for OpArgMask:
OpArgN - argument is not used
OpArgU - argument is used
OpArgR - argument is a register or a jump offset
OpArgK - argument is a constant or register/constant
]]
-- was enum OpArgMask
luaP.OpArgMask = { OpArgN = 0, OpArgU = 1, OpArgR = 2, OpArgK = 3 }
------------------------------------------------------------------------
-- e.g. to compare with symbols, luaP:getOpMode(...) == luaP.OpCode.iABC
-- * accepts opcode parameter as strings, e.g. "OP_MOVE"
------------------------------------------------------------------------
function luaP:getOpMode(m)
return self.opmodes[self.OpCode[m]] % 4
end
function luaP:getBMode(m)
return math.floor(self.opmodes[self.OpCode[m]] / 16) % 4
end
function luaP:getCMode(m)
return math.floor(self.opmodes[self.OpCode[m]] / 4) % 4
end
function luaP:testAMode(m)
return math.floor(self.opmodes[self.OpCode[m]] / 64) % 2
end
function luaP:testTMode(m)
return math.floor(self.opmodes[self.OpCode[m]] / 128)
end
-- luaP_opnames[] is set above, as the luaP.opnames table
-- number of list items to accumulate before a SETLIST instruction
luaP.LFIELDS_PER_FLUSH = 50
------------------------------------------------------------------------
-- build instruction properties array
-- * deliberately coded to look like the C equivalent
------------------------------------------------------------------------
local function opmode(t, a, b, c, m)
local luaP = luaP
return t * 128 + a * 64 +
luaP.OpArgMask[b] * 16 + luaP.OpArgMask[c] * 4 + luaP.OpMode[m]
end
-- ORDER OP
luaP.opmodes = {
-- T A B C mode opcode
opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_LOADK
opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_LOADBOOL
opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LOADNIL
opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_GETUPVAL
opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_GETGLOBAL
opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_GETTABLE
opmode(0, 0, "OpArgK", "OpArgN", "iABx"), -- OP_SETGLOBAL
opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_SETUPVAL
opmode(0, 0, "OpArgK", "OpArgK", "iABC"), -- OP_SETTABLE
opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_NEWTABLE
opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_SELF
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_ADD
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_SUB
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MUL
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_DIV
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MOD
opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_POW
opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_UNM
opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_NOT
opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LEN
opmode(0, 1, "OpArgR", "OpArgR", "iABC"), -- OP_CONCAT
opmode(0, 0, "OpArgR", "OpArgN", "iAsBx"), -- OP_JMP
opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_EQ
opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LT
opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LE
opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TEST
opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TESTSET
opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_CALL
opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_TAILCALL
opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_RETURN
opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORLOOP
opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORPREP
opmode(1, 0, "OpArgN", "OpArgU", "iABC"), -- OP_TFORLOOP
opmode(0, 0, "OpArgU", "OpArgU", "iABC"), -- OP_SETLIST
opmode(0, 0, "OpArgN", "OpArgN", "iABC"), -- OP_CLOSE
opmode(0, 1, "OpArgU", "OpArgN", "iABx"), -- OP_CLOSURE
opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_VARARG
}
-- an awkward way to set a zero-indexed table...
luaP.opmodes[0] =
opmode(0, 1, "OpArgR", "OpArgN", "iABC") -- OP_MOVE
--# selene: allow(incorrect_standard_library_use, multiple_statements, shadowing, unused_variable, empty_if, divide_by_zero, unbalanced_assignments)
--[[
lzio.lua
Lua buffered streams in Lua
This file is part of Yueliang.
Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
See the ChangeLog for more information.
]]
--[[
-- Notes:
-- * EOZ is implemented as a string, "EOZ"
-- * Format of z structure (ZIO)
-- z.n -- bytes still unread
-- z.p -- last read position position in buffer
-- z.reader -- chunk reader function
-- z.data -- additional data
-- * Current position, p, is now last read index instead of a pointer
--
-- Not implemented:
-- * luaZ_lookahead: used only in lapi.c:lua_load to detect binary chunk
-- * luaZ_read: used only in lundump.c:ezread to read +1 bytes
-- * luaZ_openspace: dropped; let Lua handle buffers as strings (used in
-- lundump.c:LoadString & lvm.c:luaV_concat)
-- * luaZ buffer macros: dropped; buffers are handled as strings
-- * lauxlib.c:getF reader implementation has an extraline flag to
-- skip over a shbang (#!) line, this is not implemented here
--
-- Added:
-- (both of the following are vaguely adapted from lauxlib.c)
-- * luaZ:make_getS: create Reader from a string
-- * luaZ:make_getF: create Reader that reads from a file
--
-- Changed in 5.1.x:
-- * Chunkreader renamed to Reader (ditto with Chunkwriter)
-- * Zio struct: no more name string, added Lua state for reader
-- (however, Yueliang readers do not require a Lua state)
]]
local luaZ = {}
------------------------------------------------------------------------
-- * reader() should return a string, or nil if nothing else to parse.
-- Additional data can be set only during stream initialization
-- * Readers are handled in lauxlib.c, see luaL_load(file|buffer|string)
-- * LUAL_BUFFERSIZE=BUFSIZ=512 in make_getF() (located in luaconf.h)
-- * Original Reader typedef:
-- const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
-- * This Lua chunk reader implementation:
-- returns string or nil, no arguments to function
------------------------------------------------------------------------
------------------------------------------------------------------------
-- create a chunk reader from a source string
------------------------------------------------------------------------
function luaZ:make_getS(buff)
local b = buff
return function() -- chunk reader anonymous function here
if not b then return nil end
local data = b
b = nil
return data
end
end
------------------------------------------------------------------------
-- create a chunk reader from a source file
------------------------------------------------------------------------
--[[
function luaZ:make_getF(filename)
local LUAL_BUFFERSIZE = 512
local h = io.open(filename, "r")
if not h then return nil end
return function() -- chunk reader anonymous function here
if not h or io.type(h) == "closed file" then return nil end
local buff = h:read(LUAL_BUFFERSIZE)
if not buff then h:close(); h = nil end
return buff
end
end
]]
------------------------------------------------------------------------
-- creates a zio input stream
-- returns the ZIO structure, z
------------------------------------------------------------------------
function luaZ:init(reader, data, name)
if not reader then return end
local z = {}
z.reader = reader
z.data = data or ""
z.name = name
-- set up additional data for reading
if not data or data == "" then z.n = 0 else z.n = #data end
z.p = 0
return z
end
------------------------------------------------------------------------
-- fill up input buffer
------------------------------------------------------------------------
function luaZ:fill(z)
local buff = z.reader()
z.data = buff
if not buff or buff == "" then return "EOZ" end
z.n, z.p = #buff - 1, 1
return string.sub(buff, 1, 1)
end
------------------------------------------------------------------------
-- get next character from the input stream
-- * local n, p are used to optimize code generation
------------------------------------------------------------------------
function luaZ:zgetc(z)
local n, p = z.n, z.p + 1
if n > 0 then
z.n, z.p = n - 1, p
return string.sub(z.data, p, p)
else
return self:fill(z)
end
end
--# selene: allow(incorrect_standard_library_use, multiple_statements, shadowing, unused_variable, empty_if, divide_by_zero, unbalanced_assignments)
--[[
ldump.lua
Save precompiled Lua chunks
This file is part of Yueliang.
Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
See the ChangeLog for more information.
]]
--[[
-- Notes:
-- * WARNING! byte order (little endian) and data type sizes for header
-- signature values hard-coded; see luaU:header
-- * chunk writer generators are included, see below
-- * one significant difference is that instructions are still in table
-- form (with OP/A/B/C/Bx fields) and luaP:Instruction() is needed to
-- convert them into 4-char strings
--
-- Not implemented:
-- * DumpVar, DumpMem has been removed
-- * DumpVector folded into folded into DumpDebug, DumpCode
--
-- Added:
-- * for convenience, the following two functions have been added:
-- luaU:make_setS: create a chunk writer that writes to a string
-- luaU:make_setF: create a chunk writer that writes to a file
-- (lua.h contains a typedef for lua_Writer/lua_Chunkwriter, and
-- a Lua-based implementation exists, writer() in lstrlib.c)
-- * luaU:ttype(o) (from lobject.h)
-- * for converting number types to its binary equivalent:
-- luaU:from_double(x): encode double value for writing
-- luaU:from_int(x): encode integer value for writing
-- (error checking is limited for these conversion functions)
-- (double conversion does not support denormals or NaNs)
--
-- Changed in 5.1.x:
-- * the dumper was mostly rewritten in Lua 5.1.x, so notes on the
-- differences between 5.0.x and 5.1.x is limited
-- * LUAC_VERSION bumped to 0x51, LUAC_FORMAT added
-- * developer is expected to adjust LUAC_FORMAT in order to identify
-- non-standard binary chunk formats
-- * header signature code is smaller, has been simplified, and is
-- tested as a single unit; its logic is shared with the undumper
-- * no more endian conversion, invalid endianness mean rejection
-- * opcode field sizes are no longer exposed in the header
-- * code moved to front of a prototype, followed by constants
-- * debug information moved to the end of the binary chunk, and the
-- relevant functions folded into a single function
-- * luaU:dump returns a writer status code
-- * chunk writer now implements status code because dumper uses it
-- * luaU:endianness removed
]]
local luaU = {}
-- mark for precompiled code ('<esc>Lua') (from lua.h)
luaU.LUA_SIGNATURE = "\27Lua"
-- constants used by dumper (from lua.h)
luaU.LUA_TNUMBER = 3
luaU.LUA_TSTRING = 4
luaU.LUA_TNIL = 0
luaU.LUA_TBOOLEAN = 1
luaU.LUA_TNONE = -1
-- constants for header of binary files (from lundump.h)
luaU.LUAC_VERSION = 0x51 -- this is Lua 5.1
luaU.LUAC_FORMAT = 0 -- this is the official format
luaU.LUAC_HEADERSIZE = 12 -- size of header of binary files
--[[
-- Additional functions to handle chunk writing
-- * to use make_setS and make_setF, see test_ldump.lua elsewhere
]]
------------------------------------------------------------------------
-- create a chunk writer that writes to a string
-- * returns the writer function and a table containing the string
-- * to get the final result, look in buff.data
------------------------------------------------------------------------
function luaU:make_setS()
local buff = {}
buff.data = ""
local writer =
function(s, buff) -- chunk writer
if not s then return 0 end
buff.data = buff.data..s
return 0
end
return writer, buff
end
------------------------------------------------------------------------
-- create a chunk writer that writes to a file
-- * returns the writer function and a table containing the file handle
-- * if a nil is passed, then writer should close the open file
------------------------------------------------------------------------
--[[
function luaU:make_setF(filename)
local buff = {}
buff.h = io.open(filename, "wb")
if not buff.h then return nil end
local writer =
function(s, buff) -- chunk writer
if not buff.h then return 0 end
if not s then
if buff.h:close() then return 0 end
else
if buff.h:write(s) then return 0 end
end
return 1
end
return writer, buff
end]]
------------------------------------------------------------------------
-- works like the lobject.h version except that TObject used in these
-- scripts only has a 'value' field, no 'tt' field (native types used)
------------------------------------------------------------------------
function luaU:ttype(o)
local tt = type(o.value)
if tt == "number" then return self.LUA_TNUMBER
elseif tt == "string" then return self.LUA_TSTRING
elseif tt == "nil" then return self.LUA_TNIL
elseif tt == "boolean" then return self.LUA_TBOOLEAN
else
return self.LUA_TNONE -- the rest should not appear
end
end
-----------------------------------------------------------------------
-- converts a IEEE754 double number to an 8-byte little-endian string
-- * luaU:from_double() and luaU:from_int() are adapted from ChunkBake
-- * supports +/- Infinity, but not denormals or NaNs
-----------------------------------------------------------------------
function luaU:from_double(x)
local function grab_byte(v)
local c = v % 256
return (v - c) / 256, string.char(c)
end
local sign = 0
if x < 0 then sign = 1; x = -x end
local mantissa, exponent = math.frexp(x)
if x == 0 then -- zero
mantissa, exponent = 0, 0
elseif x == 1/0 then
mantissa, exponent = 0, 2047
else
mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, 53)
exponent = exponent + 1022
end
local v, byte = "", nil -- convert to bytes
x = math.floor(mantissa)
for i = 1,6 do
x, byte = grab_byte(x); v = v..byte -- 47:0
end
x, byte = grab_byte(exponent * 16 + x); v = v..byte -- 55:48
x, byte = grab_byte(sign * 128 + x); v = v..byte -- 63:56
return v
end
-----------------------------------------------------------------------
-- converts a number to a little-endian 32-bit integer string
-- * input value assumed to not overflow, can be signed/unsigned
-----------------------------------------------------------------------
function luaU:from_int(x)
local v = ""
x = math.floor(x)
if x < 0 then x = 4294967296 + x end -- ULONG_MAX+1
for i = 1, 4 do
local c = x % 256
v = v..string.char(c); x = math.floor(x / 256)
end
return v
end
--[[
-- Functions to make a binary chunk
-- * many functions have the size parameter removed, since output is
-- in the form of a string and some sizes are implicit or hard-coded
]]
--[[
-- struct DumpState:
-- L -- lua_State (not used in this script)
-- writer -- lua_Writer (chunk writer function)
-- data -- void* (chunk writer context or data already written)
-- strip -- if true, don't write any debug information
-- status -- if non-zero, an error has occured
]]
------------------------------------------------------------------------
-- dumps a block of bytes
-- * lua_unlock(D.L), lua_lock(D.L) unused
------------------------------------------------------------------------
function luaU:DumpBlock(b, D)
if D.status == 0 then
-- lua_unlock(D->L);
D.status = D.write(b, D.data)
-- lua_lock(D->L);
end
end
------------------------------------------------------------------------
-- dumps a char
------------------------------------------------------------------------
function luaU:DumpChar(y, D)
self:DumpBlock(string.char(y), D)
end
------------------------------------------------------------------------
-- dumps a 32-bit signed or unsigned integer (for int) (hard-coded)
------------------------------------------------------------------------
function luaU:DumpInt(x, D)
self:DumpBlock(self:from_int(x), D)
end
------------------------------------------------------------------------
-- dumps a lua_Number (hard-coded as a double)
------------------------------------------------------------------------
function luaU:DumpNumber(x, D)
self:DumpBlock(self:from_double(x), D)
end
------------------------------------------------------------------------
-- dumps a Lua string (size type is hard-coded)
------------------------------------------------------------------------
function luaU:DumpString(s, D)
if s == nil then
self:DumpInt(0, D)
else
s = s.."\0" -- include trailing '\0'
self:DumpInt(#s, D)
self:DumpBlock(s, D)
end
end
------------------------------------------------------------------------
-- dumps instruction block from function prototype
------------------------------------------------------------------------
function luaU:DumpCode(f, D)
local n = f.sizecode
--was DumpVector
self:DumpInt(n, D)
for i = 0, n - 1 do
self:DumpBlock(luaP:Instruction(f.code[i]), D)
end
end
------------------------------------------------------------------------
-- dump constant pool from function prototype
-- * bvalue(o), nvalue(o) and rawtsvalue(o) macros removed
------------------------------------------------------------------------
function luaU:DumpConstants(f, D)
local n = f.sizek
self:DumpInt(n, D)
for i = 0, n - 1 do
local o = f.k[i] -- TValue
local tt = self:ttype(o)
self:DumpChar(tt, D)
if tt == self.LUA_TNIL then
elseif tt == self.LUA_TBOOLEAN then
self:DumpChar(o.value and 1 or 0, D)
elseif tt == self.LUA_TNUMBER then
self:DumpNumber(o.value, D)
elseif tt == self.LUA_TSTRING then
self:DumpString(o.value, D)
else
--lua_assert(0) -- cannot happen
end
end
n = f.sizep
self:DumpInt(n, D)
for i = 0, n - 1 do
self:DumpFunction(f.p[i], f.source, D)
end
end
------------------------------------------------------------------------
-- dump debug information
------------------------------------------------------------------------
function luaU:DumpDebug(f, D)
local n
n = D.strip and 0 or f.sizelineinfo -- dump line information
--was DumpVector
self:DumpInt(n, D)
for i = 0, n - 1 do
self:DumpInt(f.lineinfo[i], D)
end
n = D.strip and 0 or f.sizelocvars -- dump local information
self:DumpInt(n, D)
for i = 0, n - 1 do
self:DumpString(f.locvars[i].varname, D)
self:DumpInt(f.locvars[i].startpc, D)
self:DumpInt(f.locvars[i].endpc, D)
end
n = D.strip and 0 or f.sizeupvalues -- dump upvalue information
self:DumpInt(n, D)
for i = 0, n - 1 do