-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample.luau
More file actions
143 lines (140 loc) · 3.87 KB
/
Example.luau
File metadata and controls
143 lines (140 loc) · 3.87 KB
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
-- LOP_BREAK, LOP_COVERAGE and LOP_NOP aren't possible without the C API
-- Vector constants are supported but need to be commented in and need the ctor renamed
-- LOADKX and JUMPX support can be commented out
---------------------------------------------------------------------------------------
-- PREPVARARGS
local a = "hello world"; -- LOADK
a,a,a,a,a,a = nil, true, false, 1, 9e9, function() --[[ RETURN ]] end; -- LOADNIL, LOADB 1, LOADB 0, LOADN 1, LOADK 9e9, DUPCLOSURE (no captures)
FUNC_GLOBAL = newproxy; -- GETIMPORT, SETGLOBAL
local t = { }; -- NEWTABLE 1 1
local function stub(...) -- NEWCLOSURE (ref, val, ref captures)
local b = FUNC_GLOBAL(); -- GETGLOBAL, CALL
local t = t -- GETUPVAL
t.s = b -- SETTABLEKS
t[1] = b -- SETTABLEN 1
t[b] = b -- SETTABLE
a = t[b] -- SETUPVAL, GETTABLE
return t.s, t[1], t[b] -- GETTABLEKS, GETTABLEN, GETTABLE, RETURN 3
end
--[[ Vector constant support
local a = vector(1,2,3,4) -- LOADK
stub(a) -- CALL
--]]
local _,_,_ = stub()
local function upv()
local function foo() -- NEWCLOSURE (upval capture)
return upv -- GETUPVAL, RETURN 1
end
while FALSE_GLOBAL do end -- GETIMPORT, JUMPIFNOT, JUMPBACK
return foo(), FUNC_GLOBAL() -- GETUPVAL, RETURN -1
end
local tm = { val = upv }; -- DUPTABLE, SETTABLEKS
local a = #tm -- LENGTH
upv = upv() -- MOVE, CALL 0 1, MOVE
local t2 = { upv(tm:val(upv())) } -- NEWTABLE 0 1, MOVE, MOVE, CALL, NAMECALL, CALL -1 -1, CALL -1 -1, SETLIST -1
local _table = {} -- NEWTABLE 0 0
local function dup() return function() --[[ RETURN ]] end --[[ DUPCLOSURE, RETURN 1 ]] end -- DUPCLOSURE
local _1, _2, _3 = dup(), dup(), dup() --[[ DUPCLOSURE x3 | CALL + MOVE x3 ]]
_table = { -- NEWTABLE 0 3
_1, _2, _3 -- MOVE, MOVE, MOVE
}
for i = 1, 35 do -- LOADN 1, LOADN 35, LOADN 1
-- FORNPREP
if i then -- JUMPIFNOT
-- JUMP
else
end
if not i then -- JUMPIF
-- JUMP
else
end
if i == i then -- JUMPIFNOTEQ
-- JUMP
else
end
if i ~= i then -- JUMPIFEQ
-- JUMP
else
end
local val
if i >= i then -- JUMPIFNOTLE
val = "hello " -- LOADK
-- JUMP
else
end
if i < i then -- JUMPIFNOTLT
-- JUMP
else
end
if not (i >= i) then -- JUMPIFLE
-- JUMP
else
end
if not (i < i) then -- JUMPIFLT
-- JUMP
else
end
if i == 1 then -- JUMPXEQKN
end
if i == "hello" then -- JUMPXEQKS
end
if i == true then -- JUMPXEQKB 1
end
if i == false then -- JUMPXEQKB 0
end
if i == nil then -- JUMPXEQKNIL
end
if i ~= 1 then -- JUMXEQKN
end
if i ~= "hello" then -- JUMPXEQKS
end
if i ~= true then -- JUMPXEQKB 1
end
if i ~= false then -- JUMPXEQKB 0
end
if i == nil then -- JUMPXEQKNIL
end
local a = not i -- NOT
local a = -i -- MINUS
local a = val .. "world" -- MOVE, LOADK, CONCAT
local a = i == i -- JUMPIFEQ, LOADB C1, LOADB
local a = i and 1 -- ANDK
local a = i or 1 -- ORK
local a = i and i -- AND
local a = i or i -- ORK
i = i + 1 -- ADDK
i = i + i -- ADD
i = i - 1 -- SUBK
i = 1 - i -- SUBRK
i = i - i -- SUB
i = i * 1 -- MULK
i = i * i -- MUL
i = i / 1 -- DIVK
i = 1 / i -- DIVRK
i = i / i -- DIV
i = i // 1 -- IDIVK
i = i // i -- IDIV
i = i ^ 1 -- POWK
i = i ^ i -- POW
i = i % 1 -- MODK
i = i % i -- MOD
local a = ... -- GETVARARGS
local a = math.floor(i) -- FASTCALL1, MOVE, GETIMPORT, CALL
local a = math.floor(i, i) -- FASTCALL2, MOVE, MOVE, GETIMPORT, CALL
local a = math.floor(i, 1) -- FASTCALL2K, MOVE, LOADK, GETIMPORT, CALL
local a = math.floor(i, 1, 2) -- (LOP_FASTCALL3 | LOP_FASTCALL) & MOVE, LOADN, LOADN, GETIMPORT, CALL
local a = math.floor(i, 1, 2, 3, 4, 5) -- MOVE, LOADN, LOADN, LOADN, LOADN, LOADN, FASTCALL, GETIMPORT, CALL
-- FORNLOOP
end
for i,v in {} do end -- FORGPREP, FORGLOOP
for i,v in ipairs({}) do end -- FORGPREP_INEXT, FORGLOOP
for i,v in next, {} do end -- FORGPREP_NEXT, FORGLOOP
for i = 1, 35 do -- LOADN, LOADN, LOADN
if i then -- JUMPXEQKB 1
i = i % 1;
else -- JUMPX
end
break
end
-- CLOSEUPVALS, RETURN
print("PASSED")