-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathtable_constructor.lua
More file actions
49 lines (47 loc) · 2.34 KB
/
table_constructor.lua
File metadata and controls
49 lines (47 loc) · 2.34 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- table_constructor.lua
--
-- This Script contains the expression handler for the TableConstructorExpression.
local Ast = require("prometheus.ast");
local AstKind = Ast.AstKind;
return function(self, expression, funcDepth, numReturns)
local scope = self.activeBlock.scope;
local regs = {};
for i = 1, numReturns do
regs[i] = self:allocRegister();
if i == 1 then
local entries = {};
local entryRegs = {};
for i, entry in ipairs(expression.entries) do
if entry.kind == AstKind.TableEntry then
local value = entry.value;
if i == #expression.entries and (value.kind == AstKind.FunctionCallExpression or value.kind == AstKind.PassSelfFunctionCallExpression or value.kind == AstKind.VarargExpression) then
local reg = self:compileExpression(entry.value, funcDepth, self.RETURN_ALL)[1];
table.insert(entries, Ast.TableEntry(Ast.FunctionCallExpression(
self:unpack(scope),
{self:register(scope, reg)})));
table.insert(entryRegs, reg);
else
local reg = self:compileExpression(entry.value, funcDepth, 1)[1];
table.insert(entries, Ast.TableEntry(self:register(scope, reg)));
table.insert(entryRegs, reg);
end
else
local keyReg = self:compileExpression(entry.key, funcDepth, 1)[1];
local valReg = self:compileExpression(entry.value, funcDepth, 1)[1];
table.insert(entries, Ast.KeyedTableEntry(self:register(scope, keyReg), self:register(scope, valReg)));
table.insert(entryRegs, valReg);
table.insert(entryRegs, keyReg);
end
end
self:addStatement(self:setRegister(scope, regs[i], Ast.TableConstructorExpression(entries)), {regs[i]}, entryRegs, false);
for i, reg in ipairs(entryRegs) do
self:freeRegister(reg, false);
end
else
self:addStatement(self:setRegister(scope, regs[i], Ast.NilExpression()), {regs[i]}, {}, false);
end
end
return regs;
end;