Skip to content

Commit 9298cf0

Browse files
committed
VirtualMachine: Do not use function calls for forever loop
1 parent 7e8b6bc commit 9298cf0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/engine/virtualmachine.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,12 @@ unsigned int *VirtualMachine::run(unsigned int *pos)
198198
DISPATCH();
199199

200200
do_forever_loop:
201-
while (true)
202-
run(pos);
201+
Loop l;
202+
l.isRepeatLoop = true;
203+
l.start = pos;
204+
l.index = -1;
205+
m_loops.push_back(l);
206+
DISPATCH();
203207

204208
do_repeat_loop:
205209
loopCount = READ_LAST_REG()->toLong();
@@ -241,7 +245,7 @@ unsigned int *VirtualMachine::run(unsigned int *pos)
241245
do_loop_end : {
242246
Loop &l = m_loops.back();
243247
if (l.isRepeatLoop) {
244-
if (++l.index < l.max)
248+
if ((l.index == -1) || (++l.index < l.max))
245249
pos = l.start;
246250
else
247251
m_loops.pop_back();

0 commit comments

Comments
 (0)