forked from KPGPMC/furlang
@@ -62,6 +62,8 @@ private:
|
|||||||
explicit rzecz() = default;
|
explicit rzecz() = default;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
|
using nref_t = std::size_t; /**< Type of reference count. */
|
||||||
|
|
||||||
static constexpr thing_handle GENERATION_SIZE = 12; /**< Bit size of generation part in thing_handle. */
|
static constexpr thing_handle GENERATION_SIZE = 12; /**< Bit size of generation part in thing_handle. */
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -110,12 +112,30 @@ public:
|
|||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
const std::int32_t& int32() const;
|
const std::int32_t& int32() const;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Increments reference count of this thing by one.
|
||||||
|
*/
|
||||||
|
void add_reference() { ++m_refCount; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decrements reference count of this thing by one.
|
||||||
|
*/
|
||||||
|
void remove_reference() { --m_refCount; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns reference count of this thing.
|
||||||
|
*
|
||||||
|
* @return The reference count.
|
||||||
|
*/
|
||||||
|
constexpr nref_t reference_count() const { return m_refCount; }
|
||||||
private:
|
private:
|
||||||
thing_handle m_id;
|
thing_handle m_id;
|
||||||
thing_t m_type;
|
thing_t m_type;
|
||||||
context_p m_context;
|
context_p m_context;
|
||||||
|
|
||||||
void* m_data = nullptr;
|
nref_t m_refCount = 0;
|
||||||
|
void* m_data = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace furvm
|
} // namespace furvm
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ struct executor::frame executor::frame() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void executor::push_thing(const thing_p& thing) {
|
void executor::push_thing(const thing_p& thing) {
|
||||||
|
thing->add_reference();
|
||||||
m_stack.push(thing);
|
m_stack.push(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ thing_p executor::pop_thing() {
|
|||||||
if (m_frames.top().stackBase >= m_stack.size()) throw stack_underflow();
|
if (m_frames.top().stackBase >= m_stack.size()) throw stack_underflow();
|
||||||
thing_p top = std::move(m_stack.top());
|
thing_p top = std::move(m_stack.top());
|
||||||
m_stack.pop();
|
m_stack.pop();
|
||||||
|
top->remove_reference();
|
||||||
return top;
|
return top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user