diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 2ed84dd..889c862 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -5,6 +5,7 @@ #include #include +#include namespace cscript { @@ -353,7 +354,7 @@ lookupid: numargs++; break; case 'b': - gs.gen_int(CsIntMin); + gs.gen_int(ostd::NumericLimitMin); numargs++; break; case 'f': @@ -939,7 +940,7 @@ static void compile_cmd( if (rep) { break; } - gs.gen_int(CsIntMin); + gs.gen_int(ostd::NumericLimitMin); fakeargs++; } numargs++; diff --git a/src/cs_util.hh b/src/cs_util.hh index 0f32a61..827e54c 100644 --- a/src/cs_util.hh +++ b/src/cs_util.hh @@ -7,9 +7,6 @@ namespace cscript { -/* TODO: use actual numeric limits as soon as ostd has them */ -constexpr CsInt const CsIntMin = -(~(1ULL << (sizeof(CsInt) * CHAR_BIT - 1))) - 1; - template using CsMap = ostd::Map; diff --git a/src/cs_vm.cc b/src/cs_vm.cc index fa8b77c..dd3d547 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -3,6 +3,7 @@ #include "cs_util.hh" #include +#include namespace cscript { @@ -320,7 +321,7 @@ static inline void callcommand( if (rep) { break; } - args[i].set_int(CsIntMin); + args[i].set_int(ostd::NumericLimitMin); fakeargs++; } else { args[i].force_int(); diff --git a/src/lib_math.cc b/src/lib_math.cc index ca8fd2c..2c08445 100644 --- a/src/lib_math.cc +++ b/src/lib_math.cc @@ -1,5 +1,3 @@ -#include - /* c++ versions for overloaded math */ #include #include @@ -309,7 +307,7 @@ void cs_init_lib_math(CsState &cs) { cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) { cs_mathop( args, res, 0, [](CsInt val1, CsInt val2) { - return (val2 < CsInt(sizeof(CsInt) * CHAR_BIT)) + return (val2 < CsInt(ostd::SizeInBits)) ? (val1 << ostd::max(val2, CsInt(0))) : 0; }, CsMathNoop() @@ -319,7 +317,7 @@ void cs_init_lib_math(CsState &cs) { cs_mathop( args, res, 0, [](CsInt val1, CsInt val2) { return val1 >> ostd::clamp( - val2, CsInt(0), CsInt(sizeof(CsInt) * CHAR_BIT) + val2, CsInt(0), CsInt(ostd::SizeInBits) ); }, CsMathNoop() );