feat(phase-17): 64-bit integer overflow wrapping and FuncDecl local assignment#142
Open
davydog187 wants to merge 3 commits intophase-17-vararg-scopefrom
Open
feat(phase-17): 64-bit integer overflow wrapping and FuncDecl local assignment#142davydog187 wants to merge 3 commits intophase-17-vararg-scopefrom
davydog187 wants to merge 3 commits intophase-17-vararg-scopefrom
Conversation
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>
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