From 4068c96ec2fd6119c3391b91266d41e71c4a4c86 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sat, 20 Mar 2021 05:14:14 +0100 Subject: [PATCH] remove the auxiliary run_ APIs, they are fairly useless now --- include/cubescript/cubescript.hh | 16 ------- src/cs_vm.cc | 72 -------------------------------- src/cubescript.cc | 6 +-- src/lib_list.cc | 10 ++--- 4 files changed, 8 insertions(+), 96 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 7e241e7..d293f47 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -463,22 +463,6 @@ struct OSTD_EXPORT cs_state { void reset_var(std::string_view name); void touch_var(std::string_view name); - cs_strref run_str(cs_bcode *code); - cs_strref run_str(std::string_view code); - cs_strref run_str(cs_ident *id, cs_value_r args); - - cs_int run_int(cs_bcode *code); - cs_int run_int(std::string_view code); - cs_int run_int(cs_ident *id, cs_value_r args); - - cs_float run_float(cs_bcode *code); - cs_float run_float(std::string_view code); - cs_float run_float(cs_ident *id, cs_value_r args); - - bool run_bool(cs_bcode *code); - bool run_bool(std::string_view code); - bool run_bool(cs_ident *id, cs_value_r args); - void run(cs_bcode *code, cs_value &ret); void run(std::string_view code, cs_value &ret); void run(std::string_view code, cs_value &ret, std::string_view source); diff --git a/src/cs_vm.cc b/src/cs_vm.cc index dff7acc..70305d9 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -1661,78 +1661,6 @@ void cs_state::run(cs_ident *id, cs_value_r args, cs_value &ret) { } } -cs_strref cs_state::run_str(cs_bcode *code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_str(); -} - -cs_strref cs_state::run_str(std::string_view code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_str(); -} - -cs_strref cs_state::run_str(cs_ident *id, cs_value_r args) { - cs_value ret{*this}; - run(id, args, ret); - return ret.get_str(); -} - -cs_int cs_state::run_int(cs_bcode *code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_int(); -} - -cs_int cs_state::run_int(std::string_view code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_int(); -} - -cs_int cs_state::run_int(cs_ident *id, cs_value_r args) { - cs_value ret{*this}; - run(id, args, ret); - return ret.get_int(); -} - -cs_float cs_state::run_float(cs_bcode *code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_float(); -} - -cs_float cs_state::run_float(std::string_view code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_float(); -} - -cs_float cs_state::run_float(cs_ident *id, cs_value_r args) { - cs_value ret{*this}; - run(id, args, ret); - return ret.get_float(); -} - -bool cs_state::run_bool(cs_bcode *code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_bool(); -} - -bool cs_state::run_bool(std::string_view code) { - cs_value ret{*this}; - run(code, ret); - return ret.get_bool(); -} - -bool cs_state::run_bool(cs_ident *id, cs_value_r args) { - cs_value ret{*this}; - run(id, args, ret); - return ret.get_bool(); -} - cs_value cs_state::run(cs_bcode *code) { cs_value ret{*this}; run(code, ret); diff --git a/src/cubescript.cc b/src/cubescript.cc index 47a8113..6dd04e6 100644 --- a/src/cubescript.cc +++ b/src/cubescript.cc @@ -972,7 +972,7 @@ static inline void cs_do_loop( for (cs_int i = 0; i < n; ++i) { idv.set_int(offset + i * step); idv.push(); - if (cond && !cs.run_bool(cond)) { + if (cond && !cs.run(cond).get_bool()) { break; } switch (cs.run_loop(body)) { @@ -1057,7 +1057,7 @@ void cs_init_lib_base(cs_state &gcs) { gcs.new_command("cond", "ee2V", [](auto &cs, auto args, auto &res) { for (size_t i = 0; i < args.size(); i += 2) { if ((i + 1) < args.size()) { - if (cs.run_bool(args[i].get_code())) { + if (cs.run(args[i].get_code()).get_bool()) { cs.run(args[i + 1].get_code(), res); break; } @@ -1177,7 +1177,7 @@ void cs_init_lib_base(cs_state &gcs) { gcs.new_command("while", "ee", [](auto &cs, auto args, auto &) { cs_bcode *cond = args[0].get_code(), *body = args[1].get_code(); - while (cs.run_bool(cond)) { + while (cs.run(cond).get_bool()) { switch (cs.run_loop(body)) { case cs_loop_state::BREAK: goto end; diff --git a/src/lib_list.cc b/src/lib_list.cc index 113d3ca..e860cce 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -209,7 +209,7 @@ void cs_init_lib_list(cs_state &gcs) { ++n; idv.set_str(p.item); idv.push(); - if (cs.run_bool(body)) { + if (cs.run(body).get_bool()) { res.set_int(cs_int(n)); return; } @@ -228,7 +228,7 @@ void cs_init_lib_list(cs_state &gcs) { ++n; idv.set_str(p.item); idv.push(); - if (cs.run_bool(body)) { + if (cs.run(body).get_bool()) { if (list_parse(p, cs)) { res.set_str(list_get_item(p, cs)); } @@ -395,7 +395,7 @@ end: for (cs_list_parse_state p{args[1].get_str()}; list_parse(p, cs); ++n) { idv.set_str(p.item); idv.push(); - if (cs.run_bool(body)) { + if (cs.run(body).get_bool()) { if (r.size()) { r.push_back(' '); } @@ -415,7 +415,7 @@ end: for (cs_list_parse_state p{args[1].get_str()}; list_parse(p, cs); ++n) { idv.set_str(p.item); idv.push(); - if (cs.run_bool(body)) { + if (cs.run(body).get_bool()) { r++; } } @@ -529,7 +529,7 @@ struct ListSortFun { yv.set_str(yval.str); xv.push(); yv.push(); - return cs.run_bool(body); + return cs.run(body).get_bool(); } };