Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/engine/virtualmachine_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
atEnd = true;
return pos;
} else {
if (callTree.size() == 1)
warp = false;

pos = callTree.back();
const auto &oldState = callTree.back();
pos = oldState.first;
warp = oldState.second;
callTree.pop_back();
procedureArgTree.pop_back();
if (procedureArgTree.empty())
Expand Down Expand Up @@ -797,7 +796,7 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
unsigned int *procedurePos = procedures[pos[1]];

if (procedurePos) {
callTree.push_back(++pos);
callTree.push_back({ ++pos, warp });
procedureArgs = nextProcedureArgs;
nextProcedureArgs = nullptr;
pos = procedurePos;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/virtualmachine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct VirtualMachinePrivate
bool running = false;
bool atEnd = false;
std::vector<Loop> loops;
std::vector<unsigned int *> callTree;
std::vector<std::pair<unsigned int *, bool>> callTree;
std::vector<std::vector<Value>> procedureArgTree;
std::vector<Value> *procedureArgs = nullptr;
std::vector<Value> *nextProcedureArgs = nullptr;
Expand Down
21 changes: 21 additions & 0 deletions test/virtual_machine/virtual_machine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,27 @@ TEST(VirtualMachineTest, RunProcedures)
ASSERT_EQ(vm.registerCount(), 0);
}

TEST(VirtualMachineTest, RunNestedWarpProcedures)
{
static unsigned int bytecode[] = { OP_START, OP_INIT_PROCEDURE, OP_CALL_PROCEDURE, 0, OP_HALT };
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 };
static unsigned int procedure2[] = { OP_START, OP_WARP, OP_CONST, 0, OP_REPEAT_LOOP, OP_BREAK_FRAME, OP_LOOP_END, OP_HALT };
static unsigned int *procedures[] = { procedure1, procedure2 };
static Value constValues[] = { 1 };

VirtualMachine vm;
vm.setBytecode(bytecode);
vm.setProcedures(procedures);
vm.setConstValues(constValues);
vm.run();
ASSERT_FALSE(vm.atEnd()); // the procedure should still run in warp mode even after running a warp procedure (#470)
ASSERT_EQ(vm.registerCount(), 0);

vm.run();
ASSERT_TRUE(vm.atEnd());
ASSERT_EQ(vm.registerCount(), 0);
}

TEST(VirtualMachineTest, RunUndefinedProcedure)
{
static unsigned int bytecode[] = {
Expand Down