Support ushort[] local variables (auto lo/hi split)#442
Merged
jonathanpeppers merged 5 commits intomainfrom Apr 14, 2026
Merged
Support ushort[] local variables (auto lo/hi split)#442jonathanpeppers merged 5 commits intomainfrom
jonathanpeppers merged 5 commits 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>
…ng.cs Keep both ushort array handling (ldelem.u2/i2) and new main features (Endfinally handler, HandleMetaSpr2x2). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Delete samples/ushortarray/ and its pre-compiled test DLLs - Remove TranspilerTests.Write ushortarray InlineData entries - Add 4 RoslynTests: NewarrAndConstantStore, VariableIndexLoad, VariableIndexStore, LoadStoresIn16BitLocal - Fix HandleLdelemU2 to handle implicit array ref on eval stack (Release compiler may never store array to a local variable) - Update copilot-instructions.md to prefer RoslynTests over samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… preserve value code - Always route stelem.i2 to HandleStelemI2 (not byte fallback) - Clear _pendingArrayType after HandleStlocAfterNewarr for both struct and ushort paths to prevent ldtoken misclassification - Fix non-pending path in HandleStelemI2 to preserve runtime value-expression code (only remove array+index instructions) - Merge main: resolve RoslynTests conflict (keep both ushort and oam_begin test methods) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Change frame_count from byte to ushort with a 360-frame threshold (exceeds byte range of 255), demonstrating transparent ushort local variable support. Update test DLLs, verified snapshot, and expected local count (3 → 4 bytes). 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