1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 00:15:06 +00:00
OpenMW/components/interpreter/runtime.hpp
elsid b88f0d2dbd
Replace mwscript program serialization into a vector with simple struct
Mostly to avoid string literal lookup by index with iteration over all preciding
literals and calling strlen. This is very inefficient. In genral this makes code
much more straightforward but also makes it portable since now int and float of
different sizes are properly supported.
2023-01-14 00:07:37 +01:00

62 lines
1.3 KiB
C++

#ifndef INTERPRETER_RUNTIME_H_INCLUDED
#define INTERPRETER_RUNTIME_H_INCLUDED
#include <string_view>
#include <vector>
#include "types.hpp"
namespace Interpreter
{
class Context;
struct Program;
/// Runtime data and engine interface
class Runtime
{
Context* mContext = nullptr;
const Program* mProgram = nullptr;
int mPC = 0;
std::vector<Data> mStack;
public:
int getPC() const { return mPC; }
///< return program counter.
int getIntegerLiteral(int index) const;
float getFloatLiteral(int index) const;
std::string_view getStringLiteral(int index) const;
void configure(const Program& program, Context& context);
///< \a context and \a code must exist as least until either configure, clear or
/// the destructor is called.
void clear();
void setPC(int value) { mPC = value; }
///< set program counter.
void push(const Data& data);
///< push data on stack
void push(Type_Integer value);
///< push integer data on stack.
void push(Type_Float value);
///< push float data on stack.
void pop();
///< pop stack
Data& operator[](int index);
///< Access stack member, counted from the top.
Context& getContext();
};
}
#endif