Skip to content

Commit

Permalink
Fix wrong bytecode generator in uclo-3 test with repeat loop
Browse files Browse the repository at this point in the history
  • Loading branch information
franko committed May 21, 2020
1 parent 01d1604 commit ca5fef2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lang/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,28 @@ end
function StatementRule:RepeatStatement(node)
local base_register = self.ctx.freereg
local loop_begin_location, loop_exit_location = genid(), genid()
local loop_uclo_location = genid()
self:loop_enter(loop_exit_location, base_register)
self.ctx:here(loop_begin_location)
self.ctx:loop(loop_exit_location)
self:block_emit(node.body)
self:test_emit(node.test, loop_begin_location, base_register)
local need_body_uclo = self.ctx.scope.need_uclo
if need_body_uclo then
self:test_emit(node.test, loop_uclo_location, self.ctx.freereg)
else
self:test_emit(node.test, loop_begin_location, base_register)
end
if need_body_uclo then
self.ctx:scope_jump(loop_exit_location, base_register, true)
self.ctx:here(loop_uclo_location)
self.ctx:scope_jump(loop_begin_location, base_register, true)
else
self.ctx:close_block(self.ctx.scope.basereg)
end
self.ctx:here(loop_exit_location)
self:loop_leave(node.lastline)
self.ctx:fscope_end()
self.ctx:leave()
if node.lastline then self.ctx:line(node.lastline) end
self.ctx.freereg = base_register
end
function StatementRule:BreakStatement()
Expand Down

0 comments on commit ca5fef2

Please sign in to comment.