use a reference for the ident in stack node
parent
b5127c52bf
commit
3189d87ac9
|
@ -43,7 +43,7 @@ struct LIBCUBESCRIPT_EXPORT error {
|
||||||
*/
|
*/
|
||||||
struct stack_node {
|
struct stack_node {
|
||||||
stack_node const *next; /**< @brief Next level. */
|
stack_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. */
|
||||||
std::size_t index; /**< @brief The level index. */
|
std::size_t index; /**< @brief The level index. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,28 +22,25 @@ static typename error::stack_node *save_stack(state &cs) {
|
||||||
if (!total) {
|
if (!total) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto *st = ts.istate->create_array<typename error::stack_node>(
|
auto *st = static_cast<typename error::stack_node *>(ts.istate->alloc(
|
||||||
std::min(total, dval)
|
nullptr, 0, sizeof(typename error::stack_node) * std::min(total, dval)
|
||||||
);
|
));
|
||||||
typename error::stack_node *ret = st, *nd = st;
|
typename error::stack_node *ret = st, *nd = st;
|
||||||
++st;
|
++st;
|
||||||
for (std::size_t i = total - 1;; --i) {
|
for (std::size_t i = total - 1;; --i) {
|
||||||
auto &lev = ts.callstack[i];
|
auto &lev = ts.callstack[i];
|
||||||
++depth;
|
++depth;
|
||||||
if (depth < dval) {
|
if (depth < dval) {
|
||||||
nd->id = &lev.id;
|
new (nd) typename error::stack_node{
|
||||||
nd->index = total - depth + 1;
|
nullptr, lev.id, total - depth + 1
|
||||||
|
};
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
nd->next = nullptr;
|
|
||||||
nd = st++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nd->next = st;
|
nd->next = st;
|
||||||
nd = st++;
|
nd = st++;
|
||||||
} else if (i == 0) {
|
} else if (i == 0) {
|
||||||
nd->id = &lev.id;
|
new (nd) typename error::stack_node{nullptr, lev.id, 1};
|
||||||
nd->index = 1;
|
|
||||||
nd->next = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,15 +78,15 @@ struct internal_state {
|
||||||
template<typename T, typename ...A>
|
template<typename T, typename ...A>
|
||||||
T *create(A &&...args) {
|
T *create(A &&...args) {
|
||||||
T *ret = static_cast<T *>(alloc(nullptr, 0, sizeof(T)));
|
T *ret = static_cast<T *>(alloc(nullptr, 0, sizeof(T)));
|
||||||
new (ret) T(std::forward<A>(args)...);
|
new (ret) T{std::forward<A>(args)...};
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, typename ...A>
|
||||||
T *create_array(size_t len) {
|
T *create_array(size_t len, A &&...args) {
|
||||||
T *ret = static_cast<T *>(alloc(nullptr, 0, len * sizeof(T)));
|
T *ret = static_cast<T *>(alloc(nullptr, 0, len * sizeof(T)));
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
new (&ret[i]) T();
|
new (&ret[i]) T{std::forward<A>(args)...};
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
|
||||||
while (snd) {
|
while (snd) {
|
||||||
idv.set_integer(integer_type(snd->index));
|
idv.set_integer(integer_type(snd->index));
|
||||||
ist.set(idv);
|
ist.set(idv);
|
||||||
idv.set_string(snd->id->name().data(), cs);
|
idv.set_string(snd->id.name().data(), cs);
|
||||||
vst.set(idv);
|
vst.set(idv);
|
||||||
bc.call(cs);
|
bc.call(cs);
|
||||||
snd = snd->next;
|
snd = snd->next;
|
||||||
|
|
|
@ -260,7 +260,7 @@ static bool do_call(cs::state &cs, std::string_view line, bool file = false) {
|
||||||
std::printf("..");
|
std::printf("..");
|
||||||
}
|
}
|
||||||
pindex = nd->index;
|
pindex = nd->index;
|
||||||
std::printf("%zu) %s\n", nd->index, nd->id->name().data());
|
std::printf("%zu) %s\n", nd->index, nd->id.name().data());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue