diff --git a/CMakeLists.txt b/CMakeLists.txt index a407958..b047fd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,8 @@ FetchContent_Declare(recastnavigation # Fetch only (src has no CMakeLists.txt); core/CMakeLists.txt builds it. # Pin to the commit psxsplash's nugget uses. FetchContent_Declare(psxlua - GIT_REPOSITORY https://github.com/grumpycoders/psxlua.git - GIT_TAG abed030e686b4e34987851bd0a028c93b1f73967 + GIT_REPOSITORY https://github.com/rixnobis/psxlua.git + GIT_TAG 4401a3354e1ffe5f38b028c4d5cedf7c077638bd SOURCE_SUBDIR src) # libpsxav's SPU-ADPCM encoder (the one psxavenc uses), and dr_wav to read WAV. FetchContent_Declare(psxavenc diff --git a/core/psxlua/psxlua_host.h b/core/psxlua/psxlua_host.h index da655ad..300194f 100644 --- a/core/psxlua/psxlua_host.h +++ b/core/psxlua/psxlua_host.h @@ -36,14 +36,8 @@ #undef LUAI_UACNUMBER #define LUAI_UACNUMBER int32_t -/* -** psxlua parses numerals with luaA_strtol (llibc.c). For a decimal numeral -** with a leading zero other than "0" itself ("010", "0.5") it returns -** without setting endptr, and the PS1 build then reports "malformed number". -** Starting endptr at s gives that same error deterministically. -*/ +/* luaA_strtol works in a host long; keep the low 32 bits like the PS1. */ static inline int32_t psxlua_str2number(const char *s, char **p, int base) { - *p = (char *)s; return (int32_t)luaA_strtol(s, p, base); } #undef lua_str2number @@ -64,17 +58,18 @@ static inline int32_t psxlua_mod(int32_t a, int32_t b) { return a % b; } -/* -** psxlua's luai_numpowimpl: r = a, then r *= a once per iteration of -** `for (unsigned i = 0; i < b; i++)`. So a^b yields a^(b+1), and b is -** compared as unsigned. Same result, without the loop. -*/ +/* psxlua's luai_numpowimpl in 32 bits: a negative exponent gives 0 unless |a| is 1. */ static inline int32_t psxlua_pow(int32_t a, int32_t b) { - uint32_t base = (uint32_t)a, n = (uint32_t)b, r = (uint32_t)a; - while (n) { - if (n & 1u) r *= base; + uint32_t base = (uint32_t)a, r = 1; + if (b < 0) { + if (a == 1) return 1; + if (a == -1) return (b & 1) ? -1 : 1; + return 0; + } + while (b) { + if (b & 1) r *= base; base *= base; - n >>= 1; + b >>= 1; } return PSXLUA_I32(r); } diff --git a/tests/README.md b/tests/README.md index b264c4f..aa33b06 100644 --- a/tests/README.md +++ b/tests/README.md @@ -116,7 +116,7 @@ that a changed source gives different bytes and that a syntax error is reported. python3 luacheck.py splashpack-cli luac in.lua -o out.luac -The files cover constant folding with 32-bit overflow, division and modulo by negative constants, hex and +The files cover constant folding with 32-bit overflow, division and modulo by negative constants, hex, leading-zero and oversized literals, strings with escapes and zero bytes, long strings, more than 256 constants, closures, varargs, goto, methods, loops and a table constructor large enough to need an extra SETLIST argument. @@ -128,9 +128,6 @@ base. It writes `__done__` containing `OK` when it has finished. pcsx-redux -testmode -stdout -safe -bios openbios.bin -loadexe luac_psx.ps-exe -run \ -pcdrv -pcdrvbase -Two psxlua quirks the host build reproduces: `a ^ b` gives a to the power b + 1, and a decimal -numeral with a leading zero (`010`, `0.5`) is a "malformed number". - ## Audio `audiocheck.py` encodes the WAVs in `audio/` at their own rate and compares the ADPCM with diff --git a/tests/lua/expected/arith_fold.luac b/tests/lua/expected/arith_fold.luac index e187508..828b630 100644 Binary files a/tests/lua/expected/arith_fold.luac and b/tests/lua/expected/arith_fold.luac differ diff --git a/tests/lua/expected/numbers.luac b/tests/lua/expected/numbers.luac index 2199cc8..93ca869 100644 Binary files a/tests/lua/expected/numbers.luac and b/tests/lua/expected/numbers.luac differ diff --git a/tests/lua/expected/operators.luac b/tests/lua/expected/operators.luac index 670ddb1..e5c10be 100644 Binary files a/tests/lua/expected/operators.luac and b/tests/lua/expected/operators.luac differ diff --git a/tests/lua/numbers.lua b/tests/lua/numbers.lua index ec6d926..61f52ed 100644 --- a/tests/lua/numbers.lua +++ b/tests/lua/numbers.lua @@ -1,9 +1,10 @@ -- Hex literals and numbers beyond 32 bits. local h = { 0x0, 0x1, 0xff, 0XFF, 0xAbCd, 0x7fffffff, 0x80000000, 0xffffffff, - 0x100000000, 0x123456789, 0xdeadbeef, 0x } + 0x100000000, 0x123456789, 0xdeadbeef } local d = { 0, 1, 255, 2147483647, 2147483648, 2147483649, 4294967295, 4294967296, 4294967297, 99999999999, 12345678901234567890 } +local lead = { 010, 00, 0007, -010 } local neg = { -1, -2147483647, -2147483648, -2147483649, -4294967296 } local big = 0xffffffff + 1 local wrap = 4294967295 * 4294967295 -return h, d, neg, big, wrap +return h, d, lead, neg, big, wrap diff --git a/tests/luacheck.py b/tests/luacheck.py index 54a08df..00d42a4 100644 --- a/tests/luacheck.py +++ b/tests/luacheck.py @@ -45,7 +45,7 @@ def check(name, ok, detail=''): check('a changed source does not match', got is not None and got != want, err) bad = os.path.join(tmp, 'bad.lua') -open(bad, 'w').write('local x = 010\n') +open(bad, 'w').write('local x = 1.5\n') got, err = compile_lua(bad) check('syntax error is reported', got is None and 'malformed number' in err, err)