windows fixes and other correctness/portability stuff
parent
eddbf64c87
commit
13d46881e8
|
@ -8,6 +8,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
@ -305,7 +306,7 @@ protected:
|
||||||
alias() = default;
|
alias() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct command: ident {
|
struct LIBCUBESCRIPT_EXPORT command: ident {
|
||||||
std::string_view get_args() const;
|
std::string_view get_args() const;
|
||||||
int get_num_args() const;
|
int get_num_args() const;
|
||||||
|
|
||||||
|
@ -354,18 +355,18 @@ struct LIBCUBESCRIPT_EXPORT state {
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
hook_func set_call_hook(F &&f) {
|
hook_func set_call_hook(F &&f) {
|
||||||
return std::move(set_call_hook(
|
return set_call_hook(
|
||||||
hook_func{std::forward<F>(f), callable_alloc, this}
|
hook_func{std::forward<F>(f), callable_alloc, this}
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
hook_func const &get_call_hook() const;
|
hook_func const &get_call_hook() const;
|
||||||
hook_func &get_call_hook();
|
hook_func &get_call_hook();
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
var_print_func set_var_printer(F &&f) {
|
var_print_func set_var_printer(F &&f) {
|
||||||
return std::move(set_var_printer(
|
return set_var_printer(
|
||||||
var_print_func{std::forward<F>(f), callable_alloc, this}
|
var_print_func{std::forward<F>(f), callable_alloc, this}
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
var_print_func const &get_var_printer() const;
|
var_print_func const &get_var_printer() const;
|
||||||
|
|
||||||
|
@ -532,7 +533,7 @@ private:
|
||||||
thread_state *p_tstate = nullptr;
|
thread_state *p_tstate = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stack_state {
|
struct LIBCUBESCRIPT_EXPORT stack_state {
|
||||||
struct node {
|
struct node {
|
||||||
node const *next;
|
node const *next;
|
||||||
ident const *id;
|
ident const *id;
|
||||||
|
|
|
@ -706,7 +706,7 @@ static bool compilearg(
|
||||||
}
|
}
|
||||||
case VAL_WORD:
|
case VAL_WORD:
|
||||||
if (word) {
|
if (word) {
|
||||||
*word = std::move(gs.get_str_dup());
|
*word = gs.get_str_dup();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VAL_ANY:
|
case VAL_ANY:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "cs_std.hh"
|
#include "cs_std.hh"
|
||||||
#include "cs_thread.hh"
|
#include "cs_thread.hh"
|
||||||
|
@ -18,8 +19,8 @@ LIBCUBESCRIPT_EXPORT char const *parse_string(
|
||||||
if (str.empty() || (str.front() != '\"')) {
|
if (str.empty() || (str.front() != '\"')) {
|
||||||
return str.data();
|
return str.data();
|
||||||
}
|
}
|
||||||
char const *beg = str.begin();
|
char const *beg = &str[0];
|
||||||
char const *end = str.end();
|
char const *end = &str[str.size()];
|
||||||
char const *orig = beg++;
|
char const *orig = beg++;
|
||||||
++nl;
|
++nl;
|
||||||
while (beg != end) {
|
while (beg != end) {
|
||||||
|
@ -66,8 +67,8 @@ end:
|
||||||
LIBCUBESCRIPT_EXPORT char const *parse_word(
|
LIBCUBESCRIPT_EXPORT char const *parse_word(
|
||||||
state &cs, std::string_view str
|
state &cs, std::string_view str
|
||||||
) {
|
) {
|
||||||
char const *it = str.begin();
|
char const *it = &str[0];
|
||||||
char const *end = str.end();
|
char const *end = &str[str.size()];
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
std::string_view chrs{"\"/;()[] \t\r\n"};
|
std::string_view chrs{"\"/;()[] \t\r\n"};
|
||||||
it = std::find_first_of(it, end, chrs.begin(), chrs.end());
|
it = std::find_first_of(it, end, chrs.begin(), chrs.end());
|
||||||
|
@ -148,8 +149,8 @@ static inline bool p_check_neg(char const *&input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
integer_type parse_int(std::string_view input, std::string_view *endstr) {
|
integer_type parse_int(std::string_view input, std::string_view *endstr) {
|
||||||
char const *beg = input.begin();
|
char const *beg = &input[0];
|
||||||
char const *end = input.end();
|
char const *end = &input[input.size()];
|
||||||
char const *orig = beg;
|
char const *orig = beg;
|
||||||
beg = p_skip_white(beg, end);
|
beg = p_skip_white(beg, end);
|
||||||
if (beg == end) {
|
if (beg == end) {
|
||||||
|
@ -256,8 +257,8 @@ static inline bool parse_gen_float(
|
||||||
}
|
}
|
||||||
|
|
||||||
float_type parse_float(std::string_view input, std::string_view *endstr) {
|
float_type parse_float(std::string_view input, std::string_view *endstr) {
|
||||||
char const *beg = input.begin();
|
char const *beg = &input[0];
|
||||||
char const *end = input.end();
|
char const *end = &input[input.size()];
|
||||||
char const *orig = beg;
|
char const *orig = beg;
|
||||||
beg = p_skip_white(beg, end);
|
beg = p_skip_white(beg, end);
|
||||||
if (beg == end) {
|
if (beg == end) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "cs_state.hh"
|
#include "cs_state.hh"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
|
||||||
|
@ -191,7 +192,7 @@ float_type any_value::force_float() {
|
||||||
float_type rf = 0.0f;
|
float_type rf = 0.0f;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case value_type::INT:
|
case value_type::INT:
|
||||||
rf = csv_get<integer_type>(&p_stor);
|
rf = float_type(csv_get<integer_type>(&p_stor));
|
||||||
break;
|
break;
|
||||||
case value_type::STRING:
|
case value_type::STRING:
|
||||||
rf = parse_float(
|
rf = parse_float(
|
||||||
|
@ -211,7 +212,7 @@ integer_type any_value::force_int() {
|
||||||
integer_type ri = 0;
|
integer_type ri = 0;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case value_type::FLOAT:
|
case value_type::FLOAT:
|
||||||
ri = csv_get<float_type>(&p_stor);
|
ri = integer_type(std::floor(csv_get<float_type>(&p_stor)));
|
||||||
break;
|
break;
|
||||||
case value_type::STRING:
|
case value_type::STRING:
|
||||||
ri = parse_int(
|
ri = parse_int(
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <cubescript/cubescript.hh>
|
#include <cubescript/cubescript.hh>
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "cs_std.hh"
|
#include "cs_std.hh"
|
||||||
#include "cs_ident.hh"
|
#include "cs_ident.hh"
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
|
|
||||||
namespace cubescript {
|
namespace cubescript {
|
||||||
|
|
||||||
static constexpr float_type PI = 3.14159265358979f;
|
static constexpr float_type PI = float_type(3.14159265358979323846);
|
||||||
static constexpr float_type RAD = PI / 180.0f;
|
static constexpr float_type LN2 = float_type(0.693147180559945309417);
|
||||||
|
static constexpr float_type RAD = PI / float_type(180.0);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct math_val;
|
struct math_val;
|
||||||
|
@ -103,7 +104,7 @@ void init_lib_math(state &cs) {
|
||||||
res.set_float(std::log(args[0].get_float()));
|
res.set_float(std::log(args[0].get_float()));
|
||||||
});
|
});
|
||||||
cs.new_command("log2", "f", [](auto &, auto args, auto &res) {
|
cs.new_command("log2", "f", [](auto &, auto args, auto &res) {
|
||||||
res.set_float(std::log(args[0].get_float()) / M_LN2);
|
res.set_float(std::log(args[0].get_float()) / LN2);
|
||||||
});
|
});
|
||||||
cs.new_command("log10", "f", [](auto &, auto args, auto &res) {
|
cs.new_command("log10", "f", [](auto &, auto args, auto &res) {
|
||||||
res.set_float(std::log10(args[0].get_float()));
|
res.set_float(std::log10(args[0].get_float()));
|
||||||
|
|
|
@ -198,7 +198,6 @@ void init_lib_string(state &cs) {
|
||||||
}
|
}
|
||||||
charbuf buf{ccs};
|
charbuf buf{ccs};
|
||||||
for (size_t i = 0;; ++i) {
|
for (size_t i = 0;; ++i) {
|
||||||
std::string_view found;
|
|
||||||
auto p = s.find(oldval);
|
auto p = s.find(oldval);
|
||||||
if (p == s.npos) {
|
if (p == s.npos) {
|
||||||
buf.append(s);
|
buf.append(s);
|
||||||
|
|
|
@ -21,10 +21,20 @@ libcubescript_src = [
|
||||||
'lib_str.cc'
|
'lib_str.cc'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
lib_cxxflags = []
|
||||||
|
host_system = host_machine.system()
|
||||||
|
|
||||||
|
if host_system == 'windows' or host_system == 'cygwin'
|
||||||
|
lib_cxxflags += '-DLIBCUBESCRIPT_BUILD'
|
||||||
|
if get_option('default_library') != 'static'
|
||||||
|
lib_cxxflags += '-DLIBCUBESCRIPT_DLL'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
libcubescript_target = library('cubescript',
|
libcubescript_target = library('cubescript',
|
||||||
libcubescript_src,
|
libcubescript_src,
|
||||||
include_directories: libcubescript_includes + [include_directories('.')],
|
include_directories: libcubescript_includes + [include_directories('.')],
|
||||||
cpp_args: extra_cxxflags,
|
cpp_args: extra_cxxflags + lib_cxxflags,
|
||||||
install: true,
|
install: true,
|
||||||
pic: true,
|
pic: true,
|
||||||
version: meson.project_version()
|
version: meson.project_version()
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
|
/* avoid silly complaints about fopen */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cctype>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -183,9 +189,9 @@ static cs::state *scs = nullptr;
|
||||||
static void do_sigint(int n) {
|
static void do_sigint(int n) {
|
||||||
/* in case another SIGINT happens, terminate normally */
|
/* in case another SIGINT happens, terminate normally */
|
||||||
signal(n, SIG_DFL);
|
signal(n, SIG_DFL);
|
||||||
scs->set_call_hook([](cs::state &cs) {
|
scs->set_call_hook([](cs::state &css) {
|
||||||
cs.set_call_hook(nullptr);
|
css.set_call_hook(nullptr);
|
||||||
throw cs::error{cs, "<execution interrupted>"};
|
throw cs::error{css, "<execution interrupted>"};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,13 +361,13 @@ int main(int argc, char **argv) {
|
||||||
gcs.set_var_printer(repl_print_var);
|
gcs.set_var_printer(repl_print_var);
|
||||||
gcs.init_libs();
|
gcs.init_libs();
|
||||||
|
|
||||||
gcs.new_command("exec", "s", [](auto &cs, auto args, auto &) {
|
gcs.new_command("exec", "s", [](auto &css, auto args, auto &) {
|
||||||
auto file = args[0].get_str();
|
auto file = args[0].get_str();
|
||||||
cs::any_value val{cs};
|
cs::any_value val{css};
|
||||||
bool ret = do_run_file(cs, file, val);
|
bool ret = do_run_file(css, file, val);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw cs::error(
|
throw cs::error(
|
||||||
cs, "could not run file \"%s\"", file
|
css, "could not run file \"%s\"", file.data()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue