don't rely on MAX_ARGUMENTS where not necessary

master
Daniel Kolesa 2021-03-27 23:43:55 +01:00
parent 54c0f2ae20
commit d1e131dbf6
4 changed files with 15 additions and 15 deletions

View File

@ -294,7 +294,7 @@ lookupid:
return;
case VAL_COND:
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_LOOKUP_MARG
: BC_INST_LOOKUP_M
) | (id->get_index() << 8)
@ -303,7 +303,7 @@ lookupid:
case VAL_CODE:
case VAL_IDENT:
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_LOOKUP_MARG
: BC_INST_LOOKUP_M
) | BC_RET_STRING | (id->get_index() << 8)
@ -311,7 +311,7 @@ lookupid:
break;
default:
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_LOOKUP_ARG
: BC_INST_LOOKUP
) | ret_code(ltype, BC_RET_STRING) |
@ -552,7 +552,7 @@ lookupid:
goto done;
case ident_type::ALIAS:
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_LOOKUP_MARG
: BC_INST_LOOKUP_M
) | (id->get_index() << 8)
@ -1054,7 +1054,7 @@ static void compile_alias(codegen_state &gs, alias *id, bool &more, int prevargs
++numargs;
}
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS ? BC_INST_CALL_ARG : BC_INST_CALL)
((id->get_flags() & IDENT_FLAG_ARG) ? BC_INST_CALL_ARG : BC_INST_CALL)
| (numargs << 8) | (id->get_index() << 13)
);
}
@ -1244,7 +1244,7 @@ static void compilestatements(codegen_state &gs, int rettype, int brak, int prev
gs.gen_str();
}
gs.code.push_back(
(id->get_index() < MAX_ARGUMENTS
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_ALIAS_ARG
: BC_INST_ALIAS
) | (id->get_index() << 8)

View File

@ -110,7 +110,7 @@ struct codegen_state {
void gen_ident(ident *id) {
code.push_back(
((id->get_index() < MAX_ARGUMENTS)
((id->get_flags() & IDENT_FLAG_ARG)
? BC_INST_IDENT_ARG
: BC_INST_IDENT
) | (id->get_index() << 8)

View File

@ -370,7 +370,7 @@ LIBCUBESCRIPT_EXPORT void state::set_alias(
switch (id->get_type()) {
case ident_type::ALIAS: {
alias_impl *a = static_cast<alias_impl *>(id);
if (a->get_index() < MAX_ARGUMENTS) {
if (a->get_flags() & IDENT_FLAG_ARG) {
a->set_arg(*p_tstate, v);
} else {
a->set_alias(*p_tstate, v);
@ -653,7 +653,7 @@ state::get_alias_val(std::string_view name) {
if (!a) {
return std::nullopt;
}
if ((a->get_index() < MAX_ARGUMENTS) && !ident_is_used_arg(a, *p_tstate)) {
if ((a->get_flags() & IDENT_FLAG_ARG) && !ident_is_used_arg(a, *p_tstate)) {
return std::nullopt;
}
return a->get_value().get_str();
@ -875,7 +875,7 @@ LIBCUBESCRIPT_EXPORT void state::run(
case ident_type::ALIAS: {
alias *a = static_cast<alias *>(id);
if (
(a->get_index() < MAX_ARGUMENTS) &&
(a->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(a, *p_tstate)
) {
break;

View File

@ -9,14 +9,14 @@
namespace cubescript {
static inline void push_alias(state &cs, ident *id, ident_stack &st) {
if (id->is_alias() && (id->get_index() >= MAX_ARGUMENTS)) {
if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) {
any_value nv{cs};
static_cast<alias_impl *>(id)->push_arg(nv, st);
}
}
static inline void pop_alias(ident *id) {
if (id->is_alias() && (id->get_index() >= MAX_ARGUMENTS)) {
if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) {
static_cast<alias_impl *>(id)->pop_arg();
}
}
@ -291,7 +291,7 @@ static inline int get_lookupu_type(
break;
}
if (
(id->get_index() < MAX_ARGUMENTS) &&
(id->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(id, ts)
) {
return ID_UNKNOWN;
@ -734,7 +734,7 @@ std::uint32_t *vm_exec(
id = cs.new_ident(arg.get_str());
}
if (
(id->get_index() < MAX_ARGUMENTS) &&
(id->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(id, ts)
) {
any_value nv{cs};
@ -1358,7 +1358,7 @@ noid:
case ID_ALIAS: {
alias *a = static_cast<alias *>(id);
if (
(a->get_index() < MAX_ARGUMENTS) &&
(a->get_flags() & IDENT_FLAG_ARG) &&
!ident_is_used_arg(a, ts)
) {
args.resize(offset - 1, any_value{cs});