-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathvariable.lua
More file actions
45 lines (42 loc) · 2.33 KB
/
variable.lua
File metadata and controls
45 lines (42 loc) · 2.33 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- variable.lua
--
-- This Script contains the expression handler for the VariableExpression
local Ast = require("prometheus.ast");
return function(self, expression, funcDepth, numReturns)
local scope = self.activeBlock.scope;
local regs = {};
for i = 1, numReturns do
if i == 1 then
if expression.scope.isGlobal then
regs[i] = self:allocRegister(false);
local tmpReg = self:allocRegister(false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.StringExpression(expression.scope:getVariableName(expression.id))), {tmpReg}, {}, false);
self:addStatement(self:setRegister(scope, regs[i], Ast.IndexExpression(self:env(scope), self:register(scope, tmpReg))), {regs[i]}, {tmpReg}, true);
self:freeRegister(tmpReg, false);
else
if self.scopeFunctionDepths[expression.scope] == funcDepth then
if self:isUpvalue(expression.scope, expression.id) then
local reg = self:allocRegister(false);
local varReg = self:getVarRegister(expression.scope, expression.id, funcDepth, nil);
self:addStatement(self:setRegister(scope, reg, self:getUpvalueMember(scope, self:register(scope, varReg))), {reg}, {varReg}, true);
regs[i] = reg;
else
regs[i] = self:getVarRegister(expression.scope, expression.id, funcDepth, nil);
end
else
local reg = self:allocRegister(false);
local upvalId = self:getUpvalueId(expression.scope, expression.id);
scope:addReferenceToHigherScope(self.containerFuncScope, self.currentUpvaluesVar);
self:addStatement(self:setRegister(scope, reg, self:getUpvalueMember(scope, Ast.IndexExpression(Ast.VariableExpression(self.containerFuncScope, self.currentUpvaluesVar), Ast.NumberExpression(upvalId)))), {reg}, {}, true);
regs[i] = reg;
end
end
else
regs[i] = self:allocRegister();
self:addStatement(self:setRegister(scope, regs[i], Ast.NilExpression()), {regs[i]}, {}, false);
end
end
return regs;
end;