drop cs_cmd_internal
parent
436098cc38
commit
a5b0ce5d72
45
src/cs_vm.cc
45
src/cs_vm.cc
|
@ -7,21 +7,12 @@
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
struct cs_cmd_internal {
|
static inline bool cs_ident_has_cb(cs_ident *id) {
|
||||||
static void call(
|
if (!id->is_command() && !id->is_special()) {
|
||||||
cs_state &cs, cs_command *c, std::span<cs_value> args, cs_value &ret
|
return false;
|
||||||
) {
|
|
||||||
static_cast<cs_command_impl *>(c)->p_cb_cftv(cs, args, ret);
|
|
||||||
}
|
}
|
||||||
|
return !!static_cast<cs_command_impl *>(id)->p_cb_cftv;
|
||||||
static bool has_cb(cs_ident *id) {
|
}
|
||||||
if (!id->is_command() && !id->is_special()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
cs_command_impl *cb = static_cast<cs_command_impl *>(id);
|
|
||||||
return !!cb->p_cb_cftv;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline void cs_push_alias(cs_state &cs, cs_ident *id, cs_ident_stack &st) {
|
static inline void cs_push_alias(cs_state &cs, cs_ident *id, cs_ident_stack &st) {
|
||||||
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
|
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
|
||||||
|
@ -432,15 +423,15 @@ static inline void callcommand(
|
||||||
tv.set_str(value_list_concat(
|
tv.set_str(value_list_concat(
|
||||||
cs, std::span{args, std::size_t(i)}, " "
|
cs, std::span{args, std::size_t(i)}, " "
|
||||||
));
|
));
|
||||||
cs_cmd_internal::call(
|
static_cast<cs_command_impl *>(id)->call(
|
||||||
cs, id, std::span<cs_value>(&tv, &tv + 1), res
|
cs, std::span<cs_value>(&tv, &tv + 1), res
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'V':
|
case 'V':
|
||||||
i = std::max(i + 1, numargs);
|
i = std::max(i + 1, numargs);
|
||||||
cs_cmd_internal::call(
|
static_cast<cs_command_impl *>(id)->call(
|
||||||
cs, id, std::span{args, std::size_t(i)}, res
|
cs, std::span{args, std::size_t(i)}, res
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
case '1':
|
case '1':
|
||||||
|
@ -455,8 +446,8 @@ static inline void callcommand(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
cs_cmd_internal::call(
|
static_cast<cs_command_impl *>(id)->call(
|
||||||
cs, id, std::span<cs_value>{args, std::size_t(i)}, res
|
cs, std::span<cs_value>{args, std::size_t(i)}, res
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,7 +1303,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
|
||||||
);
|
);
|
||||||
int offset = numargs - id->get_num_args();
|
int offset = numargs - id->get_num_args();
|
||||||
result.force_none();
|
result.force_none();
|
||||||
cs_cmd_internal::call(cs, id, std::span<cs_value>{
|
id->call(cs, std::span<cs_value>{
|
||||||
&args[0] + offset, std::size_t(id->get_num_args())
|
&args[0] + offset, std::size_t(id->get_num_args())
|
||||||
}, result);
|
}, result);
|
||||||
force_arg(result, op & CS_CODE_RET_MASK);
|
force_arg(result, op & CS_CODE_RET_MASK);
|
||||||
|
@ -1330,9 +1321,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
|
||||||
std::size_t callargs = (op >> 8) & 0x1F,
|
std::size_t callargs = (op >> 8) & 0x1F,
|
||||||
offset = numargs - callargs;
|
offset = numargs - callargs;
|
||||||
result.force_none();
|
result.force_none();
|
||||||
cs_cmd_internal::call(
|
id->call(cs, std::span{&args[offset], callargs}, result);
|
||||||
cs, id, std::span{&args[offset], callargs}, result
|
|
||||||
);
|
|
||||||
force_arg(result, op & CS_CODE_RET_MASK);
|
force_arg(result, op & CS_CODE_RET_MASK);
|
||||||
numargs = offset;
|
numargs = offset;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1352,9 +1341,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
|
||||||
tv.set_str(value_list_concat(cs, std::span{
|
tv.set_str(value_list_concat(cs, std::span{
|
||||||
&args[offset], callargs
|
&args[offset], callargs
|
||||||
}, " "));
|
}, " "));
|
||||||
cs_cmd_internal::call(
|
id->call(cs, std::span<cs_value>{&tv, 1}, result);
|
||||||
cs, id, std::span<cs_value>{&tv, 1}, result
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
force_arg(result, op & CS_CODE_RET_MASK);
|
force_arg(result, op & CS_CODE_RET_MASK);
|
||||||
numargs = offset;
|
numargs = offset;
|
||||||
|
@ -1480,7 +1467,7 @@ noid:
|
||||||
result.force_none();
|
result.force_none();
|
||||||
switch (id->get_raw_type()) {
|
switch (id->get_raw_type()) {
|
||||||
default:
|
default:
|
||||||
if (!cs_cmd_internal::has_cb(id)) {
|
if (!cs_ident_has_cb(id)) {
|
||||||
numargs = offset - 1;
|
numargs = offset - 1;
|
||||||
force_arg(result, op & CS_CODE_RET_MASK);
|
force_arg(result, op & CS_CODE_RET_MASK);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1610,7 +1597,7 @@ void cs_state::run(cs_ident *id, std::span<cs_value> args, cs_value &ret) {
|
||||||
if (id) {
|
if (id) {
|
||||||
switch (id->get_type()) {
|
switch (id->get_type()) {
|
||||||
default:
|
default:
|
||||||
if (!cs_cmd_internal::has_cb(id)) {
|
if (!cs_ident_has_cb(id)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
|
@ -171,6 +171,10 @@ struct cs_alias_impl: cs_ident_impl, cs_alias {
|
||||||
struct cs_command_impl: cs_ident_impl, cs_command {
|
struct cs_command_impl: cs_ident_impl, cs_command {
|
||||||
cs_command_impl(cs_strref name, cs_strref args, int numargs, cs_command_cb func);
|
cs_command_impl(cs_strref name, cs_strref args, int numargs, cs_command_cb func);
|
||||||
|
|
||||||
|
void call(cs_state &cs, std::span<cs_value> args, cs_value &ret) {
|
||||||
|
p_cb_cftv(cs, args, ret);
|
||||||
|
}
|
||||||
|
|
||||||
cs_strref p_cargs;
|
cs_strref p_cargs;
|
||||||
cs_command_cb p_cb_cftv;
|
cs_command_cb p_cb_cftv;
|
||||||
int p_numargs;
|
int p_numargs;
|
||||||
|
|
Loading…
Reference in New Issue