Support static field byte[] arrays in ldelem.u1#275
Merged
jonathanpeppers merged 4 commits intomainfrom Mar 18, 2026
Merged
Conversation
When byte[] arrays are stored as static fields (e.g., in static class G), the IL uses ldsfld instead of ldloc to load the array reference before ldelem.u1. The transpiler only checked GetLdlocIndex(), missing these. Changes: - Transpiler: scan .cctor for newarr->stsfld to determine array sizes - Transpiler: detect ELEMENT_TYPE_SZARRAY (0x1D) in field signatures - PreAllocateStaticFields: allocate proper byte counts for array fields - IL2NESWriter: add TryResolveArrayLocal() helper for ldsfld arrays - HandleLdelemU1: resolve arrays from both ldloc and ldsfld sources - HandleLdelemU1ComplexIndex: same ldsfld fallback - HandleLdelemU1: resolve indices from ldsfld (static field scalars) - ILDispatch: handle newarr->stsfld to track runtime array allocations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
|
🤖 Took over from CCA. CI is green, all 527 tests pass. What this fixesWhen ChangesTranspiler (allocation):
IL2NESWriter (code generation):
Verified with crypto sampleThe crypto sample (PR #211) now progresses past this error. The next blocker is |
Take main's Transpiler.cs as base (methods moved to StructAnalysis.cs and LocalFrameAllocation.cs), re-apply only the static array field changes: destructuring tuple and StaticArrayFields property pass-through. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a6b1f71 to
eb26291
Compare
Three Roslyn tests with proper 6502 instruction assertions: - StaticFieldArraySimpleIndex: verifies LDA \ (load G.i), TAX, LDA \,X (indexed array load from static field) - StaticFieldArrayConstantIndex: verifies LDA \ (direct absolute load at arr base for constant index 0) - StaticFieldArrayStelem: verifies LDA #42 + STA \,X (indexed array store to static field) Also fixes: - HandleStelemI1: add ldsfld support for target array and index (same TryResolveArrayLocal fallback as HandleLdelemU1) - ILDispatch newarr→stsfld: add comment clarifying it handles Main() allocations (not dead code — .cctor path is separate) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eb26291 to
954e2d5
Compare
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.