remove gap property from stack_state
parent
6e779f827f
commit
fdcc8a09e9
|
@ -38,13 +38,13 @@ struct LIBCUBESCRIPT_EXPORT stack_state {
|
||||||
struct node {
|
struct node {
|
||||||
node const *next; /**< @brief Next level. */
|
node const *next; /**< @brief Next level. */
|
||||||
struct ident const *id; /**< @brief The ident of this level. */
|
struct ident const *id; /**< @brief The ident of this level. */
|
||||||
int index; /**< @brief The level index. */
|
std::size_t index; /**< @brief The level index. */
|
||||||
};
|
};
|
||||||
|
|
||||||
stack_state() = delete;
|
stack_state() = delete;
|
||||||
|
|
||||||
/** @brief Construct the stack state. */
|
/** @brief Construct the stack state. */
|
||||||
stack_state(state &cs, node *nd = nullptr, bool gap = false);
|
stack_state(state &cs, node *nd = nullptr);
|
||||||
|
|
||||||
stack_state(stack_state const &) = delete;
|
stack_state(stack_state const &) = delete;
|
||||||
|
|
||||||
|
@ -68,18 +68,9 @@ struct LIBCUBESCRIPT_EXPORT stack_state {
|
||||||
/** @brief Get the pointer to the topmost (current) level. */
|
/** @brief Get the pointer to the topmost (current) level. */
|
||||||
node const *get() const;
|
node const *get() const;
|
||||||
|
|
||||||
/** @brief Get whether the stack is incomplete.
|
|
||||||
*
|
|
||||||
* A value of `true` means the call stack has a gap in it, i.e. the
|
|
||||||
* bottommost node has index 1 while the node just above it has index
|
|
||||||
* greater than 2.
|
|
||||||
*/
|
|
||||||
bool gap() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
state &p_state;
|
state &p_state;
|
||||||
node *p_node;
|
node *p_node;
|
||||||
bool p_gap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Represents a Cubescript error.
|
/** @brief Represents a Cubescript error.
|
||||||
|
|
|
@ -296,15 +296,17 @@ template<typename R>
|
||||||
inline R print_stack(R writer, stack_state const &st) {
|
inline R print_stack(R writer, stack_state const &st) {
|
||||||
char buf[32] = {0};
|
char buf[32] = {0};
|
||||||
auto nd = st.get();
|
auto nd = st.get();
|
||||||
|
std::size_t pindex = 1;
|
||||||
while (nd) {
|
while (nd) {
|
||||||
auto name = nd->id->name();
|
auto name = nd->id->name();
|
||||||
*writer++ = ' ';
|
*writer++ = ' ';
|
||||||
*writer++ = ' ';
|
*writer++ = ' ';
|
||||||
if ((nd->index == 1) && st.gap()) {
|
if ((nd->index == 1) && (pindex > 2)) {
|
||||||
*writer++ = '.';
|
*writer++ = '.';
|
||||||
*writer++ = '.';
|
*writer++ = '.';
|
||||||
}
|
}
|
||||||
snprintf(buf, sizeof(buf), "%d", nd->index);
|
pindex = nd->index;
|
||||||
|
snprintf(buf, sizeof(buf), "%zu", nd->index);
|
||||||
char const *p = buf;
|
char const *p = buf;
|
||||||
std::copy(p, p + strlen(p), writer);
|
std::copy(p, p + strlen(p), writer);
|
||||||
*writer++ = ')';
|
*writer++ = ')';
|
||||||
|
|
|
@ -9,16 +9,15 @@
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT stack_state::stack_state(
|
LIBCUBESCRIPT_EXPORT stack_state::stack_state(
|
||||||
state &cs, node *nd, bool gap
|
state &cs, node *nd
|
||||||
):
|
):
|
||||||
p_state{cs}, p_node{nd}, p_gap{gap}
|
p_state{cs}, p_node{nd}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT stack_state::stack_state(stack_state &&st):
|
LIBCUBESCRIPT_EXPORT stack_state::stack_state(stack_state &&st):
|
||||||
p_state{st.p_state}, p_node{st.p_node}, p_gap{st.p_gap}
|
p_state{st.p_state}, p_node{st.p_node}
|
||||||
{
|
{
|
||||||
st.p_node = nullptr;
|
st.p_node = nullptr;
|
||||||
st.p_gap = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT stack_state::~stack_state() {
|
LIBCUBESCRIPT_EXPORT stack_state::~stack_state() {
|
||||||
|
@ -31,9 +30,7 @@ LIBCUBESCRIPT_EXPORT stack_state::~stack_state() {
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT stack_state &stack_state::operator=(stack_state &&st) {
|
LIBCUBESCRIPT_EXPORT stack_state &stack_state::operator=(stack_state &&st) {
|
||||||
p_node = st.p_node;
|
p_node = st.p_node;
|
||||||
p_gap = st.p_gap;
|
|
||||||
st.p_node = nullptr;
|
st.p_node = nullptr;
|
||||||
st.p_gap = false;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +38,6 @@ LIBCUBESCRIPT_EXPORT stack_state::node const *stack_state::get() const {
|
||||||
return p_node;
|
return p_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT bool stack_state::gap() const {
|
|
||||||
return p_gap;
|
|
||||||
}
|
|
||||||
|
|
||||||
static stack_state save_stack(state &cs) {
|
static stack_state save_stack(state &cs) {
|
||||||
auto &ts = state_p{cs}.ts();
|
auto &ts = state_p{cs}.ts();
|
||||||
builtin_var *dalias = ts.istate->ivar_dbgalias;
|
builtin_var *dalias = ts.istate->ivar_dbgalias;
|
||||||
|
@ -52,14 +45,14 @@ static stack_state save_stack(state &cs) {
|
||||||
dalias->value().get_integer(), integer_type(0), integer_type(1000)
|
dalias->value().get_integer(), integer_type(0), integer_type(1000)
|
||||||
);
|
);
|
||||||
if (!dval) {
|
if (!dval) {
|
||||||
return stack_state{cs, nullptr, !!ts.callstack};
|
return stack_state{cs, nullptr};
|
||||||
}
|
}
|
||||||
int total = 0, depth = 0;
|
int total = 0, depth = 0;
|
||||||
for (ident_link *l = ts.callstack; l; l = l->next) {
|
for (ident_link *l = ts.callstack; l; l = l->next) {
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
if (!total) {
|
if (!total) {
|
||||||
return stack_state{cs, nullptr, false};
|
return stack_state{cs, nullptr};
|
||||||
}
|
}
|
||||||
stack_state::node *st = ts.istate->create_array<stack_state::node>(
|
stack_state::node *st = ts.istate->create_array<stack_state::node>(
|
||||||
std::min(total, dval)
|
std::min(total, dval)
|
||||||
|
@ -83,7 +76,7 @@ static stack_state save_stack(state &cs) {
|
||||||
nd->next = nullptr;
|
nd->next = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stack_state{cs, ret, total > dval};
|
return stack_state{cs, ret};
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT error::error(state &cs, std::string_view msg):
|
LIBCUBESCRIPT_EXPORT error::error(state &cs, std::string_view msg):
|
||||||
|
|
Loading…
Reference in New Issue