forked from OctaForge/libcubescript
update according to ostd
parent
8dc423dcaa
commit
58bf658409
|
@ -4,6 +4,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "cubescript_conf.hh"
|
||||
|
||||
#include <ostd/platform.hh>
|
||||
|
@ -14,7 +16,6 @@
|
|||
#include <ostd/map.hh>
|
||||
#include <ostd/range.hh>
|
||||
#include <ostd/utility.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
#include <ostd/io.hh>
|
||||
#include <ostd/functional.hh>
|
||||
#include <ostd/format.hh>
|
||||
|
@ -419,10 +420,10 @@ struct OSTD_EXPORT CsState {
|
|||
return p_inloop;
|
||||
}
|
||||
|
||||
ostd::Maybe<CsString> run_file_str(ostd::ConstCharRange fname);
|
||||
ostd::Maybe<CsInt> run_file_int(ostd::ConstCharRange fname);
|
||||
ostd::Maybe<CsFloat> run_file_float(ostd::ConstCharRange fname);
|
||||
ostd::Maybe<bool> run_file_bool(ostd::ConstCharRange fname);
|
||||
std::optional<CsString> run_file_str(ostd::ConstCharRange fname);
|
||||
std::optional<CsInt> run_file_int(ostd::ConstCharRange fname);
|
||||
std::optional<CsFloat> run_file_float(ostd::ConstCharRange fname);
|
||||
std::optional<bool> run_file_bool(ostd::ConstCharRange fname);
|
||||
bool run_file(ostd::ConstCharRange fname, CsValue &ret);
|
||||
bool run_file(ostd::ConstCharRange fname);
|
||||
|
||||
|
@ -445,17 +446,17 @@ struct OSTD_EXPORT CsState {
|
|||
void set_var_float_checked(CsFvar *fv, CsFloat v);
|
||||
void set_var_str_checked(CsSvar *fv, ostd::ConstCharRange v);
|
||||
|
||||
ostd::Maybe<CsInt> get_var_int(ostd::ConstCharRange name);
|
||||
ostd::Maybe<CsFloat> get_var_float(ostd::ConstCharRange name);
|
||||
ostd::Maybe<CsString> get_var_str(ostd::ConstCharRange name);
|
||||
std::optional<CsInt> get_var_int(ostd::ConstCharRange name);
|
||||
std::optional<CsFloat> get_var_float(ostd::ConstCharRange name);
|
||||
std::optional<CsString> get_var_str(ostd::ConstCharRange name);
|
||||
|
||||
ostd::Maybe<CsInt> get_var_min_int(ostd::ConstCharRange name);
|
||||
ostd::Maybe<CsInt> get_var_max_int(ostd::ConstCharRange name);
|
||||
std::optional<CsInt> get_var_min_int(ostd::ConstCharRange name);
|
||||
std::optional<CsInt> get_var_max_int(ostd::ConstCharRange name);
|
||||
|
||||
ostd::Maybe<CsFloat> get_var_min_float(ostd::ConstCharRange name);
|
||||
ostd::Maybe<CsFloat> get_var_max_float(ostd::ConstCharRange name);
|
||||
std::optional<CsFloat> get_var_min_float(ostd::ConstCharRange name);
|
||||
std::optional<CsFloat> get_var_max_float(ostd::ConstCharRange name);
|
||||
|
||||
ostd::Maybe<CsString> get_alias_val(ostd::ConstCharRange name);
|
||||
std::optional<CsString> get_alias_val(ostd::ConstCharRange name);
|
||||
|
||||
virtual void print_var(CsVar *v);
|
||||
|
||||
|
@ -751,12 +752,12 @@ private:
|
|||
};
|
||||
|
||||
template<typename R>
|
||||
inline ostd::Ptrdiff format_int(R &&writer, CsInt val) {
|
||||
inline std::ptrdiff_t format_int(R &&writer, CsInt val) {
|
||||
return ostd::format(std::forward<R>(writer), IntFormat, val);
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
inline ostd::Ptrdiff format_float(R &&writer, CsFloat val) {
|
||||
inline std::ptrdiff_t format_float(R &&writer, CsFloat val) {
|
||||
return ostd::format(
|
||||
std::forward<R>(writer),
|
||||
(val == CsInt(val)) ? RoundFloatFormat : FloatFormat, val
|
||||
|
|
22
src/cs_vm.cc
22
src/cs_vm.cc
|
@ -117,7 +117,7 @@ ostd::ConstCharRange CsErrorException::save_msg(
|
|||
if (gs) {
|
||||
/* we can attach line number */
|
||||
ostd::CharRange r(cs.p_errbuf, sizeof(cs.p_errbuf));
|
||||
ostd::Ptrdiff sz = -1;
|
||||
std::ptrdiff_t sz = -1;
|
||||
if (!gs->src_name.empty()) {
|
||||
sz = ostd::format(r, "%s:%d: %s", gs->src_name, gs->current_line, msg);
|
||||
} else {
|
||||
|
@ -144,7 +144,7 @@ static void bcode_ref(uint32_t *code) {
|
|||
bcode_incr(&code[-1]);
|
||||
break;
|
||||
case CsCodeOffset:
|
||||
code -= ostd::Ptrdiff(code[-1] >> 8);
|
||||
code -= std::ptrdiff_t(code[-1] >> 8);
|
||||
bcode_incr(code);
|
||||
break;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ static void bcode_unref(uint32_t *code) {
|
|||
bcode_decr(&code[-1]);
|
||||
break;
|
||||
case CsCodeOffset:
|
||||
code -= ostd::Ptrdiff(code[-1] >> 8);
|
||||
code -= std::ptrdiff_t(code[-1] >> 8);
|
||||
bcode_decr(code);
|
||||
break;
|
||||
}
|
||||
|
@ -1830,34 +1830,34 @@ static bool cs_run_file(
|
|||
return true;
|
||||
}
|
||||
|
||||
ostd::Maybe<CsString> CsState::run_file_str(ostd::ConstCharRange fname) {
|
||||
std::optional<CsString> CsState::run_file_str(ostd::ConstCharRange fname) {
|
||||
CsValue ret;
|
||||
if (!cs_run_file(*this, fname, ret)) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return ret.get_str();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsInt> CsState::run_file_int(ostd::ConstCharRange fname) {
|
||||
std::optional<CsInt> CsState::run_file_int(ostd::ConstCharRange fname) {
|
||||
CsValue ret;
|
||||
if (!cs_run_file(*this, fname, ret)) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return ret.get_int();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsFloat> CsState::run_file_float(ostd::ConstCharRange fname) {
|
||||
std::optional<CsFloat> CsState::run_file_float(ostd::ConstCharRange fname) {
|
||||
CsValue ret;
|
||||
if (!cs_run_file(*this, fname, ret)) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return ret.get_float();
|
||||
}
|
||||
|
||||
ostd::Maybe<bool> CsState::run_file_bool(ostd::ConstCharRange fname) {
|
||||
std::optional<bool> CsState::run_file_bool(ostd::ConstCharRange fname) {
|
||||
CsValue ret;
|
||||
if (!cs_run_file(*this, fname, ret)) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return ret.get_bool();
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ static inline void bcode_incr(uint32_t *bc) {
|
|||
|
||||
static inline void bcode_decr(uint32_t *bc) {
|
||||
*bc -= 0x100;
|
||||
if (ostd::Int32(*bc) < 0x100) {
|
||||
if (std::int32_t(*bc) < 0x100) {
|
||||
delete[] bc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -764,70 +764,70 @@ void CsState::set_var_str(
|
|||
}
|
||||
}
|
||||
|
||||
ostd::Maybe<CsInt> CsState::get_var_int(ostd::ConstCharRange name) {
|
||||
std::optional<CsInt> CsState::get_var_int(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_ivar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsIvar *>(id)->get_value();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) {
|
||||
std::optional<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_fvar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsFvar *>(id)->get_value();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsString> CsState::get_var_str(ostd::ConstCharRange name) {
|
||||
std::optional<CsString> CsState::get_var_str(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_svar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return CsString(static_cast<CsSvar *>(id)->get_value());
|
||||
}
|
||||
|
||||
ostd::Maybe<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) {
|
||||
std::optional<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_ivar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsIvar *>(id)->get_val_min();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) {
|
||||
std::optional<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_ivar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsIvar *>(id)->get_val_max();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) {
|
||||
std::optional<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_fvar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsFvar *>(id)->get_val_min();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) {
|
||||
std::optional<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) {
|
||||
CsIdent *id = get_ident(name);
|
||||
if (!id || id->is_fvar()) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<CsFvar *>(id)->get_val_max();
|
||||
}
|
||||
|
||||
ostd::Maybe<CsString>
|
||||
std::optional<CsString>
|
||||
CsState::get_alias_val(ostd::ConstCharRange name) {
|
||||
CsAlias *a = get_alias(name);
|
||||
if (!a) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
if ((a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)) {
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return a->get_value().get_str();
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#ifndef CS_REPL_HAS_EDIT
|
||||
/* use nothing (no line editing support) */
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <ostd/string.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
|
||||
static void init_lineedit(CsState &, ostd::ConstCharRange) {
|
||||
}
|
||||
|
||||
static ostd::Maybe<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
static std::optional<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
ostd::write(pr->get_value());
|
||||
std::string ret;
|
||||
/* i really need to implement some sort of get_line for ostd streams */
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <ostd/string.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
|
||||
#include "linenoise.hh"
|
||||
|
||||
|
@ -59,13 +60,13 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
|
|||
linenoiseSetFreeHintsCallback(ln_hint_free);
|
||||
}
|
||||
|
||||
static ostd::Maybe<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
static std::optional<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
auto line = linenoise(pr->get_value().data());
|
||||
if (!line) {
|
||||
/* linenoise traps ctrl-c, detect it and let the user exit */
|
||||
if (errno == EAGAIN) {
|
||||
raise(SIGINT);
|
||||
return ostd::nothing;
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::string{};
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <ostd/string.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
@ -68,7 +69,7 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
|
|||
rl_redisplay_function = ln_hint;
|
||||
}
|
||||
|
||||
static ostd::Maybe<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
static std::optional<std::string> read_line(CsState &, CsSvar *pr) {
|
||||
auto line = readline(pr->get_value().data());
|
||||
if (!line) {
|
||||
return std::string();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include <signal.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <ostd/platform.hh>
|
||||
#include <ostd/io.hh>
|
||||
#include <ostd/string.hh>
|
||||
#include <ostd/maybe.hh>
|
||||
|
||||
#include <cubescript/cubescript.hh>
|
||||
|
||||
|
@ -110,7 +111,7 @@ static inline void fill_cmd_args(std::string &writer, ostd::ConstCharRange args)
|
|||
if (args.size() > 1) {
|
||||
writer += '{';
|
||||
}
|
||||
for (ostd::Size i = 0; i < args.size(); ++i) {
|
||||
for (std::size_t i = 0; i < args.size(); ++i) {
|
||||
if (i) {
|
||||
writer += ", ";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue