lua-obfuscator 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -14
- package/dist/prometheus/LICENSE +661 -661
- package/dist/prometheus/build.bat +9 -9
- package/dist/prometheus/doc/README.md +11 -11
- package/dist/prometheus/doc/SUMMARY.md +27 -27
- package/dist/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +31 -31
- package/dist/prometheus/doc/getting-started/command-line-options.md +13 -13
- package/dist/prometheus/doc/getting-started/installation.md +11 -11
- package/dist/prometheus/doc/getting-started/obfuscating-your-first-script.md +50 -50
- package/dist/prometheus/doc/getting-started/presets.md +10 -10
- package/dist/prometheus/doc/getting-started/the-config-object.md +58 -58
- package/dist/prometheus/doc/getting-started/writing-a-custom-config-file.md +56 -56
- package/dist/prometheus/doc/steps/anti-tamper.md +11 -11
- package/dist/prometheus/doc/steps/constantarray.md +71 -71
- package/dist/prometheus/doc/steps/encryptstrings.md +86 -86
- package/dist/prometheus/doc/steps/proxifylocals.md +47 -47
- package/dist/prometheus/doc/steps/splitstrings.md +40 -40
- package/dist/prometheus/doc/steps/vmify.md +9 -9
- package/dist/prometheus/doc/steps/wrapinfunction.md +29 -29
- package/dist/prometheus/readme.md +57 -57
- package/dist/prometheus/readme.txt +4 -4
- package/package.json +5 -1
- package/src/index.ts +81 -75
- package/tsconfig.json +12 -12
- package/src/prometheus/.editorconfig +0 -4
- package/src/prometheus/.gitattributes +0 -2
- package/src/prometheus/.gitbook.yaml +0 -1
- package/src/prometheus/.github/ISSUE_TEMPLATE/bug_report.md +0 -25
- package/src/prometheus/.github/workflows/Build.yml +0 -49
- package/src/prometheus/.github/workflows/Test.yml +0 -19
- package/src/prometheus/LICENSE +0 -661
- package/src/prometheus/benchmark.lua +0 -34
- package/src/prometheus/build.bat +0 -10
- package/src/prometheus/cli.lua +0 -12
- package/src/prometheus/doc/README.md +0 -11
- package/src/prometheus/doc/SUMMARY.md +0 -27
- package/src/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +0 -31
- package/src/prometheus/doc/getting-started/command-line-options.md +0 -13
- package/src/prometheus/doc/getting-started/installation.md +0 -11
- package/src/prometheus/doc/getting-started/obfuscating-your-first-script.md +0 -50
- package/src/prometheus/doc/getting-started/presets.md +0 -10
- package/src/prometheus/doc/getting-started/the-config-object.md +0 -58
- package/src/prometheus/doc/getting-started/writing-a-custom-config-file.md +0 -56
- package/src/prometheus/doc/steps/anti-tamper.md +0 -11
- package/src/prometheus/doc/steps/constantarray.md +0 -71
- package/src/prometheus/doc/steps/encryptstrings.md +0 -86
- package/src/prometheus/doc/steps/proxifylocals.md +0 -47
- package/src/prometheus/doc/steps/splitstrings.md +0 -40
- package/src/prometheus/doc/steps/vmify.md +0 -9
- package/src/prometheus/doc/steps/wrapinfunction.md +0 -29
- package/src/prometheus/prometheus-main.lua +0 -1
- package/src/prometheus/readme.md +0 -57
- package/src/prometheus/readme.txt +0 -5
- package/src/prometheus/src/cli.lua +0 -154
- package/src/prometheus/src/colors.lua +0 -61
- package/src/prometheus/src/highlightlua.lua +0 -61
- package/src/prometheus/src/logger.lua +0 -62
- package/src/prometheus/src/presets.lua +0 -174
- package/src/prometheus/src/prometheus/ast.lua +0 -792
- package/src/prometheus/src/prometheus/bit.lua +0 -521
- package/src/prometheus/src/prometheus/compiler/compiler.lua +0 -2365
- package/src/prometheus/src/prometheus/enums.lua +0 -106
- package/src/prometheus/src/prometheus/namegenerators/Il.lua +0 -41
- package/src/prometheus/src/prometheus/namegenerators/confuse.lua +0 -169
- package/src/prometheus/src/prometheus/namegenerators/mangled.lua +0 -26
- package/src/prometheus/src/prometheus/namegenerators/mangled_shuffled.lua +0 -35
- package/src/prometheus/src/prometheus/namegenerators/number.lua +0 -11
- package/src/prometheus/src/prometheus/namegenerators.lua +0 -7
- package/src/prometheus/src/prometheus/parser.lua +0 -969
- package/src/prometheus/src/prometheus/pipeline.lua +0 -250
- package/src/prometheus/src/prometheus/randomLiterals.lua +0 -41
- package/src/prometheus/src/prometheus/randomStrings.lua +0 -24
- package/src/prometheus/src/prometheus/scope.lua +0 -332
- package/src/prometheus/src/prometheus/step.lua +0 -79
- package/src/prometheus/src/prometheus/steps/AddVararg.lua +0 -33
- package/src/prometheus/src/prometheus/steps/AntiTamper.lua +0 -194
- package/src/prometheus/src/prometheus/steps/ConstantArray.lua +0 -521
- package/src/prometheus/src/prometheus/steps/EncryptStrings.lua +0 -239
- package/src/prometheus/src/prometheus/steps/NumbersToExpressions.lua +0 -82
- package/src/prometheus/src/prometheus/steps/ProxifyLocals.lua +0 -313
- package/src/prometheus/src/prometheus/steps/SplitStrings.lua +0 -338
- package/src/prometheus/src/prometheus/steps/Vmify.lua +0 -30
- package/src/prometheus/src/prometheus/steps/Watermark.lua +0 -61
- package/src/prometheus/src/prometheus/steps/WatermarkCheck.lua +0 -50
- package/src/prometheus/src/prometheus/steps/WrapInFunction.lua +0 -45
- package/src/prometheus/src/prometheus/steps.lua +0 -12
- package/src/prometheus/src/prometheus/tokenizer.lua +0 -546
- package/src/prometheus/src/prometheus/unparser.lua +0 -866
- package/src/prometheus/src/prometheus/util.lua +0 -297
- package/src/prometheus/src/prometheus/visitast.lua +0 -245
- package/src/prometheus/src/prometheus.lua +0 -71
- package/src/prometheus/tests/closures.lua +0 -12
- package/src/prometheus/tests/fibonacci.lua +0 -10
- package/src/prometheus/tests/loops.lua +0 -8
- package/src/prometheus/tests/primes.lua +0 -18
- package/src/prometheus/tests.lua +0 -149
|
@@ -1,792 +0,0 @@
|
|
|
1
|
-
-- This Script is Part of the Prometheus Obfuscator by Levno_710
|
|
2
|
-
--
|
|
3
|
-
-- ast.lua
|
|
4
|
-
|
|
5
|
-
local Ast = {}
|
|
6
|
-
|
|
7
|
-
local AstKind = {
|
|
8
|
-
-- Misc
|
|
9
|
-
TopNode = "TopNode";
|
|
10
|
-
Block = "Block";
|
|
11
|
-
|
|
12
|
-
-- Statements
|
|
13
|
-
ContinueStatement = "ContinueStatement";
|
|
14
|
-
BreakStatement = "BreakStatement";
|
|
15
|
-
DoStatement = "DoStatement";
|
|
16
|
-
WhileStatement = "WhileStatement";
|
|
17
|
-
ReturnStatement = "ReturnStatement";
|
|
18
|
-
RepeatStatement = "RepeatStatement";
|
|
19
|
-
ForInStatement = "ForInStatement";
|
|
20
|
-
ForStatement = "ForStatement";
|
|
21
|
-
IfStatement = "IfStatement";
|
|
22
|
-
FunctionDeclaration = "FunctionDeclaration";
|
|
23
|
-
LocalFunctionDeclaration = "LocalFunctionDeclaration";
|
|
24
|
-
LocalVariableDeclaration = "LocalVariableDeclaration";
|
|
25
|
-
FunctionCallStatement = "FunctionCallStatement";
|
|
26
|
-
PassSelfFunctionCallStatement = "PassSelfFunctionCallStatement";
|
|
27
|
-
AssignmentStatement = "AssignmentStatement";
|
|
28
|
-
|
|
29
|
-
-- LuaU Compound Statements
|
|
30
|
-
CompoundAddStatement = "CompoundAddStatement";
|
|
31
|
-
CompoundSubStatement = "CompoundSubStatement";
|
|
32
|
-
CompoundMulStatement = "CompoundMulStatement";
|
|
33
|
-
CompoundDivStatement = "CompoundDivStatement";
|
|
34
|
-
CompoundModStatement = "CompoundModStatement";
|
|
35
|
-
CompoundPowStatement = "CompoundPowStatement";
|
|
36
|
-
CompoundConcatStatement = "CompoundConcatStatement";
|
|
37
|
-
|
|
38
|
-
-- Assignment Index
|
|
39
|
-
AssignmentIndexing = "AssignmentIndexing";
|
|
40
|
-
AssignmentVariable = "AssignmentVariable";
|
|
41
|
-
|
|
42
|
-
-- Expression Nodes
|
|
43
|
-
BooleanExpression = "BooleanExpression";
|
|
44
|
-
NumberExpression = "NumberExpression";
|
|
45
|
-
StringExpression = "StringExpression";
|
|
46
|
-
NilExpression = "NilExpression";
|
|
47
|
-
VarargExpression = "VarargExpression";
|
|
48
|
-
OrExpression = "OrExpression";
|
|
49
|
-
AndExpression = "AndExpression";
|
|
50
|
-
LessThanExpression = "LessThanExpression";
|
|
51
|
-
GreaterThanExpression = "GreaterThanExpression";
|
|
52
|
-
LessThanOrEqualsExpression = "LessThanOrEqualsExpression";
|
|
53
|
-
GreaterThanOrEqualsExpression = "GreaterThanOrEqualsExpression";
|
|
54
|
-
NotEqualsExpression = "NotEqualsExpression";
|
|
55
|
-
EqualsExpression = "EqualsExpression";
|
|
56
|
-
StrCatExpression = "StrCatExpression";
|
|
57
|
-
AddExpression = "AddExpression";
|
|
58
|
-
SubExpression = "SubExpression";
|
|
59
|
-
MulExpression = "MulExpression";
|
|
60
|
-
DivExpression = "DivExpression";
|
|
61
|
-
ModExpression = "ModExpression";
|
|
62
|
-
NotExpression = "NotExpression";
|
|
63
|
-
LenExpression = "LenExpression";
|
|
64
|
-
NegateExpression = "NegateExpression";
|
|
65
|
-
PowExpression = "PowExpression";
|
|
66
|
-
IndexExpression = "IndexExpression";
|
|
67
|
-
FunctionCallExpression = "FunctionCallExpression";
|
|
68
|
-
PassSelfFunctionCallExpression = "PassSelfFunctionCallExpression";
|
|
69
|
-
VariableExpression = "VariableExpression";
|
|
70
|
-
FunctionLiteralExpression = "FunctionLiteralExpression";
|
|
71
|
-
TableConstructorExpression = "TableConstructorExpression";
|
|
72
|
-
|
|
73
|
-
-- Table Entry
|
|
74
|
-
TableEntry = "TableEntry";
|
|
75
|
-
KeyedTableEntry = "KeyedTableEntry";
|
|
76
|
-
|
|
77
|
-
-- Misc
|
|
78
|
-
NopStatement = "NopStatement";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
local astKindExpressionLookup = {
|
|
82
|
-
[AstKind.BooleanExpression] = 0;
|
|
83
|
-
[AstKind.NumberExpression] = 0;
|
|
84
|
-
[AstKind.StringExpression] = 0;
|
|
85
|
-
[AstKind.NilExpression] = 0;
|
|
86
|
-
[AstKind.VarargExpression] = 0;
|
|
87
|
-
[AstKind.OrExpression] = 12;
|
|
88
|
-
[AstKind.AndExpression] = 11;
|
|
89
|
-
[AstKind.LessThanExpression] = 10;
|
|
90
|
-
[AstKind.GreaterThanExpression] = 10;
|
|
91
|
-
[AstKind.LessThanOrEqualsExpression] = 10;
|
|
92
|
-
[AstKind.GreaterThanOrEqualsExpression] = 10;
|
|
93
|
-
[AstKind.NotEqualsExpression] = 10;
|
|
94
|
-
[AstKind.EqualsExpression] = 10;
|
|
95
|
-
[AstKind.StrCatExpression] = 9;
|
|
96
|
-
[AstKind.AddExpression] = 8;
|
|
97
|
-
[AstKind.SubExpression] = 8;
|
|
98
|
-
[AstKind.MulExpression] = 7;
|
|
99
|
-
[AstKind.DivExpression] = 7;
|
|
100
|
-
[AstKind.ModExpression] = 7;
|
|
101
|
-
[AstKind.NotExpression] = 5;
|
|
102
|
-
[AstKind.LenExpression] = 5;
|
|
103
|
-
[AstKind.NegateExpression] = 5;
|
|
104
|
-
[AstKind.PowExpression] = 4;
|
|
105
|
-
[AstKind.IndexExpression] = 1;
|
|
106
|
-
[AstKind.AssignmentIndexing] = 1;
|
|
107
|
-
[AstKind.FunctionCallExpression] = 2;
|
|
108
|
-
[AstKind.PassSelfFunctionCallExpression] = 2;
|
|
109
|
-
[AstKind.VariableExpression] = 0;
|
|
110
|
-
[AstKind.AssignmentVariable] = 0;
|
|
111
|
-
[AstKind.FunctionLiteralExpression] = 3;
|
|
112
|
-
[AstKind.TableConstructorExpression] = 3;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Ast.AstKind = AstKind;
|
|
116
|
-
|
|
117
|
-
function Ast.astKindExpressionToNumber(kind)
|
|
118
|
-
return astKindExpressionLookup[kind] or 100;
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
function Ast.ConstantNode(val)
|
|
122
|
-
if type(val) == "nil" then
|
|
123
|
-
return Ast.NilExpression();
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
if type(val) == "string" then
|
|
127
|
-
return Ast.StringExpression(val);
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
if type(val) == "number" then
|
|
131
|
-
return Ast.NumberExpression(val);
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
if type(val) == "boolean" then
|
|
135
|
-
return Ast.BooleanExpression(val);
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
function Ast.NopStatement()
|
|
142
|
-
return {
|
|
143
|
-
kind = AstKind.NopStatement;
|
|
144
|
-
}
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
-- Create Ast Top Node
|
|
148
|
-
function Ast.TopNode(body, globalScope)
|
|
149
|
-
return {
|
|
150
|
-
kind = AstKind.TopNode,
|
|
151
|
-
body = body,
|
|
152
|
-
globalScope = globalScope,
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
function Ast.TableEntry(value)
|
|
158
|
-
return {
|
|
159
|
-
kind = AstKind.TableEntry,
|
|
160
|
-
value = value,
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
function Ast.KeyedTableEntry(key, value)
|
|
166
|
-
return {
|
|
167
|
-
kind = AstKind.KeyedTableEntry,
|
|
168
|
-
key = key,
|
|
169
|
-
value = value,
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
function Ast.TableConstructorExpression(entries)
|
|
175
|
-
return {
|
|
176
|
-
kind = AstKind.TableConstructorExpression,
|
|
177
|
-
entries = entries,
|
|
178
|
-
};
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
-- Create Statement Block
|
|
182
|
-
function Ast.Block(statements, scope)
|
|
183
|
-
return {
|
|
184
|
-
kind = AstKind.Block,
|
|
185
|
-
statements = statements,
|
|
186
|
-
scope = scope,
|
|
187
|
-
}
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
-- Create Break Statement
|
|
191
|
-
function Ast.BreakStatement(loop, scope)
|
|
192
|
-
return {
|
|
193
|
-
kind = AstKind.BreakStatement,
|
|
194
|
-
loop = loop,
|
|
195
|
-
scope = scope,
|
|
196
|
-
}
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
-- Create Continue Statement
|
|
200
|
-
function Ast.ContinueStatement(loop, scope)
|
|
201
|
-
return {
|
|
202
|
-
kind = AstKind.ContinueStatement,
|
|
203
|
-
loop = loop,
|
|
204
|
-
scope = scope,
|
|
205
|
-
}
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
function Ast.PassSelfFunctionCallStatement(base, passSelfFunctionName, args)
|
|
209
|
-
return {
|
|
210
|
-
kind = AstKind.PassSelfFunctionCallStatement,
|
|
211
|
-
base = base,
|
|
212
|
-
passSelfFunctionName = passSelfFunctionName,
|
|
213
|
-
args = args,
|
|
214
|
-
}
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
function Ast.AssignmentStatement(lhs, rhs)
|
|
218
|
-
if(#lhs < 1) then
|
|
219
|
-
print(debug.traceback());
|
|
220
|
-
error("Something went wrong!");
|
|
221
|
-
end
|
|
222
|
-
return {
|
|
223
|
-
kind = AstKind.AssignmentStatement,
|
|
224
|
-
lhs = lhs,
|
|
225
|
-
rhs = rhs,
|
|
226
|
-
}
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
function Ast.CompoundAddStatement(lhs, rhs)
|
|
230
|
-
return {
|
|
231
|
-
kind = AstKind.CompoundAddStatement,
|
|
232
|
-
lhs = lhs,
|
|
233
|
-
rhs = rhs,
|
|
234
|
-
}
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
function Ast.CompoundSubStatement(lhs, rhs)
|
|
238
|
-
return {
|
|
239
|
-
kind = AstKind.CompoundSubStatement,
|
|
240
|
-
lhs = lhs,
|
|
241
|
-
rhs = rhs,
|
|
242
|
-
}
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
function Ast.CompoundMulStatement(lhs, rhs)
|
|
246
|
-
return {
|
|
247
|
-
kind = AstKind.CompoundMulStatement,
|
|
248
|
-
lhs = lhs,
|
|
249
|
-
rhs = rhs,
|
|
250
|
-
}
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
function Ast.CompoundDivStatement(lhs, rhs)
|
|
254
|
-
return {
|
|
255
|
-
kind = AstKind.CompoundDivStatement,
|
|
256
|
-
lhs = lhs,
|
|
257
|
-
rhs = rhs,
|
|
258
|
-
}
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
function Ast.CompoundPowStatement(lhs, rhs)
|
|
262
|
-
return {
|
|
263
|
-
kind = AstKind.CompoundPowStatement,
|
|
264
|
-
lhs = lhs,
|
|
265
|
-
rhs = rhs,
|
|
266
|
-
}
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
function Ast.CompoundModStatement(lhs, rhs)
|
|
270
|
-
return {
|
|
271
|
-
kind = AstKind.CompoundModStatement,
|
|
272
|
-
lhs = lhs,
|
|
273
|
-
rhs = rhs,
|
|
274
|
-
}
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
function Ast.CompoundConcatStatement(lhs, rhs)
|
|
278
|
-
return {
|
|
279
|
-
kind = AstKind.CompoundConcatStatement,
|
|
280
|
-
lhs = lhs,
|
|
281
|
-
rhs = rhs,
|
|
282
|
-
}
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
function Ast.FunctionCallStatement(base, args)
|
|
286
|
-
return {
|
|
287
|
-
kind = AstKind.FunctionCallStatement,
|
|
288
|
-
base = base,
|
|
289
|
-
args = args,
|
|
290
|
-
}
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
function Ast.ReturnStatement(args)
|
|
294
|
-
return {
|
|
295
|
-
kind = AstKind.ReturnStatement,
|
|
296
|
-
args = args,
|
|
297
|
-
}
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
function Ast.DoStatement(body)
|
|
301
|
-
return {
|
|
302
|
-
kind = AstKind.DoStatement,
|
|
303
|
-
body = body,
|
|
304
|
-
}
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
function Ast.WhileStatement(body, condition, parentScope)
|
|
308
|
-
return {
|
|
309
|
-
kind = AstKind.WhileStatement,
|
|
310
|
-
body = body,
|
|
311
|
-
condition = condition,
|
|
312
|
-
parentScope = parentScope,
|
|
313
|
-
}
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
function Ast.ForInStatement(scope, vars, expressions, body, parentScope)
|
|
317
|
-
return {
|
|
318
|
-
kind = AstKind.ForInStatement,
|
|
319
|
-
scope = scope,
|
|
320
|
-
ids = vars,
|
|
321
|
-
vars = vars,
|
|
322
|
-
expressions = expressions,
|
|
323
|
-
body = body,
|
|
324
|
-
parentScope = parentScope,
|
|
325
|
-
}
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body, parentScope)
|
|
329
|
-
return {
|
|
330
|
-
kind = AstKind.ForStatement,
|
|
331
|
-
scope = scope,
|
|
332
|
-
id = id,
|
|
333
|
-
initialValue = initialValue,
|
|
334
|
-
finalValue = finalValue,
|
|
335
|
-
incrementBy = incrementBy,
|
|
336
|
-
body = body,
|
|
337
|
-
parentScope = parentScope,
|
|
338
|
-
}
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
function Ast.RepeatStatement(condition, body, parentScope)
|
|
342
|
-
return {
|
|
343
|
-
kind = AstKind.RepeatStatement,
|
|
344
|
-
body = body,
|
|
345
|
-
condition = condition,
|
|
346
|
-
parentScope = parentScope,
|
|
347
|
-
}
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
function Ast.IfStatement(condition, body, elseifs, elsebody)
|
|
351
|
-
return {
|
|
352
|
-
kind = AstKind.IfStatement,
|
|
353
|
-
condition = condition,
|
|
354
|
-
body = body,
|
|
355
|
-
elseifs = elseifs,
|
|
356
|
-
elsebody = elsebody,
|
|
357
|
-
}
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
function Ast.FunctionDeclaration(scope, id, indices, args, body)
|
|
361
|
-
return {
|
|
362
|
-
kind = AstKind.FunctionDeclaration,
|
|
363
|
-
scope = scope,
|
|
364
|
-
baseScope = scope,
|
|
365
|
-
id = id,
|
|
366
|
-
baseId = id,
|
|
367
|
-
indices = indices,
|
|
368
|
-
args = args,
|
|
369
|
-
body = body,
|
|
370
|
-
getName = function(self)
|
|
371
|
-
return self.scope:getVariableName(self.id);
|
|
372
|
-
end,
|
|
373
|
-
}
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
function Ast.LocalFunctionDeclaration(scope, id, args, body)
|
|
377
|
-
return {
|
|
378
|
-
kind = AstKind.LocalFunctionDeclaration,
|
|
379
|
-
scope = scope,
|
|
380
|
-
id = id,
|
|
381
|
-
args = args,
|
|
382
|
-
body = body,
|
|
383
|
-
getName = function(self)
|
|
384
|
-
return self.scope:getVariableName(self.id);
|
|
385
|
-
end,
|
|
386
|
-
}
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
function Ast.LocalVariableDeclaration(scope, ids, expressions)
|
|
390
|
-
return {
|
|
391
|
-
kind = AstKind.LocalVariableDeclaration,
|
|
392
|
-
scope = scope,
|
|
393
|
-
ids = ids,
|
|
394
|
-
expressions = expressions,
|
|
395
|
-
}
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
function Ast.VarargExpression()
|
|
399
|
-
return {
|
|
400
|
-
kind = AstKind.VarargExpression;
|
|
401
|
-
isConstant = false,
|
|
402
|
-
}
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
function Ast.BooleanExpression(value)
|
|
406
|
-
return {
|
|
407
|
-
kind = AstKind.BooleanExpression,
|
|
408
|
-
isConstant = true,
|
|
409
|
-
value = value,
|
|
410
|
-
}
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
function Ast.NilExpression()
|
|
414
|
-
return {
|
|
415
|
-
kind = AstKind.NilExpression,
|
|
416
|
-
isConstant = true,
|
|
417
|
-
value = nil,
|
|
418
|
-
}
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
function Ast.NumberExpression(value)
|
|
422
|
-
return {
|
|
423
|
-
kind = AstKind.NumberExpression,
|
|
424
|
-
isConstant = true,
|
|
425
|
-
value = value,
|
|
426
|
-
}
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
function Ast.StringExpression(value)
|
|
430
|
-
return {
|
|
431
|
-
kind = AstKind.StringExpression,
|
|
432
|
-
isConstant = true,
|
|
433
|
-
value = value,
|
|
434
|
-
}
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
function Ast.OrExpression(lhs, rhs, simplify)
|
|
438
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
439
|
-
local success, val = pcall(function() return lhs.value or rhs.value end);
|
|
440
|
-
if success then
|
|
441
|
-
return Ast.ConstantNode(val);
|
|
442
|
-
end
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
return {
|
|
446
|
-
kind = AstKind.OrExpression,
|
|
447
|
-
lhs = lhs,
|
|
448
|
-
rhs = rhs,
|
|
449
|
-
isConstant = false,
|
|
450
|
-
}
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
function Ast.AndExpression(lhs, rhs, simplify)
|
|
454
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
455
|
-
local success, val = pcall(function() return lhs.value and rhs.value end);
|
|
456
|
-
if success then
|
|
457
|
-
return Ast.ConstantNode(val);
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
return {
|
|
462
|
-
kind = AstKind.AndExpression,
|
|
463
|
-
lhs = lhs,
|
|
464
|
-
rhs = rhs,
|
|
465
|
-
isConstant = false,
|
|
466
|
-
}
|
|
467
|
-
end
|
|
468
|
-
|
|
469
|
-
function Ast.LessThanExpression(lhs, rhs, simplify)
|
|
470
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
471
|
-
local success, val = pcall(function() return lhs.value < rhs.value end);
|
|
472
|
-
if success then
|
|
473
|
-
return Ast.ConstantNode(val);
|
|
474
|
-
end
|
|
475
|
-
end
|
|
476
|
-
|
|
477
|
-
return {
|
|
478
|
-
kind = AstKind.LessThanExpression,
|
|
479
|
-
lhs = lhs,
|
|
480
|
-
rhs = rhs,
|
|
481
|
-
isConstant = false,
|
|
482
|
-
}
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
function Ast.GreaterThanExpression(lhs, rhs, simplify)
|
|
486
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
487
|
-
local success, val = pcall(function() return lhs.value > rhs.value end);
|
|
488
|
-
if success then
|
|
489
|
-
return Ast.ConstantNode(val);
|
|
490
|
-
end
|
|
491
|
-
end
|
|
492
|
-
|
|
493
|
-
return {
|
|
494
|
-
kind = AstKind.GreaterThanExpression,
|
|
495
|
-
lhs = lhs,
|
|
496
|
-
rhs = rhs,
|
|
497
|
-
isConstant = false,
|
|
498
|
-
}
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
function Ast.LessThanOrEqualsExpression(lhs, rhs, simplify)
|
|
502
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
503
|
-
local success, val = pcall(function() return lhs.value <= rhs.value end);
|
|
504
|
-
if success then
|
|
505
|
-
return Ast.ConstantNode(val);
|
|
506
|
-
end
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
return {
|
|
510
|
-
kind = AstKind.LessThanOrEqualsExpression,
|
|
511
|
-
lhs = lhs,
|
|
512
|
-
rhs = rhs,
|
|
513
|
-
isConstant = false,
|
|
514
|
-
}
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
function Ast.GreaterThanOrEqualsExpression(lhs, rhs, simplify)
|
|
518
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
519
|
-
local success, val = pcall(function() return lhs.value >= rhs.value end);
|
|
520
|
-
if success then
|
|
521
|
-
return Ast.ConstantNode(val);
|
|
522
|
-
end
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
return {
|
|
526
|
-
kind = AstKind.GreaterThanOrEqualsExpression,
|
|
527
|
-
lhs = lhs,
|
|
528
|
-
rhs = rhs,
|
|
529
|
-
isConstant = false,
|
|
530
|
-
}
|
|
531
|
-
end
|
|
532
|
-
|
|
533
|
-
function Ast.NotEqualsExpression(lhs, rhs, simplify)
|
|
534
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
535
|
-
local success, val = pcall(function() return lhs.value ~= rhs.value end);
|
|
536
|
-
if success then
|
|
537
|
-
return Ast.ConstantNode(val);
|
|
538
|
-
end
|
|
539
|
-
end
|
|
540
|
-
|
|
541
|
-
return {
|
|
542
|
-
kind = AstKind.NotEqualsExpression,
|
|
543
|
-
lhs = lhs,
|
|
544
|
-
rhs = rhs,
|
|
545
|
-
isConstant = false,
|
|
546
|
-
}
|
|
547
|
-
end
|
|
548
|
-
|
|
549
|
-
function Ast.EqualsExpression(lhs, rhs, simplify)
|
|
550
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
551
|
-
local success, val = pcall(function() return lhs.value == rhs.value end);
|
|
552
|
-
if success then
|
|
553
|
-
return Ast.ConstantNode(val);
|
|
554
|
-
end
|
|
555
|
-
end
|
|
556
|
-
|
|
557
|
-
return {
|
|
558
|
-
kind = AstKind.EqualsExpression,
|
|
559
|
-
lhs = lhs,
|
|
560
|
-
rhs = rhs,
|
|
561
|
-
isConstant = false,
|
|
562
|
-
}
|
|
563
|
-
end
|
|
564
|
-
|
|
565
|
-
function Ast.StrCatExpression(lhs, rhs, simplify)
|
|
566
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
567
|
-
local success, val = pcall(function() return lhs.value .. rhs.value end);
|
|
568
|
-
if success then
|
|
569
|
-
return Ast.ConstantNode(val);
|
|
570
|
-
end
|
|
571
|
-
end
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
kind = AstKind.StrCatExpression,
|
|
575
|
-
lhs = lhs,
|
|
576
|
-
rhs = rhs,
|
|
577
|
-
isConstant = false,
|
|
578
|
-
}
|
|
579
|
-
end
|
|
580
|
-
|
|
581
|
-
function Ast.AddExpression(lhs, rhs, simplify)
|
|
582
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
583
|
-
local success, val = pcall(function() return lhs.value + rhs.value end);
|
|
584
|
-
if success then
|
|
585
|
-
return Ast.ConstantNode(val);
|
|
586
|
-
end
|
|
587
|
-
end
|
|
588
|
-
|
|
589
|
-
return {
|
|
590
|
-
kind = AstKind.AddExpression,
|
|
591
|
-
lhs = lhs,
|
|
592
|
-
rhs = rhs,
|
|
593
|
-
isConstant = false,
|
|
594
|
-
}
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
function Ast.SubExpression(lhs, rhs, simplify)
|
|
598
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
599
|
-
local success, val = pcall(function() return lhs.value - rhs.value end);
|
|
600
|
-
if success then
|
|
601
|
-
return Ast.ConstantNode(val);
|
|
602
|
-
end
|
|
603
|
-
end
|
|
604
|
-
|
|
605
|
-
return {
|
|
606
|
-
kind = AstKind.SubExpression,
|
|
607
|
-
lhs = lhs,
|
|
608
|
-
rhs = rhs,
|
|
609
|
-
isConstant = false,
|
|
610
|
-
}
|
|
611
|
-
end
|
|
612
|
-
|
|
613
|
-
function Ast.MulExpression(lhs, rhs, simplify)
|
|
614
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
615
|
-
local success, val = pcall(function() return lhs.value * rhs.value end);
|
|
616
|
-
if success then
|
|
617
|
-
return Ast.ConstantNode(val);
|
|
618
|
-
end
|
|
619
|
-
end
|
|
620
|
-
|
|
621
|
-
return {
|
|
622
|
-
kind = AstKind.MulExpression,
|
|
623
|
-
lhs = lhs,
|
|
624
|
-
rhs = rhs,
|
|
625
|
-
isConstant = false,
|
|
626
|
-
}
|
|
627
|
-
end
|
|
628
|
-
|
|
629
|
-
function Ast.DivExpression(lhs, rhs, simplify)
|
|
630
|
-
if(simplify and rhs.isConstant and lhs.isConstant and rhs.value ~= 0) then
|
|
631
|
-
local success, val = pcall(function() return lhs.value / rhs.value end);
|
|
632
|
-
if success then
|
|
633
|
-
return Ast.ConstantNode(val);
|
|
634
|
-
end
|
|
635
|
-
end
|
|
636
|
-
|
|
637
|
-
return {
|
|
638
|
-
kind = AstKind.DivExpression,
|
|
639
|
-
lhs = lhs,
|
|
640
|
-
rhs = rhs,
|
|
641
|
-
isConstant = false,
|
|
642
|
-
}
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
function Ast.ModExpression(lhs, rhs, simplify)
|
|
646
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
647
|
-
local success, val = pcall(function() return lhs.value % rhs.value end);
|
|
648
|
-
if success then
|
|
649
|
-
return Ast.ConstantNode(val);
|
|
650
|
-
end
|
|
651
|
-
end
|
|
652
|
-
|
|
653
|
-
return {
|
|
654
|
-
kind = AstKind.ModExpression,
|
|
655
|
-
lhs = lhs,
|
|
656
|
-
rhs = rhs,
|
|
657
|
-
isConstant = false,
|
|
658
|
-
}
|
|
659
|
-
end
|
|
660
|
-
|
|
661
|
-
function Ast.NotExpression(rhs, simplify)
|
|
662
|
-
if(simplify and rhs.isConstant) then
|
|
663
|
-
local success, val = pcall(function() return not rhs.value end);
|
|
664
|
-
if success then
|
|
665
|
-
return Ast.ConstantNode(val);
|
|
666
|
-
end
|
|
667
|
-
end
|
|
668
|
-
|
|
669
|
-
return {
|
|
670
|
-
kind = AstKind.NotExpression,
|
|
671
|
-
rhs = rhs,
|
|
672
|
-
isConstant = false,
|
|
673
|
-
}
|
|
674
|
-
end
|
|
675
|
-
|
|
676
|
-
function Ast.NegateExpression(rhs, simplify)
|
|
677
|
-
if(simplify and rhs.isConstant) then
|
|
678
|
-
local success, val = pcall(function() return -rhs.value end);
|
|
679
|
-
if success then
|
|
680
|
-
return Ast.ConstantNode(val);
|
|
681
|
-
end
|
|
682
|
-
end
|
|
683
|
-
|
|
684
|
-
return {
|
|
685
|
-
kind = AstKind.NegateExpression,
|
|
686
|
-
rhs = rhs,
|
|
687
|
-
isConstant = false,
|
|
688
|
-
}
|
|
689
|
-
end
|
|
690
|
-
|
|
691
|
-
function Ast.LenExpression(rhs, simplify)
|
|
692
|
-
if(simplify and rhs.isConstant) then
|
|
693
|
-
local success, val = pcall(function() return #rhs.value end);
|
|
694
|
-
if success then
|
|
695
|
-
return Ast.ConstantNode(val);
|
|
696
|
-
end
|
|
697
|
-
end
|
|
698
|
-
|
|
699
|
-
return {
|
|
700
|
-
kind = AstKind.LenExpression,
|
|
701
|
-
rhs = rhs,
|
|
702
|
-
isConstant = false,
|
|
703
|
-
}
|
|
704
|
-
end
|
|
705
|
-
|
|
706
|
-
function Ast.PowExpression(lhs, rhs, simplify)
|
|
707
|
-
if(simplify and rhs.isConstant and lhs.isConstant) then
|
|
708
|
-
local success, val = pcall(function() return lhs.value ^ rhs.value end);
|
|
709
|
-
if success then
|
|
710
|
-
return Ast.ConstantNode(val);
|
|
711
|
-
end
|
|
712
|
-
end
|
|
713
|
-
|
|
714
|
-
return {
|
|
715
|
-
kind = AstKind.PowExpression,
|
|
716
|
-
lhs = lhs,
|
|
717
|
-
rhs = rhs,
|
|
718
|
-
isConstant = false,
|
|
719
|
-
}
|
|
720
|
-
end
|
|
721
|
-
|
|
722
|
-
function Ast.IndexExpression(base, index)
|
|
723
|
-
return {
|
|
724
|
-
kind = AstKind.IndexExpression,
|
|
725
|
-
base = base,
|
|
726
|
-
index = index,
|
|
727
|
-
isConstant = false,
|
|
728
|
-
}
|
|
729
|
-
end
|
|
730
|
-
|
|
731
|
-
function Ast.AssignmentIndexing(base, index)
|
|
732
|
-
return {
|
|
733
|
-
kind = AstKind.AssignmentIndexing,
|
|
734
|
-
base = base,
|
|
735
|
-
index = index,
|
|
736
|
-
isConstant = false,
|
|
737
|
-
}
|
|
738
|
-
end
|
|
739
|
-
|
|
740
|
-
function Ast.PassSelfFunctionCallExpression(base, passSelfFunctionName, args)
|
|
741
|
-
return {
|
|
742
|
-
kind = AstKind.PassSelfFunctionCallExpression,
|
|
743
|
-
base = base,
|
|
744
|
-
passSelfFunctionName = passSelfFunctionName,
|
|
745
|
-
args = args,
|
|
746
|
-
|
|
747
|
-
}
|
|
748
|
-
end
|
|
749
|
-
|
|
750
|
-
function Ast.FunctionCallExpression(base, args)
|
|
751
|
-
return {
|
|
752
|
-
kind = AstKind.FunctionCallExpression,
|
|
753
|
-
base = base,
|
|
754
|
-
args = args,
|
|
755
|
-
}
|
|
756
|
-
end
|
|
757
|
-
|
|
758
|
-
function Ast.VariableExpression(scope, id)
|
|
759
|
-
scope:addReference(id);
|
|
760
|
-
return {
|
|
761
|
-
kind = AstKind.VariableExpression,
|
|
762
|
-
scope = scope,
|
|
763
|
-
id = id,
|
|
764
|
-
getName = function(self)
|
|
765
|
-
return self.scope.getVariableName(self.id);
|
|
766
|
-
end,
|
|
767
|
-
}
|
|
768
|
-
end
|
|
769
|
-
|
|
770
|
-
function Ast.AssignmentVariable(scope, id)
|
|
771
|
-
scope:addReference(id);
|
|
772
|
-
return {
|
|
773
|
-
kind = AstKind.AssignmentVariable,
|
|
774
|
-
scope = scope,
|
|
775
|
-
id = id,
|
|
776
|
-
getName = function(self)
|
|
777
|
-
return self.scope.getVariableName(self.id);
|
|
778
|
-
end,
|
|
779
|
-
}
|
|
780
|
-
end
|
|
781
|
-
|
|
782
|
-
function Ast.FunctionLiteralExpression(args, body)
|
|
783
|
-
return {
|
|
784
|
-
kind = AstKind.FunctionLiteralExpression,
|
|
785
|
-
args = args,
|
|
786
|
-
body = body,
|
|
787
|
-
}
|
|
788
|
-
end
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
return Ast;
|