FractalFir / rustc_codegen_clr

This rust compiler backend(module) emmits valid CIL (.NET IR), enabling you to use Rust in .NET projects.
MIT License
1.39k stars 30 forks source link

Add support for storing/loading primitives through a dereference #11

Closed karashiiro closed 11 months ago

karashiiro commented 11 months ago

See #7.

This adds support for storing and loading all remaining primitive types as defined by TyKind::is_primitive() (bool, char, int which was already supported, uint, float). 128-bit operations are not supported in this PR.

Of particular interest are bool and char. bool in its unmanaged form in .NET has a width of 1 byte, so it is natively-compatible with Rust's representation, however managed bools are 4 bytes wide, which could make interop a bit complicated further down the line. I didn't handle marshalling here, but it'll definitely be an issue eventually. char is similar in that Rust's char is always 4 bytes, whereas .NET's is always 2 bytes.

Tests have been added for all primitives, and I verified that both ldind and stind instructions are emitted in the generated IL.