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_parse.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_parse.c')
| -rw-r--r-- | src/lj_parse.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c index 181ce4d7..832f6bf4 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
| @@ -522,9 +522,9 @@ static void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg) | |||
| 522 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv)); | 522 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv)); |
| 523 | else | 523 | else |
| 524 | #else | 524 | #else |
| 525 | lua_Number n = expr_numberV(e); | 525 | int64_t i64; |
| 526 | int32_t k = lj_num2int(n); | 526 | int32_t k; |
| 527 | if (checki16(k) && n == (lua_Number)k) | 527 | if (lj_num2int_cond(expr_numberV(e), i64, k, checki16((int32_t)i64))) |
| 528 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); | 528 | ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k); |
| 529 | else | 529 | else |
| 530 | #endif | 530 | #endif |
| @@ -782,8 +782,9 @@ static int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2) | |||
| 782 | setnumV(&o, n); | 782 | setnumV(&o, n); |
| 783 | if (tvisnan(&o) || tvismzero(&o)) return 0; /* Avoid NaN and -0 as consts. */ | 783 | if (tvisnan(&o) || tvismzero(&o)) return 0; /* Avoid NaN and -0 as consts. */ |
| 784 | if (LJ_DUALNUM) { | 784 | if (LJ_DUALNUM) { |
| 785 | int32_t k = lj_num2int(n); | 785 | int64_t i64; |
| 786 | if ((lua_Number)k == n) { | 786 | int32_t k; |
| 787 | if (lj_num2int_check(n, i64, k)) { | ||
| 787 | setintV(&e1->u.nval, k); | 788 | setintV(&e1->u.nval, k); |
| 788 | return 1; | 789 | return 1; |
| 789 | } | 790 | } |
| @@ -1386,10 +1387,10 @@ static void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr) | |||
| 1386 | if (tvisnum(&n->key)) { | 1387 | if (tvisnum(&n->key)) { |
| 1387 | TValue *tv = &((TValue *)kptr)[kidx]; | 1388 | TValue *tv = &((TValue *)kptr)[kidx]; |
| 1388 | if (LJ_DUALNUM) { | 1389 | if (LJ_DUALNUM) { |
| 1389 | lua_Number nn = numV(&n->key); | 1390 | int64_t i64; |
| 1390 | int32_t k = lj_num2int(nn); | 1391 | int32_t k; |
| 1391 | lj_assertFS(!tvismzero(&n->key), "unexpected -0 key"); | 1392 | lj_assertFS(!tvismzero(&n->key), "unexpected -0 key"); |
| 1392 | if ((lua_Number)k == nn) | 1393 | if (lj_num2int_check(numV(&n->key), i64, k)) |
| 1393 | setintV(tv, k); | 1394 | setintV(tv, k); |
| 1394 | else | 1395 | else |
| 1395 | *tv = n->key; | 1396 | *tv = n->key; |
| @@ -1656,9 +1657,9 @@ static void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e) | |||
| 1656 | } | 1657 | } |
| 1657 | } | 1658 | } |
| 1658 | #else | 1659 | #else |
| 1659 | lua_Number n = expr_numberV(e); | 1660 | int64_t i64; |
| 1660 | int32_t k = lj_num2int(n); | 1661 | int32_t k; |
| 1661 | if (checku8(k) && n == (lua_Number)k) { | 1662 | if (lj_num2int_cond(expr_numberV(e), i64, k, checku8((int32_t)i64))) { |
| 1662 | t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ | 1663 | t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */ |
| 1663 | return; | 1664 | return; |
| 1664 | } | 1665 | } |
