diff --git a/include/cubescript/cubescript/ident.hh b/include/cubescript/cubescript/ident.hh index 370ee93..7c1a95a 100644 --- a/include/cubescript/cubescript/ident.hh +++ b/include/cubescript/cubescript/ident.hh @@ -19,7 +19,6 @@ struct alias; struct command; struct LIBCUBESCRIPT_EXPORT ident { - int get_raw_type() const; ident_type get_type() const; std::string_view get_name() const; int get_index() const; @@ -54,9 +53,9 @@ struct LIBCUBESCRIPT_EXPORT ident { bool is_persistent(state &cs) const; protected: - ident() = default; + friend struct ident_p; - friend struct internal_state; + ident() = default; struct ident_impl *p_impl{}; }; diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 278f0cc..ac3990b 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -1108,7 +1108,7 @@ static void compile_and_or( } if (!more) { gs.code.push_back( - ((id->get_raw_type() == ID_AND) + ((ident_p{*id}.impl().p_type == ID_AND) ? BC_INST_TRUE : BC_INST_FALSE) | ret_code(rettype) ); } else { @@ -1140,7 +1140,7 @@ static void compile_and_or( ); gs.code.push_back(numargs); } else { - std::uint32_t op = (id->get_raw_type() == ID_AND) + std::uint32_t op = (ident_p{*id}.impl().p_type == ID_AND) ? (BC_INST_JUMP_RESULT | BC_INST_FLAG_FALSE) : (BC_INST_JUMP_RESULT | BC_INST_FLAG_TRUE); gs.code.push_back(op); @@ -1271,7 +1271,7 @@ noid: } gs.code.push_back(BC_INST_RESULT); } else { - switch (id->get_raw_type()) { + switch (ident_p{*id}.impl().p_type) { case ID_ALIAS: compile_alias( gs, static_cast(id), more diff --git a/src/cs_ident.cc b/src/cs_ident.cc index cfc6545..343bf88 100644 --- a/src/cs_ident.cc +++ b/src/cs_ident.cc @@ -156,10 +156,6 @@ void alias_stack::set_alias(alias *a, thread_state &ts, any_value &v) { /* public interface */ -LIBCUBESCRIPT_EXPORT int ident::get_raw_type() const { - return p_impl->p_type; -} - LIBCUBESCRIPT_EXPORT ident_type ident::get_type() const { if (p_impl->p_type > ID_ALIAS) { return ident_type::SPECIAL; diff --git a/src/cs_ident.hh b/src/cs_ident.hh index 853d7f3..32d72e9 100644 --- a/src/cs_ident.hh +++ b/src/cs_ident.hh @@ -135,6 +135,15 @@ struct command_impl: ident_impl, command { bool ident_is_used_arg(ident *id, thread_state &ts); +struct ident_p { + ident_p(ident &id): ip{&id} {} + + ident_impl &impl() { return *ip->p_impl; } + void impl(ident_impl *impl) { ip->p_impl = impl; } + + ident *ip; +}; + } /* namespace cubescript */ #endif diff --git a/src/cs_state.cc b/src/cs_state.cc index 45cc9ff..b7cd1b4 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -22,7 +22,7 @@ internal_state::internal_state(alloc_func af, void *data): internal_state::~internal_state() { for (auto &p: idents) { - destroy(p.second->p_impl); + destroy(&ident_p{*p.second}.impl()); } bcode_free_empty(this, empty); destroy(strman); @@ -48,7 +48,7 @@ ident *internal_state::add_ident(ident *id, ident_impl *impl) { if (!id) { return nullptr; } - id->p_impl = impl; + ident_p{*id}.impl(impl); idents[id->get_name()] = id; impl->p_index = int(identmap.size()); identmap.push_back(id); diff --git a/src/cs_vm.cc b/src/cs_vm.cc index f266845..b400f5f 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -1116,7 +1116,7 @@ noid: }; } result.force_none(); - switch (id->get_raw_type()) { + switch (ident_p{*id}.impl().p_type) { default: if (!ident_is_callable(id)) { args.resize(offset - 1, any_value{cs});