-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathlocal_variable_declaration.lua
More file actions
54 lines (48 loc) · 2.4 KB
/
local_variable_declaration.lua
File metadata and controls
54 lines (48 loc) · 2.4 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- local_variable_declaration.lua
--
-- This Script contains the statement handler for the LocalVariableDeclaration
local Ast = require("prometheus.ast");
local AstKind = Ast.AstKind;
return function(self, statement, funcDepth)
local scope = self.activeBlock.scope;
local exprregs = {};
for i, expr in ipairs(statement.expressions) do
if(i == #statement.expressions and #statement.ids > #statement.expressions) then
local regs = self:compileExpression(expr, funcDepth, #statement.ids - #statement.expressions + 1);
for i, reg in ipairs(regs) do
table.insert(exprregs, reg);
end
else
if statement.ids[i] or expr.kind == AstKind.FunctionCallExpression or expr.kind == AstKind.PassSelfFunctionCallExpression then
local reg = self:compileExpression(expr, funcDepth, 1)[1];
table.insert(exprregs, reg);
end
end
end
if #exprregs == 0 then
for _=1, #statement.ids do
table.insert(exprregs, self:compileExpression(Ast.NilExpression(), funcDepth, 1)[1]);
end
end
for i, id in ipairs(statement.ids) do
if(exprregs[i]) then
if(self:isUpvalue(statement.scope, id)) then
local varreg = self:getVarRegister(statement.scope, id, funcDepth);
local varReg = self:getVarRegister(statement.scope, id, funcDepth, nil);
scope:addReferenceToHigherScope(self.scope, self.allocUpvalFunction);
self:addStatement(self:setRegister(scope, varReg, Ast.FunctionCallExpression(Ast.VariableExpression(self.scope, self.allocUpvalFunction), {})), {varReg}, {}, false);
self:addStatement(self:setUpvalueMember(scope, self:register(scope, varReg), self:register(scope, exprregs[i])), {}, {varReg, exprregs[i]}, true);
self:freeRegister(exprregs[i], false);
else
local varreg = self:getVarRegister(statement.scope, id, funcDepth, exprregs[i]);
self:addStatement(self:copyRegisters(scope, {varreg}, {exprregs[i]}), {varreg}, {exprregs[i]}, false);
self:freeRegister(exprregs[i], false);
end
end
end
if not self.scopeFunctionDepths[statement.scope] then
self.scopeFunctionDepths[statement.scope] = funcDepth;
end
end;