mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
some fix
This commit is contained in:
parent
3f5e3c3968
commit
50cde5ff03
@ -71,13 +71,18 @@ namespace std = ::std;
|
|||||||
template <size_t T>
|
template <size_t T>
|
||||||
struct NumberTraits;
|
struct NumberTraits;
|
||||||
|
|
||||||
|
inline constexpr bool is_negative_shift_well_defined(){
|
||||||
|
// rshift does not affect the sign bit
|
||||||
|
return ((int)-1) >> 1 == -1 && ((int64_t)-1) >> 1 == -1;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct NumberTraits<4> {
|
struct NumberTraits<4> {
|
||||||
using int_t = int32_t;
|
using int_t = int32_t;
|
||||||
using float_t = float;
|
using float_t = float;
|
||||||
|
|
||||||
static constexpr int_t kMaxSmallInt = (1 << 28) - 1;
|
static constexpr int_t kMaxSmallInt = (1 << 28) - 1;
|
||||||
static constexpr int_t kMinSmallInt = - (1 << 28);
|
static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1 << 28) : 0;
|
||||||
static constexpr float_t kEpsilon = (float_t)1e-4;
|
static constexpr float_t kEpsilon = (float_t)1e-4;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -87,7 +92,7 @@ struct NumberTraits<8> {
|
|||||||
using float_t = double;
|
using float_t = double;
|
||||||
|
|
||||||
static constexpr int_t kMaxSmallInt = (1ll << 60) - 1;
|
static constexpr int_t kMaxSmallInt = (1ll << 60) - 1;
|
||||||
static constexpr int_t kMinSmallInt = - (1ll << 60);
|
static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1ll << 60) : 0;
|
||||||
static constexpr float_t kEpsilon = (float_t)1e-8;
|
static constexpr float_t kEpsilon = (float_t)1e-8;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ namespace pkpy{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CodeEmitContext::emit_int(i64 value, int line){
|
int CodeEmitContext::emit_int(i64 value, int line){
|
||||||
if(value >= -5 && value <= 16){
|
bool allow_neg_int = is_negative_shift_well_defined() || value >= 0;
|
||||||
|
if(allow_neg_int && value >= -5 && value <= 16){
|
||||||
uint8_t op = OP_LOAD_INT_NEG_5 + (uint8_t)value + 5;
|
uint8_t op = OP_LOAD_INT_NEG_5 + (uint8_t)value + 5;
|
||||||
return emit_((Opcode)op, BC_NOARG, line);
|
return emit_((Opcode)op, BC_NOARG, line);
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user