Skip to content

Commit 1d8ccc4

Browse files
committed
fix #470: Store warp mode in procedure call tree
1 parent e82ef6c commit 1d8ccc4

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/engine/virtualmachine_p.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
228228
atEnd = true;
229229
return pos;
230230
} else {
231-
if (callTree.size() == 1)
232-
warp = false;
233-
234-
pos = callTree.back();
231+
const auto &oldState = callTree.back();
232+
pos = oldState.first;
233+
warp = oldState.second;
235234
callTree.pop_back();
236235
procedureArgTree.pop_back();
237236
if (procedureArgTree.empty())
@@ -797,7 +796,7 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
797796
unsigned int *procedurePos = procedures[pos[1]];
798797

799798
if (procedurePos) {
800-
callTree.push_back(++pos);
799+
callTree.push_back({ ++pos, warp });
801800
procedureArgs = nextProcedureArgs;
802801
nextProcedureArgs = nullptr;
803802
pos = procedurePos;

src/engine/virtualmachine_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct VirtualMachinePrivate
4646
bool running = false;
4747
bool atEnd = false;
4848
std::vector<Loop> loops;
49-
std::vector<unsigned int *> callTree;
49+
std::vector<std::pair<unsigned int *, bool>> callTree;
5050
std::vector<std::vector<Value>> procedureArgTree;
5151
std::vector<Value> *procedureArgs = nullptr;
5252
std::vector<Value> *nextProcedureArgs = nullptr;

test/virtual_machine/virtual_machine_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,27 @@ TEST(VirtualMachineTest, RunProcedures)
14661466
ASSERT_EQ(vm.registerCount(), 0);
14671467
}
14681468

1469+
TEST(VirtualMachineTest, RunNestedWarpProcedures)
1470+
{
1471+
static unsigned int bytecode[] = { OP_START, OP_INIT_PROCEDURE, OP_CALL_PROCEDURE, 0, OP_HALT };
1472+
static unsigned int procedure1[] = { OP_START, OP_INIT_PROCEDURE, OP_CALL_PROCEDURE, 1, OP_CONST, 0, OP_REPEAT_LOOP, OP_BREAK_FRAME, OP_LOOP_END, OP_HALT };
1473+
static unsigned int procedure2[] = { OP_START, OP_WARP, OP_CONST, 0, OP_REPEAT_LOOP, OP_BREAK_FRAME, OP_LOOP_END, OP_HALT };
1474+
static unsigned int *procedures[] = { procedure1, procedure2 };
1475+
static Value constValues[] = { 1 };
1476+
1477+
VirtualMachine vm;
1478+
vm.setBytecode(bytecode);
1479+
vm.setProcedures(procedures);
1480+
vm.setConstValues(constValues);
1481+
vm.run();
1482+
ASSERT_FALSE(vm.atEnd()); // the procedure should still run in warp mode even after running a warp procedure (#470)
1483+
ASSERT_EQ(vm.registerCount(), 0);
1484+
1485+
vm.run();
1486+
ASSERT_TRUE(vm.atEnd());
1487+
ASSERT_EQ(vm.registerCount(), 0);
1488+
}
1489+
14691490
TEST(VirtualMachineTest, RunUndefinedProcedure)
14701491
{
14711492
static unsigned int bytecode[] = {

0 commit comments

Comments
 (0)