fix(vm): handle Lua 5.3 hex and string coercion for bitwise ops#198
Merged
Conversation
Make hex integer literals overflow-wrap to signed 64-bit per Lua 5.3 §3.1 (0xFFFFFFFFFFFFFFFF == -1), accept signed and hex-float strings in Value.parse_number for the string-to-number bitwise path, tighten Executor.to_integer! to reject floats that don't represent integers exactly per §3.4.3, and add a narrow package.preload lookup in require so modules registered via package.preload[name] resolve before the path search. Together these unblock most of bitwise.lua (lines 1–270). Plan: A5 Closes #166
Records what changed, sets pr: 198, status: review. Adds A5a (math.fmod) as the deferred follow-up needed to complete bitwise.lua end-to-end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix bitwise.lua failing assertion
Plan:
.agents/plans/A5-bitwise-suite.mdCloses #166
Goal
Make
bitwise.luapass the official Lua 5.3 suite. Pre-A5, it failedimmediately on
assert(0xFFFFFFFFFFFFFFFF == -1)(line 16). Post-A5, itruns cleanly through line 270; the final third (lines 274–328) is blocked
on
math.fmod, deferred to A5a.Success criteria
mix testpasses (1382 → 1394, no regressions, +12 from newtest/lua/vm/bitwise_test.exs)test/lua/vm/bitwise_test.exs(12 tests, 0 failures).bitwise.luapasses end-to-end. Partial — lines 1–270 nowpass; final third deferred to A5a (needs
math.fmod).Changes
Four narrow fixes, one new follow-up plan:
Lua.Lexer.scan_hex_number— wrap parsed hex integer literal tosigned 64-bit per Lua 5.3 §3.1 (
0xFFFFFFFFFFFFFFFF→-1). Inlinedthe wrap (lexer doesn't depend on
Lua.VM.Numeric).Lua.VM.Value.parse_number— apply the same wrap to hex intstrings, accept a leading
-/+sign, and add hex-float stringparsing (
"0xAA.0","0x1.8p3").Lua.VM.Executor.to_integer!— for bitwise operands, only acceptfloats that represent an integer exactly and fit in the signed
64-bit range, per §3.4.3. Previously did unconditional
trunc/1.Lua.VM.Stdlib.lua_require— consultpackage.preload[name]before the filesystem search.
bitwise.luaregisters itsbit32shim via
package.preload.bit32 = function () ... endand thenrequire'bit32'. Did not introduce a fullpackage.searcherstable — that's separate.Discoveries
A0 covered integer arithmetic wrapping but not literal lexing, string
coercion, or float→int rules. The four fixes above are the minimal set
that gets
bitwise.luafrom immediate-fail to running through line 270.A new plan A5a (
A5a-bitwise-suite-math-fmod.md) covers theremaining gap:
math.fmod, used at lines 278–279 to numerically verifybit32.lshift. Withmath.fmodin place,bitwise.luais expected topass end-to-end (line-by-line bisect found no other gaps after line 278).
Verification
End-to-end run of
bitwise.lua(proves lines 1–270 pass):Out of scope (intentional)
package.searcherstable.math.*functions, includingmath.fmoditself(deferred to A5a).
bitwise.luaonly exerciseshex).