blueloveTH há 1 ano atrás
pai
commit
89b6fd59f1
3 ficheiros alterados com 7 adições e 9 exclusões
  1. 1 3
      src/compiler/compiler.c
  2. 3 3
      src/modules/pickle.c
  3. 3 3
      src/objects/codeobject.c

+ 1 - 3
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;

+ 3 - 3
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 {

+ 3 - 3
src/objects/codeobject.c

@@ -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) {