Implement IntPtr.Size and sizeof(nint) for the 6502#91
Merged
jonathanpeppers merged 3 commits intomainfrom Mar 6, 2026
Merged
Conversation
b81becb to
1abe149
Compare
Fixes #33 The 6502 is an 8-bit CPU, so IntPtr.Size returns 1. Two IL patterns are handled: - IntPtr.Size emits 'call IntPtr::get_Size()' -> handled in the Call switch as a compile-time constant (LDA #1) - sizeof(nint) emits the Sizeof IL opcode -> new case in the int operand handler (LDA #1) Both produce identical output: a single LDA #1 instruction. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1abe149 to
10893da
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements support for IntPtr.Size and sizeof(nint) in the dotnes transpiler, resolving issue #33. On the 6502 (an 8-bit CPU), the native integer size is 1 byte, so both expressions produce LDA #$01.
Changes:
- Added a
SizeofIL opcode handler inIL2NESWriter.Write(ILInstruction, int)that emitsLDA #1 - Added an
IntPtr.get_Sizecase in theCallhandler inIL2NESWriter.Write(ILInstruction, string)that emitsLDA #1 - Added two Roslyn-based tests (
IntPtrSizeandSizeofNint) verifying the output containsA901(LDA #$01)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/dotnes.tasks/Utilities/IL2NESWriter.cs | Added Sizeof opcode case (line 1225) and IntPtr.get_Size call case (line 1762), both emitting WriteLdc(1) |
| src/dotnes.tests/RoslynTests.cs | Added two test methods verifying that IntPtr.Size and sizeof(nint) produce the expected LDA #$01 instruction |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+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.
Fixes #33
The 6502 is an 8-bit CPU, so
IntPtr.Sizereturns1.Two IL patterns are handled:
IntPtr.Sizeemitscall IntPtr::get_Size()→ handled in the Call switch as a compile-time constant (LDA #1)sizeof(nint)emits theSizeofIL opcode → new case in the int operand handler (LDA #1)Both produce identical output: a single
LDA #instruction.Example usage
Tests added
IntPtrSize— verifiesIntPtr.SizeemitsLDA #SizeofNint— verifiessizeof(nint)emitsLDA #All 307 tests pass.