remove reliance on hardcoded indexes entirely
parent
e65e141741
commit
c177013ea2
|
@ -84,9 +84,7 @@ LIBCUBESCRIPT_EXPORT char *error::request_buf(
|
|||
}
|
||||
|
||||
LIBCUBESCRIPT_EXPORT stack_state error::save_stack(thread_state &ts) {
|
||||
integer_var *dalias = static_cast<integer_var *>(
|
||||
ts.istate->identmap[ID_IDX_DBGALIAS]
|
||||
);
|
||||
integer_var *dalias = ts.istate->ivar_dbgalias;
|
||||
auto dval = std::clamp(
|
||||
dalias->get_value(), integer_type(0), integer_type(1000)
|
||||
);
|
||||
|
|
|
@ -15,10 +15,6 @@
|
|||
|
||||
namespace cubescript {
|
||||
|
||||
static constexpr int ID_IDX_DUMMY = MAX_ARGUMENTS;
|
||||
static constexpr int ID_IDX_NUMARGS = MAX_ARGUMENTS + 1;
|
||||
static constexpr int ID_IDX_DBGALIAS = MAX_ARGUMENTS + 2;
|
||||
|
||||
struct codegen_state {
|
||||
thread_state &ts;
|
||||
codegen_state *prevps;
|
||||
|
@ -112,7 +108,7 @@ struct codegen_state {
|
|||
}
|
||||
|
||||
void gen_ident() {
|
||||
gen_ident(ts.istate->identmap[ID_IDX_DUMMY]);
|
||||
gen_ident(ts.istate->id_dummy);
|
||||
}
|
||||
|
||||
void gen_ident(std::string_view word) {
|
||||
|
|
|
@ -120,20 +120,10 @@ state::state(alloc_func func, void *data) {
|
|||
);
|
||||
}
|
||||
|
||||
ident *id = statep->new_ident(*this, "//dummy", IDENT_FLAG_UNKNOWN);
|
||||
if (id->get_index() != ID_IDX_DUMMY) {
|
||||
throw internal_error{"invalid dummy index"};
|
||||
}
|
||||
statep->id_dummy = statep->new_ident(*this, "//dummy", IDENT_FLAG_UNKNOWN);
|
||||
|
||||
id = new_ivar("numargs", 0, true);
|
||||
if (id->get_index() != ID_IDX_NUMARGS) {
|
||||
throw internal_error{"invalid numargs index"};
|
||||
}
|
||||
|
||||
id = new_ivar("dbgalias", 4);
|
||||
if (id->get_index() != ID_IDX_DBGALIAS) {
|
||||
throw internal_error{"invalid dbgalias index"};
|
||||
}
|
||||
statep->ivar_numargs = new_ivar("numargs", 0, true);
|
||||
statep->ivar_dbgalias = new_ivar("dbgalias", 4);
|
||||
|
||||
/* default handlers for variables */
|
||||
|
||||
|
|
|
@ -52,6 +52,11 @@ struct internal_state {
|
|||
string_pool *strman;
|
||||
empty_block *empty;
|
||||
|
||||
ident *id_dummy;
|
||||
|
||||
integer_var *ivar_numargs;
|
||||
integer_var *ivar_dbgalias;
|
||||
|
||||
command *cmd_ivar;
|
||||
command *cmd_fvar;
|
||||
command *cmd_svar;
|
||||
|
|
|
@ -152,7 +152,7 @@ void exec_command(
|
|||
if (rep) {
|
||||
break;
|
||||
}
|
||||
args[i].set_ident(ts.istate->identmap[ID_IDX_DUMMY]);
|
||||
args[i].set_ident(ts.istate->id_dummy);
|
||||
fakeargs++;
|
||||
} else {
|
||||
args[i].force_ident(*ts.pstate);
|
||||
|
@ -217,9 +217,7 @@ bool exec_alias(
|
|||
}
|
||||
/* excess arguments get ignored (make error maybe?) */
|
||||
callargs = std::min(callargs, MAX_ARGUMENTS);
|
||||
integer_var *anargs = static_cast<integer_var *>(
|
||||
ts.istate->identmap[ID_IDX_NUMARGS]
|
||||
);
|
||||
integer_var *anargs = ts.istate->ivar_numargs;
|
||||
argset uargs{};
|
||||
std::size_t noff = ts.idstack.size();
|
||||
for(std::size_t i = 0; i < callargs; i++) {
|
||||
|
@ -771,7 +769,7 @@ std::uint32_t *vm_exec(
|
|||
}
|
||||
case BC_INST_IDENT_U: {
|
||||
any_value &arg = args.back();
|
||||
ident *id = ts.istate->identmap[ID_IDX_DUMMY];
|
||||
ident *id = ts.istate->id_dummy;
|
||||
if (arg.get_type() == value_type::STRING) {
|
||||
id = ts.istate->new_ident(
|
||||
cs, arg.get_str(), IDENT_FLAG_UNKNOWN
|
||||
|
|
Loading…
Reference in New Issue