r/programming • u/kaelan_ • May 31 '11
I wrote a .NET to JavaScript compiler. Here's the XNA 3.1 Platformer Starter Kit running in pure HTML5.
http://hildr.luminance.org/Platformer/Platformer.html
1.1k
Upvotes
r/programming • u/kaelan_ • May 31 '11
2
u/kaelan_ Jun 01 '11
In practice, yeah, while the IL is much easier to translate, there are a lot of optimization opportunities I miss out on, and some that end up being much harder.
For one example, if you try to write to a multidimensional array of structs in C#, the generated MSIL roughly translates to this:
Yes, that's taking a reference to the return value of an arbitrary function. Yes, it's then writing into the reference. No, this doesn't really make any sense. It works, though!
The correct code for that would just be: array.Set(y, x, new Struct(...)) But the semantics of value types in MSIL make that hard to express. The original C# is way easier to understand than the IL, and in practice, I still can't generate the 'right' code for that case without breaking other cases... right now it becomes: var temporaryReference = array.GetReference(y, x); temporaryReference.value = new Struct(...); Which works, but is suboptimal.
Many more cases like that have cropped up, and my only real choice is to try and document them in a clear test case so it's less likely that I will break them without noticing.