Skip to content

Instantly share code, notes, and snippets.

@kg
Created June 7, 2011 08:13
Show Gist options
  • Save kg/1011883 to your computer and use it in GitHub Desktop.
Save kg/1011883 to your computer and use it in GitHub Desktop.
JSIL Code Sample: ref parameters
using System;
public static class Program {
public static void Increment (ref int x) {
x += 1;
}
public static void Main (string[] args) {
Func<int, int> inc = (i) => {
Increment(ref i);
return i;
};
Console.WriteLine("{0}, {1}", inc(1), inc(2));
}
}
JSIL.MakeStaticClass("Program", true, [], function ($) {
$.Method({Static:true , Public:true }, "Increment",
$sig.get(1, null, [$jsilcore.TypeRef("JSIL.Reference", [$.Int32])], []),
function Increment (/* ref */ x) {
++x.value;
}
);
$.Method({Static:true , Public:true }, "Main",
$sig.get(2, null, [$jsilcore.TypeRef("System.Array", [$.String])], []),
function Main (args) {
var inc = function ($i) {
var i = new JSIL.Variable($i);
$asm00.Program.Increment(/* ref */ i);
return i.value;
};
$asm01.System.Console.WriteLine(
"{0}, {1}",
inc(1),
inc(2)
);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment