Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 11 additions & 16 deletions core/psxlua/psxlua_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ that a changed source gives different bytes and that a syntax error is reported.
python3 luacheck.py <splashpack-cli>
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.
Expand All @@ -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 <dir>

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
Expand Down
Binary file modified tests/lua/expected/arith_fold.luac
Binary file not shown.
Binary file modified tests/lua/expected/numbers.luac
Binary file not shown.
Binary file modified tests/lua/expected/operators.luac
Binary file not shown.
5 changes: 3 additions & 2 deletions tests/lua/numbers.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/luacheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading