make alias pushing separate from setting value

master
Daniel Kolesa 2021-03-30 20:24:46 +02:00
parent d1243c5cc3
commit 970e37f318
4 changed files with 16 additions and 28 deletions

View File

@ -114,11 +114,10 @@ alias_impl::alias_impl(state &cs, string_ref name, any_value v, int fl):
p_val = v; p_val = v;
} }
void alias_impl::push_arg(any_value &v, ident_stack &st, bool um) { void alias_impl::push_arg(ident_stack &st, bool um) {
st.val_s = std::move(p_val); st.val_s = std::move(p_val);
st.next = p_astack; st.next = p_astack;
p_astack = &st; p_astack = &st;
p_val = std::move(v);
clean_code(); clean_code();
if (um) { if (um) {
p_flags &= ~IDENT_FLAG_UNKNOWN; p_flags &= ~IDENT_FLAG_UNKNOWN;
@ -154,12 +153,12 @@ void alias_impl::redo_arg(ident_stack &st) {
void alias_impl::set_arg(thread_state &ts, any_value &v) { void alias_impl::set_arg(thread_state &ts, any_value &v) {
if (ident_is_used_arg(this, ts)) { if (ident_is_used_arg(this, ts)) {
p_val = std::move(v);
clean_code(); clean_code();
} else { } else {
push_arg(v, ts.idstack.emplace_back(*ts.pstate), false); push_arg(ts.idstack.emplace_back(*ts.pstate), false);
ts.callstack->usedargs[get_index()] = true; ts.callstack->usedargs[get_index()] = true;
} }
p_val = std::move(v);
} }
void alias_impl::set_alias(thread_state &ts, any_value &v) { void alias_impl::set_alias(thread_state &ts, any_value &v) {
@ -445,14 +444,12 @@ LIBCUBESCRIPT_EXPORT bool alias_stack::push(any_value val) {
return false; return false;
} }
auto &ts = *p_state.thread_pointer(); auto &ts = *p_state.thread_pointer();
auto &ap = *static_cast<alias_impl *>(p_alias);
if (!p_pushed) { if (!p_pushed) {
static_cast<alias_impl *>(p_alias)->push_arg( ap.push_arg(ts.idstack.emplace_back(p_state));
val, ts.idstack.emplace_back(p_state)
);
p_pushed = true; p_pushed = true;
} else {
static_cast<alias_impl *>(p_alias)->p_val = std::move(val);
} }
ap.p_val = std::move(val);
return true; return true;
} }

View File

@ -95,7 +95,7 @@ struct alias_impl: ident_impl, alias {
alias_impl(state &cs, string_ref n, int flags); alias_impl(state &cs, string_ref n, int flags);
alias_impl(state &cs, string_ref n, any_value v, int flags); alias_impl(state &cs, string_ref n, any_value v, int flags);
void push_arg(any_value &v, ident_stack &st, bool um = true); void push_arg(ident_stack &st, bool um = true);
void pop_arg(); void pop_arg();
void undo_arg(ident_stack &st); void undo_arg(ident_stack &st);
void redo_arg(ident_stack &st); void redo_arg(ident_stack &st);

View File

@ -452,16 +452,12 @@ bool stacked_value::push() {
return false; return false;
} }
auto &ts = *p_state.thread_pointer(); auto &ts = *p_state.thread_pointer();
auto &ap = *static_cast<alias_impl *>(p_a);
if (!p_pushed) { if (!p_pushed) {
static_cast<alias_impl *>(p_a)->push_arg( ap.push_arg(ts.idstack.emplace_back(p_state));
*this, ts.idstack.emplace_back(p_state)
);
p_pushed = true; p_pushed = true;
} else {
static_cast<alias_impl *>(p_a)->p_val = std::move(
*static_cast<any_value *>(this)
);
} }
ap.p_val = std::move(*static_cast<any_value *>(this));
return true; return true;
} }

View File

@ -10,8 +10,7 @@ namespace cubescript {
static inline void push_alias(state &cs, ident *id, ident_stack &st) { static inline void push_alias(state &cs, ident *id, ident_stack &st) {
if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) { if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) {
any_value nv{cs}; static_cast<alias_impl *>(id)->push_arg(st);
static_cast<alias_impl *>(id)->push_arg(nv, st);
} }
} }
@ -210,9 +209,9 @@ void exec_alias(
argset uargs{}; argset uargs{};
std::size_t noff = ts.idstack.size(); std::size_t noff = ts.idstack.size();
for(std::size_t i = 0; i < callargs; i++) { for(std::size_t i = 0; i < callargs; i++) {
static_cast<alias_impl *>(ts.istate->identmap[i])->push_arg( auto &ap = *static_cast<alias_impl *>(ts.istate->identmap[i]);
args[offset + i], ts.idstack.emplace_back(*ts.pstate), false ap.push_arg(ts.idstack.emplace_back(*ts.pstate), false);
); ap.p_val = std::move(args[offset + i]);
uargs[i] = true; uargs[i] = true;
} }
auto oldargs = anargs->get_value(); auto oldargs = anargs->get_value();
@ -728,10 +727,8 @@ std::uint32_t *vm_exec(
(a->get_flags() & IDENT_FLAG_ARG) && (a->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(a, ts) !ident_is_used_arg(a, ts)
) { ) {
any_value nv{cs};
static_cast<alias_impl *>(a)->push_arg( static_cast<alias_impl *>(a)->push_arg(
nv, ts.idstack.emplace_back(*ts.pstate), ts.idstack.emplace_back(*ts.pstate), false
false
); );
ts.callstack->usedargs[a->get_index()] = true; ts.callstack->usedargs[a->get_index()] = true;
} }
@ -748,10 +745,8 @@ std::uint32_t *vm_exec(
(id->get_flags() & IDENT_FLAG_ARG) && (id->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(id, ts) !ident_is_used_arg(id, ts)
) { ) {
any_value nv{cs};
static_cast<alias_impl *>(id)->push_arg( static_cast<alias_impl *>(id)->push_arg(
nv, ts.idstack.emplace_back(*ts.pstate), ts.idstack.emplace_back(*ts.pstate), false
false
); );
ts.callstack->usedargs[id->get_index()] = true; ts.callstack->usedargs[id->get_index()] = true;
} }