Skip to content

Commit

Permalink
Merge pull request #93 from levno-710/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
levno-710 authored Oct 30, 2022
2 parents 1b51e3f + 38061cd commit e0aa566
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/prometheus/compiler/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,19 @@ function Compiler:compileStatement(statement, funcDepth)
self:addStatement(self:setRegister(scope, varRegs[i], Ast.NilExpression()), {varRegs[i]}, {}, false);
end

-- Upvalue fix
for i, id in ipairs(statement.ids) do
if(self:isUpvalue(statement.scope, id)) then
local varreg = varRegs[i];
local tmpReg = self:allocRegister(false);
scope:addReferenceToHigherScope(self.scope, self.allocUpvalFunction);
self:addStatement(self:setRegister(scope, tmpReg, Ast.FunctionCallExpression(Ast.VariableExpression(self.scope, self.allocUpvalFunction), {})), {tmpReg}, {}, false);
self:addStatement(self:setUpvalueMember(scope, self:register(scope, tmpReg), self:register(scope, varreg)), {}, {tmpReg, varreg}, true);
self:addStatement(self:copyRegisters(scope, {varreg}, {tmpReg}), {varreg}, {tmpReg}, false);
self:freeRegister(tmpReg, false);
end
end

self:compileBlock(statement.body, funcDepth);
self:addStatement(self:setPos(scope, checkBlock.id), {self.POS_REGISTER}, {}, false);
self:setActiveBlock(finalBlock);
Expand Down Expand Up @@ -2345,7 +2358,7 @@ function Compiler:compileExpression(expression, funcDepth, numReturns)
return regs;
end

logger:error(string.format("%s is not an compileable expression!", expression.kind));
logger:error(string.format("%s is not an compliable expression!", expression.kind));
end

return Compiler;

0 comments on commit e0aa566

Please sign in to comment.