diff options
| author | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
| commit | f80b349d5490aa289b2925d297f3f3c618977570 (patch) | |
| tree | 8d8fb0d2beb3e863592139d603ada63e5aa6ce77 /src/lj_bcwrite.c | |
| parent | 3215838aa744d148e79a8ea0bd7c014e984302cb (diff) | |
| download | luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.gz luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.bz2 luajit-f80b349d5490aa289b2925d297f3f3c618977570.zip | |
Unify Lua number to FFI integer conversions.
Phew. #1411
Diffstat (limited to 'src/lj_bcwrite.c')
| -rw-r--r-- | src/lj_bcwrite.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c index ec6f13c8..cd7ae942 100644 --- a/src/lj_bcwrite.c +++ b/src/lj_bcwrite.c | |||
| @@ -59,9 +59,9 @@ static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow) | |||
| 59 | p = lj_strfmt_wuleb128(p, intV(o)); | 59 | p = lj_strfmt_wuleb128(p, intV(o)); |
| 60 | } else if (tvisnum(o)) { | 60 | } else if (tvisnum(o)) { |
| 61 | if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ | 61 | if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */ |
| 62 | lua_Number num = numV(o); | 62 | int64_t i64; |
| 63 | int32_t k = lj_num2int(num); | 63 | int32_t k; |
| 64 | if (num == (lua_Number)k) { /* -0 is never a constant. */ | 64 | if (lj_num2int_check(numV(o), i64, k)) { /* -0 is never a constant. */ |
| 65 | *p++ = BCDUMP_KTAB_INT; | 65 | *p++ = BCDUMP_KTAB_INT; |
| 66 | p = lj_strfmt_wuleb128(p, k); | 66 | p = lj_strfmt_wuleb128(p, k); |
| 67 | ctx->sb.w = p; | 67 | ctx->sb.w = p; |
| @@ -270,9 +270,8 @@ static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt) | |||
| 270 | /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */ | 270 | /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */ |
| 271 | if (!LJ_DUALNUM && o->u32.hi != LJ_KEYINDEX) { | 271 | if (!LJ_DUALNUM && o->u32.hi != LJ_KEYINDEX) { |
| 272 | /* Narrow number constants to integers. */ | 272 | /* Narrow number constants to integers. */ |
| 273 | lua_Number num = numV(o); | 273 | int64_t i64; |
| 274 | k = lj_num2int(num); | 274 | if (lj_num2int_check(numV(o), i64, k)) { /* -0 is never a constant. */ |
| 275 | if (num == (lua_Number)k) { /* -0 is never a constant. */ | ||
| 276 | save_int: | 275 | save_int: |
| 277 | p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u)); | 276 | p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u)); |
| 278 | if (k < 0) | 277 | if (k < 0) |
