Skip to content

Commit 0e55c81

Browse files
authored
Merge pull request #17 from levno-710/develop
2 parents 7342a18 + 829b9a6 commit 0e55c81

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/prometheus/ast.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,19 @@ function Ast.WhileStatement(body, condition, parentScope)
248248
}
249249
end
250250

251-
function Ast.ForInStatement(scope, vars, expressions, body)
251+
function Ast.ForInStatement(scope, vars, expressions, body, parentScope)
252252
return {
253253
kind = AstKind.ForInStatement,
254254
scope = scope,
255255
ids = vars,
256256
vars = vars,
257257
expressions = expressions,
258258
body = body,
259+
parentScope = parentScope,
259260
}
260261
end
261262

262-
function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body)
263+
function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body, parentScope)
263264
return {
264265
kind = AstKind.ForStatement,
265266
scope = scope,
@@ -268,6 +269,7 @@ function Ast.ForStatement(scope, id, initialValue, finalValue, incrementBy, body
268269
finalValue = finalValue,
269270
incrementBy = incrementBy,
270271
body = body,
272+
parentScope = parentScope,
271273
}
272274
end
273275

src/prometheus/compiler_secure/compiler.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ function Compiler:compileStatement(statement)
371371
ir:instruction(IR:JMP(endNop));
372372
ir:instruction(IR:PUSHTEMPSTACK());
373373

374+
statement.__endnop = endNop;
375+
statement.__startnop = fskip;
376+
374377
table.insert(self.scopeStack, self.currentScope);
375378
self.currentScope = statement.body.scope;
376379

@@ -398,6 +401,9 @@ function Compiler:compileStatement(statement)
398401
local fskip = IR:FORINSKIP();
399402
local endNop = IR:NOP();
400403

404+
statement.__endnop = endNop;
405+
statement.__endnop = endNop;
406+
401407
ir:instruction(fskip);
402408
ir:instruction(IR:JMP(endNop));
403409

src/prometheus/parser.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function Parser:statement(scope, currentLoop)
355355
incrementBy = self:expression(scope);
356356
end
357357

358-
local stat = Ast.ForStatement(forScope, varId, initialValue, finalValue, incrementBy, nil);
358+
local stat = Ast.ForStatement(forScope, varId, initialValue, finalValue, incrementBy, nil, scope);
359359
forScope:enableVariable(varId);
360360
expect(self, TokenKind.Keyword, "do");
361361
stat.body = self:block(nil, stat, forScope);
@@ -376,8 +376,8 @@ function Parser:statement(scope, currentLoop)
376376
-- end
377377
self:enableNameList(forScope, ids);
378378
expect(self, TokenKind.Keyword, "do");
379-
local stat = Ast.ForInStatement(forScope, ids, expressions, nil);
380-
stat.body = self:block(nil, true, forScope);
379+
local stat = Ast.ForInStatement(forScope, ids, expressions, nil, scope);
380+
stat.body = self:block(nil, stat, forScope);
381381
expect(self, TokenKind.Keyword, "end");
382382

383383
return stat;

0 commit comments

Comments
 (0)