This commit is contained in:
blueloveTH 2024-12-14 13:15:59 +08:00
parent 8999de5ad7
commit 89b6fd59f1
3 changed files with 7 additions and 9 deletions

View File

@ -1110,8 +1110,6 @@ static void Ctx__dtor(Ctx* self) {
c11_smallmap_s2n__dtor(&self->co_consts_string_dedup_map);
}
static bool is_small_int(int64_t value) { return value >= INT16_MIN && value <= INT16_MAX; }
static int Ctx__prepare_loop_divert(Ctx* self, int line, bool is_break) {
int index = self->curr_iblock;
while(index >= 0) {
@ -1191,7 +1189,7 @@ static void Ctx__revert_last_emit_(Ctx* self) {
}
static int Ctx__emit_int(Ctx* self, int64_t value, int line) {
if(is_small_int(value)) {
if((int16_t)value == value) {
return Ctx__emit_(self, OP_LOAD_SMALL_INT, (uint16_t)value, line);
} else {
py_TValue tmp;

View File

@ -47,13 +47,13 @@ static void pkl__emit_op(PickleObject* buf, PickleOp op) {
}
static void pkl__emit_int(PickleObject* buf, py_i64 val) {
if(val >= INT8_MIN && val <= INT8_MAX) {
if((int8_t)val == val) {
pkl__emit_op(buf, PKL_INT8);
PickleObject__write_bytes(buf, &val, 1);
} else if(val >= INT16_MIN && val <= INT16_MAX) {
} else if((int16_t)val == val) {
pkl__emit_op(buf, PKL_INT16);
PickleObject__write_bytes(buf, &val, 2);
} else if(val >= INT32_MIN && val <= INT32_MAX) {
} else if((int32_t)val == val) {
pkl__emit_op(buf, PKL_INT32);
PickleObject__write_bytes(buf, &val, 4);
} else {

View File

@ -4,10 +4,10 @@
#include <stdint.h>
void Bytecode__set_signed_arg(Bytecode* self, int arg) {
if(arg < INT16_MIN || arg > INT16_MAX) {
c11__abort("set_signed_arg: %d is out of range", arg);
}
self->arg = (int16_t)arg;
if((int16_t)self->arg != arg) {
c11__abort("Bytecode__set_signed_arg(): %d is not representable in int16_t", arg);
}
}
bool Bytecode__is_forward_jump(const Bytecode* self) {