-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathpass_self_function_call.lua
More file actions
70 lines (58 loc) · 3.24 KB
/
pass_self_function_call.lua
File metadata and controls
70 lines (58 loc) · 3.24 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- pass_self_function_call.lua
--
-- This Script contains the expression handler for the PassSelfFunctionCallExpression.
local Ast = require("prometheus.ast");
local AstKind = Ast.AstKind;
return function(self, expression, funcDepth, numReturns)
local scope = self.activeBlock.scope;
local baseReg = self:compileExpression(expression.base, funcDepth, 1)[1];
local retRegs = {};
local returnAll = numReturns == self.RETURN_ALL;
if returnAll then
retRegs[1] = self:allocRegister(false);
else
for i = 1, numReturns do
retRegs[i] = self:allocRegister(false);
end
end
local args = { self:register(scope, baseReg) };
local regs = { baseReg };
for i, expr in ipairs(expression.args) do
if i == #expression.args and (expr.kind == AstKind.FunctionCallExpression or expr.kind == AstKind.PassSelfFunctionCallExpression or expr.kind == AstKind.VarargExpression) then
local reg = self:compileExpression(expr, funcDepth, self.RETURN_ALL)[1];
table.insert(args, Ast.FunctionCallExpression(
self:unpack(scope),
{self:register(scope, reg)}));
table.insert(regs, reg);
else
local reg = self:compileExpression(expr, funcDepth, 1)[1];
table.insert(args, self:register(scope, reg));
table.insert(regs, reg);
end
end
if returnAll or numReturns > 1 then
local tmpReg = self:allocRegister(false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.StringExpression(expression.passSelfFunctionName)), {tmpReg}, {}, false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.IndexExpression(self:register(scope, baseReg), self:register(scope, tmpReg))), {tmpReg}, {baseReg, tmpReg}, false);
if returnAll then
self:addStatement(self:setRegister(scope, retRegs[1], Ast.TableConstructorExpression{Ast.TableEntry(Ast.FunctionCallExpression(self:register(scope, tmpReg), args))}), {retRegs[1]}, {tmpReg, unpack(regs)}, true);
else
self:addStatement(self:setRegister(scope, tmpReg, Ast.TableConstructorExpression{Ast.TableEntry(Ast.FunctionCallExpression(self:register(scope, tmpReg), args))}), {tmpReg}, {tmpReg, unpack(regs)}, true);
for i, reg in ipairs(retRegs) do
self:addStatement(self:setRegister(scope, reg, Ast.IndexExpression(self:register(scope, tmpReg), Ast.NumberExpression(i))), {reg}, {tmpReg}, false);
end
end
self:freeRegister(tmpReg, false);
else
local tmpReg = retRegs[1] or self:allocRegister(false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.StringExpression(expression.passSelfFunctionName)), {tmpReg}, {}, false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.IndexExpression(self:register(scope, baseReg), self:register(scope, tmpReg))), {tmpReg}, {baseReg, tmpReg}, false);
self:addStatement(self:setRegister(scope, retRegs[1], Ast.FunctionCallExpression(self:register(scope, tmpReg), args)), {retRegs[1]}, {baseReg, unpack(regs)}, true);
end
for i, reg in ipairs(regs) do
self:freeRegister(reg, false);
end
return retRegs;
end;