Skip to content

Commit 1e1cf4a

Browse files
committed
VirtualMachine: Add atEnd property
1 parent 49d5e0c commit 1e1cf4a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/engine/virtualmachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void VirtualMachine::setBytecode(const std::vector<unsigned int> &code)
7373
/*! Runs the script. */
7474
unsigned int *VirtualMachine::run(RunningScript *script)
7575
{
76+
m_atEnd = false;
7677
return run(m_bytecode, script);
7778
}
7879

@@ -127,6 +128,7 @@ unsigned int *VirtualMachine::run(unsigned int *pos, RunningScript *script)
127128
if (m_regCount > 0) {
128129
std::cout << "warning: VM: " << m_regCount << " registers were leaked by the script; this is most likely a bug in the VM or in the compiler" << std::endl;
129130
}
131+
m_atEnd = true;
130132
return pos;
131133

132134
do_const:

src/engine/virtualmachine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class LIBSCRATCHCPP_EXPORT VirtualMachine
7777

7878
unsigned int *run(RunningScript *script);
7979

80+
/*! Returns true if the VM has reached the vm::OP_HALT instruction. */
81+
bool atEnd() const { return m_atEnd; };
82+
8083
private:
8184
unsigned int *run(unsigned int *pos, RunningScript *script);
8285

@@ -89,6 +92,7 @@ class LIBSCRATCHCPP_EXPORT VirtualMachine
8992
Engine *m_engine = nullptr;
9093
RunningScript *m_script = nullptr;
9194
unsigned int *m_globalPos = nullptr;
95+
bool m_atEnd = false;
9296

9397
BlockFunc *m_functions;
9498
std::vector<BlockFunc> m_functionsVector;

0 commit comments

Comments
 (0)