-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathrepeat_statement.lua
More file actions
40 lines (33 loc) · 1.87 KB
/
repeat_statement.lua
File metadata and controls
40 lines (33 loc) · 1.87 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
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- repeat_statement.lua
--
-- This Script contains the statement handler for the RepeatStatement.
local Ast = require("prometheus.ast");
return function(self, statement, funcDepth)
local scope = self.activeBlock.scope;
local innerBlock = self:createBlock();
local finalBlock = self:createBlock();
statement.__start_block = innerBlock;
statement.__final_block = finalBlock;
self:addStatement(self:setRegister(scope, self.POS_REGISTER, Ast.NumberExpression(innerBlock.id)), {self.POS_REGISTER}, {}, false);
self:setActiveBlock(innerBlock);
for _, stat in ipairs(statement.body.statements) do
self:compileStatement(stat, funcDepth);
end;
local scope = self.activeBlock.scope;
local conditionReg = (self:compileExpression(statement.condition, funcDepth, 1))[1];
self:addStatement(self:setRegister(scope, self.POS_REGISTER, Ast.OrExpression(Ast.AndExpression(self:register(scope, conditionReg), Ast.NumberExpression(finalBlock.id)), Ast.NumberExpression(innerBlock.id))), { self.POS_REGISTER }, { conditionReg }, false);
self:freeRegister(conditionReg, false);
for id, _ in ipairs(statement.body.scope.variables) do
local varReg = self:getVarRegister(statement.body.scope, id, funcDepth, nil);
if self:isUpvalue(statement.body.scope, id) then
scope:addReferenceToHigherScope(self.scope, self.freeUpvalueFunc);
self:addStatement(self:setRegister(scope, varReg, Ast.FunctionCallExpression(Ast.VariableExpression(self.scope, self.freeUpvalueFunc), { self:register(scope, varReg) })), { varReg }, { varReg }, false);
else
self:addStatement(self:setRegister(scope, varReg, Ast.NilExpression()), { varReg }, {}, false);
end;
self:freeRegister(varReg, true);
end;
self:setActiveBlock(finalBlock);
end;