feat(phase-17): 64-bit integer overflow wrapping and FuncDecl local assignment#142
Open
davydog187 wants to merge 5 commits intomainfrom
Open
feat(phase-17): 64-bit integer overflow wrapping and FuncDecl local assignment#142davydog187 wants to merge 5 commits intomainfrom
davydog187 wants to merge 5 commits intomainfrom
Conversation
Implement multi-return expansion across call arguments, table constructors, and return statements using state.multi_return_count tracking. Fix floor division/modulo to use Lua 5.3 floor semantics. Add _ENV support, fix assert to return all args, support hex float literals, fix local function redefinition scoping, and fix table.unpack nil handling. Suite tests passing: 3/29 (simple_test.lua, api.lua, code.lua) Tests: 1257 passing, 0 failures, 33 skipped Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes: - Add 64-bit signed integer overflow wrapping for all arithmetic and bitwise operations - Bitwise operations (<<, >>, &, |, ~, ^) now wrap to signed 64-bit - Arithmetic operations (+, -, *, //, %, unary -) wrap for integer operands - FuncDecl now correctly assigns to local variables when they exist in scope - Scope resolution records if a FuncDecl should target a local - Prevents treating future locals as current scope during codegen These fixes improve Lua 5.3 compliance for integer arithmetic and function definitions. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2090fc9 to
f041e44
Compare
Add 24 new tests covering: **64-bit Integer Overflow Wrapping (13 tests)**: - maxint + 1 wraps to minint - minint - 1 wraps to maxint - Bitwise operations (<<, >>, &, |, ~, ^) wrap to signed 64-bit - Arithmetic operations (+, -, *, //, %, unary -) wrap for integers - Float operations preserve IEEE 754 semantics (no wrapping) - Edge cases: shifts >= 64 bits, mixed integer/float arithmetic **FuncDecl Local Assignment (11 tests)**: - function f() updates local f when it exists in scope - function f() creates global when no local exists - Nested scopes handle local updates correctly - Works with upvalue capture - Multiple redefinitions in same scope - Forward reference patterns - Dotted names (t.f) always use table assignment - Method syntax (:) works correctly - Loop iterations create independent locals All tests verify Lua 5.3 spec compliance and pass with 0 failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Critical fixes for Lua 5.3 integer semantics and function declaration behavior.
64-bit Integer Overflow Wrapping ⭐
All integer operations now wrap to signed 64-bit per Lua 5.3 spec:
<<,>>,&,|,~,^wrap to signed 64-bit+,-,*,//,%, unary-wrap for integer operandsto_signed_int64/1helper for proper IEEE 754 compliancemaxint + 1now correctly equalsminint1 << 63now correctly equalsminint(not overflow to big integer)FuncDecl Local Assignment ⭐
Fixed
function f()syntax to properly update local variables:function f()now correctly updates localfwhen one exists in scopevar_mapat declaration timelocal f = function()...is followed byfunction f()Example fixed pattern:
Implementation Details
Integer Wrapping:
to_signed_int64/1masks to 64 bits then converts to signed rangeband,bor,bxor,bnot,bsl,bsrsafe_add,safe_subtract,safe_multiply,safe_negate,lua_idiv,safe_moduloFuncDecl Fix:
{:func_decl_target, decl}invar_mapctx.scope.locals(which contains all function-scope locals)Test Status
Dependencies
Depends on #141 (vararg and scope fixes).
🤖 Generated with Claude Code