forked from OctaForge/libcubescript
use standard type traits
parent
2241bcf4b8
commit
2536179500
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "cubescript_conf.hh"
|
#include "cubescript_conf.hh"
|
||||||
|
|
||||||
#include <ostd/platform.hh>
|
#include <ostd/platform.hh>
|
||||||
#include <ostd/types.hh>
|
#include <ostd/types.hh>
|
||||||
#include <ostd/type_traits.hh>
|
|
||||||
#include <ostd/string.hh>
|
#include <ostd/string.hh>
|
||||||
#include <ostd/vector.hh>
|
#include <ostd/vector.hh>
|
||||||
#include <ostd/range.hh>
|
#include <ostd/range.hh>
|
||||||
|
@ -23,9 +23,9 @@ namespace cscript {
|
||||||
|
|
||||||
using CsString = std::string;
|
using CsString = std::string;
|
||||||
|
|
||||||
static_assert(ostd::IsIntegral<CsInt>, "CsInt must be integral");
|
static_assert(std::is_integral_v<CsInt>, "CsInt must be integral");
|
||||||
static_assert(ostd::IsSigned<CsInt>, "CsInt must be signed");
|
static_assert(std::is_signed_v<CsInt>, "CsInt must be signed");
|
||||||
static_assert(ostd::IsFloatingPoint<CsFloat>, "CsFloat must be floating point");
|
static_assert(std::is_floating_point_v<CsFloat>, "CsFloat must be floating point");
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CsIdfPersist = 1 << 0,
|
CsIdfPersist = 1 << 0,
|
||||||
|
@ -108,7 +108,7 @@ struct OSTD_EXPORT CsValue {
|
||||||
bool code_is_empty() const;
|
bool code_is_empty() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ostd::AlignedUnion<1, CsInt, CsFloat, void *> p_stor;
|
std::aligned_union_t<1, CsInt, CsFloat, void *> p_stor;
|
||||||
size_t p_len;
|
size_t p_len;
|
||||||
CsValueType p_type;
|
CsValueType p_type;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <ostd/limits.hh>
|
#include <limits>
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ lookupid:
|
||||||
numargs++;
|
numargs++;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
gs.gen_int(ostd::NumericLimitMin<CsInt>);
|
gs.gen_int(std::numeric_limits<CsInt>::min());
|
||||||
numargs++;
|
numargs++;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
|
@ -942,7 +942,7 @@ static void compile_cmd(
|
||||||
if (rep) {
|
if (rep) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gs.gen_int(ostd::NumericLimitMin<CsInt>);
|
gs.gen_int(std::numeric_limits<CsInt>::min());
|
||||||
fakeargs++;
|
fakeargs++;
|
||||||
}
|
}
|
||||||
numargs++;
|
numargs++;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#ifndef LIBCUBESCRIPT_CS_UTIL_HH
|
#ifndef LIBCUBESCRIPT_CS_UTIL_HH
|
||||||
#define LIBCUBESCRIPT_CS_UTIL_HH
|
#define LIBCUBESCRIPT_CS_UTIL_HH
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include <ostd/string.hh>
|
#include <ostd/string.hh>
|
||||||
#include <ostd/utility.hh>
|
#include <ostd/utility.hh>
|
||||||
#include <ostd/type_traits.hh>
|
|
||||||
#include <ostd/unordered_map.hh>
|
#include <ostd/unordered_map.hh>
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
@ -29,7 +30,7 @@ struct CsScopeExit {
|
||||||
~CsScopeExit() {
|
~CsScopeExit() {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
ostd::Decay<F> func;
|
std::decay_t<F> func;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename F1, typename F2>
|
template<typename F1, typename F2>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "cs_vm.hh"
|
#include "cs_vm.hh"
|
||||||
#include "cs_util.hh"
|
#include "cs_util.hh"
|
||||||
|
|
||||||
#include <ostd/limits.hh>
|
#include <limits>
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ static inline void callcommand(
|
||||||
if (rep) {
|
if (rep) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
args[i].set_int(ostd::NumericLimitMin<CsInt>);
|
args[i].set_int(std::numeric_limits<CsInt>::min());
|
||||||
fakeargs++;
|
fakeargs++;
|
||||||
} else {
|
} else {
|
||||||
args[i].force_int();
|
args[i].force_int();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <climits>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ void cs_init_lib_math(CsState &cs) {
|
||||||
cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) {
|
cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) {
|
||||||
cs_mathop<CsInt>(
|
cs_mathop<CsInt>(
|
||||||
args, res, 0, [](CsInt val1, CsInt val2) {
|
args, res, 0, [](CsInt val1, CsInt val2) {
|
||||||
return (val2 < CsInt(ostd::SizeInBits<CsInt>))
|
return (val2 < CsInt(sizeof(CsInt) * CHAR_BIT))
|
||||||
? (val1 << std::max(val2, CsInt(0)))
|
? (val1 << std::max(val2, CsInt(0)))
|
||||||
: 0;
|
: 0;
|
||||||
}, CsMathNoop<CsInt>()
|
}, CsMathNoop<CsInt>()
|
||||||
|
@ -253,7 +254,7 @@ void cs_init_lib_math(CsState &cs) {
|
||||||
cs_mathop<CsInt>(
|
cs_mathop<CsInt>(
|
||||||
args, res, 0, [](CsInt val1, CsInt val2) {
|
args, res, 0, [](CsInt val1, CsInt val2) {
|
||||||
return val1 >> std::clamp(
|
return val1 >> std::clamp(
|
||||||
val2, CsInt(0), CsInt(ostd::SizeInBits<CsInt>)
|
val2, CsInt(0), CsInt(sizeof(CsInt) * CHAR_BIT)
|
||||||
);
|
);
|
||||||
}, CsMathNoop<CsInt>()
|
}, CsMathNoop<CsInt>()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue