unexpose get_flags from ident, replace with specific methods
parent
2a8d2103b8
commit
238e5a6ac5
|
@ -211,7 +211,6 @@ struct LIBCUBESCRIPT_EXPORT ident {
|
||||||
int get_raw_type() const;
|
int get_raw_type() const;
|
||||||
ident_type get_type() const;
|
ident_type get_type() const;
|
||||||
std::string_view get_name() const;
|
std::string_view get_name() const;
|
||||||
int get_flags() const;
|
|
||||||
int get_index() const;
|
int get_index() const;
|
||||||
|
|
||||||
bool is_alias() const;
|
bool is_alias() const;
|
||||||
|
@ -243,13 +242,14 @@ struct LIBCUBESCRIPT_EXPORT ident {
|
||||||
protected:
|
protected:
|
||||||
ident() = default;
|
ident() = default;
|
||||||
|
|
||||||
private:
|
|
||||||
friend struct state;
|
friend struct state;
|
||||||
|
|
||||||
ident_impl *p_impl{};
|
ident_impl *p_impl{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LIBCUBESCRIPT_EXPORT global_var: ident {
|
struct LIBCUBESCRIPT_EXPORT global_var: ident {
|
||||||
|
bool is_read_only() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
global_var() = default;
|
global_var() = default;
|
||||||
};
|
};
|
||||||
|
@ -279,6 +279,8 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LIBCUBESCRIPT_EXPORT alias: ident {
|
struct LIBCUBESCRIPT_EXPORT alias: ident {
|
||||||
|
bool is_arg() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
alias() = default;
|
alias() = default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -142,10 +142,6 @@ LIBCUBESCRIPT_EXPORT std::string_view ident::get_name() const {
|
||||||
return p_impl->p_name;
|
return p_impl->p_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT int ident::get_flags() const {
|
|
||||||
return p_impl->p_flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT int ident::get_index() const {
|
LIBCUBESCRIPT_EXPORT int ident::get_index() const {
|
||||||
return p_impl->p_index;
|
return p_impl->p_index;
|
||||||
}
|
}
|
||||||
|
@ -270,6 +266,10 @@ LIBCUBESCRIPT_EXPORT string_var const *ident::get_svar() const {
|
||||||
return static_cast<string_var const *>(this);
|
return static_cast<string_var const *>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LIBCUBESCRIPT_EXPORT bool global_var::is_read_only() const {
|
||||||
|
return (p_impl->p_flags & IDENT_FLAG_READONLY);
|
||||||
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT integer_type integer_var::get_value() const {
|
LIBCUBESCRIPT_EXPORT integer_type integer_var::get_value() const {
|
||||||
return static_cast<ivar_impl const *>(this)->p_storage;
|
return static_cast<ivar_impl const *>(this)->p_storage;
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,10 @@ LIBCUBESCRIPT_EXPORT void string_var::set_value(string_ref val) {
|
||||||
static_cast<svar_impl *>(this)->p_storage = val;
|
static_cast<svar_impl *>(this)->p_storage = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LIBCUBESCRIPT_EXPORT bool alias::is_arg() const {
|
||||||
|
return (static_cast<alias_impl const *>(this)->p_flags & IDENT_FLAG_ARG);
|
||||||
|
}
|
||||||
|
|
||||||
LIBCUBESCRIPT_EXPORT std::string_view command::get_args() const {
|
LIBCUBESCRIPT_EXPORT std::string_view command::get_args() const {
|
||||||
return static_cast<command_impl const *>(this)->p_cargs;
|
return static_cast<command_impl const *>(this)->p_cargs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,7 +330,7 @@ LIBCUBESCRIPT_EXPORT void state::set_alias(
|
||||||
case ident_type::ALIAS: {
|
case ident_type::ALIAS: {
|
||||||
alias *a = static_cast<alias *>(id);
|
alias *a = static_cast<alias *>(id);
|
||||||
auto &ast = p_tstate->get_astack(a);
|
auto &ast = p_tstate->get_astack(a);
|
||||||
if (a->get_flags() & IDENT_FLAG_ARG) {
|
if (a->is_arg()) {
|
||||||
ast.set_arg(a, *p_tstate, v);
|
ast.set_arg(a, *p_tstate, v);
|
||||||
} else {
|
} else {
|
||||||
ast.set_alias(a, *p_tstate, v);
|
ast.set_alias(a, *p_tstate, v);
|
||||||
|
@ -421,7 +421,7 @@ state::get_alias_val(std::string_view name) {
|
||||||
if (!a) {
|
if (!a) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if ((a->get_flags() & IDENT_FLAG_ARG) && !ident_is_used_arg(a, *p_tstate)) {
|
if (a->is_arg() && !ident_is_used_arg(a, *p_tstate)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return p_tstate->get_astack(a).node->val_s.get_str();
|
return p_tstate->get_astack(a).node->val_s.get_str();
|
||||||
|
@ -566,10 +566,7 @@ LIBCUBESCRIPT_EXPORT void state::run(
|
||||||
}
|
}
|
||||||
case ident_type::ALIAS: {
|
case ident_type::ALIAS: {
|
||||||
alias *a = static_cast<alias *>(id);
|
alias *a = static_cast<alias *>(id);
|
||||||
if (
|
if (a->is_arg() && !ident_is_used_arg(a, *p_tstate)) {
|
||||||
(a->get_flags() & IDENT_FLAG_ARG) &&
|
|
||||||
!ident_is_used_arg(a, *p_tstate)
|
|
||||||
) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
exec_alias(
|
exec_alias(
|
||||||
|
|
48
src/cs_vm.cc
48
src/cs_vm.cc
|
@ -10,7 +10,7 @@
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
|
||||||
static inline void push_alias(thread_state &ts, ident *id, ident_stack &st) {
|
static inline void push_alias(thread_state &ts, ident *id, ident_stack &st) {
|
||||||
if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) {
|
if (id->is_alias() && !static_cast<alias *>(id)->is_arg()) {
|
||||||
auto *aimp = static_cast<alias_impl *>(id);
|
auto *aimp = static_cast<alias_impl *>(id);
|
||||||
ts.get_astack(aimp).push(st);
|
ts.get_astack(aimp).push(st);
|
||||||
aimp->p_flags &= ~IDENT_FLAG_UNKNOWN;
|
aimp->p_flags &= ~IDENT_FLAG_UNKNOWN;
|
||||||
|
@ -18,7 +18,7 @@ static inline void push_alias(thread_state &ts, ident *id, ident_stack &st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void pop_alias(thread_state &ts, ident *id) {
|
static inline void pop_alias(thread_state &ts, ident *id) {
|
||||||
if (id->is_alias() && !(id->get_flags() & IDENT_FLAG_ARG)) {
|
if (id->is_alias() && !static_cast<alias *>(id)->is_arg()) {
|
||||||
ts.get_astack(static_cast<alias *>(id)).pop();
|
ts.get_astack(static_cast<alias *>(id)).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,13 +285,13 @@ run_depth_guard::~run_depth_guard() { --rundepth; }
|
||||||
|
|
||||||
static inline alias *get_lookup_id(thread_state &ts, std::uint32_t op) {
|
static inline alias *get_lookup_id(thread_state &ts, std::uint32_t op) {
|
||||||
ident *id = ts.istate->identmap[op >> 8];
|
ident *id = ts.istate->identmap[op >> 8];
|
||||||
|
auto *a = static_cast<alias_impl *>(id);
|
||||||
|
|
||||||
auto flags = id->get_flags();
|
if (a->is_arg()) {
|
||||||
if (flags & IDENT_FLAG_ARG) {
|
|
||||||
if (!ident_is_used_arg(id, ts)) {
|
if (!ident_is_used_arg(id, ts)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else if (flags & IDENT_FLAG_UNKNOWN) {
|
} else if (a->p_flags & IDENT_FLAG_UNKNOWN) {
|
||||||
throw error{
|
throw error{
|
||||||
*ts.pstate, "unknown alias lookup: %s", id->get_name().data()
|
*ts.pstate, "unknown alias lookup: %s", id->get_name().data()
|
||||||
};
|
};
|
||||||
|
@ -308,17 +308,16 @@ static inline int get_lookupu_type(
|
||||||
id = ts.pstate->get_ident(arg.get_str());
|
id = ts.pstate->get_ident(arg.get_str());
|
||||||
if (id) {
|
if (id) {
|
||||||
switch(id->get_type()) {
|
switch(id->get_type()) {
|
||||||
case ident_type::ALIAS:
|
case ident_type::ALIAS: {
|
||||||
if (id->get_flags() & IDENT_FLAG_UNKNOWN) {
|
auto *a = static_cast<alias_impl *>(id);
|
||||||
|
if (a->p_flags & IDENT_FLAG_UNKNOWN) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (
|
if (a->is_arg() && !ident_is_used_arg(id, ts)) {
|
||||||
(id->get_flags() & IDENT_FLAG_ARG) &&
|
|
||||||
!ident_is_used_arg(id, ts)
|
|
||||||
) {
|
|
||||||
return ID_UNKNOWN;
|
return ID_UNKNOWN;
|
||||||
}
|
}
|
||||||
return ID_ALIAS;
|
return ID_ALIAS;
|
||||||
|
}
|
||||||
case ident_type::SVAR:
|
case ident_type::SVAR:
|
||||||
return ID_SVAR;
|
return ID_SVAR;
|
||||||
case ident_type::IVAR:
|
case ident_type::IVAR:
|
||||||
|
@ -745,10 +744,7 @@ std::uint32_t *vm_exec(
|
||||||
alias *a = static_cast<alias *>(
|
alias *a = static_cast<alias *>(
|
||||||
ts.istate->identmap[op >> 8]
|
ts.istate->identmap[op >> 8]
|
||||||
);
|
);
|
||||||
if (
|
if (a->is_arg() && !ident_is_used_arg(a, ts)) {
|
||||||
(a->get_flags() & IDENT_FLAG_ARG) &&
|
|
||||||
!ident_is_used_arg(a, ts)
|
|
||||||
) {
|
|
||||||
ts.get_astack(a).push(ts.idstack.emplace_back(*ts.pstate));
|
ts.get_astack(a).push(ts.idstack.emplace_back(*ts.pstate));
|
||||||
ts.callstack->usedargs[a->get_index()] = true;
|
ts.callstack->usedargs[a->get_index()] = true;
|
||||||
}
|
}
|
||||||
|
@ -761,11 +757,8 @@ std::uint32_t *vm_exec(
|
||||||
if (arg.get_type() == value_type::STRING) {
|
if (arg.get_type() == value_type::STRING) {
|
||||||
id = cs.new_ident(arg.get_str(), IDENT_FLAG_UNKNOWN);
|
id = cs.new_ident(arg.get_str(), IDENT_FLAG_UNKNOWN);
|
||||||
}
|
}
|
||||||
if (
|
alias *a = static_cast<alias *>(id);
|
||||||
(id->get_flags() & IDENT_FLAG_ARG) &&
|
if (a->is_arg() && !ident_is_used_arg(id, ts)) {
|
||||||
!ident_is_used_arg(id, ts)
|
|
||||||
) {
|
|
||||||
auto *a = static_cast<alias *>(id);
|
|
||||||
ts.get_astack(a).push(ts.idstack.emplace_back(*ts.pstate));
|
ts.get_astack(a).push(ts.idstack.emplace_back(*ts.pstate));
|
||||||
ts.callstack->usedargs[id->get_index()] = true;
|
ts.callstack->usedargs[id->get_index()] = true;
|
||||||
}
|
}
|
||||||
|
@ -1022,7 +1015,7 @@ std::uint32_t *vm_exec(
|
||||||
ts.istate->identmap[op >> 8]
|
ts.istate->identmap[op >> 8]
|
||||||
);
|
);
|
||||||
auto &ast = ts.get_astack(a);
|
auto &ast = ts.get_astack(a);
|
||||||
if (a->get_flags() & IDENT_FLAG_ARG) {
|
if (a->is_arg()) {
|
||||||
ast.set_arg(a, ts, args.back());
|
ast.set_arg(a, ts, args.back());
|
||||||
} else {
|
} else {
|
||||||
ast.set_alias(a, ts, args.back());
|
ast.set_alias(a, ts, args.back());
|
||||||
|
@ -1047,21 +1040,21 @@ std::uint32_t *vm_exec(
|
||||||
std::size_t callargs = *code++;
|
std::size_t callargs = *code++;
|
||||||
std::size_t nnargs = args.size();
|
std::size_t nnargs = args.size();
|
||||||
std::size_t offset = nnargs - callargs;
|
std::size_t offset = nnargs - callargs;
|
||||||
auto flags = id->get_flags();
|
auto *imp = static_cast<alias_impl *>(id);
|
||||||
if (flags & IDENT_FLAG_ARG) {
|
if (imp->is_arg()) {
|
||||||
if (!ident_is_used_arg(id, ts)) {
|
if (!ident_is_used_arg(id, ts)) {
|
||||||
args.resize(offset, any_value{cs});
|
args.resize(offset, any_value{cs});
|
||||||
force_arg(result, op & BC_INST_RET_MASK);
|
force_arg(result, op & BC_INST_RET_MASK);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (flags & IDENT_FLAG_UNKNOWN) {
|
} else if (imp->p_flags & IDENT_FLAG_UNKNOWN) {
|
||||||
force_arg(result, op & BC_INST_RET_MASK);
|
force_arg(result, op & BC_INST_RET_MASK);
|
||||||
throw error{
|
throw error{
|
||||||
cs, "unknown command: %s", id->get_name().data()
|
cs, "unknown command: %s", id->get_name().data()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exec_alias(
|
exec_alias(
|
||||||
ts, static_cast<alias *>(id), &args[0], result, callargs,
|
ts, imp, &args[0], result, callargs,
|
||||||
nnargs, offset, 0, op
|
nnargs, offset, 0, op
|
||||||
);
|
);
|
||||||
args.resize(nnargs, any_value{cs});
|
args.resize(nnargs, any_value{cs});
|
||||||
|
@ -1197,10 +1190,7 @@ noid:
|
||||||
}
|
}
|
||||||
case ID_ALIAS: {
|
case ID_ALIAS: {
|
||||||
alias *a = static_cast<alias *>(id);
|
alias *a = static_cast<alias *>(id);
|
||||||
if (
|
if (a->is_arg() && !ident_is_used_arg(a, ts)) {
|
||||||
(a->get_flags() & IDENT_FLAG_ARG) &&
|
|
||||||
!ident_is_used_arg(a, ts)
|
|
||||||
) {
|
|
||||||
args.resize(offset - 1, any_value{cs});
|
args.resize(offset - 1, any_value{cs});
|
||||||
force_arg(result, op & BC_INST_RET_MASK);
|
force_arg(result, op & BC_INST_RET_MASK);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -159,7 +159,7 @@ void init_lib_base(state &gcs) {
|
||||||
|
|
||||||
gcs.new_command("pushif", "rte", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("pushif", "rte", [](auto &cs, auto args, auto &res) {
|
||||||
if (alias_local st{cs, args[0].get_ident()}; st) {
|
if (alias_local st{cs, args[0].get_ident()}; st) {
|
||||||
if (st.get_alias()->get_flags() & IDENT_FLAG_ARG) {
|
if (st.get_alias()->is_arg()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args[1].get_bool()) {
|
if (args[1].get_bool()) {
|
||||||
|
@ -304,7 +304,7 @@ end:
|
||||||
|
|
||||||
gcs.new_command("push", "rte", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("push", "rte", [](auto &cs, auto args, auto &res) {
|
||||||
if (alias_local st{cs, args[0].get_ident()}; st) {
|
if (alias_local st{cs, args[0].get_ident()}; st) {
|
||||||
if (st.get_alias()->get_flags() & IDENT_FLAG_ARG) {
|
if (st.get_alias()->is_arg()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
st.set(args[1]);
|
st.set(args[1]);
|
||||||
|
|
Loading…
Reference in New Issue