fix build after style update
parent
74edc2821d
commit
8343979e03
|
@ -90,12 +90,12 @@ struct OSTD_EXPORT cs_value {
|
||||||
void set_str(cs_string val);
|
void set_str(cs_string val);
|
||||||
void set_null();
|
void set_null();
|
||||||
void set_code(cs_bcode *val);
|
void set_code(cs_bcode *val);
|
||||||
void set_cstr(ostd::ConstCharRange val);
|
void set_cstr(ostd::string_range val);
|
||||||
void set_ident(cs_ident *val);
|
void set_ident(cs_ident *val);
|
||||||
void set_macro(ostd::ConstCharRange val);
|
void set_macro(ostd::string_range val);
|
||||||
|
|
||||||
cs_string get_str() const;
|
cs_string get_str() const;
|
||||||
ostd::ConstCharRange get_strr() const;
|
ostd::string_range get_strr() const;
|
||||||
cs_int get_int() const;
|
cs_int get_int() const;
|
||||||
cs_float get_float() const;
|
cs_float get_float() const;
|
||||||
cs_bcode *get_code() const;
|
cs_bcode *get_code() const;
|
||||||
|
@ -107,7 +107,7 @@ struct OSTD_EXPORT cs_value {
|
||||||
void force_null();
|
void force_null();
|
||||||
cs_float force_float();
|
cs_float force_float();
|
||||||
cs_int force_int();
|
cs_int force_int();
|
||||||
ostd::ConstCharRange force_str();
|
ostd::string_range force_str();
|
||||||
|
|
||||||
bool code_is_empty() const;
|
bool code_is_empty() const;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ struct OSTD_EXPORT cs_ident {
|
||||||
cs_ident &operator=(cs_ident &&) = delete;
|
cs_ident &operator=(cs_ident &&) = delete;
|
||||||
|
|
||||||
cs_ident_type get_type() const;
|
cs_ident_type get_type() const;
|
||||||
ostd::ConstCharRange get_name() const;
|
ostd::string_range get_name() const;
|
||||||
int get_flags() const;
|
int get_flags() const;
|
||||||
int get_index() const;
|
int get_index() const;
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ struct OSTD_EXPORT cs_ident {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cs_ident(cs_ident_type tp, ostd::ConstCharRange name, int flags = 0);
|
cs_ident(cs_ident_type tp, ostd::string_range name, int flags = 0);
|
||||||
|
|
||||||
cs_string p_name;
|
cs_string p_name;
|
||||||
/* represents the cs_ident_type above, but internally it has a wider variety
|
/* represents the cs_ident_type above, but internally it has a wider variety
|
||||||
|
@ -204,7 +204,7 @@ struct OSTD_EXPORT cs_var: cs_ident {
|
||||||
friend struct cs_shared_state;
|
friend struct cs_shared_state;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cs_var(cs_ident_type tp, ostd::ConstCharRange name, cs_var_cb func, int flags = 0);
|
cs_var(cs_ident_type tp, ostd::string_range name, cs_var_cb func, int flags = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_var_cb cb_var;
|
cs_var_cb cb_var;
|
||||||
|
@ -232,7 +232,7 @@ struct OSTD_EXPORT cs_ivar: cs_var {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_ivar(
|
cs_ivar(
|
||||||
ostd::ConstCharRange n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
ostd::string_range n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
||||||
);
|
);
|
||||||
|
|
||||||
cs_int p_storage, p_minval, p_maxval, p_overrideval;
|
cs_int p_storage, p_minval, p_maxval, p_overrideval;
|
||||||
|
@ -252,7 +252,7 @@ struct OSTD_EXPORT cs_fvar: cs_var {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_fvar(
|
cs_fvar(
|
||||||
ostd::ConstCharRange n, cs_float m, cs_float x, cs_float v,
|
ostd::string_range n, cs_float m, cs_float x, cs_float v,
|
||||||
cs_var_cb f, int flags
|
cs_var_cb f, int flags
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -263,13 +263,13 @@ struct OSTD_EXPORT cs_svar: cs_var {
|
||||||
friend struct cs_state;
|
friend struct cs_state;
|
||||||
friend struct cs_shared_state;
|
friend struct cs_shared_state;
|
||||||
|
|
||||||
ostd::ConstCharRange get_value() const;
|
ostd::string_range get_value() const;
|
||||||
void set_value(cs_string val);
|
void set_value(cs_string val);
|
||||||
|
|
||||||
cs_string to_printable() const final;
|
cs_string to_printable() const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_svar(ostd::ConstCharRange n, cs_string v, cs_var_cb f, int flags);
|
cs_svar(ostd::string_range n, cs_string v, cs_var_cb f, int flags);
|
||||||
|
|
||||||
cs_string p_storage, p_overrideval;
|
cs_string p_storage, p_overrideval;
|
||||||
};
|
};
|
||||||
|
@ -290,11 +290,11 @@ struct OSTD_EXPORT cs_alias: cs_ident {
|
||||||
void get_cstr(cs_value &v) const;
|
void get_cstr(cs_value &v) const;
|
||||||
void get_cval(cs_value &v) const;
|
void get_cval(cs_value &v) const;
|
||||||
private:
|
private:
|
||||||
cs_alias(ostd::ConstCharRange n, cs_string a, int flags);
|
cs_alias(ostd::string_range n, cs_string a, int flags);
|
||||||
cs_alias(ostd::ConstCharRange n, cs_int a, int flags);
|
cs_alias(ostd::string_range n, cs_int a, int flags);
|
||||||
cs_alias(ostd::ConstCharRange n, cs_float a, int flags);
|
cs_alias(ostd::string_range n, cs_float a, int flags);
|
||||||
cs_alias(ostd::ConstCharRange n, int flags);
|
cs_alias(ostd::string_range n, int flags);
|
||||||
cs_alias(ostd::ConstCharRange n, cs_value v, int flags);
|
cs_alias(ostd::string_range n, cs_value v, int flags);
|
||||||
|
|
||||||
cs_bcode *p_acode;
|
cs_bcode *p_acode;
|
||||||
cs_ident_stack *p_astack;
|
cs_ident_stack *p_astack;
|
||||||
|
@ -306,12 +306,12 @@ struct cs_command: cs_ident {
|
||||||
friend struct cs_shared_state;
|
friend struct cs_shared_state;
|
||||||
friend struct cs_cmd_internal;
|
friend struct cs_cmd_internal;
|
||||||
|
|
||||||
ostd::ConstCharRange get_args() const;
|
ostd::string_range get_args() const;
|
||||||
int get_num_args() const;
|
int get_num_args() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_command(
|
cs_command(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange args,
|
ostd::string_range name, ostd::string_range args,
|
||||||
int numargs, cs_command_cb func
|
int numargs, cs_command_cb func
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -362,58 +362,58 @@ struct OSTD_EXPORT cs_state {
|
||||||
void clear_override(cs_ident &id);
|
void clear_override(cs_ident &id);
|
||||||
void clear_overrides();
|
void clear_overrides();
|
||||||
|
|
||||||
cs_ident *new_ident(ostd::ConstCharRange name, int flags = CS_IDF_UNKNOWN);
|
cs_ident *new_ident(ostd::string_range name, int flags = CS_IDF_UNKNOWN);
|
||||||
cs_ident *force_ident(cs_value &v);
|
cs_ident *force_ident(cs_value &v);
|
||||||
|
|
||||||
cs_ivar *new_ivar(
|
cs_ivar *new_ivar(
|
||||||
ostd::ConstCharRange n, cs_int m, cs_int x, cs_int v,
|
ostd::string_range n, cs_int m, cs_int x, cs_int v,
|
||||||
cs_var_cb f = cs_var_cb(), int flags = 0
|
cs_var_cb f = cs_var_cb(), int flags = 0
|
||||||
);
|
);
|
||||||
cs_fvar *new_fvar(
|
cs_fvar *new_fvar(
|
||||||
ostd::ConstCharRange n, cs_float m, cs_float x, cs_float v,
|
ostd::string_range n, cs_float m, cs_float x, cs_float v,
|
||||||
cs_var_cb f = cs_var_cb(), int flags = 0
|
cs_var_cb f = cs_var_cb(), int flags = 0
|
||||||
);
|
);
|
||||||
cs_svar *new_svar(
|
cs_svar *new_svar(
|
||||||
ostd::ConstCharRange n, cs_string v,
|
ostd::string_range n, cs_string v,
|
||||||
cs_var_cb f = cs_var_cb(), int flags = 0
|
cs_var_cb f = cs_var_cb(), int flags = 0
|
||||||
);
|
);
|
||||||
|
|
||||||
cs_command *new_command(
|
cs_command *new_command(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange args, cs_command_cb func
|
ostd::string_range name, ostd::string_range args, cs_command_cb func
|
||||||
);
|
);
|
||||||
|
|
||||||
cs_ident *get_ident(ostd::ConstCharRange name);
|
cs_ident *get_ident(ostd::string_range name);
|
||||||
cs_alias *get_alias(ostd::ConstCharRange name);
|
cs_alias *get_alias(ostd::string_range name);
|
||||||
bool have_ident(ostd::ConstCharRange name);
|
bool have_ident(ostd::string_range name);
|
||||||
|
|
||||||
cs_ident_r get_idents();
|
cs_ident_r get_idents();
|
||||||
cs_const_ident_r get_idents() const;
|
cs_const_ident_r get_idents() const;
|
||||||
|
|
||||||
void reset_var(ostd::ConstCharRange name);
|
void reset_var(ostd::string_range name);
|
||||||
void touch_var(ostd::ConstCharRange name);
|
void touch_var(ostd::string_range name);
|
||||||
|
|
||||||
cs_string run_str(cs_bcode *code);
|
cs_string run_str(cs_bcode *code);
|
||||||
cs_string run_str(ostd::ConstCharRange code);
|
cs_string run_str(ostd::string_range code);
|
||||||
cs_string run_str(cs_ident *id, cs_value_r args);
|
cs_string run_str(cs_ident *id, cs_value_r args);
|
||||||
|
|
||||||
cs_int run_int(cs_bcode *code);
|
cs_int run_int(cs_bcode *code);
|
||||||
cs_int run_int(ostd::ConstCharRange code);
|
cs_int run_int(ostd::string_range code);
|
||||||
cs_int run_int(cs_ident *id, cs_value_r args);
|
cs_int run_int(cs_ident *id, cs_value_r args);
|
||||||
|
|
||||||
cs_float run_float(cs_bcode *code);
|
cs_float run_float(cs_bcode *code);
|
||||||
cs_float run_float(ostd::ConstCharRange code);
|
cs_float run_float(ostd::string_range code);
|
||||||
cs_float run_float(cs_ident *id, cs_value_r args);
|
cs_float run_float(cs_ident *id, cs_value_r args);
|
||||||
|
|
||||||
bool run_bool(cs_bcode *code);
|
bool run_bool(cs_bcode *code);
|
||||||
bool run_bool(ostd::ConstCharRange code);
|
bool run_bool(ostd::string_range code);
|
||||||
bool run_bool(cs_ident *id, cs_value_r args);
|
bool run_bool(cs_ident *id, cs_value_r args);
|
||||||
|
|
||||||
void run(cs_bcode *code, cs_value &ret);
|
void run(cs_bcode *code, cs_value &ret);
|
||||||
void run(ostd::ConstCharRange code, cs_value &ret);
|
void run(ostd::string_range code, cs_value &ret);
|
||||||
void run(cs_ident *id, cs_value_r args, cs_value &ret);
|
void run(cs_ident *id, cs_value_r args, cs_value &ret);
|
||||||
|
|
||||||
void run(cs_bcode *code);
|
void run(cs_bcode *code);
|
||||||
void run(ostd::ConstCharRange code);
|
void run(ostd::string_range code);
|
||||||
void run(cs_ident *id, cs_value_r args);
|
void run(cs_ident *id, cs_value_r args);
|
||||||
|
|
||||||
CsLoopState run_loop(cs_bcode *code, cs_value &ret);
|
CsLoopState run_loop(cs_bcode *code, cs_value &ret);
|
||||||
|
@ -423,43 +423,43 @@ struct OSTD_EXPORT cs_state {
|
||||||
return p_inloop;
|
return p_inloop;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_string> run_file_str(ostd::ConstCharRange fname);
|
std::optional<cs_string> run_file_str(ostd::string_range fname);
|
||||||
std::optional<cs_int> run_file_int(ostd::ConstCharRange fname);
|
std::optional<cs_int> run_file_int(ostd::string_range fname);
|
||||||
std::optional<cs_float> run_file_float(ostd::ConstCharRange fname);
|
std::optional<cs_float> run_file_float(ostd::string_range fname);
|
||||||
std::optional<bool> run_file_bool(ostd::ConstCharRange fname);
|
std::optional<bool> run_file_bool(ostd::string_range fname);
|
||||||
bool run_file(ostd::ConstCharRange fname, cs_value &ret);
|
bool run_file(ostd::string_range fname, cs_value &ret);
|
||||||
bool run_file(ostd::ConstCharRange fname);
|
bool run_file(ostd::string_range fname);
|
||||||
|
|
||||||
void set_alias(ostd::ConstCharRange name, cs_value v);
|
void set_alias(ostd::string_range name, cs_value v);
|
||||||
|
|
||||||
void set_var_int(
|
void set_var_int(
|
||||||
ostd::ConstCharRange name, cs_int v,
|
ostd::string_range name, cs_int v,
|
||||||
bool dofunc = true, bool doclamp = true
|
bool dofunc = true, bool doclamp = true
|
||||||
);
|
);
|
||||||
void set_var_float(
|
void set_var_float(
|
||||||
ostd::ConstCharRange name, cs_float v,
|
ostd::string_range name, cs_float v,
|
||||||
bool dofunc = true, bool doclamp = true
|
bool dofunc = true, bool doclamp = true
|
||||||
);
|
);
|
||||||
void set_var_str(
|
void set_var_str(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange v, bool dofunc = true
|
ostd::string_range name, ostd::string_range v, bool dofunc = true
|
||||||
);
|
);
|
||||||
|
|
||||||
void set_var_int_checked(cs_ivar *iv, cs_int v);
|
void set_var_int_checked(cs_ivar *iv, cs_int v);
|
||||||
void set_var_int_checked(cs_ivar *iv, cs_value_r args);
|
void set_var_int_checked(cs_ivar *iv, cs_value_r args);
|
||||||
void set_var_float_checked(cs_fvar *fv, cs_float v);
|
void set_var_float_checked(cs_fvar *fv, cs_float v);
|
||||||
void set_var_str_checked(cs_svar *fv, ostd::ConstCharRange v);
|
void set_var_str_checked(cs_svar *fv, ostd::string_range v);
|
||||||
|
|
||||||
std::optional<cs_int> get_var_int(ostd::ConstCharRange name);
|
std::optional<cs_int> get_var_int(ostd::string_range name);
|
||||||
std::optional<cs_float> get_var_float(ostd::ConstCharRange name);
|
std::optional<cs_float> get_var_float(ostd::string_range name);
|
||||||
std::optional<cs_string> get_var_str(ostd::ConstCharRange name);
|
std::optional<cs_string> get_var_str(ostd::string_range name);
|
||||||
|
|
||||||
std::optional<cs_int> get_var_min_int(ostd::ConstCharRange name);
|
std::optional<cs_int> get_var_min_int(ostd::string_range name);
|
||||||
std::optional<cs_int> get_var_max_int(ostd::ConstCharRange name);
|
std::optional<cs_int> get_var_max_int(ostd::string_range name);
|
||||||
|
|
||||||
std::optional<cs_float> get_var_min_float(ostd::ConstCharRange name);
|
std::optional<cs_float> get_var_min_float(ostd::string_range name);
|
||||||
std::optional<cs_float> get_var_max_float(ostd::ConstCharRange name);
|
std::optional<cs_float> get_var_max_float(ostd::string_range name);
|
||||||
|
|
||||||
std::optional<cs_string> get_alias_val(ostd::ConstCharRange name);
|
std::optional<cs_string> get_alias_val(ostd::string_range name);
|
||||||
|
|
||||||
virtual void print_var(cs_var *v);
|
virtual void print_var(cs_var *v);
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ struct cs_error {
|
||||||
p_errmsg(v.p_errmsg), p_stack(std::move(v.p_stack))
|
p_errmsg(v.p_errmsg), p_stack(std::move(v.p_stack))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ostd::ConstCharRange what() const {
|
ostd::string_range what() const {
|
||||||
return p_errmsg;
|
return p_errmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ struct cs_error {
|
||||||
return p_stack;
|
return p_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_error(cs_state &cs, ostd::ConstCharRange msg):
|
cs_error(cs_state &cs, ostd::string_range msg):
|
||||||
p_errmsg(), p_stack(cs)
|
p_errmsg(), p_stack(cs)
|
||||||
{
|
{
|
||||||
p_errmsg = save_msg(cs, msg);
|
p_errmsg = save_msg(cs, msg);
|
||||||
|
@ -530,16 +530,16 @@ struct cs_error {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
cs_error(cs_state &cs, ostd::ConstCharRange msg, A &&...args):
|
cs_error(cs_state &cs, ostd::string_range msg, A &&...args):
|
||||||
p_errmsg(), p_stack(cs)
|
p_errmsg(), p_stack(cs)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
char fbuf[512];
|
char fbuf[512];
|
||||||
auto ret = ostd::format(
|
auto ret = ostd::format(
|
||||||
ostd::CharRange(fbuf, fbuf + sizeof(fbuf)), msg,
|
ostd::char_range(fbuf, fbuf + sizeof(fbuf)), msg,
|
||||||
std::forward<A>(args)...
|
std::forward<A>(args)...
|
||||||
);
|
);
|
||||||
p_errmsg = save_msg(cs, ostd::CharRange(fbuf, fbuf + ret));
|
p_errmsg = save_msg(cs, ostd::char_range(fbuf, fbuf + ret));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
p_errmsg = save_msg(cs, msg);
|
p_errmsg = save_msg(cs, msg);
|
||||||
}
|
}
|
||||||
|
@ -548,9 +548,9 @@ struct cs_error {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cs_stack_state save_stack(cs_state &cs);
|
cs_stack_state save_stack(cs_state &cs);
|
||||||
ostd::ConstCharRange save_msg(cs_state &cs, ostd::ConstCharRange v);
|
ostd::string_range save_msg(cs_state &cs, ostd::string_range v);
|
||||||
|
|
||||||
ostd::ConstCharRange p_errmsg;
|
ostd::string_range p_errmsg;
|
||||||
cs_stack_state p_stack;
|
cs_stack_state p_stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ private:
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
template<typename R>
|
template<typename R>
|
||||||
inline size_t escape_string(R &&writer, ostd::ConstCharRange str) {
|
inline size_t escape_string(R &&writer, ostd::string_range str) {
|
||||||
size_t ret = 2;
|
size_t ret = 2;
|
||||||
writer.put('"');
|
writer.put('"');
|
||||||
for (; !str.empty(); str.pop_front()) {
|
for (; !str.empty(); str.pop_front()) {
|
||||||
|
@ -612,7 +612,7 @@ namespace util {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
inline size_t unescape_string(R &&writer, ostd::ConstCharRange str) {
|
inline size_t unescape_string(R &&writer, ostd::string_range str) {
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
for (; !str.empty(); str.pop_front()) {
|
for (; !str.empty(); str.pop_front()) {
|
||||||
if (str.front() == '^') {
|
if (str.front() == '^') {
|
||||||
|
@ -660,24 +660,24 @@ namespace util {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSTD_EXPORT ostd::ConstCharRange parse_string(
|
OSTD_EXPORT ostd::string_range parse_string(
|
||||||
cs_state &cs, ostd::ConstCharRange str, size_t &nlines
|
cs_state &cs, ostd::string_range str, size_t &nlines
|
||||||
);
|
);
|
||||||
|
|
||||||
inline ostd::ConstCharRange parse_string(
|
inline ostd::string_range parse_string(
|
||||||
cs_state &cs, ostd::ConstCharRange str
|
cs_state &cs, ostd::string_range str
|
||||||
) {
|
) {
|
||||||
size_t nlines;
|
size_t nlines;
|
||||||
return parse_string(cs, str, nlines);
|
return parse_string(cs, str, nlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSTD_EXPORT ostd::ConstCharRange parse_word(
|
OSTD_EXPORT ostd::string_range parse_word(
|
||||||
cs_state &cs, ostd::ConstCharRange str
|
cs_state &cs, ostd::string_range str
|
||||||
);
|
);
|
||||||
|
|
||||||
struct OSTD_EXPORT ListParser {
|
struct OSTD_EXPORT ListParser {
|
||||||
ListParser() = delete;
|
ListParser() = delete;
|
||||||
ListParser(cs_state &cs, ostd::ConstCharRange src):
|
ListParser(cs_state &cs, ostd::string_range src):
|
||||||
p_state(cs), p_input(src)
|
p_state(cs), p_input(src)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -700,23 +700,23 @@ namespace util {
|
||||||
return std::move(app.get());
|
return std::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange &get_raw_item(bool quoted = false) {
|
ostd::string_range &get_raw_item(bool quoted = false) {
|
||||||
return quoted ? p_quote : p_item;
|
return quoted ? p_quote : p_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange const &get_raw_item(bool quoted = false) const {
|
ostd::string_range const &get_raw_item(bool quoted = false) const {
|
||||||
return quoted ? p_quote : p_item;
|
return quoted ? p_quote : p_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange &get_input() {
|
ostd::string_range &get_input() {
|
||||||
return p_input;
|
return p_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ostd::ConstCharRange p_quote = ostd::ConstCharRange();
|
ostd::string_range p_quote = ostd::string_range();
|
||||||
ostd::ConstCharRange p_item = ostd::ConstCharRange();
|
ostd::string_range p_item = ostd::string_range();
|
||||||
cs_state &p_state;
|
cs_state &p_state;
|
||||||
ostd::ConstCharRange p_input;
|
ostd::string_range p_input;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
|
@ -743,7 +743,7 @@ private:
|
||||||
template<typename R>
|
template<typename R>
|
||||||
inline size_t tvals_concat(
|
inline size_t tvals_concat(
|
||||||
R &&writer, cs_value_r vals,
|
R &&writer, cs_value_r vals,
|
||||||
ostd::ConstCharRange sep = ostd::ConstCharRange()
|
ostd::string_range sep = ostd::string_range()
|
||||||
) {
|
) {
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
for (size_t i = 0; i < vals.size(); ++i) {
|
for (size_t i = 0; i < vals.size(); ++i) {
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
ostd::ConstCharRange cs_gen_state::get_str() {
|
ostd::string_range cs_gen_state::get_str() {
|
||||||
size_t nl;
|
size_t nl;
|
||||||
ostd::ConstCharRange beg = source;
|
ostd::string_range beg = source;
|
||||||
source = util::parse_string(cs, source, nl);
|
source = util::parse_string(cs, source, nl);
|
||||||
current_line += nl - 1;
|
current_line += nl - 1;
|
||||||
ostd::ConstCharRange ret = ostd::slice_until(beg, source);
|
ostd::string_range ret = ostd::slice_until(beg, source);
|
||||||
return ret.slice(1, ret.size() - 1);
|
return ret.slice(1, ret.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ cs_string cs_gen_state::get_str_dup(bool unescape) {
|
||||||
return std::move(app.get());
|
return std::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_gen_state::read_macro_name() {
|
ostd::string_range cs_gen_state::read_macro_name() {
|
||||||
auto op = source;
|
auto op = source;
|
||||||
char c = current();
|
char c = current();
|
||||||
if (!isalpha(c) && (c != '_')) {
|
if (!isalpha(c) && (c != '_')) {
|
||||||
|
@ -40,7 +40,7 @@ ostd::ConstCharRange cs_gen_state::read_macro_name() {
|
||||||
return ostd::slice_until(op, source);
|
return ostd::slice_until(op, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
char cs_gen_state::skip_until(ostd::ConstCharRange chars) {
|
char cs_gen_state::skip_until(ostd::string_range chars) {
|
||||||
char c = current();
|
char c = current();
|
||||||
while (c && ostd::find(chars, c).empty()) {
|
while (c && ostd::find(chars, c).empty()) {
|
||||||
next_char();
|
next_char();
|
||||||
|
@ -92,7 +92,7 @@ void cs_gen_state::skip_comments() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_gen_state::get_word() {
|
ostd::string_range cs_gen_state::get_word() {
|
||||||
auto beg = source;
|
auto beg = source;
|
||||||
source = util::parse_word(cs, source);
|
source = util::parse_word(cs, source);
|
||||||
return ostd::slice_until(beg, source);
|
return ostd::slice_until(beg, source);
|
||||||
|
@ -108,20 +108,20 @@ static inline int cs_ret_code(int type, int def = 0) {
|
||||||
static void compilestatements(
|
static void compilestatements(
|
||||||
cs_gen_state &gs, int rettype, int brak = '\0', int prevargs = 0
|
cs_gen_state &gs, int rettype, int brak = '\0', int prevargs = 0
|
||||||
);
|
);
|
||||||
static inline std::pair<ostd::ConstCharRange, size_t> compileblock(
|
static inline std::pair<ostd::string_range, size_t> compileblock(
|
||||||
cs_gen_state &gs, ostd::ConstCharRange p, size_t line,
|
cs_gen_state &gs, ostd::string_range p, size_t line,
|
||||||
int rettype = CsRetNull, int brak = '\0'
|
int rettype = CsRetNull, int brak = '\0'
|
||||||
);
|
);
|
||||||
|
|
||||||
void cs_gen_state::gen_int(ostd::ConstCharRange word) {
|
void cs_gen_state::gen_int(ostd::string_range word) {
|
||||||
gen_int(cs_parse_int(word));
|
gen_int(cs_parse_int(word));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_gen_state::gen_float(ostd::ConstCharRange word) {
|
void cs_gen_state::gen_float(ostd::string_range word) {
|
||||||
gen_float(cs_parse_float(word));
|
gen_float(cs_parse_float(word));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_gen_state::gen_value(int wordtype, ostd::ConstCharRange word, int line) {
|
void cs_gen_state::gen_value(int wordtype, ostd::string_range word, int line) {
|
||||||
switch (wordtype) {
|
switch (wordtype) {
|
||||||
case CsValCany:
|
case CsValCany:
|
||||||
if (!word.empty()) {
|
if (!word.empty()) {
|
||||||
|
@ -171,15 +171,15 @@ static inline void compileblock(cs_gen_state &gs) {
|
||||||
gs.code.push_back(CsCodeEmpty);
|
gs.code.push_back(CsCodeEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::pair<ostd::ConstCharRange, size_t> compileblock(
|
static inline std::pair<ostd::string_range, size_t> compileblock(
|
||||||
cs_gen_state &gs, ostd::ConstCharRange p, size_t line, int rettype, int brak
|
cs_gen_state &gs, ostd::string_range p, size_t line, int rettype, int brak
|
||||||
) {
|
) {
|
||||||
size_t start = gs.code.size();
|
size_t start = gs.code.size();
|
||||||
gs.code.push_back(CsCodeBlock);
|
gs.code.push_back(CsCodeBlock);
|
||||||
gs.code.push_back(CsCodeOffset | ((start + 2) << 8));
|
gs.code.push_back(CsCodeOffset | ((start + 2) << 8));
|
||||||
size_t retline = line;
|
size_t retline = line;
|
||||||
if (p) {
|
if (p) {
|
||||||
ostd::ConstCharRange op = gs.source;
|
ostd::string_range op = gs.source;
|
||||||
size_t oldline = gs.current_line;
|
size_t oldline = gs.current_line;
|
||||||
gs.source = p;
|
gs.source = p;
|
||||||
gs.current_line = line;
|
gs.current_line = line;
|
||||||
|
@ -207,7 +207,7 @@ static inline void compileunescapestr(cs_gen_state &gs, bool macro = false) {
|
||||||
);
|
);
|
||||||
size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(uint32_t);
|
size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(uint32_t);
|
||||||
char *buf = new char[bufs + 1];
|
char *buf = new char[bufs + 1];
|
||||||
auto writer = ostd::CharRange(buf, buf + bufs);
|
auto writer = ostd::char_range(buf, buf + bufs);
|
||||||
size_t len = util::unescape_string(writer, str);
|
size_t len = util::unescape_string(writer, str);
|
||||||
memset(&buf[len], 0, sizeof(uint32_t) - len % sizeof(uint32_t));
|
memset(&buf[len], 0, sizeof(uint32_t) - len % sizeof(uint32_t));
|
||||||
gs.code.back() |= len << 8;
|
gs.code.back() |= len << 8;
|
||||||
|
@ -346,7 +346,7 @@ lookupid:
|
||||||
numargs++;
|
numargs++;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
gs.gen_str(ostd::ConstCharRange(), true);
|
gs.gen_str(ostd::string_range(), true);
|
||||||
numargs++;
|
numargs++;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
@ -478,7 +478,7 @@ invalid:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool compileblockstr(cs_gen_state &gs, ostd::ConstCharRange str, bool macro) {
|
static bool compileblockstr(cs_gen_state &gs, ostd::string_range str, bool macro) {
|
||||||
int startc = gs.code.size();
|
int startc = gs.code.size();
|
||||||
gs.code.push_back(macro ? CsCodeMacro : CsCodeVal | CsRetString);
|
gs.code.push_back(macro ? CsCodeMacro : CsCodeVal | CsRetString);
|
||||||
gs.code.reserve(gs.code.size() + str.size() / sizeof(uint32_t) + 1);
|
gs.code.reserve(gs.code.size() + str.size() / sizeof(uint32_t) + 1);
|
||||||
|
@ -486,7 +486,7 @@ static bool compileblockstr(cs_gen_state &gs, ostd::ConstCharRange str, bool mac
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (!str.empty()) {
|
while (!str.empty()) {
|
||||||
char const *p = str.data();
|
char const *p = str.data();
|
||||||
str = ostd::find_one_of(str, ostd::ConstCharRange("\r/\"@]"));
|
str = ostd::find_one_of(str, ostd::string_range("\r/\"@]"));
|
||||||
memcpy(&buf[len], p, str.data() - p);
|
memcpy(&buf[len], p, str.data() - p);
|
||||||
len += str.data() - p;
|
len += str.data() - p;
|
||||||
if (str.empty()) {
|
if (str.empty()) {
|
||||||
|
@ -497,9 +497,9 @@ static bool compileblockstr(cs_gen_state &gs, ostd::ConstCharRange str, bool mac
|
||||||
str.pop_front();
|
str.pop_front();
|
||||||
break;
|
break;
|
||||||
case '\"': {
|
case '\"': {
|
||||||
ostd::ConstCharRange start = str;
|
ostd::string_range start = str;
|
||||||
str = util::parse_string(gs.cs, str);
|
str = util::parse_string(gs.cs, str);
|
||||||
ostd::ConstCharRange strr = ostd::slice_until(start, str);
|
ostd::string_range strr = ostd::slice_until(start, str);
|
||||||
memcpy(&buf[len], strr.data(), strr.size());
|
memcpy(&buf[len], strr.data(), strr.size());
|
||||||
len += strr.size();
|
len += strr.size();
|
||||||
break;
|
break;
|
||||||
|
@ -631,7 +631,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) {
|
||||||
concs = 1;
|
concs = 1;
|
||||||
}
|
}
|
||||||
if (compileblockstr(
|
if (compileblockstr(
|
||||||
gs, ostd::ConstCharRange(start, esc), true
|
gs, ostd::string_range(start, esc), true
|
||||||
)) {
|
)) {
|
||||||
concs++;
|
concs++;
|
||||||
}
|
}
|
||||||
|
@ -658,7 +658,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) {
|
||||||
return;
|
return;
|
||||||
case CsValCode:
|
case CsValCode:
|
||||||
case CsValCond: {
|
case CsValCond: {
|
||||||
auto ret = compileblock(gs, ostd::ConstCharRange(
|
auto ret = compileblock(gs, ostd::string_range(
|
||||||
start, gs.source.data() + gs.source.size()
|
start, gs.source.data() + gs.source.size()
|
||||||
), curline, CsRetNull, ']');
|
), curline, CsRetNull, ']');
|
||||||
gs.source = ret.first;
|
gs.source = ret.first;
|
||||||
|
@ -666,7 +666,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case CsValIdent:
|
case CsValIdent:
|
||||||
gs.gen_ident(ostd::ConstCharRange(start, gs.source.data() - 1));
|
gs.gen_ident(ostd::string_range(start, gs.source.data() - 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,12 +677,12 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) {
|
||||||
case CsValCany:
|
case CsValCany:
|
||||||
case CsValCond:
|
case CsValCond:
|
||||||
compileblockstr(
|
compileblockstr(
|
||||||
gs, ostd::ConstCharRange(start, gs.source.data() - 1), true
|
gs, ostd::string_range(start, gs.source.data() - 1), true
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
compileblockstr(
|
compileblockstr(
|
||||||
gs, ostd::ConstCharRange(start, gs.source.data() - 1), concs > 0
|
gs, ostd::string_range(start, gs.source.data() - 1), concs > 0
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -728,7 +728,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) {
|
||||||
case CsValCstring:
|
case CsValCstring:
|
||||||
case CsValCany:
|
case CsValCany:
|
||||||
if (!concs && gs.source.data() - 1 <= start) {
|
if (!concs && gs.source.data() - 1 <= start) {
|
||||||
gs.gen_str(ostd::ConstCharRange(), true);
|
gs.gen_str(ostd::string_range(), true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CsValString:
|
case CsValString:
|
||||||
|
@ -902,7 +902,7 @@ static void compile_cmd(
|
||||||
if (rep) {
|
if (rep) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gs.gen_str(ostd::ConstCharRange(), *fmt == 's');
|
gs.gen_str(ostd::string_range(), *fmt == 's');
|
||||||
fakeargs++;
|
fakeargs++;
|
||||||
} else if (fmt.size() == 1) {
|
} else if (fmt.size() == 1) {
|
||||||
int numconc = 1;
|
int numconc = 1;
|
||||||
|
@ -1352,7 +1352,7 @@ noid:
|
||||||
switch (rettype) {
|
switch (rettype) {
|
||||||
case CsValAny:
|
case CsValAny:
|
||||||
case CsValCany: {
|
case CsValCany: {
|
||||||
ostd::ConstCharRange end = idname;
|
ostd::string_range end = idname;
|
||||||
cs_int val = cs_parse_int(end, &end);
|
cs_int val = cs_parse_int(end, &end);
|
||||||
if (!end.empty()) {
|
if (!end.empty()) {
|
||||||
gs.gen_str(idname, rettype == CsValCany);
|
gs.gen_str(idname, rettype == CsValCany);
|
||||||
|
@ -1495,7 +1495,7 @@ endstatement:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_gen_state::gen_main(ostd::ConstCharRange s, int ret_type) {
|
void cs_gen_state::gen_main(ostd::string_range s, int ret_type) {
|
||||||
source = s;
|
source = s;
|
||||||
code.push_back(CsCodeStart);
|
code.push_back(CsCodeStart);
|
||||||
compilestatements(*this, CsValAny);
|
compilestatements(*this, CsValAny);
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
static inline void p_skip_white(ostd::ConstCharRange &v) {
|
static inline void p_skip_white(ostd::string_range &v) {
|
||||||
while (!v.empty() && isspace(*v)) {
|
while (!v.empty() && isspace(*v)) {
|
||||||
++v;
|
++v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void p_set_end(
|
static inline void p_set_end(
|
||||||
const ostd::ConstCharRange &v, ostd::ConstCharRange *end
|
const ostd::string_range &v, ostd::string_range *end
|
||||||
) {
|
) {
|
||||||
if (!end) {
|
if (!end) {
|
||||||
return;
|
return;
|
||||||
|
@ -32,7 +32,7 @@ static inline cs_int p_hexd_to_int(char c) {
|
||||||
return c - '0';
|
return c - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool p_check_neg(ostd::ConstCharRange &input) {
|
static inline bool p_check_neg(ostd::string_range &input) {
|
||||||
bool neg = (*input == '-');
|
bool neg = (*input == '-');
|
||||||
if (neg || (*input == '+')) {
|
if (neg || (*input == '+')) {
|
||||||
++input;
|
++input;
|
||||||
|
@ -40,8 +40,8 @@ static inline bool p_check_neg(ostd::ConstCharRange &input) {
|
||||||
return neg;
|
return neg;
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_int cs_parse_int(ostd::ConstCharRange input, ostd::ConstCharRange *end) {
|
cs_int cs_parse_int(ostd::string_range input, ostd::string_range *end) {
|
||||||
ostd::ConstCharRange orig = input;
|
ostd::string_range orig = input;
|
||||||
p_skip_white(input);
|
p_skip_white(input);
|
||||||
if (input.empty()) {
|
if (input.empty()) {
|
||||||
p_set_end(orig, end);
|
p_set_end(orig, end);
|
||||||
|
@ -49,9 +49,9 @@ cs_int cs_parse_int(ostd::ConstCharRange input, ostd::ConstCharRange *end) {
|
||||||
}
|
}
|
||||||
bool neg = p_check_neg(input);
|
bool neg = p_check_neg(input);
|
||||||
cs_int ret = 0;
|
cs_int ret = 0;
|
||||||
ostd::ConstCharRange past = input;
|
ostd::string_range past = input;
|
||||||
if (input.size() >= 2) {
|
if (input.size() >= 2) {
|
||||||
ostd::ConstCharRange pfx = input.slice(0, 2);
|
ostd::string_range pfx = input.slice(0, 2);
|
||||||
if ((pfx == "0x") || (pfx == "0X")) {
|
if ((pfx == "0x") || (pfx == "0X")) {
|
||||||
input += 2;
|
input += 2;
|
||||||
past = input;
|
past = input;
|
||||||
|
@ -87,7 +87,7 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool Hex, char e1 = Hex ? 'p' : 'e', char e2 = Hex ? 'P' : 'E'>
|
template<bool Hex, char e1 = Hex ? 'p' : 'e', char e2 = Hex ? 'P' : 'E'>
|
||||||
static inline bool p_read_exp(ostd::ConstCharRange &input, cs_int &fn) {
|
static inline bool p_read_exp(ostd::string_range &input, cs_int &fn) {
|
||||||
if (input.empty()) {
|
if (input.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ static inline bool p_read_exp(ostd::ConstCharRange &input, cs_int &fn) {
|
||||||
|
|
||||||
template<bool Hex>
|
template<bool Hex>
|
||||||
static inline bool parse_gen_float(
|
static inline bool parse_gen_float(
|
||||||
ostd::ConstCharRange input, ostd::ConstCharRange *end, cs_float &ret
|
ostd::string_range input, ostd::string_range *end, cs_float &ret
|
||||||
) {
|
) {
|
||||||
auto read_digits = [&input](double r, cs_int &n) {
|
auto read_digits = [&input](double r, cs_int &n) {
|
||||||
while (!input.empty() && (Hex ? isxdigit(*input) : isdigit(*input))) {
|
while (!input.empty() && (Hex ? isxdigit(*input) : isdigit(*input))) {
|
||||||
|
@ -152,8 +152,8 @@ static inline bool parse_gen_float(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_float cs_parse_float(ostd::ConstCharRange input, ostd::ConstCharRange *end) {
|
cs_float cs_parse_float(ostd::string_range input, ostd::string_range *end) {
|
||||||
ostd::ConstCharRange orig = input;
|
ostd::string_range orig = input;
|
||||||
p_skip_white(input);
|
p_skip_white(input);
|
||||||
if (input.empty()) {
|
if (input.empty()) {
|
||||||
p_set_end(orig, end);
|
p_set_end(orig, end);
|
||||||
|
@ -162,7 +162,7 @@ cs_float cs_parse_float(ostd::ConstCharRange input, ostd::ConstCharRange *end) {
|
||||||
bool neg = p_check_neg(input);
|
bool neg = p_check_neg(input);
|
||||||
cs_float ret = cs_float(0);
|
cs_float ret = cs_float(0);
|
||||||
if (input.size() >= 2) {
|
if (input.size() >= 2) {
|
||||||
ostd::ConstCharRange pfx = input.slice(0, 2);
|
ostd::string_range pfx = input.slice(0, 2);
|
||||||
if ((pfx == "0x") || (pfx == "0X")) {
|
if ((pfx == "0x") || (pfx == "0X")) {
|
||||||
input += 2;
|
input += 2;
|
||||||
if (!parse_gen_float<true>(input, end, ret)) {
|
if (!parse_gen_float<true>(input, end, ret)) {
|
||||||
|
@ -184,15 +184,15 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
OSTD_EXPORT ostd::ConstCharRange parse_string(
|
OSTD_EXPORT ostd::string_range parse_string(
|
||||||
cs_state &cs, ostd::ConstCharRange str, size_t &nlines
|
cs_state &cs, ostd::string_range str, size_t &nlines
|
||||||
) {
|
) {
|
||||||
size_t nl = 0;
|
size_t nl = 0;
|
||||||
nlines = nl;
|
nlines = nl;
|
||||||
if (str.empty() || (*str != '\"')) {
|
if (str.empty() || (*str != '\"')) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange orig = str;
|
ostd::string_range orig = str;
|
||||||
++str;
|
++str;
|
||||||
++nl;
|
++nl;
|
||||||
while (!str.empty()) {
|
while (!str.empty()) {
|
||||||
|
@ -235,11 +235,11 @@ end:
|
||||||
return str + 1;
|
return str + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSTD_EXPORT ostd::ConstCharRange parse_word(
|
OSTD_EXPORT ostd::string_range parse_word(
|
||||||
cs_state &cs, ostd::ConstCharRange str
|
cs_state &cs, ostd::string_range str
|
||||||
) {
|
) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
str = ostd::find_one_of(str, ostd::ConstCharRange("\"/;()[] \t\r\n"));
|
str = ostd::find_one_of(str, ostd::string_range("\"/;()[] \t\r\n"));
|
||||||
if (str.empty()) {
|
if (str.empty()) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ end:
|
||||||
int brak = 1;
|
int brak = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
p_input = ostd::find_one_of(
|
p_input = ostd::find_one_of(
|
||||||
p_input, ostd::ConstCharRange("\"/;()[]")
|
p_input, ostd::string_range("\"/;()[]")
|
||||||
);
|
);
|
||||||
if (p_input.empty()) {
|
if (p_input.empty()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -357,7 +357,7 @@ endblock:
|
||||||
case ']':
|
case ']':
|
||||||
return false;
|
return false;
|
||||||
default: {
|
default: {
|
||||||
ostd::ConstCharRange e = parse_word(p_state, p_input);
|
ostd::string_range e = parse_word(p_state, p_input);
|
||||||
p_quote = p_item = ostd::slice_until(p_input, e);
|
p_quote = p_item = ostd::slice_until(p_input, e);
|
||||||
p_input = e;
|
p_input = e;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -16,11 +16,11 @@ template<typename T>
|
||||||
using CsVector = std::vector<T>;
|
using CsVector = std::vector<T>;
|
||||||
|
|
||||||
cs_int cs_parse_int(
|
cs_int cs_parse_int(
|
||||||
ostd::ConstCharRange input, ostd::ConstCharRange *end = nullptr
|
ostd::string_range input, ostd::string_range *end = nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
cs_float cs_parse_float(
|
cs_float cs_parse_float(
|
||||||
ostd::ConstCharRange input, ostd::ConstCharRange *end = nullptr
|
ostd::string_range input, ostd::string_range *end = nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
|
|
|
@ -114,7 +114,7 @@ void cs_value::set_code(cs_bcode *val) {
|
||||||
csv_get<cs_bcode *>(p_stor) = val;
|
csv_get<cs_bcode *>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_value::set_cstr(ostd::ConstCharRange val) {
|
void cs_value::set_cstr(ostd::string_range val) {
|
||||||
csv_cleanup(p_type, p_stor);
|
csv_cleanup(p_type, p_stor);
|
||||||
p_type = cs_value_type::Cstring;
|
p_type = cs_value_type::Cstring;
|
||||||
p_len = val.size();
|
p_len = val.size();
|
||||||
|
@ -127,7 +127,7 @@ void cs_value::set_ident(cs_ident *val) {
|
||||||
csv_get<cs_ident *>(p_stor) = val;
|
csv_get<cs_ident *>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_value::set_macro(ostd::ConstCharRange val) {
|
void cs_value::set_macro(ostd::string_range val) {
|
||||||
csv_cleanup(p_type, p_stor);
|
csv_cleanup(p_type, p_stor);
|
||||||
p_type = cs_value_type::Macro;
|
p_type = cs_value_type::Macro;
|
||||||
p_len = val.size();
|
p_len = val.size();
|
||||||
|
@ -150,7 +150,7 @@ cs_float cs_value::force_float() {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
rf = cs_parse_float(ostd::ConstCharRange(
|
rf = cs_parse_float(ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
));
|
));
|
||||||
|
@ -173,7 +173,7 @@ cs_int cs_value::force_int() {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
ri = cs_parse_int(ostd::ConstCharRange(
|
ri = cs_parse_int(ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
));
|
));
|
||||||
|
@ -187,7 +187,7 @@ cs_int cs_value::force_int() {
|
||||||
return ri;
|
return ri;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_value::force_str() {
|
ostd::string_range cs_value::force_str() {
|
||||||
cs_string rs;
|
cs_string rs;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case cs_value_type::Float:
|
case cs_value_type::Float:
|
||||||
|
@ -198,13 +198,13 @@ ostd::ConstCharRange cs_value::force_str() {
|
||||||
break;
|
break;
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
rs = ostd::ConstCharRange(
|
rs = ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
return ostd::ConstCharRange(
|
return ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
);
|
);
|
||||||
|
@ -212,7 +212,7 @@ ostd::ConstCharRange cs_value::force_str() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
set_str(std::move(rs));
|
set_str(std::move(rs));
|
||||||
return ostd::ConstCharRange(
|
return ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
);
|
);
|
||||||
|
@ -227,7 +227,7 @@ cs_int cs_value::get_int() const {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
return cs_parse_int(ostd::ConstCharRange(
|
return cs_parse_int(ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
));
|
));
|
||||||
|
@ -246,7 +246,7 @@ cs_float cs_value::get_float() const {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
return cs_parse_float(ostd::ConstCharRange(
|
return cs_parse_float(ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
));
|
));
|
||||||
|
@ -286,19 +286,19 @@ cs_string cs_value::get_str() const {
|
||||||
return cs_string("");
|
return cs_string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_value::get_strr() const {
|
ostd::string_range cs_value::get_strr() const {
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
return ostd::ConstCharRange(
|
return ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor)+ p_len
|
csv_get<char const *>(p_stor)+ p_len
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ostd::ConstCharRange();
|
return ostd::string_range();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_value::get_val(cs_value &r) const {
|
void cs_value::get_val(cs_value &r) const {
|
||||||
|
@ -338,11 +338,11 @@ bool cs_value::code_is_empty() const {
|
||||||
return cscript::cs_code_is_empty(csv_get<cs_bcode *>(p_stor));
|
return cscript::cs_code_is_empty(csv_get<cs_bcode *>(p_stor));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool cs_get_bool(ostd::ConstCharRange s) {
|
static inline bool cs_get_bool(ostd::string_range s) {
|
||||||
if (s.empty()) {
|
if (s.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange end = s;
|
ostd::string_range end = s;
|
||||||
cs_int ival = cs_parse_int(end, &end);
|
cs_int ival = cs_parse_int(end, &end);
|
||||||
if (end.empty()) {
|
if (end.empty()) {
|
||||||
return !!ival;
|
return !!ival;
|
||||||
|
@ -364,7 +364,7 @@ bool cs_value::get_bool() const {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring:
|
case cs_value_type::Cstring:
|
||||||
return cs_get_bool(ostd::ConstCharRange(
|
return cs_get_bool(ostd::string_range(
|
||||||
csv_get<char const *>(p_stor),
|
csv_get<char const *>(p_stor),
|
||||||
csv_get<char const *>(p_stor) + p_len
|
csv_get<char const *>(p_stor) + p_len
|
||||||
));
|
));
|
||||||
|
|
46
src/cs_vm.cc
46
src/cs_vm.cc
|
@ -106,8 +106,8 @@ cs_stack_state cs_error::save_stack(cs_state &cs) {
|
||||||
return cs_stack_state(cs, ret, total > dalias->get_value());
|
return cs_stack_state(cs, ret, total > dalias->get_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_error::save_msg(
|
ostd::string_range cs_error::save_msg(
|
||||||
cs_state &cs, ostd::ConstCharRange msg
|
cs_state &cs, ostd::string_range msg
|
||||||
) {
|
) {
|
||||||
if (msg.size() > sizeof(cs.p_errbuf)) {
|
if (msg.size() > sizeof(cs.p_errbuf)) {
|
||||||
msg = msg.slice(0, sizeof(cs.p_errbuf));
|
msg = msg.slice(0, sizeof(cs.p_errbuf));
|
||||||
|
@ -117,7 +117,7 @@ ostd::ConstCharRange cs_error::save_msg(
|
||||||
/* we can attach line number */
|
/* we can attach line number */
|
||||||
std::size_t sz = 0;
|
std::size_t sz = 0;
|
||||||
try {
|
try {
|
||||||
ostd::CharRange r(cs.p_errbuf, cs.p_errbuf + sizeof(cs.p_errbuf));
|
ostd::char_range r(cs.p_errbuf, cs.p_errbuf + sizeof(cs.p_errbuf));
|
||||||
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 {
|
||||||
|
@ -127,10 +127,10 @@ ostd::ConstCharRange cs_error::save_msg(
|
||||||
memcpy(cs.p_errbuf, msg.data(), msg.size());
|
memcpy(cs.p_errbuf, msg.data(), msg.size());
|
||||||
sz = msg.size();
|
sz = msg.size();
|
||||||
}
|
}
|
||||||
return ostd::ConstCharRange(cs.p_errbuf, cs.p_errbuf + sz);
|
return ostd::string_range(cs.p_errbuf, cs.p_errbuf + sz);
|
||||||
}
|
}
|
||||||
memcpy(cs.p_errbuf, msg.data(), msg.size());
|
memcpy(cs.p_errbuf, msg.data(), msg.size());
|
||||||
return ostd::ConstCharRange(cs.p_errbuf, cs.p_errbuf + msg.size());
|
return ostd::string_range(cs.p_errbuf, cs.p_errbuf + msg.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bcode_ref(uint32_t *code) {
|
static void bcode_ref(uint32_t *code) {
|
||||||
|
@ -770,7 +770,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
|
||||||
|
|
||||||
case CsCodeMacro: {
|
case CsCodeMacro: {
|
||||||
uint32_t len = op >> 8;
|
uint32_t len = op >> 8;
|
||||||
args[numargs++].set_macro(ostd::ConstCharRange(
|
args[numargs++].set_macro(ostd::string_range(
|
||||||
reinterpret_cast<char const *>(code),
|
reinterpret_cast<char const *>(code),
|
||||||
reinterpret_cast<char const *>(code) + len
|
reinterpret_cast<char const *>(code) + len
|
||||||
));
|
));
|
||||||
|
@ -931,7 +931,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
|
||||||
case cs_value_type::String:
|
case cs_value_type::String:
|
||||||
case cs_value_type::Macro:
|
case cs_value_type::Macro:
|
||||||
case cs_value_type::Cstring: {
|
case cs_value_type::Cstring: {
|
||||||
ostd::ConstCharRange s = arg.get_strr();
|
ostd::string_range s = arg.get_strr();
|
||||||
if (!s.empty()) {
|
if (!s.empty()) {
|
||||||
cs_gen_state gs(cs);
|
cs_gen_state gs(cs);
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
|
@ -1611,7 +1611,7 @@ void cs_state::run(cs_bcode *code, cs_value &ret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cs_run(
|
static void cs_run(
|
||||||
cs_state &cs, ostd::ConstCharRange file, ostd::ConstCharRange code,
|
cs_state &cs, ostd::string_range file, ostd::string_range code,
|
||||||
cs_value &ret
|
cs_value &ret
|
||||||
) {
|
) {
|
||||||
cs_gen_state gs(cs);
|
cs_gen_state gs(cs);
|
||||||
|
@ -1627,8 +1627,8 @@ static void cs_run(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::run(ostd::ConstCharRange code, cs_value &ret) {
|
void cs_state::run(ostd::string_range code, cs_value &ret) {
|
||||||
cs_run(*this, ostd::ConstCharRange(), code, ret);
|
cs_run(*this, ostd::string_range(), code, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::run(cs_ident *id, cs_value_r args, cs_value &ret) {
|
void cs_state::run(cs_ident *id, cs_value_r args, cs_value &ret) {
|
||||||
|
@ -1708,7 +1708,7 @@ cs_string cs_state::run_str(cs_bcode *code) {
|
||||||
return ret.get_str();
|
return ret.get_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_string cs_state::run_str(ostd::ConstCharRange code) {
|
cs_string cs_state::run_str(ostd::string_range code) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
return ret.get_str();
|
return ret.get_str();
|
||||||
|
@ -1726,7 +1726,7 @@ cs_int cs_state::run_int(cs_bcode *code) {
|
||||||
return ret.get_int();
|
return ret.get_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_int cs_state::run_int(ostd::ConstCharRange code) {
|
cs_int cs_state::run_int(ostd::string_range code) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
return ret.get_int();
|
return ret.get_int();
|
||||||
|
@ -1744,7 +1744,7 @@ cs_float cs_state::run_float(cs_bcode *code) {
|
||||||
return ret.get_float();
|
return ret.get_float();
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_float cs_state::run_float(ostd::ConstCharRange code) {
|
cs_float cs_state::run_float(ostd::string_range code) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
return ret.get_float();
|
return ret.get_float();
|
||||||
|
@ -1762,7 +1762,7 @@ bool cs_state::run_bool(cs_bcode *code) {
|
||||||
return ret.get_bool();
|
return ret.get_bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cs_state::run_bool(ostd::ConstCharRange code) {
|
bool cs_state::run_bool(ostd::string_range code) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
return ret.get_bool();
|
return ret.get_bool();
|
||||||
|
@ -1779,7 +1779,7 @@ void cs_state::run(cs_bcode *code) {
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::run(ostd::ConstCharRange code) {
|
void cs_state::run(ostd::string_range code) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
run(code, ret);
|
run(code, ret);
|
||||||
}
|
}
|
||||||
|
@ -1812,7 +1812,7 @@ CsLoopState cs_state::run_loop(cs_bcode *code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cs_run_file(
|
static bool cs_run_file(
|
||||||
cs_state &cs, ostd::ConstCharRange fname, cs_value &ret
|
cs_state &cs, ostd::string_range fname, cs_value &ret
|
||||||
) {
|
) {
|
||||||
std::unique_ptr<char[]> buf;
|
std::unique_ptr<char[]> buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -1829,11 +1829,11 @@ static bool cs_run_file(
|
||||||
}
|
}
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
cs_run(cs, fname, ostd::ConstCharRange(buf.get(), buf.get() + len), ret);
|
cs_run(cs, fname, ostd::string_range(buf.get(), buf.get() + len), ret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_string> cs_state::run_file_str(ostd::ConstCharRange fname) {
|
std::optional<cs_string> cs_state::run_file_str(ostd::string_range fname) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
if (!cs_run_file(*this, fname, ret)) {
|
if (!cs_run_file(*this, fname, ret)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -1841,7 +1841,7 @@ std::optional<cs_string> cs_state::run_file_str(ostd::ConstCharRange fname) {
|
||||||
return ret.get_str();
|
return ret.get_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_int> cs_state::run_file_int(ostd::ConstCharRange fname) {
|
std::optional<cs_int> cs_state::run_file_int(ostd::string_range fname) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
if (!cs_run_file(*this, fname, ret)) {
|
if (!cs_run_file(*this, fname, ret)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -1849,7 +1849,7 @@ std::optional<cs_int> cs_state::run_file_int(ostd::ConstCharRange fname) {
|
||||||
return ret.get_int();
|
return ret.get_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_float> cs_state::run_file_float(ostd::ConstCharRange fname) {
|
std::optional<cs_float> cs_state::run_file_float(ostd::string_range fname) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
if (!cs_run_file(*this, fname, ret)) {
|
if (!cs_run_file(*this, fname, ret)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -1857,7 +1857,7 @@ std::optional<cs_float> cs_state::run_file_float(ostd::ConstCharRange fname) {
|
||||||
return ret.get_float();
|
return ret.get_float();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<bool> cs_state::run_file_bool(ostd::ConstCharRange fname) {
|
std::optional<bool> cs_state::run_file_bool(ostd::string_range fname) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
if (!cs_run_file(*this, fname, ret)) {
|
if (!cs_run_file(*this, fname, ret)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -1865,11 +1865,11 @@ std::optional<bool> cs_state::run_file_bool(ostd::ConstCharRange fname) {
|
||||||
return ret.get_bool();
|
return ret.get_bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cs_state::run_file(ostd::ConstCharRange fname, cs_value &ret) {
|
bool cs_state::run_file(ostd::string_range fname, cs_value &ret) {
|
||||||
return cs_run_file(*this, fname, ret);
|
return cs_run_file(*this, fname, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cs_state::run_file(ostd::ConstCharRange fname) {
|
bool cs_state::run_file(ostd::string_range fname) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
if (!cs_run_file(*this, fname, ret)) {
|
if (!cs_run_file(*this, fname, ret)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
28
src/cs_vm.hh
28
src/cs_vm.hh
|
@ -95,7 +95,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cs_shared_state {
|
struct cs_shared_state {
|
||||||
CsMap<ostd::ConstCharRange, cs_ident *> idents;
|
CsMap<ostd::string_range, cs_ident *> idents;
|
||||||
CsVector<cs_ident *> identmap;
|
CsVector<cs_ident *> identmap;
|
||||||
cs_alloc_cb allocf;
|
cs_alloc_cb allocf;
|
||||||
void *aptr;
|
void *aptr;
|
||||||
|
@ -148,9 +148,9 @@ struct cs_gen_state {
|
||||||
cs_gen_state *prevps;
|
cs_gen_state *prevps;
|
||||||
bool parsing = true;
|
bool parsing = true;
|
||||||
CsVector<uint32_t> code;
|
CsVector<uint32_t> code;
|
||||||
ostd::ConstCharRange source;
|
ostd::string_range source;
|
||||||
size_t current_line;
|
size_t current_line;
|
||||||
ostd::ConstCharRange src_name;
|
ostd::string_range src_name;
|
||||||
|
|
||||||
cs_gen_state() = delete;
|
cs_gen_state() = delete;
|
||||||
cs_gen_state(cs_state &csr):
|
cs_gen_state(cs_state &csr):
|
||||||
|
@ -172,12 +172,12 @@ struct cs_gen_state {
|
||||||
parsing = false;
|
parsing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange get_str();
|
ostd::string_range get_str();
|
||||||
cs_string get_str_dup(bool unescape = true);
|
cs_string get_str_dup(bool unescape = true);
|
||||||
|
|
||||||
ostd::ConstCharRange get_word();
|
ostd::string_range get_word();
|
||||||
|
|
||||||
void gen_str(ostd::ConstCharRange word, bool macro = false) {
|
void gen_str(ostd::string_range word, bool macro = false) {
|
||||||
if (word.size() <= 3 && !macro) {
|
if (word.size() <= 3 && !macro) {
|
||||||
uint32_t op = CsCodeValInt | CsRetString;
|
uint32_t op = CsCodeValInt | CsRetString;
|
||||||
for (size_t i = 0; i < word.size(); ++i) {
|
for (size_t i = 0; i < word.size(); ++i) {
|
||||||
|
@ -225,7 +225,7 @@ struct cs_gen_state {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_int(ostd::ConstCharRange word);
|
void gen_int(ostd::string_range word);
|
||||||
|
|
||||||
void gen_float(cs_float f = 0.0f) {
|
void gen_float(cs_float f = 0.0f) {
|
||||||
if (cs_int(f) == f && f >= -0x800000 && f <= 0x7FFFFF) {
|
if (cs_int(f) == f && f >= -0x800000 && f <= 0x7FFFFF) {
|
||||||
|
@ -241,7 +241,7 @@ struct cs_gen_state {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_float(ostd::ConstCharRange word);
|
void gen_float(ostd::string_range word);
|
||||||
|
|
||||||
void gen_ident(cs_ident *id) {
|
void gen_ident(cs_ident *id) {
|
||||||
code.push_back(
|
code.push_back(
|
||||||
|
@ -256,16 +256,16 @@ struct cs_gen_state {
|
||||||
gen_ident(cs.p_state->identmap[DummyIdx]);
|
gen_ident(cs.p_state->identmap[DummyIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_ident(ostd::ConstCharRange word) {
|
void gen_ident(ostd::string_range word) {
|
||||||
gen_ident(cs.new_ident(word));
|
gen_ident(cs.new_ident(word));
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_value(
|
void gen_value(
|
||||||
int wordtype, ostd::ConstCharRange word = ostd::ConstCharRange(),
|
int wordtype, ostd::string_range word = ostd::string_range(),
|
||||||
int line = 0
|
int line = 0
|
||||||
);
|
);
|
||||||
|
|
||||||
void gen_main(ostd::ConstCharRange s, int ret_type = CsValAny);
|
void gen_main(ostd::string_range s, int ret_type = CsValAny);
|
||||||
|
|
||||||
void next_char() {
|
void next_char() {
|
||||||
if (source.empty()) {
|
if (source.empty()) {
|
||||||
|
@ -284,9 +284,9 @@ struct cs_gen_state {
|
||||||
return source[ahead];
|
return source[ahead];
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange read_macro_name();
|
ostd::string_range read_macro_name();
|
||||||
|
|
||||||
char skip_until(ostd::ConstCharRange chars);
|
char skip_until(ostd::string_range chars);
|
||||||
char skip_until(char cf);
|
char skip_until(char cf);
|
||||||
|
|
||||||
void skip_comments();
|
void skip_comments();
|
||||||
|
@ -295,7 +295,7 @@ struct cs_gen_state {
|
||||||
cs_string intstr(cs_int v);
|
cs_string intstr(cs_int v);
|
||||||
cs_string floatstr(cs_float v);
|
cs_string floatstr(cs_float v);
|
||||||
|
|
||||||
bool cs_check_num(ostd::ConstCharRange s);
|
bool cs_check_num(ostd::string_range s);
|
||||||
|
|
||||||
static inline void bcode_incr(uint32_t *bc) {
|
static inline void bcode_incr(uint32_t *bc) {
|
||||||
*bc += 0x100;
|
*bc += 0x100;
|
||||||
|
|
|
@ -15,7 +15,7 @@ cs_string floatstr(cs_float v) {
|
||||||
return std::move(app.get());
|
return std::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cs_check_num(ostd::ConstCharRange s) {
|
bool cs_check_num(ostd::string_range s) {
|
||||||
if (isdigit(s[0])) {
|
if (isdigit(s[0])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -30,64 +30,64 @@ bool cs_check_num(ostd::ConstCharRange s) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_ident::cs_ident(cs_ident_type tp, ostd::ConstCharRange nm, int fl):
|
cs_ident::cs_ident(cs_ident_type tp, ostd::string_range nm, int fl):
|
||||||
p_name(nm), p_type(int(tp)), p_flags(fl)
|
p_name(nm), p_type(int(tp)), p_flags(fl)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_var::cs_var(cs_ident_type tp, ostd::ConstCharRange name, cs_var_cb f, int fl):
|
cs_var::cs_var(cs_ident_type tp, ostd::string_range name, cs_var_cb f, int fl):
|
||||||
cs_ident(tp, name, fl), cb_var(std::move(f))
|
cs_ident(tp, name, fl), cb_var(std::move(f))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_ivar::cs_ivar(
|
cs_ivar::cs_ivar(
|
||||||
ostd::ConstCharRange name, cs_int m, cs_int x, cs_int v, cs_var_cb f, int fl
|
ostd::string_range name, cs_int m, cs_int x, cs_int v, cs_var_cb f, int fl
|
||||||
):
|
):
|
||||||
cs_var(cs_ident_type::Ivar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
cs_var(cs_ident_type::Ivar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
||||||
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_fvar::cs_fvar(
|
cs_fvar::cs_fvar(
|
||||||
ostd::ConstCharRange name, cs_float m, cs_float x, cs_float v, cs_var_cb f, int fl
|
ostd::string_range name, cs_float m, cs_float x, cs_float v, cs_var_cb f, int fl
|
||||||
):
|
):
|
||||||
cs_var(cs_ident_type::Fvar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
cs_var(cs_ident_type::Fvar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
||||||
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_svar::cs_svar(ostd::ConstCharRange name, cs_string v, cs_var_cb f, int fl):
|
cs_svar::cs_svar(ostd::string_range name, cs_string v, cs_var_cb f, int fl):
|
||||||
cs_var(cs_ident_type::Svar, name, std::move(f), fl),
|
cs_var(cs_ident_type::Svar, name, std::move(f), fl),
|
||||||
p_storage(std::move(v)), p_overrideval()
|
p_storage(std::move(v)), p_overrideval()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_alias::cs_alias(ostd::ConstCharRange name, cs_string a, int fl):
|
cs_alias::cs_alias(ostd::string_range name, cs_string a, int fl):
|
||||||
cs_ident(cs_ident_type::Alias, name, fl),
|
cs_ident(cs_ident_type::Alias, name, fl),
|
||||||
p_acode(nullptr), p_astack(nullptr)
|
p_acode(nullptr), p_astack(nullptr)
|
||||||
{
|
{
|
||||||
p_val.set_str(std::move(a));
|
p_val.set_str(std::move(a));
|
||||||
}
|
}
|
||||||
cs_alias::cs_alias(ostd::ConstCharRange name, cs_int a, int fl):
|
cs_alias::cs_alias(ostd::string_range name, cs_int a, int fl):
|
||||||
cs_ident(cs_ident_type::Alias, name, fl),
|
cs_ident(cs_ident_type::Alias, name, fl),
|
||||||
p_acode(nullptr), p_astack(nullptr)
|
p_acode(nullptr), p_astack(nullptr)
|
||||||
{
|
{
|
||||||
p_val.set_int(a);
|
p_val.set_int(a);
|
||||||
}
|
}
|
||||||
cs_alias::cs_alias(ostd::ConstCharRange name, cs_float a, int fl):
|
cs_alias::cs_alias(ostd::string_range name, cs_float a, int fl):
|
||||||
cs_ident(cs_ident_type::Alias, name, fl),
|
cs_ident(cs_ident_type::Alias, name, fl),
|
||||||
p_acode(nullptr), p_astack(nullptr)
|
p_acode(nullptr), p_astack(nullptr)
|
||||||
{
|
{
|
||||||
p_val.set_float(a);
|
p_val.set_float(a);
|
||||||
}
|
}
|
||||||
cs_alias::cs_alias(ostd::ConstCharRange name, int fl):
|
cs_alias::cs_alias(ostd::string_range name, int fl):
|
||||||
cs_ident(cs_ident_type::Alias, name, fl),
|
cs_ident(cs_ident_type::Alias, name, fl),
|
||||||
p_acode(nullptr), p_astack(nullptr)
|
p_acode(nullptr), p_astack(nullptr)
|
||||||
{
|
{
|
||||||
p_val.set_null();
|
p_val.set_null();
|
||||||
}
|
}
|
||||||
cs_alias::cs_alias(ostd::ConstCharRange name, cs_value v, int fl):
|
cs_alias::cs_alias(ostd::string_range name, cs_value v, int fl):
|
||||||
cs_ident(cs_ident_type::Alias, name, fl),
|
cs_ident(cs_ident_type::Alias, name, fl),
|
||||||
p_acode(nullptr), p_astack(nullptr), p_val(std::move(v))
|
p_acode(nullptr), p_astack(nullptr), p_val(std::move(v))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
cs_command::cs_command(
|
cs_command::cs_command(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange args,
|
ostd::string_range name, ostd::string_range args,
|
||||||
int nargs, cs_command_cb f
|
int nargs, cs_command_cb f
|
||||||
):
|
):
|
||||||
cs_ident(cs_ident_type::Command, name, 0),
|
cs_ident(cs_ident_type::Command, name, 0),
|
||||||
|
@ -268,7 +268,7 @@ cs_string cs_fvar::to_printable() const {
|
||||||
return std::move(app.get());
|
return std::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_svar::get_value() const {
|
ostd::string_range cs_svar::get_value() const {
|
||||||
return ostd::iter(p_storage);
|
return ostd::iter(p_storage);
|
||||||
}
|
}
|
||||||
void cs_svar::set_value(cs_string val) {
|
void cs_svar::set_value(cs_string val) {
|
||||||
|
@ -276,7 +276,7 @@ void cs_svar::set_value(cs_string val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_string cs_svar::to_printable() const {
|
cs_string cs_svar::to_printable() const {
|
||||||
ostd::ConstCharRange s = p_storage;
|
ostd::string_range s = p_storage;
|
||||||
auto app = ostd::appender<cs_string>();
|
auto app = ostd::appender<cs_string>();
|
||||||
try {
|
try {
|
||||||
if (ostd::find(s, '"').empty()) {
|
if (ostd::find(s, '"').empty()) {
|
||||||
|
@ -290,7 +290,7 @@ cs_string cs_svar::to_printable() const {
|
||||||
return std::move(app.get());
|
return std::move(app.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_command::get_args() const {
|
ostd::string_range cs_command::get_args() const {
|
||||||
return p_cargs;
|
return p_cargs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ cs_ident *cs_state::add_ident(cs_ident *id) {
|
||||||
return p_state->identmap.back();
|
return p_state->identmap.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_ident *cs_state::new_ident(ostd::ConstCharRange name, int flags) {
|
cs_ident *cs_state::new_ident(ostd::string_range name, int flags) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
if (cs_check_num(name)) {
|
if (cs_check_num(name)) {
|
||||||
|
@ -530,7 +530,7 @@ cs_ident *cs_state::force_ident(cs_value &v) {
|
||||||
return p_state->identmap[DummyIdx];
|
return p_state->identmap[DummyIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_ident *cs_state::get_ident(ostd::ConstCharRange name) {
|
cs_ident *cs_state::get_ident(ostd::string_range name) {
|
||||||
auto id = p_state->idents.find(name);
|
auto id = p_state->idents.find(name);
|
||||||
if (id != p_state->idents.end()) {
|
if (id != p_state->idents.end()) {
|
||||||
return id->second;
|
return id->second;
|
||||||
|
@ -538,7 +538,7 @@ cs_ident *cs_state::get_ident(ostd::ConstCharRange name) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_alias *cs_state::get_alias(ostd::ConstCharRange name) {
|
cs_alias *cs_state::get_alias(ostd::string_range name) {
|
||||||
auto id = get_ident(name);
|
auto id = get_ident(name);
|
||||||
if (!id || !id->is_alias()) {
|
if (!id || !id->is_alias()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -546,7 +546,7 @@ cs_alias *cs_state::get_alias(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_alias *>(id);
|
return static_cast<cs_alias *>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cs_state::have_ident(ostd::ConstCharRange name) {
|
bool cs_state::have_ident(ostd::string_range name) {
|
||||||
return p_state->idents.find(name) != p_state->idents.end();
|
return p_state->idents.find(name) != p_state->idents.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ cs_const_ident_r cs_state::get_idents() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_ivar *cs_state::new_ivar(
|
cs_ivar *cs_state::new_ivar(
|
||||||
ostd::ConstCharRange n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
ostd::string_range n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
||||||
) {
|
) {
|
||||||
return add_ident(
|
return add_ident(
|
||||||
p_state->create<cs_ivar>(n, m, x, v, std::move(f), flags)
|
p_state->create<cs_ivar>(n, m, x, v, std::move(f), flags)
|
||||||
|
@ -571,7 +571,7 @@ cs_ivar *cs_state::new_ivar(
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_fvar *cs_state::new_fvar(
|
cs_fvar *cs_state::new_fvar(
|
||||||
ostd::ConstCharRange n, cs_float m, cs_float x, cs_float v, cs_var_cb f, int flags
|
ostd::string_range n, cs_float m, cs_float x, cs_float v, cs_var_cb f, int flags
|
||||||
) {
|
) {
|
||||||
return add_ident(
|
return add_ident(
|
||||||
p_state->create<cs_fvar>(n, m, x, v, std::move(f), flags)
|
p_state->create<cs_fvar>(n, m, x, v, std::move(f), flags)
|
||||||
|
@ -579,14 +579,14 @@ cs_fvar *cs_state::new_fvar(
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_svar *cs_state::new_svar(
|
cs_svar *cs_state::new_svar(
|
||||||
ostd::ConstCharRange n, cs_string v, cs_var_cb f, int flags
|
ostd::string_range n, cs_string v, cs_var_cb f, int flags
|
||||||
) {
|
) {
|
||||||
return add_ident(
|
return add_ident(
|
||||||
p_state->create<cs_svar>(n, std::move(v), std::move(f), flags)
|
p_state->create<cs_svar>(n, std::move(v), std::move(f), flags)
|
||||||
)->get_svar();
|
)->get_svar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::reset_var(ostd::ConstCharRange name) {
|
void cs_state::reset_var(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
throw cs_error(*this, "variable %s does not exist", name);
|
throw cs_error(*this, "variable %s does not exist", name);
|
||||||
|
@ -597,14 +597,14 @@ void cs_state::reset_var(ostd::ConstCharRange name) {
|
||||||
clear_override(*id);
|
clear_override(*id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::touch_var(ostd::ConstCharRange name) {
|
void cs_state::touch_var(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (id && id->is_var()) {
|
if (id && id->is_var()) {
|
||||||
static_cast<cs_var *>(id)->changed(*this);
|
static_cast<cs_var *>(id)->changed(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::set_alias(ostd::ConstCharRange name, cs_value v) {
|
void cs_state::set_alias(ostd::string_range name, cs_value v) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (id) {
|
if (id) {
|
||||||
switch (id->get_type()) {
|
switch (id->get_type()) {
|
||||||
|
@ -692,7 +692,7 @@ cs_ident_type cs_ident::get_type() const {
|
||||||
return cs_ident_type(p_type);
|
return cs_ident_type(p_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ostd::ConstCharRange cs_ident::get_name() const {
|
ostd::string_range cs_ident::get_name() const {
|
||||||
return p_name;
|
return p_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ static inline void cs_override_var(cs_state &cs, cs_var *v, int &vflags, SF sf)
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::set_var_int(
|
void cs_state::set_var_int(
|
||||||
ostd::ConstCharRange name, cs_int v, bool dofunc, bool doclamp
|
ostd::string_range name, cs_int v, bool dofunc, bool doclamp
|
||||||
) {
|
) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_ivar()) {
|
if (!id || id->is_ivar()) {
|
||||||
|
@ -746,7 +746,7 @@ void cs_state::set_var_int(
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::set_var_float(
|
void cs_state::set_var_float(
|
||||||
ostd::ConstCharRange name, cs_float v, bool dofunc, bool doclamp
|
ostd::string_range name, cs_float v, bool dofunc, bool doclamp
|
||||||
) {
|
) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_fvar()) {
|
if (!id || id->is_fvar()) {
|
||||||
|
@ -768,7 +768,7 @@ void cs_state::set_var_float(
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::set_var_str(
|
void cs_state::set_var_str(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange v, bool dofunc
|
ostd::string_range name, ostd::string_range v, bool dofunc
|
||||||
) {
|
) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_svar()) {
|
if (!id || id->is_svar()) {
|
||||||
|
@ -785,7 +785,7 @@ void cs_state::set_var_str(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_int> cs_state::get_var_int(ostd::ConstCharRange name) {
|
std::optional<cs_int> cs_state::get_var_int(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_ivar()) {
|
if (!id || id->is_ivar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -793,7 +793,7 @@ std::optional<cs_int> cs_state::get_var_int(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_ivar *>(id)->get_value();
|
return static_cast<cs_ivar *>(id)->get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_float> cs_state::get_var_float(ostd::ConstCharRange name) {
|
std::optional<cs_float> cs_state::get_var_float(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_fvar()) {
|
if (!id || id->is_fvar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -801,7 +801,7 @@ std::optional<cs_float> cs_state::get_var_float(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_fvar *>(id)->get_value();
|
return static_cast<cs_fvar *>(id)->get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_string> cs_state::get_var_str(ostd::ConstCharRange name) {
|
std::optional<cs_string> cs_state::get_var_str(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_svar()) {
|
if (!id || id->is_svar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -809,7 +809,7 @@ std::optional<cs_string> cs_state::get_var_str(ostd::ConstCharRange name) {
|
||||||
return cs_string(static_cast<cs_svar *>(id)->get_value());
|
return cs_string(static_cast<cs_svar *>(id)->get_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_int> cs_state::get_var_min_int(ostd::ConstCharRange name) {
|
std::optional<cs_int> cs_state::get_var_min_int(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_ivar()) {
|
if (!id || id->is_ivar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -817,7 +817,7 @@ std::optional<cs_int> cs_state::get_var_min_int(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_ivar *>(id)->get_val_min();
|
return static_cast<cs_ivar *>(id)->get_val_min();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_int> cs_state::get_var_max_int(ostd::ConstCharRange name) {
|
std::optional<cs_int> cs_state::get_var_max_int(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_ivar()) {
|
if (!id || id->is_ivar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -825,7 +825,7 @@ std::optional<cs_int> cs_state::get_var_max_int(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_ivar *>(id)->get_val_max();
|
return static_cast<cs_ivar *>(id)->get_val_max();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_float> cs_state::get_var_min_float(ostd::ConstCharRange name) {
|
std::optional<cs_float> cs_state::get_var_min_float(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_fvar()) {
|
if (!id || id->is_fvar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -833,7 +833,7 @@ std::optional<cs_float> cs_state::get_var_min_float(ostd::ConstCharRange name) {
|
||||||
return static_cast<cs_fvar *>(id)->get_val_min();
|
return static_cast<cs_fvar *>(id)->get_val_min();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_float> cs_state::get_var_max_float(ostd::ConstCharRange name) {
|
std::optional<cs_float> cs_state::get_var_max_float(ostd::string_range name) {
|
||||||
cs_ident *id = get_ident(name);
|
cs_ident *id = get_ident(name);
|
||||||
if (!id || id->is_fvar()) {
|
if (!id || id->is_fvar()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -842,7 +842,7 @@ std::optional<cs_float> cs_state::get_var_max_float(ostd::ConstCharRange name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<cs_string>
|
std::optional<cs_string>
|
||||||
cs_state::get_alias_val(ostd::ConstCharRange name) {
|
cs_state::get_alias_val(ostd::string_range name) {
|
||||||
cs_alias *a = get_alias(name);
|
cs_alias *a = get_alias(name);
|
||||||
if (!a) {
|
if (!a) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -934,7 +934,7 @@ void cs_state::set_var_float_checked(cs_fvar *fv, cs_float v) {
|
||||||
fv->changed(*this);
|
fv->changed(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cs_state::set_var_str_checked(cs_svar *sv, ostd::ConstCharRange v) {
|
void cs_state::set_var_str_checked(cs_svar *sv, ostd::string_range v) {
|
||||||
if (sv->get_flags() & CS_IDF_READONLY) {
|
if (sv->get_flags() & CS_IDF_READONLY) {
|
||||||
throw cs_error(
|
throw cs_error(
|
||||||
*this, "variable '%s' is read only", sv->get_name()
|
*this, "variable '%s' is read only", sv->get_name()
|
||||||
|
@ -949,10 +949,10 @@ void cs_state::set_var_str_checked(cs_svar *sv, ostd::ConstCharRange v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_command *cs_state::new_command(
|
cs_command *cs_state::new_command(
|
||||||
ostd::ConstCharRange name, ostd::ConstCharRange args, cs_command_cb func
|
ostd::string_range name, ostd::string_range args, cs_command_cb func
|
||||||
) {
|
) {
|
||||||
int nargs = 0;
|
int nargs = 0;
|
||||||
for (ostd::ConstCharRange fmt(args); !fmt.empty(); ++fmt) {
|
for (ostd::string_range fmt(args); !fmt.empty(); ++fmt) {
|
||||||
switch (*fmt) {
|
switch (*fmt) {
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'b':
|
case 'b':
|
||||||
|
|
|
@ -23,8 +23,8 @@ struct CsArgVal<cs_float> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct CsArgVal<ostd::ConstCharRange> {
|
struct CsArgVal<ostd::string_range> {
|
||||||
static ostd::ConstCharRange get(cs_value &tv) {
|
static ostd::string_range get(cs_value &tv) {
|
||||||
return tv.get_strr();
|
return tv.get_strr();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -70,7 +70,7 @@ static inline void cs_list_assoc(
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cs_loop_list_conc(
|
static void cs_loop_list_conc(
|
||||||
cs_state &cs, cs_value &res, cs_ident *id, ostd::ConstCharRange list,
|
cs_state &cs, cs_value &res, cs_ident *id, ostd::string_range list,
|
||||||
cs_bcode *body, bool space
|
cs_bcode *body, bool space
|
||||||
) {
|
) {
|
||||||
cs_stacked_value idv{id};
|
cs_stacked_value idv{id};
|
||||||
|
@ -101,7 +101,7 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
int cs_list_includes(
|
int cs_list_includes(
|
||||||
cs_state &cs, ostd::ConstCharRange list, ostd::ConstCharRange needle
|
cs_state &cs, ostd::string_range list, ostd::string_range needle
|
||||||
) {
|
) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (util::ListParser p(cs, list); p.parse();) {
|
for (util::ListParser p(cs, list); p.parse();) {
|
||||||
|
@ -117,8 +117,8 @@ template<bool PushList, bool Swap, typename F>
|
||||||
static inline void cs_list_merge(
|
static inline void cs_list_merge(
|
||||||
cs_state &cs, cs_value_r args, cs_value &res, F cmp
|
cs_state &cs, cs_value_r args, cs_value &res, F cmp
|
||||||
) {
|
) {
|
||||||
ostd::ConstCharRange list = args[0].get_strr();
|
ostd::string_range list = args[0].get_strr();
|
||||||
ostd::ConstCharRange elems = args[1].get_strr();
|
ostd::string_range elems = args[1].get_strr();
|
||||||
cs_string buf;
|
cs_string buf;
|
||||||
if (PushList) {
|
if (PushList) {
|
||||||
buf += list;
|
buf += list;
|
||||||
|
@ -160,7 +160,7 @@ void cs_init_lib_list(cs_state &gcs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos > 0 || !p.parse()) {
|
if (pos > 0 || !p.parse()) {
|
||||||
p.get_raw_item() = p.get_raw_item(true) = ostd::ConstCharRange();
|
p.get_raw_item() = p.get_raw_item(true) = ostd::string_range();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.set_str(p.get_item());
|
res.set_str(p.get_item());
|
||||||
|
@ -187,11 +187,11 @@ void cs_init_lib_list(cs_state &gcs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char const *list = p.get_input().data();
|
char const *list = p.get_input().data();
|
||||||
p.get_raw_item(true) = ostd::ConstCharRange();
|
p.get_raw_item(true) = ostd::string_range();
|
||||||
if (len > 0 && p.parse()) {
|
if (len > 0 && p.parse()) {
|
||||||
while (--len > 0 && p.parse());
|
while (--len > 0 && p.parse());
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange quote = p.get_raw_item(true);
|
ostd::string_range quote = p.get_raw_item(true);
|
||||||
char const *qend = !quote.empty() ? "e[quote.size()] : list;
|
char const *qend = !quote.empty() ? "e[quote.size()] : list;
|
||||||
res.set_str(cs_string{list, size_t(qend - list)});
|
res.set_str(cs_string{list, size_t(qend - list)});
|
||||||
});
|
});
|
||||||
|
@ -254,8 +254,8 @@ void cs_init_lib_list(cs_state &gcs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
gcs.new_command("listfind=s", "s", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("listfind=s", "s", [](auto &cs, auto args, auto &res) {
|
||||||
cs_list_find<ostd::ConstCharRange>(
|
cs_list_find<ostd::string_range>(
|
||||||
cs, args, res, [](const util::ListParser &p, ostd::ConstCharRange val) {
|
cs, args, res, [](const util::ListParser &p, ostd::string_range val) {
|
||||||
return p.get_raw_item() == val;
|
return p.get_raw_item() == val;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -276,8 +276,8 @@ void cs_init_lib_list(cs_state &gcs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
gcs.new_command("listassoc=s", "s", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("listassoc=s", "s", [](auto &cs, auto args, auto &res) {
|
||||||
cs_list_assoc<ostd::ConstCharRange>(
|
cs_list_assoc<ostd::string_range>(
|
||||||
cs, args, res, [](const util::ListParser &p, ostd::ConstCharRange val) {
|
cs, args, res, [](const util::ListParser &p, ostd::string_range val) {
|
||||||
return p.get_raw_item() == val;
|
return p.get_raw_item() == val;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -422,8 +422,8 @@ end:
|
||||||
|
|
||||||
gcs.new_command("prettylist", "ss", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("prettylist", "ss", [](auto &cs, auto args, auto &res) {
|
||||||
auto buf = ostd::appender<cs_string>();
|
auto buf = ostd::appender<cs_string>();
|
||||||
ostd::ConstCharRange s = args[0].get_strr();
|
ostd::string_range s = args[0].get_strr();
|
||||||
ostd::ConstCharRange conj = args[1].get_strr();
|
ostd::string_range conj = args[1].get_strr();
|
||||||
size_t len = util::ListParser(cs, s).count();
|
size_t len = util::ListParser(cs, s).count();
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
for (util::ListParser p(cs, s); p.parse(); ++n) {
|
for (util::ListParser p(cs, s); p.parse(); ++n) {
|
||||||
|
@ -468,8 +468,8 @@ end:
|
||||||
gcs.new_command("listsplice", "ssii", [](auto &cs, auto args, auto &res) {
|
gcs.new_command("listsplice", "ssii", [](auto &cs, auto args, auto &res) {
|
||||||
cs_int offset = ostd::max(args[2].get_int(), cs_int(0));
|
cs_int offset = ostd::max(args[2].get_int(), cs_int(0));
|
||||||
cs_int len = ostd::max(args[3].get_int(), cs_int(0));
|
cs_int len = ostd::max(args[3].get_int(), cs_int(0));
|
||||||
ostd::ConstCharRange s = args[0].get_strr();
|
ostd::string_range s = args[0].get_strr();
|
||||||
ostd::ConstCharRange vals = args[1].get_strr();
|
ostd::string_range vals = args[1].get_strr();
|
||||||
char const *list = s.data();
|
char const *list = s.data();
|
||||||
util::ListParser p(cs, s);
|
util::ListParser p(cs, s);
|
||||||
for (cs_int i = 0; i < offset; ++i) {
|
for (cs_int i = 0; i < offset; ++i) {
|
||||||
|
@ -477,11 +477,11 @@ end:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange quote = p.get_raw_item(true);
|
ostd::string_range quote = p.get_raw_item(true);
|
||||||
char const *qend = !quote.empty() ? "e[quote.size()] : list;
|
char const *qend = !quote.empty() ? "e[quote.size()] : list;
|
||||||
cs_string buf;
|
cs_string buf;
|
||||||
if (qend > list) {
|
if (qend > list) {
|
||||||
buf += ostd::ConstCharRange(list, qend);
|
buf += ostd::string_range(list, qend);
|
||||||
}
|
}
|
||||||
if (!vals.empty()) {
|
if (!vals.empty()) {
|
||||||
if (!buf.empty()) {
|
if (!buf.empty()) {
|
||||||
|
@ -515,8 +515,8 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ListSortItem {
|
struct ListSortItem {
|
||||||
ostd::ConstCharRange str;
|
ostd::string_range str;
|
||||||
ostd::ConstCharRange quote;
|
ostd::string_range quote;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ListSortFun {
|
struct ListSortFun {
|
||||||
|
@ -534,7 +534,7 @@ struct ListSortFun {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void cs_list_sort(
|
static void cs_list_sort(
|
||||||
cs_state &cs, cs_value &res, ostd::ConstCharRange list,
|
cs_state &cs, cs_value &res, ostd::string_range list,
|
||||||
cs_ident *x, cs_ident *y, cs_bcode *body, cs_bcode *unique
|
cs_ident *x, cs_ident *y, cs_bcode *body, cs_bcode *unique
|
||||||
) {
|
) {
|
||||||
if (x == y || !x->is_alias() || !y->is_alias()) {
|
if (x == y || !x->is_alias() || !y->is_alias()) {
|
||||||
|
|
|
@ -14,8 +14,8 @@ static inline void cs_strgcmp(cs_value_r args, cs_value &res, F cfunc) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val = cfunc(
|
val = cfunc(
|
||||||
!args.empty() ? args[0].get_strr() : ostd::ConstCharRange(),
|
!args.empty() ? args[0].get_strr() : ostd::string_range(),
|
||||||
ostd::ConstCharRange()
|
ostd::string_range()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
res.set_int(cs_int(val));
|
res.set_int(cs_int(val));
|
||||||
|
@ -23,8 +23,8 @@ static inline void cs_strgcmp(cs_value_r args, cs_value &res, F cfunc) {
|
||||||
|
|
||||||
void cs_init_lib_string(cs_state &cs) {
|
void cs_init_lib_string(cs_state &cs) {
|
||||||
cs.new_command("strstr", "ss", [](auto &, auto args, auto &res) {
|
cs.new_command("strstr", "ss", [](auto &, auto args, auto &res) {
|
||||||
ostd::ConstCharRange a = args[0].get_strr(), b = args[1].get_strr();
|
ostd::string_range a = args[0].get_strr(), b = args[1].get_strr();
|
||||||
ostd::ConstCharRange s = a;
|
ostd::string_range s = a;
|
||||||
for (cs_int i = 0; b.size() <= s.size(); ++i) {
|
for (cs_int i = 0; b.size() <= s.size(); ++i) {
|
||||||
if (b == s.slice(0, b.size())) {
|
if (b == s.slice(0, b.size())) {
|
||||||
res.set_int(i);
|
res.set_int(i);
|
||||||
|
@ -40,7 +40,7 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("strcode", "si", [](auto &, auto args, auto &res) {
|
cs.new_command("strcode", "si", [](auto &, auto args, auto &res) {
|
||||||
ostd::ConstCharRange str = args[0].get_strr();
|
ostd::string_range str = args[0].get_strr();
|
||||||
cs_int i = args[1].get_int();
|
cs_int i = args[1].get_int();
|
||||||
if (i >= cs_int(str.size())) {
|
if (i >= cs_int(str.size())) {
|
||||||
res.set_int(0);
|
res.set_int(0);
|
||||||
|
@ -99,7 +99,7 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
}
|
}
|
||||||
cs_string s;
|
cs_string s;
|
||||||
cs_string fs = args[0].get_str();
|
cs_string fs = args[0].get_str();
|
||||||
ostd::ConstCharRange f = ostd::iter(fs);
|
ostd::string_range f = ostd::iter(fs);
|
||||||
while (!f.empty()) {
|
while (!f.empty()) {
|
||||||
char c = *f;
|
char c = *f;
|
||||||
++f;
|
++f;
|
||||||
|
@ -135,7 +135,7 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("substr", "siiN", [](auto &, auto args, auto &res) {
|
cs.new_command("substr", "siiN", [](auto &, auto args, auto &res) {
|
||||||
ostd::ConstCharRange s = args[0].get_strr();
|
ostd::string_range s = args[0].get_strr();
|
||||||
cs_int start = args[1].get_int(), count = args[2].get_int();
|
cs_int start = args[1].get_int(), count = args[2].get_int();
|
||||||
cs_int numargs = args[3].get_int();
|
cs_int numargs = args[3].get_int();
|
||||||
cs_int len = cs_int(s.size()), offset = ostd::clamp(start, cs_int(0), len);
|
cs_int len = cs_int(s.size()), offset = ostd::clamp(start, cs_int(0), len);
|
||||||
|
@ -148,30 +148,30 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("strcmp", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command("strcmp", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::equal_to<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::equal_to<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command("=s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command("=s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::equal_to<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::equal_to<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command("!=s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command("!=s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::not_equal_to<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::not_equal_to<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command("<s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command("<s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::less<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::less<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command(">s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command(">s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::greater<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::greater<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command("<=s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command("<=s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::less_equal<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::less_equal<ostd::string_range>());
|
||||||
});
|
});
|
||||||
cs.new_command(">=s", "s1V", [](auto &, auto args, auto &res) {
|
cs.new_command(">=s", "s1V", [](auto &, auto args, auto &res) {
|
||||||
cs_strgcmp(args, res, std::greater_equal<ostd::ConstCharRange>());
|
cs_strgcmp(args, res, std::greater_equal<ostd::string_range>());
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("strreplace", "ssss", [](auto &, auto args, auto &res) {
|
cs.new_command("strreplace", "ssss", [](auto &, auto args, auto &res) {
|
||||||
ostd::ConstCharRange s = args[0].get_strr();
|
ostd::string_range s = args[0].get_strr();
|
||||||
ostd::ConstCharRange oldval = args[1].get_strr(),
|
ostd::string_range oldval = args[1].get_strr(),
|
||||||
newval = args[2].get_strr(),
|
newval = args[2].get_strr(),
|
||||||
newval2 = args[3].get_strr();
|
newval2 = args[3].get_strr();
|
||||||
if (newval2.empty()) {
|
if (newval2.empty()) {
|
||||||
|
@ -183,8 +183,8 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (size_t i = 0;; ++i) {
|
for (size_t i = 0;; ++i) {
|
||||||
ostd::ConstCharRange found;
|
ostd::string_range found;
|
||||||
ostd::ConstCharRange trys = s;
|
ostd::string_range trys = s;
|
||||||
for (; oldval.size() <= trys.size(); ++trys) {
|
for (; oldval.size() <= trys.size(); ++trys) {
|
||||||
if (trys.slice(0, oldval.size()) == oldval) {
|
if (trys.slice(0, oldval.size()) == oldval) {
|
||||||
found = trys;
|
found = trys;
|
||||||
|
@ -204,8 +204,8 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("strsplice", "ssii", [](auto &, auto args, auto &res) {
|
cs.new_command("strsplice", "ssii", [](auto &, auto args, auto &res) {
|
||||||
ostd::ConstCharRange s = args[0].get_strr();
|
ostd::string_range s = args[0].get_strr();
|
||||||
ostd::ConstCharRange vals = args[1].get_strr();
|
ostd::string_range vals = args[1].get_strr();
|
||||||
cs_int skip = args[2].get_int(),
|
cs_int skip = args[2].get_int(),
|
||||||
count = args[3].get_int();
|
count = args[3].get_int();
|
||||||
cs_int offset = ostd::clamp(skip, cs_int(0), cs_int(s.size())),
|
cs_int offset = ostd::clamp(skip, cs_int(0), cs_int(s.size())),
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <ostd/string.hh>
|
#include <ostd/string.hh>
|
||||||
|
|
||||||
static void init_lineedit(cs_state &, ostd::ConstCharRange) {
|
static void init_lineedit(cs_state &, ostd::string_range) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||||
|
@ -18,7 +18,7 @@ static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||||
return std::move(ret);
|
return std::move(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_history(cs_state &, ostd::ConstCharRange) {
|
static void add_history(cs_state &, ostd::string_range) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
static cs_state *ln_cs = nullptr;
|
static cs_state *ln_cs = nullptr;
|
||||||
|
|
||||||
static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
||||||
ostd::ConstCharRange cmd = get_complete_cmd(buf);
|
ostd::string_range cmd = get_complete_cmd(buf);
|
||||||
for (auto id: ln_cs->get_idents()) {
|
for (auto id: ln_cs->get_idents()) {
|
||||||
if (!id->is_command()) {
|
if (!id->is_command()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange idname = id->get_name();
|
ostd::string_range idname = id->get_name();
|
||||||
if (idname.size() <= cmd.size()) {
|
if (idname.size() <= cmd.size()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ static void ln_hint_free(void *hint) {
|
||||||
delete[] static_cast<char *>(hint);
|
delete[] static_cast<char *>(hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_lineedit(cs_state &cs, ostd::ConstCharRange) {
|
static void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||||
/* sensible default history size */
|
/* sensible default history size */
|
||||||
linenoiseHistorySetMaxLen(1000);
|
linenoiseHistorySetMaxLen(1000);
|
||||||
ln_cs = &cs;
|
ln_cs = &cs;
|
||||||
|
@ -75,7 +75,7 @@ static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||||
return std::move(ret);
|
return std::move(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_history(cs_state &, ostd::ConstCharRange line) {
|
static void add_history(cs_state &, ostd::string_range line) {
|
||||||
/* backed by std::string so it's terminated */
|
/* backed by std::string so it's terminated */
|
||||||
linenoiseHistoryAdd(line.data());
|
linenoiseHistoryAdd(line.data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
static cs_state *rd_cs = nullptr;
|
static cs_state *rd_cs = nullptr;
|
||||||
|
|
||||||
static char *ln_complete_list(char const *buf, int state) {
|
static char *ln_complete_list(char const *buf, int state) {
|
||||||
static ostd::ConstCharRange cmd;
|
static ostd::string_range cmd;
|
||||||
static ostd::PointerRange<cs_ident *> itr;
|
static ostd::PointerRange<cs_ident *> itr;
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
|
@ -28,7 +28,7 @@ static char *ln_complete_list(char const *buf, int state) {
|
||||||
if (!id->is_command()) {
|
if (!id->is_command()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange idname = id->get_name();
|
ostd::string_range idname = id->get_name();
|
||||||
if (idname.size() <= cmd.size()) {
|
if (idname.size() <= cmd.size()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ void ln_hint() {
|
||||||
rl_replace_line(old.data(), 0);
|
rl_replace_line(old.data(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_lineedit(cs_state &cs, ostd::ConstCharRange) {
|
static void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||||
rd_cs = &cs;
|
rd_cs = &cs;
|
||||||
rl_attempted_completion_function = ln_complete;
|
rl_attempted_completion_function = ln_complete;
|
||||||
rl_redisplay_function = ln_hint;
|
rl_redisplay_function = ln_hint;
|
||||||
|
@ -79,7 +79,7 @@ static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||||
return std::move(ret);
|
return std::move(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_history(cs_state &, ostd::ConstCharRange line) {
|
static void add_history(cs_state &, ostd::string_range line) {
|
||||||
/* backed by std::string so it's terminated */
|
/* backed by std::string so it's terminated */
|
||||||
add_history(line.data());
|
add_history(line.data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
using namespace cscript;
|
using namespace cscript;
|
||||||
|
|
||||||
ostd::ConstCharRange version = "CubeScript 0.0.1";
|
ostd::string_range version = "CubeScript 0.0.1";
|
||||||
|
|
||||||
/* util */
|
/* util */
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ static bool stdin_is_tty() {
|
||||||
|
|
||||||
/* line editing support */
|
/* line editing support */
|
||||||
|
|
||||||
static inline ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) {
|
static inline ostd::string_range get_complete_cmd(ostd::string_range buf) {
|
||||||
ostd::ConstCharRange not_allowed = "\"/;()[] \t\r\n\0";
|
ostd::string_range not_allowed = "\"/;()[] \t\r\n\0";
|
||||||
ostd::ConstCharRange found = ostd::find_one_of(buf, not_allowed);
|
ostd::string_range found = ostd::find_one_of(buf, not_allowed);
|
||||||
while (!found.empty()) {
|
while (!found.empty()) {
|
||||||
++found;
|
++found;
|
||||||
buf = found;
|
buf = found;
|
||||||
|
@ -39,7 +39,7 @@ static inline ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline ostd::ConstCharRange get_arg_type(char arg) {
|
static inline ostd::string_range get_arg_type(char arg) {
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case 'i':
|
case 'i':
|
||||||
return "int";
|
return "int";
|
||||||
|
@ -71,7 +71,7 @@ static inline ostd::ConstCharRange get_arg_type(char arg) {
|
||||||
return "illegal";
|
return "illegal";
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fill_cmd_args(std::string &writer, ostd::ConstCharRange args) {
|
static inline void fill_cmd_args(std::string &writer, ostd::string_range args) {
|
||||||
char variadic = '\0';
|
char variadic = '\0';
|
||||||
int nrep = 0;
|
int nrep = 0;
|
||||||
if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) {
|
if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) {
|
||||||
|
@ -128,8 +128,8 @@ static inline void fill_cmd_args(std::string &writer, ostd::ConstCharRange args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline cs_command *get_hint_cmd(cs_state &cs, ostd::ConstCharRange buf) {
|
static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) {
|
||||||
ostd::ConstCharRange nextchars = "([;";
|
ostd::string_range nextchars = "([;";
|
||||||
auto lp = ostd::find_one_of(buf, nextchars);
|
auto lp = ostd::find_one_of(buf, nextchars);
|
||||||
if (!lp.empty()) {
|
if (!lp.empty()) {
|
||||||
cs_command *cmd = get_hint_cmd(cs, buf + 1);
|
cs_command *cmd = get_hint_cmd(cs, buf + 1);
|
||||||
|
@ -140,8 +140,8 @@ static inline cs_command *get_hint_cmd(cs_state &cs, ostd::ConstCharRange buf) {
|
||||||
while (!buf.empty() && isspace(buf.front())) {
|
while (!buf.empty() && isspace(buf.front())) {
|
||||||
++buf;
|
++buf;
|
||||||
}
|
}
|
||||||
ostd::ConstCharRange spaces = " \t\r\n";
|
ostd::string_range spaces = " \t\r\n";
|
||||||
ostd::ConstCharRange s = ostd::find_one_of(buf, spaces);
|
ostd::string_range s = ostd::find_one_of(buf, spaces);
|
||||||
if (!s.empty()) {
|
if (!s.empty()) {
|
||||||
buf = ostd::slice_until(buf, s);
|
buf = ostd::slice_until(buf, s);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ static inline cs_command *get_hint_cmd(cs_state &cs, ostd::ConstCharRange buf) {
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
|
|
||||||
void print_usage(ostd::ConstCharRange progname, bool err) {
|
void print_usage(ostd::string_range progname, bool err) {
|
||||||
auto &s = err ? ostd::err : ostd::out;
|
auto &s = err ? ostd::err : ostd::out;
|
||||||
s.writeln(
|
s.writeln(
|
||||||
"Usage: ", progname, " [options] [file]\n"
|
"Usage: ", progname, " [options] [file]\n"
|
||||||
|
@ -187,7 +187,7 @@ static void do_sigint(int n) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool do_call(cs_state &cs, ostd::ConstCharRange line, bool file = false) {
|
static bool do_call(cs_state &cs, ostd::string_range line, bool file = false) {
|
||||||
cs_value ret;
|
cs_value ret;
|
||||||
scs = &cs;
|
scs = &cs;
|
||||||
signal(SIGINT, do_sigint);
|
signal(SIGINT, do_sigint);
|
||||||
|
@ -202,7 +202,7 @@ static bool do_call(cs_state &cs, ostd::ConstCharRange line, bool file = false)
|
||||||
} catch (cscript::cs_error const &e) {
|
} catch (cscript::cs_error const &e) {
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
scs = nullptr;
|
scs = nullptr;
|
||||||
ostd::ConstCharRange terr = e.what();
|
ostd::string_range terr = e.what();
|
||||||
auto col = ostd::find(terr, ':');
|
auto col = ostd::find(terr, ':');
|
||||||
bool is_lnum = false;
|
bool is_lnum = false;
|
||||||
if (!col.empty()) {
|
if (!col.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue