Skip to content

Add comprehensive C# → WAT test suite and fix type mapping bugs in compiler pipeline#44

Draft
Copilot wants to merge 3 commits into
Stablefrom
copilot/update-program-cs-testing
Draft

Add comprehensive C# → WAT test suite and fix type mapping bugs in compiler pipeline#44
Copilot wants to merge 3 commits into
Stablefrom
copilot/update-program-cs-testing

Conversation

Copilot AI commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Testing/Program.cs was missing, leaving the C#→WAT compilation pipeline untested. Running tests exposed several real bugs in MapSet.cs and RuleSet.cs that caused incorrect or empty WAT output for typed variables.

New: Testing/Program.cs

26 tests covering the full CDTk compilation pipeline (Tokens + Rules + WASM MapSet):

  • Primitive types (int, long, float, double, bool)
  • Arithmetic, control flow (if/else, while, for)
  • Methods with params and return types, namespaces, comments, string literals
// Usage
var (passed, failed) = CRAB.Testing.TestProgram.RunAll();

Bug Fixes

RuleSet.cs

  • FloatingPointType was a plain string rule without .Returns("type") — unlike IntegralType which has it — causing float/double keywords to never be captured in the AST.
// Before
public Rule FloatingPointType = "type:@KwFloat | type:@KwDouble";

// After
public Rule FloatingPointType = new Rule("type:@KwFloat | type:@KwDouble")
    .Returns("type");

MapSet.cs

Map Before After Reason
IntegralType "i32" "{type}" Hardcoded; blocked longi64, ulongi64
FloatingPointType "f64" "{type}" Hardcoded; blocked floatf32
LocalVariableType "{type}" "{base}" CDTk places the matched node in base, not type
LocalDeclaration "{type} {declarators}" "{modifier} {type}" CDTk field-shifts when the optional modifier is absent, putting the type into modifier and declarators into type

Known Limitations (documented in tests)

Three CDTk parser-level issues are beyond the scope of these Map fixes and are documented in the relevant tests:

  • Arithmetic initializer expressions (e.g. 4 * 7) are not emitted into function bodies
  • else blocks are not wrapped in WAT (else …) due to IfStatement field shifting
  • Method call (call $fn) is not emitted; invocation suffix is parsed but not propagated

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 23, 2026 01:10
… and fix MapSet/RuleSet bugs

Co-authored-by: TristinPorter <232979486+TristinPorter@users.noreply.github.com>
Co-authored-by: TristinPorter <232979486+TristinPorter@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Program.cs for testing CSharp to WAT compilation Add comprehensive C# → WAT test suite and fix type mapping bugs in compiler pipeline Feb 23, 2026
Copilot AI requested a review from TristinPorter February 23, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants