diff --git a/include/cubescript/cubescript/error.hh b/include/cubescript/cubescript/error.hh index 30fc1ef..f0fa8f4 100644 --- a/include/cubescript/cubescript/error.hh +++ b/include/cubescript/cubescript/error.hh @@ -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. */ }; diff --git a/src/cs_error.cc b/src/cs_error.cc index ec0be5e..ec1f30a 100644 --- a/src/cs_error.cc +++ b/src/cs_error.cc @@ -22,28 +22,25 @@ static typename error::stack_node *save_stack(state &cs) { if (!total) { return nullptr; } - auto *st = ts.istate->create_array( - std::min(total, dval) - ); + auto *st = static_cast(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; } } diff --git a/src/cs_state.hh b/src/cs_state.hh index e721239..108975b 100644 --- a/src/cs_state.hh +++ b/src/cs_state.hh @@ -78,15 +78,15 @@ struct internal_state { template T *create(A &&...args) { T *ret = static_cast(alloc(nullptr, 0, sizeof(T))); - new (ret) T(std::forward(args)...); + new (ret) T{std::forward(args)...}; return ret; } - template - T *create_array(size_t len) { + template + T *create_array(size_t len, A &&...args) { T *ret = static_cast(alloc(nullptr, 0, len * sizeof(T))); for (size_t i = 0; i < len; ++i) { - new (&ret[i]) T(); + new (&ret[i]) T{std::forward(args)...}; } return ret; } diff --git a/src/lib_base.cc b/src/lib_base.cc index 19f92b0..5759853 100644 --- a/src/lib_base.cc +++ b/src/lib_base.cc @@ -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; diff --git a/tools/repl.cc b/tools/repl.cc index c89ff7e..557c677 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -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; }