Support ushort[] local variables (auto lo/hi split)#442
Open
jonathanpeppers wants to merge 1 commit intomainfrom
Open
Support ushort[] local variables (auto lo/hi split)#442jonathanpeppers wants to merge 1 commit intomainfrom
jonathanpeppers wants to merge 1 commit intomainfrom
Conversation
Add transpiler support for ushort[] arrays, handling the IL opcodes C# emits for ushort array operations. This allows users to write ushort[] arr = new ushort[N] instead of manually managing separate byte[] lo and byte[] hi arrays with carry propagation. New IL opcodes handled: - newarr System.UInt16: pre-allocates count*2 bytes in zero page - stelem.i2: stores 16-bit values (constant/variable index, constant/runtime values) - ldelem.u2: loads 16-bit values into A:X (constant/variable index via AbsoluteY) - ldelema System.UInt16 + ldind.u2 + stind.i2: compound assignment (arr[i] += val) Key implementation details: - Constant index: compile-time address computation (LDA base+i*2) - Variable index: uses Y register with AbsoluteY addressing (ASL; TAY; LDA base,Y) - Music note tables (newarr; dup; ldtoken; InitializeArray) are detected via look-ahead and excluded from the new handling - Pending array state tracks arrays during initialization (before stloc) Includes ushortarray sample and test DLLs exercising newarr, constant-index stelem.i2, variable-index ldelem.u2, and variable-index stelem.i2. Fixes #422 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Add transpiler support for
ushort[]arrays, handling the IL opcodes C# emits for ushort array operations. This allows users to writeushort[] arr = new ushort[N]instead of manually managing separatebyte[] loandbyte[] hiarrays with carry propagation.New IL opcodes handled
arr[i] += val)6502 addressing strategy
LDA base+i*2)ASL; TAY; LDA base,Y)Key details
newarr; dup; ldtoken; InitializeArray) are detected via look-ahead and excluded from the new handlingushortarraysample and test DLLs exercising newarr, constant-index stelem.i2, variable-index ldelem.u2, and variable-index stelem.i2Fixes #422