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