s/run/call/

master
Daniel Kolesa 2021-04-30 02:55:20 +02:00
parent 9c14e6ca65
commit 4dd1518f6c
9 changed files with 88 additions and 88 deletions

View File

@ -73,7 +73,7 @@ using command_func = internal::callable<
/** @brief The loop state /** @brief The loop state
* *
* This is returned by state::run_loop(). * This is returned by state::call_loop().
*/ */
enum class loop_state { enum class loop_state {
NORMAL = 0, /**< @brief The iteration ended normally. */ NORMAL = 0, /**< @brief The iteration ended normally. */
@ -381,13 +381,13 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* @return the return value * @return the return value
*/ */
any_value run(bcode_ref const &code); any_value call(bcode_ref const &code);
/** @brief Execute the given string as code /** @brief Execute the given string as code
* *
* @return the return value * @return the return value
*/ */
any_value run(std::string_view code); any_value call(std::string_view code);
/** @brief Execute the given string as code /** @brief Execute the given string as code
* *
@ -399,7 +399,7 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* @return the return value * @return the return value
*/ */
any_value run(std::string_view code, std::string_view source); any_value call(std::string_view code, std::string_view source);
/** @brief Execute the given ident /** @brief Execute the given ident
* *
@ -411,7 +411,7 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* @return the return value * @return the return value
*/ */
any_value run(ident &id, span_type<any_value> args); any_value call(ident &id, span_type<any_value> args);
/** @brief Execute a loop body /** @brief Execute a loop body
* *
@ -423,13 +423,13 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* Some loops may evaluate to values, while others may not. * Some loops may evaluate to values, while others may not.
*/ */
loop_state run_loop(bcode_ref const &code, any_value &ret); loop_state call_loop(bcode_ref const &code, any_value &ret);
/** @brief Execute a loop body /** @brief Execute a loop body
* *
* This version ignores the return value of the body. * This version ignores the return value of the body.
*/ */
loop_state run_loop(bcode_ref const &code); loop_state call_loop(bcode_ref const &code);
/** @brief Get if the thread is in override mode /** @brief Get if the thread is in override mode
* *
@ -475,16 +475,16 @@ struct LIBCUBESCRIPT_EXPORT state {
*/ */
bool set_persist_mode(bool v); bool set_persist_mode(bool v);
/** @brief Get the maximum run depth of the VM /** @brief Get the maximum call depth of the VM
* *
* If zero, it is unlimited, otherwise it specifies how much the VM is * If zero, it is unlimited, otherwise it specifies how much the VM is
* allowed to recurse. By default, it is zero. * allowed to recurse. By default, it is zero.
* *
* @see set_max_run_depth() * @see set_max_call_depth()
*/ */
std::size_t get_max_run_depth() const; std::size_t get_max_call_depth() const;
/** @brief Set the maximum run depth ov the VM /** @brief Set the maximum call depth ov the VM
* *
* If zero, it is unlimited (this is the default). You can limit how much * If zero, it is unlimited (this is the default). You can limit how much
* the VM is allowed to recurse if you have specific constraints to adhere * the VM is allowed to recurse if you have specific constraints to adhere
@ -492,7 +492,7 @@ struct LIBCUBESCRIPT_EXPORT state {
* *
* @return the old value * @return the old value
*/ */
std::size_t set_max_run_depth(std::size_t v); std::size_t set_max_call_depth(std::size_t v);
private: private:
friend struct state_p; friend struct state_p;

View File

@ -173,19 +173,19 @@ state::state(alloc_func func, void *data) {
/* builtins */ /* builtins */
p = &new_command("do", "b", [](auto &cs, auto args, auto &res) { p = &new_command("do", "b", [](auto &cs, auto args, auto &res) {
res = cs.run(args[0].get_code()); res = cs.call(args[0].get_code());
}); });
static_cast<command_impl *>(p)->p_type = ID_DO; static_cast<command_impl *>(p)->p_type = ID_DO;
p = &new_command("doargs", "b", [](auto &cs, auto args, auto &res) { p = &new_command("doargs", "b", [](auto &cs, auto args, auto &res) {
call_with_args(*cs.p_tstate, [&cs, &res, &args]() { call_with_args(*cs.p_tstate, [&cs, &res, &args]() {
res = cs.run(args[0].get_code()); res = cs.call(args[0].get_code());
}); });
}); });
static_cast<command_impl *>(p)->p_type = ID_DOARGS; static_cast<command_impl *>(p)->p_type = ID_DOARGS;
p = &new_command("if", "abb", [](auto &cs, auto args, auto &res) { p = &new_command("if", "abb", [](auto &cs, auto args, auto &res) {
res = cs.run((args[0].get_bool() ? args[1] : args[2]).get_code()); res = cs.call((args[0].get_bool() ? args[1] : args[2]).get_code());
}); });
static_cast<command_impl *>(p)->p_type = ID_IF; static_cast<command_impl *>(p)->p_type = ID_IF;
@ -206,7 +206,7 @@ state::state(alloc_func func, void *data) {
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
auto code = args[i].get_code(); auto code = args[i].get_code();
if (code) { if (code) {
res = cs.run(code); res = cs.call(code);
} else { } else {
res = std::move(args[i]); res = std::move(args[i]);
} }
@ -225,7 +225,7 @@ state::state(alloc_func func, void *data) {
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
auto code = args[i].get_code(); auto code = args[i].get_code();
if (code) { if (code) {
res = cs.run(code); res = cs.call(code);
} else { } else {
res = std::move(args[i]); res = std::move(args[i]);
} }
@ -485,7 +485,7 @@ LIBCUBESCRIPT_EXPORT void state::assign_value(
case ident_type::IVAR: case ident_type::IVAR:
case ident_type::FVAR: case ident_type::FVAR:
case ident_type::SVAR: case ident_type::SVAR:
run(id->get(), span_type<any_value>{&v, 1}); call(id->get(), span_type<any_value>{&v, 1});
break; break;
default: default:
throw error{ throw error{
@ -693,13 +693,13 @@ do_add:
return *cmd; return *cmd;
} }
LIBCUBESCRIPT_EXPORT any_value state::run(bcode_ref const &code) { LIBCUBESCRIPT_EXPORT any_value state::call(bcode_ref const &code) {
any_value ret{}; any_value ret{};
vm_exec(*p_tstate, bcode_p{code}.get()->get_raw(), ret); vm_exec(*p_tstate, bcode_p{code}.get()->get_raw(), ret);
return ret; return ret;
} }
static any_value do_run( static any_value do_call(
thread_state &ts, std::string_view file, std::string_view code thread_state &ts, std::string_view file, std::string_view code
) { ) {
any_value ret{}; any_value ret{};
@ -710,22 +710,22 @@ static any_value do_run(
return ret; return ret;
} }
LIBCUBESCRIPT_EXPORT any_value state::run(std::string_view code) { LIBCUBESCRIPT_EXPORT any_value state::call(std::string_view code) {
return do_run(*p_tstate, std::string_view{}, code); return do_call(*p_tstate, std::string_view{}, code);
} }
LIBCUBESCRIPT_EXPORT any_value state::run( LIBCUBESCRIPT_EXPORT any_value state::call(
std::string_view code, std::string_view source std::string_view code, std::string_view source
) { ) {
return do_run(*p_tstate, source, code); return do_call(*p_tstate, source, code);
} }
LIBCUBESCRIPT_EXPORT any_value state::run( LIBCUBESCRIPT_EXPORT any_value state::call(
ident &id, span_type<any_value> args ident &id, span_type<any_value> args
) { ) {
any_value ret{}; any_value ret{};
std::size_t nargs = args.size(); std::size_t nargs = args.size();
run_depth_guard level{*p_tstate}; /* incr and decr on scope exit */ call_depth_guard level{*p_tstate}; /* incr and decr on scope exit */
switch (id.get_type()) { switch (id.get_type()) {
default: default:
if (!ident_is_callable(&id)) { if (!ident_is_callable(&id)) {
@ -819,12 +819,12 @@ LIBCUBESCRIPT_EXPORT any_value state::run(
return ret; return ret;
} }
LIBCUBESCRIPT_EXPORT loop_state state::run_loop( LIBCUBESCRIPT_EXPORT loop_state state::call_loop(
bcode_ref const &code, any_value &ret bcode_ref const &code, any_value &ret
) { ) {
++p_tstate->loop_level; ++p_tstate->loop_level;
try { try {
ret = run(code); ret = call(code);
} catch (break_exception) { } catch (break_exception) {
--p_tstate->loop_level; --p_tstate->loop_level;
return loop_state::BREAK; return loop_state::BREAK;
@ -838,9 +838,9 @@ LIBCUBESCRIPT_EXPORT loop_state state::run_loop(
return loop_state::NORMAL; return loop_state::NORMAL;
} }
LIBCUBESCRIPT_EXPORT loop_state state::run_loop(bcode_ref const &code) { LIBCUBESCRIPT_EXPORT loop_state state::call_loop(bcode_ref const &code) {
any_value ret{}; any_value ret{};
return run_loop(code, ret); return call_loop(code, ret);
} }
LIBCUBESCRIPT_EXPORT bool state::get_override_mode() const { LIBCUBESCRIPT_EXPORT bool state::get_override_mode() const {
@ -871,13 +871,13 @@ LIBCUBESCRIPT_EXPORT bool state::set_persist_mode(bool v) {
return was; return was;
} }
LIBCUBESCRIPT_EXPORT std::size_t state::get_max_run_depth() const { LIBCUBESCRIPT_EXPORT std::size_t state::get_max_call_depth() const {
return p_tstate->max_run_depth; return p_tstate->max_call_depth;
} }
LIBCUBESCRIPT_EXPORT std::size_t state::set_max_run_depth(std::size_t v) { LIBCUBESCRIPT_EXPORT std::size_t state::set_max_call_depth(std::size_t v) {
auto old = p_tstate->max_run_depth; auto old = p_tstate->max_call_depth;
p_tstate->max_run_depth = v; p_tstate->max_call_depth = v;
return old; return old;
} }

View File

@ -35,10 +35,10 @@ struct thread_state {
bool owner = false; bool owner = false;
/* thread ident flags */ /* thread ident flags */
int ident_flags = 0; int ident_flags = 0;
/* run depth limit */ /* call depth limit */
std::size_t max_run_depth = 0; std::size_t max_call_depth = 0;
/* current run depth */ /* current call depth */
std::size_t run_depth = 0; std::size_t call_depth = 0;
/* loop nesting level */ /* loop nesting level */
std::size_t loop_level = 0; std::size_t loop_level = 0;
/* debug info */ /* debug info */

View File

@ -210,14 +210,14 @@ bool exec_alias(
return true; return true;
} }
run_depth_guard::run_depth_guard(thread_state &ts): tsp(&ts) { call_depth_guard::call_depth_guard(thread_state &ts): tsp(&ts) {
if (ts.max_run_depth && (ts.run_depth >= ts.max_run_depth)) { if (ts.max_call_depth && (ts.call_depth >= ts.max_call_depth)) {
throw error{*ts.pstate, "exceeded recursion limit"}; throw error{*ts.pstate, "exceeded recursion limit"};
} }
++ts.run_depth; ++ts.call_depth;
} }
run_depth_guard::~run_depth_guard() { --tsp->run_depth; } call_depth_guard::~call_depth_guard() { --tsp->call_depth; }
static inline alias *get_lookup_id( static inline alias *get_lookup_id(
thread_state &ts, std::uint32_t op, alias_stack *&ast thread_state &ts, std::uint32_t op, alias_stack *&ast
@ -246,7 +246,7 @@ std::uint32_t *vm_exec(
) { ) {
result.set_none(); result.set_none();
auto &cs = *ts.pstate; auto &cs = *ts.pstate;
run_depth_guard level{ts}; /* incr and decr on scope exit */ call_depth_guard level{ts}; /* incr and decr on scope exit */
stack_guard guard{ts}; /* resize back to original */ stack_guard guard{ts}; /* resize back to original */
auto &args = ts.vmstack; auto &args = ts.vmstack;
auto &chook = cs.get_call_hook(); auto &chook = cs.get_call_hook();
@ -458,7 +458,7 @@ std::uint32_t *vm_exec(
call_with_args(ts, [&]() { call_with_args(ts, [&]() {
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
result = cs.run(v.get_code()); result = cs.call(v.get_code());
force_arg(cs, result, op & BC_INST_RET_MASK); force_arg(cs, result, op & BC_INST_RET_MASK);
}); });
continue; continue;
@ -469,7 +469,7 @@ std::uint32_t *vm_exec(
case BC_INST_DO | BC_RET_FLOAT: { case BC_INST_DO | BC_RET_FLOAT: {
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
result = cs.run(v.get_code()); result = cs.call(v.get_code());
force_arg(cs, result, op & BC_INST_RET_MASK); force_arg(cs, result, op & BC_INST_RET_MASK);
continue; continue;
} }
@ -500,7 +500,7 @@ std::uint32_t *vm_exec(
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
if (v.get_type() == value_type::CODE) { if (v.get_type() == value_type::CODE) {
result = cs.run(v.get_code()); result = cs.call(v.get_code());
} else { } else {
result = std::move(v); result = std::move(v);
} }
@ -514,7 +514,7 @@ std::uint32_t *vm_exec(
auto v = std::move(args.back()); auto v = std::move(args.back());
args.pop_back(); args.pop_back();
if (v.get_type() == value_type::CODE) { if (v.get_type() == value_type::CODE) {
result = cs.run(v.get_code()); result = cs.call(v.get_code());
} else { } else {
result = std::move(v); result = std::move(v);
} }

View File

@ -15,12 +15,12 @@ struct break_exception {
struct continue_exception { struct continue_exception {
}; };
struct run_depth_guard { struct call_depth_guard {
run_depth_guard() = delete; call_depth_guard() = delete;
run_depth_guard(thread_state &ts); call_depth_guard(thread_state &ts);
run_depth_guard(run_depth_guard const &) = delete; call_depth_guard(call_depth_guard const &) = delete;
run_depth_guard(run_depth_guard &&) = delete; call_depth_guard(call_depth_guard &&) = delete;
~run_depth_guard(); ~call_depth_guard();
thread_state *tsp; thread_state *tsp;
}; };

View File

@ -20,10 +20,10 @@ static inline void do_loop(
for (integer_type i = 0; i < n; ++i) { for (integer_type i = 0; i < n; ++i) {
idv.set_integer(offset + i * step); idv.set_integer(offset + i * step);
st.set(idv); st.set(idv);
if (cond && !cs.run(cond).get_bool()) { if (cond && !cs.call(cond).get_bool()) {
break; break;
} }
switch (cs.run_loop(body)) { switch (cs.call_loop(body)) {
case loop_state::BREAK: case loop_state::BREAK:
return; return;
default: /* continue and normal */ default: /* continue and normal */
@ -46,7 +46,7 @@ static inline void do_loop_conc(
idv.set_integer(offset + i * step); idv.set_integer(offset + i * step);
st.set(idv); st.set(idv);
any_value v{}; any_value v{};
switch (cs.run_loop(body, v)) { switch (cs.call_loop(body, v)) {
case loop_state::BREAK: case loop_state::BREAK:
goto end; goto end;
case loop_state::CONTINUE: case loop_state::CONTINUE:
@ -80,7 +80,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
any_value result{}, tback{}; any_value result{}, tback{};
bool rc = true; bool rc = true;
try { try {
result = cs.run(args[0].get_code()); result = cs.call(args[0].get_code());
} catch (error const &e) { } catch (error const &e) {
result.set_string(e.what(), cs); result.set_string(e.what(), cs);
if (e.get_stack().get()) { if (e.get_stack().get()) {
@ -109,12 +109,12 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
new_cmd_quiet(gcs, "cond", "bb2...", [](auto &cs, auto args, auto &res) { new_cmd_quiet(gcs, "cond", "bb2...", [](auto &cs, auto args, auto &res) {
for (size_t i = 0; i < args.size(); i += 2) { for (size_t i = 0; i < args.size(); i += 2) {
if ((i + 1) < args.size()) { if ((i + 1) < args.size()) {
if (cs.run(args[i].get_code()).get_bool()) { if (cs.call(args[i].get_code()).get_bool()) {
res = cs.run(args[i + 1].get_code()); res = cs.call(args[i + 1].get_code());
break; break;
} }
} else { } else {
res = cs.run(args[i].get_code()); res = cs.call(args[i].get_code());
break; break;
} }
} }
@ -127,7 +127,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
(args[i].get_type() == value_type::NONE) || (args[i].get_type() == value_type::NONE) ||
(args[i].get_integer() == val) (args[i].get_integer() == val)
) { ) {
res = cs.run(args[i + 1].get_code()); res = cs.call(args[i + 1].get_code());
return; return;
} }
} }
@ -140,7 +140,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
(args[i].get_type() == value_type::NONE) || (args[i].get_type() == value_type::NONE) ||
(args[i].get_float() == val) (args[i].get_float() == val)
) { ) {
res = cs.run(args[i + 1].get_code()); res = cs.call(args[i + 1].get_code());
return; return;
} }
} }
@ -153,7 +153,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
(args[i].get_type() == value_type::NONE) || (args[i].get_type() == value_type::NONE) ||
(args[i].get_string(cs) == val) (args[i].get_string(cs) == val)
) { ) {
res = cs.run(args[i + 1].get_code()); res = cs.call(args[i + 1].get_code());
return; return;
} }
} }
@ -166,7 +166,7 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
} }
if (args[1].get_bool()) { if (args[1].get_bool()) {
st.set(args[1]); st.set(args[1]);
res = cs.run(args[2].get_code()); res = cs.call(args[2].get_code());
} }
}); });
@ -233,8 +233,8 @@ LIBCUBESCRIPT_EXPORT void std_init_base(state &gcs) {
new_cmd_quiet(gcs, "while", "bb", [](auto &cs, auto args, auto &) { new_cmd_quiet(gcs, "while", "bb", [](auto &cs, auto args, auto &) {
auto cond = args[0].get_code(); auto cond = args[0].get_code();
auto body = args[1].get_code(); auto body = args[1].get_code();
while (cs.run(cond).get_bool()) { while (cs.call(cond).get_bool()) {
switch (cs.run_loop(body)) { switch (cs.call_loop(body)) {
case loop_state::BREAK: case loop_state::BREAK:
goto end; goto end;
default: /* continue and normal */ default: /* continue and normal */
@ -325,7 +325,7 @@ end:
throw error{cs, "cannot push an argument"}; throw error{cs, "cannot push an argument"};
} }
st.set(args[1]); st.set(args[1]);
res = cs.run(args[2].get_code()); res = cs.call(args[2].get_code());
}); });
new_cmd_quiet(gcs, "resetvar", "s", [](auto &cs, auto args, auto &) { new_cmd_quiet(gcs, "resetvar", "s", [](auto &cs, auto args, auto &) {

View File

@ -87,7 +87,7 @@ static void loop_list_conc(
r.push_back(' '); r.push_back(' ');
} }
any_value v{}; any_value v{};
switch (cs.run_loop(body, v)) { switch (cs.call_loop(body, v)) {
case loop_state::BREAK: case loop_state::BREAK:
goto end; goto end;
case loop_state::CONTINUE: case loop_state::CONTINUE:
@ -213,7 +213,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
++n; ++n;
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.get_raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (cs.run(body).get_bool()) { if (cs.call(body).get_bool()) {
res.set_integer(integer_type(n)); res.set_integer(integer_type(n));
return; return;
} }
@ -230,7 +230,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
++n; ++n;
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.get_raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (cs.run(body).get_bool()) { if (cs.call(body).get_bool()) {
if (p.parse()) { if (p.parse()) {
res.set_string(p.get_item()); res.set_string(p.get_item());
} }
@ -294,7 +294,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) {
idv.set_string(p.get_item()); idv.set_string(p.get_item());
st.set(std::move(idv)); st.set(std::move(idv));
switch (cs.run_loop(body)) { switch (cs.call_loop(body)) {
case loop_state::BREAK: case loop_state::BREAK:
return; return;
default: /* continue and normal */ default: /* continue and normal */
@ -318,7 +318,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
idv.set_string("", cs); idv.set_string("", cs);
} }
st2.set(std::move(idv)); st2.set(std::move(idv));
switch (cs.run_loop(body)) { switch (cs.call_loop(body)) {
case loop_state::BREAK: case loop_state::BREAK:
return; return;
default: /* continue and normal */ default: /* continue and normal */
@ -349,7 +349,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
idv.set_string("", cs); idv.set_string("", cs);
} }
st3.set(std::move(idv)); st3.set(std::move(idv));
switch (cs.run_loop(body)) { switch (cs.call_loop(body)) {
case loop_state::BREAK: case loop_state::BREAK:
return; return;
default: /* continue and normal */ default: /* continue and normal */
@ -387,7 +387,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) {
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.get_raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (cs.run(body).get_bool()) { if (cs.call(body).get_bool()) {
if (r.size()) { if (r.size()) {
r.push_back(' '); r.push_back(' ');
} }
@ -405,7 +405,7 @@ LIBCUBESCRIPT_EXPORT void std_init_list(state &gcs) {
for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) { for (list_parser p{cs, args[1].get_string(cs)}; p.parse(); ++n) {
idv.set_string(p.get_raw_item(), cs); idv.set_string(p.get_raw_item(), cs);
st.set(std::move(idv)); st.set(std::move(idv));
if (cs.run(body).get_bool()) { if (cs.call(body).get_bool()) {
r++; r++;
} }
} }
@ -525,7 +525,7 @@ struct ListSortFun {
xst.set(std::move(v)); xst.set(std::move(v));
v.set_string(yval.str, cs); v.set_string(yval.str, cs);
yst.set(std::move(v)); yst.set(std::move(v));
return cs.run(*body).get_bool(); return cs.call(*body).get_bool();
} }
}; };

View File

@ -15,7 +15,7 @@ namespace cs = cubescript;
struct skip_test {}; struct skip_test {};
static bool do_run_file(cs::state &cs, char const *fname) { static bool do_exec_file(cs::state &cs, char const *fname) {
FILE *f = std::fopen(fname, "rb"); FILE *f = std::fopen(fname, "rb");
if (!f) { if (!f) {
return false; return false;
@ -38,7 +38,7 @@ static bool do_run_file(cs::state &cs, char const *fname) {
buf[len] = '\0'; buf[len] = '\0';
cs.run(std::string_view{buf.get(), std::size_t(len)}, fname); cs.call(std::string_view{buf.get(), std::size_t(len)}, fname);
return true; return true;
} }
@ -62,7 +62,7 @@ int main(int argc, char **argv) {
gcs.new_command("assert", "ss#", [](auto &s, auto args, auto &ret) { gcs.new_command("assert", "ss#", [](auto &s, auto args, auto &ret) {
auto val = args[0]; auto val = args[0];
val.force_code(s); val.force_code(s);
if (!s.run(val.get_code()).get_bool()) { if (!s.call(val.get_code()).get_bool()) {
if (args[2].get_integer() > 1) { if (args[2].get_integer() > 1) {
throw cs::error{ throw cs::error{
s, "assertion failed: [%s] (%s)", s, "assertion failed: [%s] (%s)",
@ -79,7 +79,7 @@ int main(int argc, char **argv) {
}); });
try { try {
do_run_file(gcs, argv[1]); do_exec_file(gcs, argv[1]);
} catch (skip_test) { } catch (skip_test) {
return 77; return 77;
} catch (cs::error const &e) { } catch (cs::error const &e) {

View File

@ -164,7 +164,7 @@ void print_usage(std::string_view progname, bool err) {
err ? stderr : stdout, err ? stderr : stdout,
"Usage: %s [options] [file]\n" "Usage: %s [options] [file]\n"
"Options:\n" "Options:\n"
" -e str run string \"str\"\n" " -e str call string \"str\"\n"
" -i enter interactive mode after the above\n" " -i enter interactive mode after the above\n"
" -v show version information\n" " -v show version information\n"
" -h show this message\n" " -h show this message\n"
@ -189,7 +189,7 @@ static void do_sigint(int n) {
}); });
} }
static bool do_run_file( static bool do_exec_file(
cs::state &cs, std::string_view fname, cs::any_value &ret cs::state &cs, std::string_view fname, cs::any_value &ret
) { ) {
FILE *f = std::fopen(fname.data(), "rb"); FILE *f = std::fopen(fname.data(), "rb");
@ -214,7 +214,7 @@ static bool do_run_file(
buf[len] = '\0'; buf[len] = '\0';
ret = cs.run(std::string_view{buf.get(), std::size_t(len)}, fname); ret = cs.call(std::string_view{buf.get(), std::size_t(len)}, fname);
return true; return true;
} }
@ -224,11 +224,11 @@ static bool do_call(cs::state &cs, std::string_view line, bool file = false) {
signal(SIGINT, do_sigint); signal(SIGINT, do_sigint);
try { try {
if (file) { if (file) {
if (!do_run_file(cs, line, ret)) { if (!do_exec_file(cs, line, ret)) {
std::fprintf(stderr, "cannot read file: %s\n", line.data()); std::fprintf(stderr, "cannot read file: %s\n", line.data());
} }
} else { } else {
ret = cs.run(line); ret = cs.call(line);
} }
} catch (cs::error const &e) { } catch (cs::error const &e) {
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
@ -355,10 +355,10 @@ int main(int argc, char **argv) {
gcs.new_command("exec", "s", [](auto &css, auto args, auto &) { gcs.new_command("exec", "s", [](auto &css, auto args, auto &) {
auto file = args[0].get_string(css); auto file = args[0].get_string(css);
cs::any_value val{}; cs::any_value val{};
bool ret = do_run_file(css, file, val); bool ret = do_exec_file(css, file, val);
if (!ret) { if (!ret) {
throw cs::error( throw cs::error(
css, "could not run file \"%s\"", file.data() css, "could not execute file \"%s\"", file.data()
); );
} }
}); });