don't create a new virtual machine for each script and frame

actorid
Marc Zinnschlag 14 years ago
parent a133920eb0
commit 80691250ec

@ -223,11 +223,11 @@ namespace MWGui
try
{
ConsoleInterpreterContext interpreterContext (*this, mEnvironment, MWWorld::Ptr());
Interpreter::Interpreter interpreter (interpreterContext);
Interpreter::Interpreter interpreter;
MWScript::installOpcodes (interpreter);
std::vector<Interpreter::Type_Code> code;
output.getCode (code);
interpreter.run (&code[0], code.size());
interpreter.run (&code[0], code.size(), interpreterContext);
}
catch (const std::exception& error)
{

@ -12,8 +12,6 @@
#include <components/compiler/scanner.hpp>
#include <components/compiler/context.hpp>
#include <components/interpreter/interpreter.hpp>
#include "extensions.hpp"
namespace MWScript
@ -21,7 +19,8 @@ namespace MWScript
ScriptManager::ScriptManager (const ESMS::ESMStore& store, bool verbose,
Compiler::Context& compilerContext)
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext)
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
mOpcodesInstalled (false)
{}
bool ScriptManager::compile (const std::string& name)
@ -99,9 +98,13 @@ namespace MWScript
if (!iter->second.empty())
try
{
Interpreter::Interpreter interpreter (interpreterContext);
installOpcodes (interpreter);
interpreter.run (&iter->second[0], iter->second.size());
if (!mOpcodesInstalled)
{
installOpcodes (mInterpreter);
mOpcodesInstalled = true;
}
mInterpreter.run (&iter->second[0], iter->second.size(), interpreterContext);
}
catch (const std::exception& e)
{

@ -8,6 +8,7 @@
#include <components/compiler/streamerrorhandler.hpp>
#include <components/compiler/fileparser.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/types.hpp>
namespace ESMS
@ -35,6 +36,8 @@ namespace MWScript
bool mVerbose;
Compiler::Context& mCompilerContext;
Compiler::FileParser mParser;
Interpreter::Interpreter mInterpreter;
bool mOpcodesInstalled;
std::map<std::string, std::vector<Interpreter::Type_Code> > mScripts;

@ -134,8 +134,7 @@ namespace Interpreter
throw std::runtime_error (error.str());
}
Interpreter::Interpreter (Context& context)
: mRuntime (context)
Interpreter::Interpreter()
{}
Interpreter::~Interpreter()
@ -195,11 +194,11 @@ namespace Interpreter
mSegment5.insert (std::make_pair (code, opcode));
}
void Interpreter::run (const Type_Code *code, int codeSize)
void Interpreter::run (const Type_Code *code, int codeSize, Context& context)
{
assert (codeSize>=4);
mRuntime.configure (code, codeSize);
mRuntime.configure (code, codeSize, context);
int opcodes = static_cast<int> (code[0]);

@ -34,7 +34,7 @@ namespace Interpreter
public:
Interpreter (Context& context);
Interpreter();
~Interpreter();
@ -56,9 +56,8 @@ namespace Interpreter
void installSegment5 (int code, Opcode0 *opcode);
///< ownership of \a opcode is transferred to *this.
void run (const Type_Code *code, int codeSize);
void run (const Type_Code *code, int codeSize, Context& context);
};
}
#endif

@ -7,7 +7,7 @@
namespace Interpreter
{
Runtime::Runtime (Context& context) : mContext (context), mCode (0), mPC (0) {}
Runtime::Runtime() : mContext (0), mCode (0), mPC (0) {}
int Runtime::getPC() const
{
@ -47,10 +47,11 @@ namespace Interpreter
return literalBlock;
}
void Runtime::configure (const Interpreter::Type_Code *code, int codeSize)
void Runtime::configure (const Interpreter::Type_Code *code, int codeSize, Context& context)
{
clear();
mContext = &context;
mCode = code;
mCodeSize = codeSize;
mPC = 0;
@ -58,6 +59,7 @@ namespace Interpreter
void Runtime::clear()
{
mContext = 0;
mCode = 0;
mCodeSize = 0;
mStack.clear();
@ -105,7 +107,7 @@ namespace Interpreter
Context& Runtime::getContext()
{
return mContext;
assert (mContext);
return *mContext;
}
}

@ -14,7 +14,7 @@ namespace Interpreter
class Runtime
{
Context& mContext;
Context *mContext;
const Type_Code *mCode;
int mCodeSize;
int mPC;
@ -22,7 +22,7 @@ namespace Interpreter
public:
Runtime (Context& context);
Runtime ();
int getPC() const;
///< return program counter.
@ -33,7 +33,7 @@ namespace Interpreter
std::string getStringLiteral (int index) const;
void configure (const Type_Code *code, int codeSize);
void configure (const Type_Code *code, int codeSize, Context& context);
///< \a context and \a code must exist as least until either configure, clear or
/// the destructor is called. \a codeSize is given in 32-bit words.

Loading…
Cancel
Save