-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathcompound.lua
More file actions
62 lines (58 loc) · 3.54 KB
/
Copy pathcompound.lua
File metadata and controls
62 lines (58 loc) · 3.54 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- compound.lua
--
-- This Script contains the statement handler for the Compound statements (compound add, sub, mul, etc.)
local Ast = require("prometheus.ast");
local AstKind = Ast.AstKind;
local compoundConstructors = {
[AstKind.CompoundAddStatement] = Ast.CompoundAddStatement,
[AstKind.CompoundSubStatement] = Ast.CompoundSubStatement,
[AstKind.CompoundMulStatement] = Ast.CompoundMulStatement,
[AstKind.CompoundDivStatement] = Ast.CompoundDivStatement,
[AstKind.CompoundModStatement] = Ast.CompoundModStatement,
[AstKind.CompoundPowStatement] = Ast.CompoundPowStatement,
[AstKind.CompoundConcatStatement] = Ast.CompoundConcatStatement,
};
return function(self, statement, funcDepth)
local scope = self.activeBlock.scope;
local compoundConstructor = compoundConstructors[statement.kind];
if statement.lhs.kind == AstKind.AssignmentIndexing then
local indexing = statement.lhs;
local baseReg = self:compileExpression(indexing.base, funcDepth, 1)[1];
local indexReg = self:compileExpression(indexing.index, funcDepth, 1)[1];
local valueReg = self:compileExpression(statement.rhs, funcDepth, 1)[1];
self:addStatement(compoundConstructor(Ast.AssignmentIndexing(self:register(scope, baseReg), self:register(scope, indexReg)), self:register(scope, valueReg)), {}, {baseReg, indexReg, valueReg}, true);
self:freeRegister(baseReg, false);
self:freeRegister(indexReg, false);
self:freeRegister(valueReg, false);
else
local valueReg = self:compileExpression(statement.rhs, funcDepth, 1)[1];
local primaryExpr = statement.lhs;
if primaryExpr.scope.isGlobal then
local tmpReg = self:allocRegister(false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.StringExpression(primaryExpr.scope:getVariableName(primaryExpr.id))), {tmpReg}, {}, false);
self:addStatement(compoundConstructor(Ast.AssignmentIndexing(self:env(scope), self:register(scope, tmpReg)),
self:register(scope, valueReg)), {}, {tmpReg, valueReg}, true);
self:freeRegister(tmpReg, false);
self:freeRegister(valueReg, false);
else
if self.scopeFunctionDepths[primaryExpr.scope] == funcDepth then
if self:isUpvalue(primaryExpr.scope, primaryExpr.id) then
local reg = self:getVarRegister(primaryExpr.scope, primaryExpr.id, funcDepth);
self:addStatement(self:setUpvalueMember(scope, self:register(scope, reg), self:register(scope, valueReg), compoundConstructor), {}, {reg, valueReg}, true);
else
local reg = self:getVarRegister(primaryExpr.scope, primaryExpr.id, funcDepth, valueReg);
if reg ~= valueReg then
self:addStatement(self:setRegister(scope, reg, self:register(scope, valueReg), compoundConstructor), {reg}, {valueReg}, false);
end
end
else
local upvalId = self:getUpvalueId(primaryExpr.scope, primaryExpr.id);
scope:addReferenceToHigherScope(self.containerFuncScope, self.currentUpvaluesVar);
self:addStatement(self:setUpvalueMember(scope, Ast.IndexExpression(Ast.VariableExpression(self.containerFuncScope, self.currentUpvaluesVar), Ast.NumberExpression(upvalId)), self:register(scope, valueReg), compoundConstructor), {}, {valueReg}, true);
end
self:freeRegister(valueReg, false);
end
end
end;