2010-06-28 17:20:45 +00:00
|
|
|
#ifndef INTERPRETER_RUNTIME_H_INCLUDED
|
|
|
|
#define INTERPRETER_RUNTIME_H_INCLUDED
|
|
|
|
|
2022-05-21 08:48:32 +00:00
|
|
|
#include <string_view>
|
2010-06-28 19:49:48 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
#include "types.hpp"
|
|
|
|
|
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
class Context;
|
2023-01-10 03:10:18 +00:00
|
|
|
struct Program;
|
2010-06-28 17:20:45 +00:00
|
|
|
|
|
|
|
/// Runtime data and engine interface
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
class Runtime
|
|
|
|
{
|
2023-01-10 03:13:17 +00:00
|
|
|
Context* mContext = nullptr;
|
2023-01-10 03:10:18 +00:00
|
|
|
const Program* mProgram = nullptr;
|
2023-01-10 03:13:17 +00:00
|
|
|
int mPC = 0;
|
2010-07-14 13:28:55 +00:00
|
|
|
std::vector<Data> mStack;
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
public:
|
2023-01-10 03:14:13 +00:00
|
|
|
int getPC() const { return mPC; }
|
2010-06-28 18:46:15 +00:00
|
|
|
///< return program counter.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 19:49:48 +00:00
|
|
|
int getIntegerLiteral(int index) const;
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 19:49:48 +00:00
|
|
|
float getFloatLiteral(int index) const;
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2022-05-20 23:21:55 +00:00
|
|
|
std::string_view getStringLiteral(int index) const;
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2023-01-10 03:10:18 +00:00
|
|
|
void configure(const Program& program, Context& context);
|
2010-06-28 17:20:45 +00:00
|
|
|
///< \a context and \a code must exist as least until either configure, clear or
|
2023-01-10 03:10:18 +00:00
|
|
|
/// the destructor is called.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
void clear();
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2023-01-10 03:14:13 +00:00
|
|
|
void setPC(int value) { mPC = value; }
|
2010-06-28 18:46:15 +00:00
|
|
|
///< set program counter.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-07-14 13:28:55 +00:00
|
|
|
void push(const Data& data);
|
2010-06-28 19:49:48 +00:00
|
|
|
///< push data on stack
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-07-14 13:28:55 +00:00
|
|
|
void push(Type_Integer value);
|
|
|
|
///< push integer data on stack.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-07-14 13:28:55 +00:00
|
|
|
void push(Type_Float value);
|
|
|
|
///< push float data on stack.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 19:49:48 +00:00
|
|
|
void pop();
|
|
|
|
///< pop stack
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2023-01-10 03:42:46 +00:00
|
|
|
Data& operator[](int index);
|
2010-06-28 19:49:48 +00:00
|
|
|
///< Access stack member, counted from the top.
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 19:49:48 +00:00
|
|
|
Context& getContext();
|
2010-06-28 17:20:45 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|