forked from mirror/openmw-tes3mp
deal with script execution from within a script (Fixes #2964)
This commit is contained in:
parent
a134b87e5b
commit
8eb6d337d5
2 changed files with 55 additions and 11 deletions
|
@ -132,7 +132,34 @@ namespace Interpreter
|
||||||
throw std::runtime_error (error.str());
|
throw std::runtime_error (error.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter::Interpreter()
|
void Interpreter::begin()
|
||||||
|
{
|
||||||
|
if (mRunning)
|
||||||
|
{
|
||||||
|
mCallstack.push (mRuntime);
|
||||||
|
mRuntime.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Interpreter::end()
|
||||||
|
{
|
||||||
|
if (mCallstack.empty())
|
||||||
|
{
|
||||||
|
mRuntime.clear();
|
||||||
|
mRunning = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mRuntime = mCallstack.top();
|
||||||
|
mCallstack.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Interpreter::Interpreter() : mRunning (false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Interpreter::~Interpreter()
|
Interpreter::~Interpreter()
|
||||||
|
@ -202,19 +229,29 @@ namespace Interpreter
|
||||||
{
|
{
|
||||||
assert (codeSize>=4);
|
assert (codeSize>=4);
|
||||||
|
|
||||||
mRuntime.configure (code, codeSize, context);
|
begin();
|
||||||
|
|
||||||
int opcodes = static_cast<int> (code[0]);
|
try
|
||||||
|
|
||||||
const Type_Code *codeBlock = code + 4;
|
|
||||||
|
|
||||||
while (mRuntime.getPC()>=0 && mRuntime.getPC()<opcodes)
|
|
||||||
{
|
{
|
||||||
Type_Code code = codeBlock[mRuntime.getPC()];
|
mRuntime.configure (code, codeSize, context);
|
||||||
mRuntime.setPC (mRuntime.getPC()+1);
|
|
||||||
execute (code);
|
int opcodes = static_cast<int> (code[0]);
|
||||||
|
|
||||||
|
const Type_Code *codeBlock = code + 4;
|
||||||
|
|
||||||
|
while (mRuntime.getPC()>=0 && mRuntime.getPC()<opcodes)
|
||||||
|
{
|
||||||
|
Type_Code code = codeBlock[mRuntime.getPC()];
|
||||||
|
mRuntime.setPC (mRuntime.getPC()+1);
|
||||||
|
execute (code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
end();
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
mRuntime.clear();
|
end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define INTERPRETER_INTERPRETER_H_INCLUDED
|
#define INTERPRETER_INTERPRETER_H_INCLUDED
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include "runtime.hpp"
|
#include "runtime.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
@ -14,6 +15,8 @@ namespace Interpreter
|
||||||
|
|
||||||
class Interpreter
|
class Interpreter
|
||||||
{
|
{
|
||||||
|
std::stack<Runtime> mCallstack;
|
||||||
|
bool mRunning;
|
||||||
Runtime mRuntime;
|
Runtime mRuntime;
|
||||||
std::map<int, Opcode1 *> mSegment0;
|
std::map<int, Opcode1 *> mSegment0;
|
||||||
std::map<int, Opcode2 *> mSegment1;
|
std::map<int, Opcode2 *> mSegment1;
|
||||||
|
@ -32,6 +35,10 @@ namespace Interpreter
|
||||||
|
|
||||||
void abortUnknownSegment (Type_Code code);
|
void abortUnknownSegment (Type_Code code);
|
||||||
|
|
||||||
|
void begin();
|
||||||
|
|
||||||
|
void end();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Interpreter();
|
Interpreter();
|
||||||
|
|
Loading…
Reference in a new issue