From 89b6fd59f1d773c086d8001c3b4e501cba43521c Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 14 Dec 2024 13:15:59 +0800 Subject: [PATCH] ... --- src/compiler/compiler.c | 4 +--- src/modules/pickle.c | 6 +++--- src/objects/codeobject.c | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index b97ee107..7ef73957 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -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; diff --git a/src/modules/pickle.c b/src/modules/pickle.c index db6f9431..75a7bf0e 100644 --- a/src/modules/pickle.c +++ b/src/modules/pickle.c @@ -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 { diff --git a/src/objects/codeobject.c b/src/objects/codeobject.c index 8ca32bd3..23a9fa7b 100644 --- a/src/objects/codeobject.c +++ b/src/objects/codeobject.c @@ -4,10 +4,10 @@ #include 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) {