update according to ostd

master
Daniel Kolesa 2017-01-30 19:38:11 +01:00
parent 8dc423dcaa
commit 58bf658409
8 changed files with 58 additions and 53 deletions

View File

@ -4,6 +4,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <optional>
#include "cubescript_conf.hh" #include "cubescript_conf.hh"
#include <ostd/platform.hh> #include <ostd/platform.hh>
@ -14,7 +16,6 @@
#include <ostd/map.hh> #include <ostd/map.hh>
#include <ostd/range.hh> #include <ostd/range.hh>
#include <ostd/utility.hh> #include <ostd/utility.hh>
#include <ostd/maybe.hh>
#include <ostd/io.hh> #include <ostd/io.hh>
#include <ostd/functional.hh> #include <ostd/functional.hh>
#include <ostd/format.hh> #include <ostd/format.hh>
@ -419,10 +420,10 @@ struct OSTD_EXPORT CsState {
return p_inloop; return p_inloop;
} }
ostd::Maybe<CsString> run_file_str(ostd::ConstCharRange fname); std::optional<CsString> run_file_str(ostd::ConstCharRange fname);
ostd::Maybe<CsInt> run_file_int(ostd::ConstCharRange fname); std::optional<CsInt> run_file_int(ostd::ConstCharRange fname);
ostd::Maybe<CsFloat> run_file_float(ostd::ConstCharRange fname); std::optional<CsFloat> run_file_float(ostd::ConstCharRange fname);
ostd::Maybe<bool> run_file_bool(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, CsValue &ret);
bool run_file(ostd::ConstCharRange fname); 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_float_checked(CsFvar *fv, CsFloat v);
void set_var_str_checked(CsSvar *fv, ostd::ConstCharRange v); void set_var_str_checked(CsSvar *fv, ostd::ConstCharRange v);
ostd::Maybe<CsInt> get_var_int(ostd::ConstCharRange name); std::optional<CsInt> get_var_int(ostd::ConstCharRange name);
ostd::Maybe<CsFloat> get_var_float(ostd::ConstCharRange name); std::optional<CsFloat> get_var_float(ostd::ConstCharRange name);
ostd::Maybe<CsString> get_var_str(ostd::ConstCharRange name); std::optional<CsString> get_var_str(ostd::ConstCharRange name);
ostd::Maybe<CsInt> get_var_min_int(ostd::ConstCharRange name); std::optional<CsInt> get_var_min_int(ostd::ConstCharRange name);
ostd::Maybe<CsInt> get_var_max_int(ostd::ConstCharRange name); std::optional<CsInt> get_var_max_int(ostd::ConstCharRange name);
ostd::Maybe<CsFloat> get_var_min_float(ostd::ConstCharRange name); std::optional<CsFloat> get_var_min_float(ostd::ConstCharRange name);
ostd::Maybe<CsFloat> get_var_max_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); virtual void print_var(CsVar *v);
@ -751,12 +752,12 @@ private:
}; };
template<typename R> 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); return ostd::format(std::forward<R>(writer), IntFormat, val);
} }
template<typename R> 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( return ostd::format(
std::forward<R>(writer), std::forward<R>(writer),
(val == CsInt(val)) ? RoundFloatFormat : FloatFormat, val (val == CsInt(val)) ? RoundFloatFormat : FloatFormat, val

View File

@ -117,7 +117,7 @@ ostd::ConstCharRange CsErrorException::save_msg(
if (gs) { if (gs) {
/* we can attach line number */ /* we can attach line number */
ostd::CharRange r(cs.p_errbuf, sizeof(cs.p_errbuf)); ostd::CharRange r(cs.p_errbuf, sizeof(cs.p_errbuf));
ostd::Ptrdiff sz = -1; std::ptrdiff_t sz = -1;
if (!gs->src_name.empty()) { if (!gs->src_name.empty()) {
sz = ostd::format(r, "%s:%d: %s", gs->src_name, gs->current_line, msg); sz = ostd::format(r, "%s:%d: %s", gs->src_name, gs->current_line, msg);
} else { } else {
@ -144,7 +144,7 @@ static void bcode_ref(uint32_t *code) {
bcode_incr(&code[-1]); bcode_incr(&code[-1]);
break; break;
case CsCodeOffset: case CsCodeOffset:
code -= ostd::Ptrdiff(code[-1] >> 8); code -= std::ptrdiff_t(code[-1] >> 8);
bcode_incr(code); bcode_incr(code);
break; break;
} }
@ -163,7 +163,7 @@ static void bcode_unref(uint32_t *code) {
bcode_decr(&code[-1]); bcode_decr(&code[-1]);
break; break;
case CsCodeOffset: case CsCodeOffset:
code -= ostd::Ptrdiff(code[-1] >> 8); code -= std::ptrdiff_t(code[-1] >> 8);
bcode_decr(code); bcode_decr(code);
break; break;
} }
@ -1830,34 +1830,34 @@ static bool cs_run_file(
return true; return true;
} }
ostd::Maybe<CsString> CsState::run_file_str(ostd::ConstCharRange fname) { std::optional<CsString> CsState::run_file_str(ostd::ConstCharRange fname) {
CsValue ret; CsValue ret;
if (!cs_run_file(*this, fname, ret)) { if (!cs_run_file(*this, fname, ret)) {
return ostd::nothing; return std::nullopt;
} }
return ret.get_str(); 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; CsValue ret;
if (!cs_run_file(*this, fname, ret)) { if (!cs_run_file(*this, fname, ret)) {
return ostd::nothing; return std::nullopt;
} }
return ret.get_int(); 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; CsValue ret;
if (!cs_run_file(*this, fname, ret)) { if (!cs_run_file(*this, fname, ret)) {
return ostd::nothing; return std::nullopt;
} }
return ret.get_float(); 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; CsValue ret;
if (!cs_run_file(*this, fname, ret)) { if (!cs_run_file(*this, fname, ret)) {
return ostd::nothing; return std::nullopt;
} }
return ret.get_bool(); return ret.get_bool();
} }

View File

@ -303,7 +303,7 @@ static inline void bcode_incr(uint32_t *bc) {
static inline void bcode_decr(uint32_t *bc) { static inline void bcode_decr(uint32_t *bc) {
*bc -= 0x100; *bc -= 0x100;
if (ostd::Int32(*bc) < 0x100) { if (std::int32_t(*bc) < 0x100) {
delete[] bc; delete[] bc;
} }
} }

View File

@ -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); CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsIvar *>(id)->get_value(); 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); CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsFvar *>(id)->get_value(); 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); CsIdent *id = get_ident(name);
if (!id || id->is_svar()) { if (!id || id->is_svar()) {
return ostd::nothing; return std::nullopt;
} }
return CsString(static_cast<CsSvar *>(id)->get_value()); 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); CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsIvar *>(id)->get_val_min(); 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); CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsIvar *>(id)->get_val_max(); 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); CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsFvar *>(id)->get_val_min(); 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); CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return std::nullopt;
} }
return static_cast<CsFvar *>(id)->get_val_max(); return static_cast<CsFvar *>(id)->get_val_max();
} }
ostd::Maybe<CsString> std::optional<CsString>
CsState::get_alias_val(ostd::ConstCharRange name) { CsState::get_alias_val(ostd::ConstCharRange name) {
CsAlias *a = get_alias(name); CsAlias *a = get_alias(name);
if (!a) { if (!a) {
return ostd::nothing; return std::nullopt;
} }
if ((a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)) { if ((a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)) {
return ostd::nothing; return std::nullopt;
} }
return a->get_value().get_str(); return a->get_value().get_str();
} }

View File

@ -1,13 +1,14 @@
#ifndef CS_REPL_HAS_EDIT #ifndef CS_REPL_HAS_EDIT
/* use nothing (no line editing support) */ /* use nothing (no line editing support) */
#include <optional>
#include <ostd/string.hh> #include <ostd/string.hh>
#include <ostd/maybe.hh>
static void init_lineedit(CsState &, ostd::ConstCharRange) { 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()); ostd::write(pr->get_value());
std::string ret; std::string ret;
/* i really need to implement some sort of get_line for ostd streams */ /* i really need to implement some sort of get_line for ostd streams */

View File

@ -8,8 +8,9 @@
#include <ctype.h> #include <ctype.h>
#include <signal.h> #include <signal.h>
#include <optional>
#include <ostd/string.hh> #include <ostd/string.hh>
#include <ostd/maybe.hh>
#include "linenoise.hh" #include "linenoise.hh"
@ -59,13 +60,13 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
linenoiseSetFreeHintsCallback(ln_hint_free); 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()); auto line = linenoise(pr->get_value().data());
if (!line) { if (!line) {
/* linenoise traps ctrl-c, detect it and let the user exit */ /* linenoise traps ctrl-c, detect it and let the user exit */
if (errno == EAGAIN) { if (errno == EAGAIN) {
raise(SIGINT); raise(SIGINT);
return ostd::nothing; return std::nullopt;
} }
return std::string{}; return std::string{};
} }

View File

@ -5,8 +5,9 @@
#include <string.h> #include <string.h>
#include <optional>
#include <ostd/string.hh> #include <ostd/string.hh>
#include <ostd/maybe.hh>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
@ -68,7 +69,7 @@ static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
rl_redisplay_function = ln_hint; 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()); auto line = readline(pr->get_value().data());
if (!line) { if (!line) {
return std::string(); return std::string();

View File

@ -1,9 +1,10 @@
#include <signal.h> #include <signal.h>
#include <optional>
#include <ostd/platform.hh> #include <ostd/platform.hh>
#include <ostd/io.hh> #include <ostd/io.hh>
#include <ostd/string.hh> #include <ostd/string.hh>
#include <ostd/maybe.hh>
#include <cubescript/cubescript.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) { if (args.size() > 1) {
writer += '{'; writer += '{';
} }
for (ostd::Size i = 0; i < args.size(); ++i) { for (std::size_t i = 0; i < args.size(); ++i) {
if (i) { if (i) {
writer += ", "; writer += ", ";
} }