diff --git a/include/cubescript/cubescript/util.hh b/include/cubescript/cubescript/util.hh index ec2c042..a66b343 100644 --- a/include/cubescript/cubescript/util.hh +++ b/include/cubescript/cubescript/util.hh @@ -86,17 +86,11 @@ struct LIBCUBESCRIPT_EXPORT alias_local { /** @brief Local handlers are not move assignable */ alias_local &operator=(alias_local &&v) = delete; - /** @brief Get the contained alias - * - * @return the alias or `nullptr` if none set - */ - alias *get_alias() noexcept { return p_alias; } + /** @brief Get the contained alias */ + alias &get_alias() noexcept { return *p_alias; } - /** @brief Get the contained alias - * - * @return the alias or `nullptr` if none set - */ - alias const *get_alias() const noexcept { return p_alias; } + /** @brief Get the contained alias */ + alias const &get_alias() const noexcept { return *p_alias; } /** @brief Set the contained alias's value * diff --git a/include/cubescript/cubescript/value.hh b/include/cubescript/cubescript/value.hh index f393278..316e78b 100644 --- a/include/cubescript/cubescript/value.hh +++ b/include/cubescript/cubescript/value.hh @@ -339,7 +339,7 @@ struct LIBCUBESCRIPT_EXPORT any_value { * performed, so after main thread destruction this may become * dangling (and unsafe to use). */ - void set_ident(ident *val); + void set_ident(ident &val); /** @brief Get the value as a string reference. * diff --git a/src/cs_ident.cc b/src/cs_ident.cc index bb9493b..d4de5c4 100644 --- a/src/cs_ident.cc +++ b/src/cs_ident.cc @@ -88,7 +88,7 @@ void var_changed(thread_state &ts, ident *id) { } auto *cimp = static_cast(cid); any_value val{}; - val.set_ident(id); + val.set_ident(*id); cimp->call(ts, span_type{&val, 1}, val); } diff --git a/src/cs_val.cc b/src/cs_val.cc index 7433cce..b94081b 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -165,10 +165,10 @@ void any_value::set_code(bcode_ref const &val) { csv_get(&p_stor) = p; } -void any_value::set_ident(ident *val) { +void any_value::set_ident(ident &val) { csv_cleanup(p_type, &p_stor); p_type = value_type::IDENT; - csv_get(&p_stor) = val; + csv_get(&p_stor) = &val; } void any_value::force_none() { @@ -270,7 +270,7 @@ ident &any_value::force_ident(state &cs) { auto &id = state_p{cs}.ts().istate->new_ident( cs, get_string(cs), IDENT_FLAG_UNKNOWN ); - set_ident(&id); + set_ident(id); return id; } diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 9eb68d5..f383196 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -154,7 +154,7 @@ void exec_command( if (rep) { break; } - args[i].set_ident(ts.istate->id_dummy); + args[i].set_ident(*ts.istate->id_dummy); fakeargs++; } else { args[i].force_ident(*ts.pstate); @@ -162,7 +162,7 @@ void exec_command( break; case '$': i += 1; - args[i].set_ident(self); + args[i].set_ident(*self); break; case 'N': i += 1; @@ -734,7 +734,7 @@ std::uint32_t *vm_exec( ts.get_astack(a).push(ts.idstack.emplace_back()); ts.callstack->usedargs[a->get_index()] = true; } - args.emplace_back().set_ident(a); + args.emplace_back().set_ident(*a); continue; } case BC_INST_IDENT_U: { @@ -750,7 +750,7 @@ std::uint32_t *vm_exec( ts.get_astack(a).push(ts.idstack.emplace_back()); ts.callstack->usedargs[id->get_index()] = true; } - arg.set_ident(id); + arg.set_ident(*id); continue; } diff --git a/src/lib_base.cc b/src/lib_base.cc index 9668b6e..b308952 100644 --- a/src/lib_base.cc +++ b/src/lib_base.cc @@ -157,7 +157,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) { new_cmd_quiet(gcs, "pushif", "rte", [](auto &cs, auto args, auto &res) { alias_local st{cs, args[0]}; - if (st.get_alias()->is_arg()) { + if (st.get_alias().is_arg()) { throw error{cs, "cannot push an argument"}; } if (args[1].get_bool()) { @@ -317,7 +317,7 @@ end: new_cmd_quiet(gcs, "push", "rte", [](auto &cs, auto args, auto &res) { alias_local st{cs, args[0]}; - if (st.get_alias()->is_arg()) { + if (st.get_alias().is_arg()) { throw error{cs, "cannot push an argument"}; } st.set(args[1]);