As if compiling LLVM bytecode to Javascript wasn’t crazy enough there is now the JSIL, a project by Mozilla engineer Kevin Gadd. JSIL compiles CIL (.NET’s bytecode format) to readable Javascript.For instance, after compiling the following C# code using the C# compiler to CIL: using System;
using System.Collections.Generic;public static class Program {
public static void Main (string[] args) {
var array = new[] { 1, 2, 4, 8, 16 }; foreach (var i in array)
Console.WriteLine(i); var list = new List<int>(array); foreach (var j in list)
Console.WriteLine(j);
}
}JSIL compiles it to the following Javascript (which we had to somewhat awkwardly reformat to fit the width of this site): JSIL.MakeStaticClass("Program", true);Program.Main = function (args) {
var array = JSIL.Array.New(System.Int32,
[1, 2, 4, 8, 16]);
var array2 = array;
__loop0__:
for (var k = 0; k < array2.length; ++k) {
var i = array2[k];
System.Console.WriteLine(i);
}
var list = new (System.Collections.Generic
.List$b1.Of(System.Int32))
(array);
Read more: State of Code
QR:
using System.Collections.Generic;public static class Program {
public static void Main (string[] args) {
var array = new[] { 1, 2, 4, 8, 16 }; foreach (var i in array)
Console.WriteLine(i); var list = new List<int>(array); foreach (var j in list)
Console.WriteLine(j);
}
}JSIL compiles it to the following Javascript (which we had to somewhat awkwardly reformat to fit the width of this site): JSIL.MakeStaticClass("Program", true);Program.Main = function (args) {
var array = JSIL.Array.New(System.Int32,
[1, 2, 4, 8, 16]);
var array2 = array;
__loop0__:
for (var k = 0; k < array2.length; ++k) {
var i = array2[k];
System.Console.WriteLine(i);
}
var list = new (System.Collections.Generic
.List$b1.Of(System.Int32))
(array);
Read more: State of Code
QR:
0 comments:
Post a Comment