From 184f04491e799c4230bee25f23f2ca64ab3b2cf0 Mon Sep 17 00:00:00 2001 From: Kevin Gadd Date: Wed, 11 Apr 2012 05:45:45 -0700 Subject: [PATCH] Mannux sample works again. When there is only one overload of a method with a given argument count, use fast dispatch instead of signature-based dispatch. Fix some copy-and-paste errors from skeletons. --- JSIL/JavascriptAstEmitter.cs | 19 + JSIL/MethodSignature.cs | 6 + JSIL/Util.cs | 6 + Libraries/JSIL.Bootstrap.js | 58 +- Libraries/JSIL.Core.js | 22 +- Libraries/JSIL.XNACore.js | 23 +- Libraries/System.Drawing.js | 652 ++++++++++-------- Libraries/System.Windows.js | 163 +++-- Proxies/Forms.cs | 31 - Tests/FormattingTests.cs | 20 + .../SpecialTestCases/FastOverloadDispatch.cs | 36 + Tests/Tests.csproj | 1 + 12 files changed, 616 insertions(+), 421 deletions(-) create mode 100644 Tests/SpecialTestCases/FastOverloadDispatch.cs diff --git a/JSIL/JavascriptAstEmitter.cs b/JSIL/JavascriptAstEmitter.cs index a22920fa9..f943849d9 100644 --- a/JSIL/JavascriptAstEmitter.cs +++ b/JSIL/JavascriptAstEmitter.cs @@ -1144,9 +1144,28 @@ public void VisitNode (JSInvocationExpression invocation) { Output.RPar(); }; + // If there's only one overload with this argument count, we don't need to use + // the expensive overloaded method dispatch path. + if (isOverloaded) { + MethodSignatureSet mss; + if (method.DeclaringType.MethodSignatures.TryGet(method.Name, out mss)) { + int argCount = method.Parameters.Length; + int overloadCount = 0; + + foreach (var signature in mss.Signatures) { + if (signature.ParameterCount == argCount) + overloadCount += 1; + } + + if (overloadCount < 2) + isOverloaded = false; + } + } + var oldInvoking = ReferenceContext.InvokingMethod; try { if (isOverloaded) { + var methodName = Util.EscapeIdentifier(method.GetName(true), EscapingMode.MemberIdentifier); Output.MethodSignature(jsm.Reference, method.Signature, ReferenceContext); diff --git a/JSIL/MethodSignature.cs b/JSIL/MethodSignature.cs index 6ed3714c0..18985bf18 100644 --- a/JSIL/MethodSignature.cs +++ b/JSIL/MethodSignature.cs @@ -165,6 +165,12 @@ public MethodSignatureSet () { ); } + public IEnumerable Signatures { + get { + return Counts.Keys; + } + } + public void Add (MethodSignature signature) { var count = Counts.GetOrCreate( signature, () => new Count() diff --git a/JSIL/Util.cs b/JSIL/Util.cs index 0b0ca5da0..2e3b8b911 100644 --- a/JSIL/Util.cs +++ b/JSIL/Util.cs @@ -412,6 +412,12 @@ public void Clear () { States.Clear(); } + public IEnumerable Keys { + get { + return Storage.Keys; + } + } + public bool MightContainKey (TKey key) { return Storage.ContainsKey(key) || States.ContainsKey(key); } diff --git a/Libraries/JSIL.Bootstrap.js b/Libraries/JSIL.Bootstrap.js index c57eeb3e7..4ff192ce0 100644 --- a/Libraries/JSIL.Bootstrap.js +++ b/Libraries/JSIL.Bootstrap.js @@ -533,7 +533,7 @@ JSIL.ImplementExternals( ); $.Method({Static:false, Public:true }, ".ctor", - (new JSIL.MethodSignature(null, [$.String, $asms[5].TypeRef("System.Exception")], [])), + (new JSIL.MethodSignature(null, [$.String, mscorlib.TypeRef("System.Exception")], [])), function _ctor (message, innerException) { this._message = message; this._innerException = innerException; @@ -541,7 +541,7 @@ JSIL.ImplementExternals( ); $.Method({Static:false, Public:true }, "get_InnerException", - (new JSIL.MethodSignature($asms[5].TypeRef("System.Exception"), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Exception"), [], [])), function get_InnerException () { return this._innerException; } @@ -762,13 +762,10 @@ JSIL.MakeClass("System.Object", "System.Threading.Thread", true, [], function ($ $.Property({Public: true , Static: true }, "ManagedThreadId"); }); -$jsilcore.$ListExternals = function ($, isArrayList) { +$jsilcore.$ListExternals = function ($, T, isArrayList) { var mscorlib = JSIL.GetCorlib(); - var T; - if (isArrayList) { - T = $.Object; - } else { + if (typeof (T) === "undefined") { T = new JSIL.GenericParameter("T", "System.Collections.Generic.List`1"); } @@ -993,16 +990,25 @@ $jsilcore.$ListExternals = function ($, isArrayList) { indexOfImpl ); - $.Method({Static:false, Public:true }, "Remove", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), - function (item) { - var index = this._items.indexOf(item); - if (index === -1) - return false; + var removeImpl = function (item) { + var index = this._items.indexOf(item); + if (index === -1) + return false; - this.RemoveAt(index); - } - ); + return this.RemoveAt(index); + }; + + if (isArrayList) { + $.Method({Static:false, Public:true }, "Remove", + new JSIL.MethodSignature(null, [T], []), + removeImpl + ); + } else { + $.Method({Static:false, Public:true }, "Remove", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Boolean"), [T], []), + removeImpl + ); + } $.Method({Static:false, Public:true }, "RemoveAll", new JSIL.MethodSignature(mscorlib.TypeRef("System.Int32"), [mscorlib.TypeRef("System.Predicate`1", [T])], []), @@ -1024,6 +1030,7 @@ $jsilcore.$ListExternals = function ($, isArrayList) { function (index) { this._items.splice(index, 1); this._size -= 1; + return true; } ); @@ -1064,11 +1071,11 @@ $jsilcore.$ListExternals = function ($, isArrayList) { }; JSIL.ImplementExternals("System.Collections.Generic.List`1", function ($) { - $jsilcore.$ListExternals($, false); + $jsilcore.$ListExternals($); }); $jsilcore.$ArrayListExternals = function ($) { - $jsilcore.$ListExternals($, true); + $jsilcore.$ListExternals($, $.Object, true); var mscorlib = JSIL.GetCorlib(); var toArrayImpl = function () { @@ -1090,7 +1097,7 @@ $jsilcore.$ArrayListExternals = function ($) { JSIL.ImplementExternals("System.Collections.ArrayList", $jsilcore.$ArrayListExternals); $jsilcore.$CollectionExternals = function ($) { - $jsilcore.$ListExternals($, false); + $jsilcore.$ListExternals($); var mscorlib = JSIL.GetCorlib(); @@ -1114,7 +1121,7 @@ $jsilcore.$CollectionExternals = function ($) { JSIL.ImplementExternals("System.Collections.ObjectModel.Collection`1", $jsilcore.$CollectionExternals); $jsilcore.$ReadOnlyCollectionExternals = function ($) { - $jsilcore.$ListExternals($, false); + $jsilcore.$ListExternals($); var mscorlib = JSIL.GetCorlib(); @@ -1905,6 +1912,8 @@ JSIL.MakeStruct("System.ValueType", "System.TimeSpan", true, [], function ($) { }); JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) { + var mscorlib = JSIL.GetCorlib(); + $.RawMethod(false, "$getHash", function (key) { if ((typeof (key) !== "undefined") && (key !== null) && (typeof (key.GetHashCode) === "function") && (key.GetHashCode.__IsPlaceholder__ !== true)) { return key.GetHashCode(); @@ -2025,7 +2034,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) ); $.Method({Static:false, Public:true }, "get_Keys", - (new JSIL.MethodSignature($asms[5].TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/KeyCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), function get_Keys () { if (this.tKeysEnumerator === null) { this.tKeysEnumerator = JSIL.ArrayEnumerator.Of(this.TKey); @@ -2051,7 +2060,7 @@ JSIL.ImplementExternals("System.Collections.Generic.Dictionary`2", function ($) ); $.Method({Static:false, Public:true }, "get_Values", - (new JSIL.MethodSignature($asms[5].TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Collections.Generic.Dictionary`2/ValueCollection", [new JSIL.GenericParameter("TKey", "System.Collections.Generic.Dictionary`2"), new JSIL.GenericParameter("TValue", "System.Collections.Generic.Dictionary`2")]), [], [])), function get_Values () { if (this.tValuesEnumerator === null) { this.tValuesEnumerator = JSIL.ArrayEnumerator.Of(this.TValue); @@ -2714,7 +2723,7 @@ JSIL.ImplementExternals("System.Diagnostics.StackTrace", function ($) { ); $.Method({Static:false, Public:true }, "GetFrame", - (new JSIL.MethodSignature($asms[5].TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Diagnostics.StackFrame"), [$.Int32], [])), function GetFrame (index) { // FIXME return new System.Diagnostics.StackFrame(); @@ -2724,6 +2733,7 @@ JSIL.ImplementExternals("System.Diagnostics.StackTrace", function ($) { }); JSIL.ImplementExternals("System.Diagnostics.StackFrame", function ($) { + var mscorlib = JSIL.GetCorlib(); $.Method({Static:false, Public:true }, ".ctor", (new JSIL.MethodSignature(null, [], [])), @@ -2733,7 +2743,7 @@ JSIL.ImplementExternals("System.Diagnostics.StackFrame", function ($) { ); $.Method({Static:false, Public:true }, "GetMethod", - (new JSIL.MethodSignature($asms[5].TypeRef("System.Reflection.MethodBase"), [], [])), + (new JSIL.MethodSignature(mscorlib.TypeRef("System.Reflection.MethodBase"), [], [])), function GetMethod () { // FIXME return new System.Reflection.MethodBase(); diff --git a/Libraries/JSIL.Core.js b/Libraries/JSIL.Core.js index 94336be1e..e1547d776 100644 --- a/Libraries/JSIL.Core.js +++ b/Libraries/JSIL.Core.js @@ -3382,9 +3382,9 @@ JSIL.InterfaceBuilder.prototype.Method = function (_descriptor, methodName, sign }); }; -JSIL.InterfaceBuilder.prototype.InheritDefaultConstructor = function () { +JSIL.InterfaceBuilder.prototype.InheritBaseMethod = function (name) { var signature = new JSIL.MethodSignature(null, [], []); - var descriptor = this.ParseDescriptor({Public: true, Static: false}, ".ctor", signature); + var descriptor = this.ParseDescriptor({Public: true, Static: false}, name, signature); var mangledName = signature.GetKey(descriptor.EscapedName); @@ -3392,25 +3392,25 @@ JSIL.InterfaceBuilder.prototype.InheritDefaultConstructor = function () { fn[0] = function () { var proto = Object.getPrototypeOf(this); - var baseCtor; + var baseMethod; while (true) { - baseCtor = proto[mangledName]; - if (baseCtor === fn[0]) + baseMethod = proto[mangledName]; + if (baseMethod === fn[0]) proto = Object.getPrototypeOf(proto); else break; } - if (typeof (baseCtor) === "function") - baseCtor.call(this); + if (typeof (baseMethod) === "function") + baseMethod.apply(this, arguments); else - JSIL.Host.warning("InheritDefaultConstructor() used but no default constructor was found to inherit!"); + JSIL.Host.warning("InheritBaseMethod() used but no method was found to inherit!"); }; JSIL.SetValueProperty(fn[0], "toString", function () { - return ""; + return ""; } ); @@ -3423,6 +3423,10 @@ JSIL.InterfaceBuilder.prototype.InheritDefaultConstructor = function () { }); }; +JSIL.InterfaceBuilder.prototype.InheritDefaultConstructor = function () { + this.InheritBaseMethod(".ctor"); +}; + JSIL.InterfaceBuilder.prototype.ImplementInterfaces = function (/* ...interfacesToImplement */) { var interfaces = this.typeObject.__Interfaces__; if (typeof (interfaces) === "undefined") diff --git a/Libraries/JSIL.XNACore.js b/Libraries/JSIL.XNACore.js index 19a499896..6fd514d67 100644 --- a/Libraries/JSIL.XNACore.js +++ b/Libraries/JSIL.XNACore.js @@ -15,6 +15,8 @@ var $asms = new JSIL.AssemblyCollection({ 1: "Microsoft.Xna.Framework.Game", 3: "Microsoft.Xna.Framework.Graphics", 5: "mscorlib", + 11: "System.Drawing", + 15: "System.Windows.Forms", }); $jsilxna.nextImageId = 0; @@ -1875,15 +1877,6 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector4", function ($) { }); }); -JSIL.ImplementExternals("Microsoft.Xna.Framework.Matrix", true, { - xScale: 1, - yScale: 1, - zScale: 1, - xTranslation: 0, - yTranslation: 0, - zTranslation: 0 -}); - JSIL.ImplementExternals("Microsoft.Xna.Framework.Matrix", function ($) { $.Method({ Static: true, @@ -2407,10 +2400,7 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Input.KeyboardState", function }); JSIL.ImplementExternals("Microsoft.Xna.Framework.Input.Mouse", function ($) { - $.Method({ - Static: false, - Public: true - }, "GetState", new JSIL.MethodSignature(null, [], []), function (playerIndex) { + var getStateImpl = function (playerIndex) { var buttons = JSIL.Host.getHeldButtons(); var position = JSIL.Host.getMousePosition(); @@ -2425,7 +2415,12 @@ JSIL.ImplementExternals("Microsoft.Xna.Framework.Input.Mouse", function ($) { (buttons.indexOf(1) >= 0) ? pressed : released, released, released ); - }); + }; + + $.Method({Static:true , Public:true }, "GetState", + (new JSIL.MethodSignature($asms[0].TypeRef("Microsoft.Xna.Framework.Input.MouseState"), [], [])), + getStateImpl + ); }); JSIL.ImplementExternals("Microsoft.Xna.Framework.Input.MouseState", function ($) { diff --git a/Libraries/System.Drawing.js b/Libraries/System.Drawing.js index 52b9a2f00..320287050 100644 --- a/Libraries/System.Drawing.js +++ b/Libraries/System.Drawing.js @@ -9,350 +9,412 @@ JSIL.DeclareNamespace("System"); JSIL.DeclareNamespace("System.Drawing"); if (JSIL.HostType.IsBrowser) { - JSIL.ImplementExternals( - "System.Drawing.Image", function ($) { - var mscorlib = JSIL.GetAssembly("mscorlib", true); + JSIL.ImplementExternals("System.Drawing.Image", function ($) { + var mscorlib = JSIL.GetAssembly("mscorlib", true); - $.Method({Static:false, Public:true }, "Save", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String")], []), - function (filename) { - this.context.putImageData(this.buffer, 0, 0); - } - ); + $.Method({Static:false, Public:true }, "Save", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String")], []), + function (filename) { + this.context.putImageData(this.buffer, 0, 0); + } + ); - } - ); + }); - JSIL.ImplementExternals( - "System.Drawing.Bitmap", function ($) { - var systemDrawing = JSIL.GetAssembly("System.Drawing", true); - var mscorlib = JSIL.GetAssembly("mscorlib", true); + JSIL.ImplementExternals("System.Drawing.Bitmap", function ($) { + var systemDrawing = JSIL.GetAssembly("System.Drawing", true); + var mscorlib = JSIL.GetAssembly("mscorlib", true); - var constructFromFile = function (filename) { - // System.Drawing.Image.prototype._ctor.call(this); + var constructFromFile = function (filename) { + // System.Drawing.Image.prototype._ctor.call(this); - this.image = JSIL.Host.getImage(filename); + this.image = JSIL.Host.getImage(filename); - this.canvas = JSIL.Host.createCanvas(this.image.naturalWidth, this.image.naturalHeight); - this.context = this.canvas.getContext('2d'); - this.context.globalCompositeOperation = "copy"; + this.canvas = JSIL.Host.createCanvas(this.image.naturalWidth, this.image.naturalHeight); + this.context = this.canvas.getContext('2d'); + this.context.globalCompositeOperation = "copy"; - this.context.drawImage(this.image, 0, 0); - /* - try { - this.buffer = this.context.getImageData(0, 0, this.image.naturalWidth, this.image.naturalHeight); - } catch (e) { - JSIL.Host.warning("Failed to read image pixels for '" + filename + "'", e); - this.buffer = this.context.createImageData(this.image.naturalWidth, this.image.naturalHeight); - } - */ - this.buffer = null; - }; + this.context.drawImage(this.image, 0, 0); + /* + try { + this.buffer = this.context.getImageData(0, 0, this.image.naturalWidth, this.image.naturalHeight); + } catch (e) { + JSIL.Host.warning("Failed to read image pixels for '" + filename + "'", e); + this.buffer = this.context.createImageData(this.image.naturalWidth, this.image.naturalHeight); + } + */ + this.buffer = null; + }; - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String")], []), - constructFromFile - ); + $.Method({Static:false, Public:true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String")], []), + constructFromFile + ); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String"), mscorlib.TypeRef("System.Boolean")], []), - constructFromFile - ); + $.Method({Static:false, Public:true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.String"), mscorlib.TypeRef("System.Boolean")], []), + constructFromFile + ); - $.Method({Static:false, Public:true }, ".ctor", - new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32")], []), - function (width, height) { - // System.Drawing.Image.prototype._ctor.call(this); + $.Method({Static:false, Public:true }, ".ctor", + new JSIL.MethodSignature(null, [mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32")], []), + function (width, height) { + // System.Drawing.Image.prototype._ctor.call(this); - this.canvas = JSIL.Host.getCanvas(width, height); - this.context = this.canvas.getContext('2d'); - this.context.globalCompositeOperation = "copy"; + this.canvas = JSIL.Host.getCanvas(width, height); + this.context = this.canvas.getContext('2d'); + this.context.globalCompositeOperation = "copy"; - this.buffer = this.context.createImageData(width, height); - this.context.putImageData(this.buffer, 0, 0); + this.buffer = this.context.createImageData(width, height); + this.context.putImageData(this.buffer, 0, 0); + this.setPixelCount = 0; + this.flushInterval = width - 1; + } + ); + + $.Method({Static:false, Public:true }, "SetPixel", + new JSIL.MethodSignature(null, [ + mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), + systemDrawing.TypeRef("System.Drawing.Color") + ], []), + function (x, y, color) { + var index = ((y * this.buffer.width) + x) * 4; + var data = this.buffer.data; + data[index] = color.R; + data[index + 1] = color.G; + data[index + 2] = color.B; + data[index + 3] = 255; + + if (this.setPixelCount++ >= this.flushInterval) { this.setPixelCount = 0; - this.flushInterval = width - 1; - } - ); - - $.Method({Static:false, Public:true }, "SetPixel", - new JSIL.MethodSignature(null, [ - mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), - systemDrawing.TypeRef("System.Drawing.Color") - ], []), - function (x, y, color) { - var index = ((y * this.buffer.width) + x) * 4; - var data = this.buffer.data; - data[index] = color.R; - data[index + 1] = color.G; - data[index + 2] = color.B; - data[index + 3] = 255; - - if (this.setPixelCount++ >= this.flushInterval) { - this.setPixelCount = 0; - this.context.putImageData(this.buffer, 0, 0); - } + this.context.putImageData(this.buffer, 0, 0); } - ); + } + ); - } - ); + }); } -JSIL.ImplementExternals( - "System.Drawing.Color", function ($) { - var systemDrawing = JSIL.GetAssembly("System.Drawing", true); - var mscorlib = JSIL.GetAssembly("mscorlib", true); +JSIL.ImplementExternals("System.Drawing.Color", function ($) { + var systemDrawing = JSIL.GetAssembly("System.Drawing", true); + var mscorlib = JSIL.GetAssembly("mscorlib", true); - var makeColor = function (a, r, g, b, name) { - var prototype = systemDrawing.System.Drawing.Color.prototype; - var result = Object.create(prototype); + var makeColor = function (a, r, g, b, name) { + var prototype = systemDrawing.System.Drawing.Color.prototype; + var result = Object.create(prototype); - result.a = a; - result.r = r; - result.g = g; - result.b = b; - result.name = name; + result.a = a; + result.r = r; + result.g = g; + result.b = b; + result.name = name; - return result; - }; + return result; + }; - $.Method({Static:true , Public:false}, ".cctor2", - new JSIL.MethodSignature(null, [], []), - function _cctor2 () { - var sdc = systemDrawing.System.Drawing.Color; + $.Method({Static:true , Public:false}, ".cctor2", + new JSIL.MethodSignature(null, [], []), + function _cctor2 () { + var sdc = systemDrawing.System.Drawing.Color; - var makeNamedColor = function (a, r, g, b, name) { - var color = makeColor(a, r, g, b, name); + var makeNamedColor = function (a, r, g, b, name) { + var color = makeColor(a, r, g, b, name); - JSIL.SetValueProperty(sdc, "get_" + name, function () { - return color; - }); + JSIL.SetValueProperty(sdc, "get_" + name, function () { + return color; + }); - JSIL.SetValueProperty(sdc, name, color); - }; + JSIL.SetValueProperty(sdc, name, color); + }; - makeNamedColor(0xFF, 0x00, 0x00, 0x00, "Black"); - makeNamedColor(0xFF, 0xFF, 0xFF, 0xFF, "White"); - makeNamedColor(0xFF, 0xFD, 0xF5, 0xE6, "OldLace"); - makeNamedColor(0xFF, 0x8A, 0x2B, 0xE2, "BlueViolet"); - makeNamedColor(0xFF, 0x7F, 0xFF, 0xD4, "Aquamarine"); - } - ); + makeNamedColor(0xFF, 0x00, 0x00, 0x00, "Black"); + makeNamedColor(0xFF, 0xFF, 0xFF, 0xFF, "White"); + makeNamedColor(0xFF, 0xFD, 0xF5, 0xE6, "OldLace"); + makeNamedColor(0xFF, 0x8A, 0x2B, 0xE2, "BlueViolet"); + makeNamedColor(0xFF, 0x7F, 0xFF, 0xD4, "Aquamarine"); + } + ); - $.Method({Static:true , Public:true }, "FromArgb", - new JSIL.MethodSignature(systemDrawing.TypeRef("System.Drawing.Color"), [ - mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), - mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32") - ], []), - function (alpha, red, green, blue) { - return makeColor(alpha, red, green, blue, null); - } - ); + $.Method({Static:true , Public:true }, "FromArgb", + new JSIL.MethodSignature(systemDrawing.TypeRef("System.Drawing.Color"), [ + mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), + mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32") + ], []), + function (alpha, red, green, blue) { + return makeColor(alpha, red, green, blue, null); + } + ); - $.Method({Static:true , Public:true }, "FromArgb", - new JSIL.MethodSignature(systemDrawing.TypeRef("System.Drawing.Color"), [ - mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), - mscorlib.TypeRef("System.Int32") - ], []), - function (red, green, blue) { - return makeColor(255, red, green, blue, null); - } - ); + $.Method({Static:true , Public:true }, "FromArgb", + new JSIL.MethodSignature(systemDrawing.TypeRef("System.Drawing.Color"), [ + mscorlib.TypeRef("System.Int32"), mscorlib.TypeRef("System.Int32"), + mscorlib.TypeRef("System.Int32") + ], []), + function (red, green, blue) { + return makeColor(255, red, green, blue, null); + } + ); - $.Method({Static:false, Public:true }, "get_A", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), - function () { - return this.a; - } - ); + $.Method({Static:false, Public:true }, "get_A", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), + function () { + return this.a; + } + ); - $.Method({Static:false, Public:true }, "get_R", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), - function () { - return this.r; - } - ); + $.Method({Static:false, Public:true }, "get_R", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), + function () { + return this.r; + } + ); - $.Method({Static:false, Public:true }, "get_G", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), - function () { - return this.g; - } - ); + $.Method({Static:false, Public:true }, "get_G", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), + function () { + return this.g; + } + ); - $.Method({Static:false, Public:true }, "get_B", - new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), - function () { - return this.b; - } - ); + $.Method({Static:false, Public:true }, "get_B", + new JSIL.MethodSignature(mscorlib.TypeRef("System.Byte"), [], []), + function () { + return this.b; + } + ); - $.Method({Static:false, Public:true }, "get_Name", - new JSIL.MethodSignature(mscorlib.TypeRef("System.String"), [], []), - function () { + $.Method({Static:false, Public:true }, "get_Name", + new JSIL.MethodSignature(mscorlib.TypeRef("System.String"), [], []), + function () { + return this.name; + } + ); + + $.Method({Static:false, Public:true }, "toString", + new JSIL.MethodSignature(mscorlib.TypeRef("System.String"), [], []), + function () { + if ((typeof (this.name) != "undefined") && (this.name != null)) return this.name; - } - ); + else + return System.String.Format("({0}, {1}, {2}, {3})", this.a, this.r, this.g, this.b); + } + ); - $.Method({Static:false, Public:true }, "toString", - new JSIL.MethodSignature(mscorlib.TypeRef("System.String"), [], []), - function () { - if ((typeof (this.name) != "undefined") && (this.name != null)) - return this.name; - else - return System.String.Format("({0}, {1}, {2}, {3})", this.a, this.r, this.g, this.b); + $.Method({Static:false, Public:true }, "MemberwiseClone", + new JSIL.MethodSignature("System.Object", [], [], $jsilcore), + function () { + if ((typeof (this.name) != "undefined") && (this.name != null)) { + return this; + } else { + var result = Object.create(systemDrawing.System.Drawing.Color.prototype); + result.a = this.a; + result.r = this.r; + result.g = this.g; + result.b = this.b; + return result; } - ); + } + ); +}); + +JSIL.ImplementExternals("System.Drawing.Size", function ($) { + $.RawMethod(true, ".cctor", function () { + System.Drawing.Size.prototype.width = 0; + System.Drawing.Size.prototype.height = 0; + System.Drawing.Size.Empty = new System.Drawing.Size(); + }); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32, $.Int32], [])), + function _ctor (width, height) { + this.width = width; + this.height = height; + } + ); - $.Method({Static:false, Public:true }, "MemberwiseClone", - new JSIL.MethodSignature("System.Object", [], [], $jsilcore), - function () { - if ((typeof (this.name) != "undefined") && (this.name != null)) { - return this; - } else { - var result = Object.create(systemDrawing.System.Drawing.Color.prototype); - result.a = this.a; - result.r = this.r; - result.g = this.g; - result.b = this.b; - return result; - } - } - ); - } -); - -JSIL.ImplementExternals( - "System.Drawing.Size", true, { - _ctor: function (w, h) { - this.width = w; - this.height = h; - }, - get_Width: function () { - return this.width; - }, - get_Height: function () { + $.Method({Static:false, Public:true }, "get_Height", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Height () { return this.height; - }, - set_Width: function (value) { - this.width = value; - }, - set_Height: function (value) { + } + ); + + $.Method({Static:false, Public:true }, "get_Width", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Width () { + return this.width; + } + ); + + $.Method({Static:false, Public:true }, "set_Height", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Height (value) { this.height = value; } - } -); -JSIL.ImplementExternals( - "System.Drawing.Size", false, { - _cctor: function () { - System.Drawing.Size.prototype.width = 0; - System.Drawing.Size.prototype.height = 0; - System.Drawing.Size.Empty = new System.Drawing.Size(); - } - } -); - -JSIL.ImplementExternals( - "System.Drawing.Point", false, { - _cctor: function () { - System.Drawing.Point.prototype.x = 0; - System.Drawing.Point.prototype.y = 0; - System.Drawing.Point.Empty = new System.Drawing.Point(); - } - } -); -JSIL.ImplementExternals( - "System.Drawing.Point", true, { - _ctor: function (x, y) { + ); + + $.Method({Static:false, Public:true }, "set_Width", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Width (value) { + this.width = value; + } + ); +}); + +JSIL.ImplementExternals("System.Drawing.Point", function ($) { + $.RawMethod(true, ".cctor", function () { + System.Drawing.Point.prototype.x = 0; + System.Drawing.Point.prototype.y = 0; + System.Drawing.Point.Empty = new System.Drawing.Point(); + }); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$.Int32, $.Int32], [])), + function _ctor (x, y) { this.x = x; this.y = y; - }, - get_X: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_X", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_X () { return this.x; - }, - get_Y: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_Y", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Y () { return this.y; - }, - set_X: function (value) { + } + ); + + $.Method({Static:false, Public:true }, "set_X", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_X (value) { this.x = value; - }, - set_Y: function (value) { + } + ); + + $.Method({Static:false, Public:true }, "set_Y", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Y (value) { this.y = value; } - } -); - -JSIL.ImplementExternals( - "System.Drawing.Rectangle", false, { - _cctor: function () { - System.Drawing.Rectangle.Empty = new System.Drawing.Rectangle(); - } - } -); -JSIL.ImplementExternals( - "System.Drawing.Rectangle", true, { - x: 0, - y: 0, - width: 0, - height: 0, - _ctor: function (x, y, w, h) { - if ((typeof (x) === "object") && (typeof (y) === "object")) { - this.x = x.X; - this.y = x.Y; - this.width = y.Width; - this.height = y.Height; - } else { - this.x = x; - this.y = y; - this.width = w; - this.height = h; - } - }, - get_X: function () { + ); +}); + +JSIL.ImplementExternals("System.Drawing.Rectangle", function ($) { + $.RawMethod(true, ".cctor", function () { + System.Drawing.Rectangle.Empty = new System.Drawing.Rectangle(); + }); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [ + $.Int32, $.Int32, + $.Int32, $.Int32 + ], [])), + function _ctor (x, y, width, height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + ); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$asms[11].TypeRef("System.Drawing.Point"), $asms[11].TypeRef("System.Drawing.Size")], [])), + function _ctor (location, size) { + this.x = location.X; + this.y = location.Y; + this.width = size.Width; + this.height = size.Height; + } + ); + + $.Method({Static:false, Public:true }, "get_Bottom", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Bottom () { + return this.y + this.height; + } + ); + + $.Method({Static:false, Public:true }, "get_Height", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Height () { + return this.height; + } + ); + + $.Method({Static:false, Public:true }, "get_Left", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Left () { return this.x; - }, - get_Y: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_Right", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Right () { + return this.x + this.width; + } + ); + + $.Method({Static:false, Public:true }, "get_Top", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Top () { return this.y; - }, - set_X: function (value) { - this.x = value; - }, - set_Y: function (value) { - this.y = value; - }, - get_Width: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_Width", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Width () { return this.width; - }, - get_Height: function () { - return this.height; - }, - set_Width: function (value) { - this.width = value; - }, - set_Height: function (value) { - this.height = value; - }, - get_Left: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_X", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_X () { return this.x; - }, - get_Top: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_Y", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_Y () { return this.y; - }, - get_Right: function () { - return this.x + this.width; - }, - get_Bottom: function () { - return this.y + this.height; - }, - MemberwiseClone: function () { - var result = Object.create(System.Drawing.Rectangle.prototype); - result.x = this.x; - result.y = this.y; - result.width = this.width; - result.height = this.height; - return result; - } - } -); \ No newline at end of file + } + ); + + $.Method({Static:false, Public:true }, "set_Height", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Height (value) { + this.height = value; + } + ); + + $.Method({Static:false, Public:true }, "set_Width", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Width (value) { + this.width = value; + } + ); + + $.Method({Static:false, Public:true }, "set_X", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_X (value) { + this.x = value; + } + ); + + $.Method({Static:false, Public:true }, "set_Y", + (new JSIL.MethodSignature(null, [$.Int32], [])), + function set_Y (value) { + this.y = value; + } + ); +}); \ No newline at end of file diff --git a/Libraries/System.Windows.js b/Libraries/System.Windows.js index a80ea366d..0b286a5ad 100644 --- a/Libraries/System.Windows.js +++ b/Libraries/System.Windows.js @@ -7,60 +7,127 @@ JSIL.DeclareAssembly("JSIL.Windows"); JSIL.DeclareNamespace("JSIL"); -JSIL.ImplementExternals( - "System.Windows.Forms.Control", true, { - clientWidth: 16, - clientHeight: 16, - SetStyle: function (styles, newState) { - }, - _ctor: function () { - this._controls = new (System.Collections.Generic.List$b1.Of(System.Object)) (); - }, - get_Controls: function () { +JSIL.ImplementExternals("System.Windows.Forms.Control", function ($) { + var coreCtor = function _ctor () { + this._controls = new $asms[15].System.Windows.Forms.Control_ControlCollection (); + }; + + $.RawMethod(false, "$coreCtor", coreCtor); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + coreCtor + ); + + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [$.String], [])), + coreCtor + ); + + $.Method({Static:false, Public:true }, "get_Controls", + (new JSIL.MethodSignature($asms[15].TypeRef("System.Windows.Forms.Control/ControlCollection"), [], [])), + function get_Controls () { return this._controls; - }, - get_ClientSize: function () { + } + ); + + $.Method({Static:false, Public:true }, "get_ClientSize", + (new JSIL.MethodSignature($asms[11].TypeRef("System.Drawing.Size"), [], [])), + function get_ClientSize () { return new System.Drawing.Size(this.clientWidth, this.clientHeight); - }, - set_ClientSize: function (size) { - this.clientWidth = size.Width; - this.clientHeight = size.Height; - }, - add_Paint: function (handler) { - }, - Show: function () { - }, - Refresh: function () { } - } -); + ); + + $.Method({Static:false, Public:true }, "set_ClientSize", + (new JSIL.MethodSignature(null, [$asms[11].TypeRef("System.Drawing.Size")], [])), + function set_ClientSize (value) { + this.clientWidth = value.Width; + this.clientHeight = value.Height; + } + ); +}); + +JSIL.ImplementExternals("System.Windows.Forms.Control/ControlCollection", function ($) { + $jsilcore.$ListExternals($, $asms[15].TypeRef("System.Windows.Forms.Control"), false); +}); + +JSIL.ImplementExternals("System.Windows.Forms.StatusBar/StatusBarPanelCollection", function ($) { + $jsilcore.$ListExternals($, $asms[15].TypeRef("System.Windows.Forms.StatusBarPanel"), true); +}); + +JSIL.ImplementExternals("System.Windows.Forms.TabControl/TabPageCollection", function ($) { + $jsilcore.$ListExternals($, $asms[15].TypeRef("System.Windows.Forms.TabPage"), true); +}); + +JSIL.ImplementExternals("System.Windows.Forms.ListBox/ObjectCollection", function ($) { + $jsilcore.$ListExternals($, $.Object, true); +}); + +JSIL.ImplementExternals("System.Windows.Forms.Form", function ($) { + $.InheritDefaultConstructor(); +}); -JSIL.ImplementExternals( - "System.Windows.Forms.Form", true, { - _ctor: function () { - System.Windows.Forms.Control.prototype._ctor.call(this); +JSIL.ImplementExternals("System.Windows.Forms.ListBox", function ($) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor () { + this.$coreCtor(); + this._items = new $asms[15].System.Windows.Forms.ListBox_ObjectCollection (); } - } -); - -JSIL.ImplementExternals( - "System.Windows.Forms.StatusBar", true, { - _ctor: function () { - this._panels = new (System.Collections.Generic.List$b1.Of(System.Object)) (); - }, - get_Panels: function () { + ); + + $.Method({Static:false, Public:true }, "get_Items", + (new JSIL.MethodSignature($asms[15].TypeRef("System.Windows.Forms.ListBox/ObjectCollection"), [], [])), + function get_Items () { + return this._items; + } + ); + + $.Method({Static:false, Public:true }, "get_SelectedIndex", + (new JSIL.MethodSignature($.Int32, [], [])), + function get_SelectedIndex () { + return 0; + } + ); + + $.Method({Static:false, Public:true }, "get_SelectedItem", + (new JSIL.MethodSignature($.Object, [], [])), + function get_SelectedItem () { + return null; + } + ); +}); + +JSIL.ImplementExternals("System.Windows.Forms.StatusBar", function ($) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor () { + this.$coreCtor(); + this._panels = new $asms[15].System.Windows.Forms.StatusBar_StatusBarPanelCollection (); + } + ); + + $.Method({Static:false, Public:true }, "get_Panels", + (new JSIL.MethodSignature($asms[15].TypeRef("System.Windows.Forms.StatusBar/StatusBarPanelCollection"), [], [])), + function get_Panels () { return this._panels; } - } -); - -JSIL.ImplementExternals( - "System.Windows.Forms.TabControl", true, { - _ctor: function () { - this._tabPages = new (System.Collections.Generic.List$b1.Of(System.Object)) (); - }, - get_TabPages: function () { + ); +}); + +JSIL.ImplementExternals("System.Windows.Forms.TabControl", function ($) { + $.Method({Static:false, Public:true }, ".ctor", + (new JSIL.MethodSignature(null, [], [])), + function _ctor () { + this.$coreCtor(); + this._tabPages = new $asms[15].System.Windows.Forms.TabControl_TabPageCollection (); + } + ); + + $.Method({Static:false, Public:true }, "get_TabPages", + (new JSIL.MethodSignature($asms[15].TypeRef("System.Windows.Forms.TabControl/TabPageCollection"), [], [])), + function get_TabPages () { return this._tabPages; } - } -); + ); +}); diff --git a/Proxies/Forms.cs b/Proxies/Forms.cs index 2c47b7558..3295b7844 100644 --- a/Proxies/Forms.cs +++ b/Proxies/Forms.cs @@ -13,35 +13,4 @@ namespace JSIL.Proxies { [JSIgnore] public abstract class AccessibleObjectProxy { } - - [JSProxy( - "System.Windows.Forms.Control", - JSProxyMemberPolicy.ReplaceDeclared, - inheritable: true - )] - public abstract class ControlProxy { - [JSRuntimeDispatch] - [JSExternal] - public ControlProxy (params AnyType[] values) { - } - } - - [JSProxy( - new[] { - "System.Windows.Forms.StatusBar/StatusBarPanelCollection", - "System.Windows.Forms.TabControl/TabPageCollection" - }, - JSProxyMemberPolicy.ReplaceDeclared - )] - public abstract class ControlCollectionProxy { - [JSRuntimeDispatch] - [JSExternal] - public abstract AnyType Add (params AnyType[] values); - - [JSRuntimeDispatch] - [JSExternal] - public abstract AnyType this[AnyType key] { - get; - } - } } diff --git a/Tests/FormattingTests.cs b/Tests/FormattingTests.cs index 836e2a9fe..056466fb3 100644 --- a/Tests/FormattingTests.cs +++ b/Tests/FormattingTests.cs @@ -494,5 +494,25 @@ public void CorlibTypeRefs () { throw; } } + + [Test] + public void FastOverloadDispatch () { + var output = "A()\r\nA(1)\r\nA(1, str)\r\nB()\r\nB(int 1)\r\nB(string str)"; + + var generatedJs = GenericTest( + @"SpecialTestCases\FastOverloadDispatch.cs", + output, output + ); + + try { + Assert.IsFalse(generatedJs.Contains("CallStatic($asm00.Program, \"A\", ")); + Assert.IsTrue(generatedJs.Contains("$asm00.Program.B();")); + Assert.IsTrue(generatedJs.Contains("CallStatic($asm00.Program, \"B\", ")); + } catch { + Console.WriteLine(generatedJs); + + throw; + } + } } } diff --git a/Tests/SpecialTestCases/FastOverloadDispatch.cs b/Tests/SpecialTestCases/FastOverloadDispatch.cs new file mode 100644 index 000000000..3e3e4615c --- /dev/null +++ b/Tests/SpecialTestCases/FastOverloadDispatch.cs @@ -0,0 +1,36 @@ +using System; + +public static class Program { + public static void A () { + Console.WriteLine("A()"); + } + + public static void A (int i) { + Console.WriteLine("A({0})", i); + } + + public static void A (int i, string s) { + Console.WriteLine("A({0}, {1})", i, s); + } + + public static void B () { + Console.WriteLine("B()"); + } + + public static void B (int i) { + Console.WriteLine("B(int {0})", i); + } + + public static void B (string s) { + Console.WriteLine("B(string {0})", s); + } + + public static void Main (string[] args) { + A(); + A(1); + A(1, "str"); + B(); + B(1); + B("str"); + } +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 5c5a29a9e..b847404a7 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -335,6 +335,7 @@ +