feat(furvm): add step function to executor
This commit is contained in:
@@ -9,6 +9,7 @@ namespace furvm {
|
||||
|
||||
enum class executor_flags : std::uint32_t {
|
||||
Suspended = (1 << 0), /**< Execution suspended. */
|
||||
Done = (1 << 1), /**< Execution is finished. */
|
||||
};
|
||||
|
||||
static inline executor_flags operator|(executor_flags lhs, executor_flags rhs) {
|
||||
@@ -132,6 +133,11 @@ public:
|
||||
* @return The thing.
|
||||
*/
|
||||
thing_p thing() const;
|
||||
public:
|
||||
/**
|
||||
* @brief Executes next instruction.
|
||||
*/
|
||||
void step();
|
||||
private:
|
||||
executor_handle m_id;
|
||||
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
||||
|
||||
@@ -75,6 +75,12 @@ using module_handle = std::uint32_t;
|
||||
*/
|
||||
enum class thing_t : std::uint8_t;
|
||||
|
||||
/**
|
||||
* @class bad_thing_access
|
||||
* @brief Bad thing access exception.
|
||||
*/
|
||||
class bad_thing_access;
|
||||
|
||||
/**
|
||||
* @class thing
|
||||
* @brief Furvm thing.
|
||||
|
||||
@@ -42,6 +42,14 @@ public:
|
||||
* @return The id.
|
||||
*/
|
||||
constexpr module_handle id() const { return m_id; }
|
||||
|
||||
/**
|
||||
* @brief Returns a byte from bytecode of this module.
|
||||
*
|
||||
* @param offset An offset of the byte.
|
||||
* @return The byte.
|
||||
*/
|
||||
constexpr byte byte(std::size_t offset) const { return m_bytecode.at(offset); }
|
||||
private:
|
||||
module_handle m_id;
|
||||
bytecode_t m_bytecode;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace furvm {
|
||||
|
||||
enum class thing_t : std::uint8_t {
|
||||
Int,
|
||||
Int32,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -17,6 +17,39 @@ enum class thing_t : std::uint8_t {
|
||||
*/
|
||||
std::size_t thing_type_size(thing_t type);
|
||||
|
||||
class bad_thing_access : public std::exception {
|
||||
public:
|
||||
bad_thing_access() = default;
|
||||
~bad_thing_access() override = default;
|
||||
|
||||
/**
|
||||
* @brief Move constructor.
|
||||
*/
|
||||
bad_thing_access(bad_thing_access&&) noexcept = default;
|
||||
|
||||
/**
|
||||
* @brief Move constructor.
|
||||
*/
|
||||
bad_thing_access& operator=(bad_thing_access&&) noexcept = default;
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
*/
|
||||
bad_thing_access(const bad_thing_access&) = default;
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
*/
|
||||
bad_thing_access& operator=(const bad_thing_access&) = default;
|
||||
public:
|
||||
/**
|
||||
* @brief Returns a C-style string describing the cause of the error.
|
||||
*
|
||||
* @return The cause of the error.
|
||||
*/
|
||||
const char* what() const noexcept override { return "bad thing access"; }
|
||||
};
|
||||
|
||||
class thing {
|
||||
friend class executor;
|
||||
private:
|
||||
@@ -61,6 +94,20 @@ public:
|
||||
* @return Shared pointer to the new thing.
|
||||
*/
|
||||
static thing_p create(const context_p& context, thing_t type);
|
||||
public:
|
||||
/**
|
||||
* @brief Returns an int32 value from this thing.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
std::int32_t& int32();
|
||||
|
||||
/**
|
||||
* @brief Returns an int32 value from this thing.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
const std::int32_t& int32() const;
|
||||
private:
|
||||
thing_handle m_id;
|
||||
thing_t m_type;
|
||||
|
||||
Reference in New Issue
Block a user