Skip to content

Commit

Permalink
Merge pull request #17 from levno-710/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
levno-710 committed Jan 20, 2022
2 parents 7342a18 + 829b9a6 commit 0e55c81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/prometheus/ast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,19 @@ function Ast.WhileStatement(body, condition, parentScope)
}
end

function Ast.ForInStatement(scope, vars, expressions, body)
function Ast.ForInStatement(scope, vars, expressions, body, parentScope)
return {
kind = AstKind.ForInStatement,
scope = scope,
ids = vars,
vars = vars,
expressions = expressions,
body = body,
parentScope = parentScope,
}
end

function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body)
function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body, parentScope)
return {
kind = AstKind.ForStatement,
scope = scope,
Expand All @@ -268,6 +269,7 @@ function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body
finalValue = finalValue,
incrementBy = incrementBy,
body = body,
parentScope = parentScope,
}
end

Expand Down
6 changes: 6 additions & 0 deletions src/prometheus/compiler_secure/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ function Compiler:compileStatement(statement)
ir:instruction(IR:JMP(endNop));
ir:instruction(IR:PUSHTEMPSTACK());

statement.__endnop = endNop;
statement.__startnop = fskip;

table.insert(self.scopeStack, self.currentScope);
self.currentScope = statement.body.scope;

Expand Down Expand Up @@ -398,6 +401,9 @@ function Compiler:compileStatement(statement)
local fskip = IR:FORINSKIP();
local endNop = IR:NOP();

statement.__endnop = endNop;
statement.__endnop = endNop;

ir:instruction(fskip);
ir:instruction(IR:JMP(endNop));

Expand Down
6 changes: 3 additions & 3 deletions src/prometheus/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function Parser:statement(scope, currentLoop)
incrementBy = self:expression(scope);
end

local stat = Ast.ForStatement(forScope, varId, initialValue, finalValue, incrementBy, nil);
local stat = Ast.ForStatement(forScope, varId, initialValue, finalValue, incrementBy, nil, scope);
forScope:enableVariable(varId);
expect(self, TokenKind.Keyword, "do");
stat.body = self:block(nil, stat, forScope);
Expand All @@ -376,8 +376,8 @@ function Parser:statement(scope, currentLoop)
-- end
self:enableNameList(forScope, ids);
expect(self, TokenKind.Keyword, "do");
local stat = Ast.ForInStatement(forScope, ids, expressions, nil);
stat.body = self:block(nil, true, forScope);
local stat = Ast.ForInStatement(forScope, ids, expressions, nil, scope);
stat.body = self:block(nil, stat, forScope);
expect(self, TokenKind.Keyword, "end");

return stat;
Expand Down

0 comments on commit 0e55c81

Please sign in to comment.