diff --git a/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/IronRuby.Libraries.Yaml.csproj b/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/IronRuby.Libraries.Yaml.csproj index ef58354511..ccefe3596a 100644 --- a/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/IronRuby.Libraries.Yaml.csproj +++ b/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/Yaml/IronRuby.Libraries.Yaml/IronRuby.Libraries.Yaml.csproj @@ -1,9 +1,9 @@  - + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {AA18A245-E342-4368-A474-83178311A742} Library diff --git a/Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.csproj b/Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.csproj index c46378e4f5..0217437e1b 100644 --- a/Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.csproj +++ b/Merlin/Main/Debugging/Microsoft.Scripting.Debugging/Microsoft.Scripting.Debugging.csproj @@ -1,9 +1,9 @@  - + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF} Library @@ -140,4 +140,4 @@ - + \ No newline at end of file diff --git a/Merlin/Main/Hosts/SilverLight/Chiron/Chiron.csproj b/Merlin/Main/Hosts/SilverLight/Chiron/Chiron.csproj index a274dcf97c..db153bfd33 100644 --- a/Merlin/Main/Hosts/SilverLight/Chiron/Chiron.csproj +++ b/Merlin/Main/Hosts/SilverLight/Chiron/Chiron.csproj @@ -1,9 +1,9 @@  - + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {7D07B0CE-FFA3-4402-BFF2-5F42B4267D2A} Exe @@ -23,6 +23,7 @@ Signed Unsigned true + v3.5 true diff --git a/Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj b/Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj index da2d846891..0dd4bfeb84 100644 --- a/Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj +++ b/Merlin/Main/Hosts/SilverLight/Microsoft.Scripting.SilverLight/Microsoft.Scripting.Silverlight.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {C86A7A7B-3086-4136-9B56-17E8DCB38C8D} Library @@ -19,6 +20,7 @@ true true ..\..\..\Utilities\Silverlight\x86ret\ + v2.0 true @@ -127,4 +129,4 @@ - + \ No newline at end of file diff --git a/Merlin/Main/Languages/IronPython/IronPython.Modules/IronPython.Modules.csproj b/Merlin/Main/Languages/IronPython/IronPython.Modules/IronPython.Modules.csproj index e29c231115..594cd81d05 100644 --- a/Merlin/Main/Languages/IronPython/IronPython.Modules/IronPython.Modules.csproj +++ b/Merlin/Main/Languages/IronPython/IronPython.Modules/IronPython.Modules.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {155CE436-1669-4A48-8095-410F2430237F} Library @@ -13,7 +14,6 @@ SAK SAK SAK - 2.0 618,1685 ..\..\..\Support\MSSharedLibKey.snk true @@ -21,6 +21,7 @@ true ..\..\..\Utilities\Silverlight\x86ret\ 885063680 + v2.0 true diff --git a/Merlin/Main/Languages/IronPython/IronPython/IronPython.csproj b/Merlin/Main/Languages/IronPython/IronPython/IronPython.csproj index 6e0abf8484..07c19690ff 100644 --- a/Merlin/Main/Languages/IronPython/IronPython/IronPython.csproj +++ b/Merlin/Main/Languages/IronPython/IronPython/IronPython.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {95289EA9-5778-489D-AB48-F81F2CE2DA32} Library @@ -13,7 +14,6 @@ SAK SAK SAK - 2.0 true 618,1685 ..\..\..\Support\MSSharedLibKey.snk @@ -22,6 +22,7 @@ true ..\..\..\Utilities\Silverlight\x86ret\ 879755264 + v2.0 true diff --git a/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs b/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs index 145843a5dd..396d6c935f 100644 --- a/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs +++ b/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/MetaPythonFunction.cs @@ -34,7 +34,7 @@ namespace IronPython.Runtime.Binding { using Ast = System.Linq.Expressions.Expression; using AstUtils = Microsoft.Scripting.Ast.Utils; - class MetaPythonFunction : MetaPythonObject, IPythonInvokable, IPythonOperable, IPythonConvertible, IInferableInvokable { + class MetaPythonFunction : MetaPythonObject, IPythonInvokable, IPythonOperable, IPythonConvertible, IInferableInvokable, IConvertibleMetaObject { public MetaPythonFunction(Expression/*!*/ expression, BindingRestrictions/*!*/ restrictions, PythonFunction/*!*/ value) : base(expression, BindingRestrictions.Empty, value) { Assert.NotNull(value); @@ -930,5 +930,13 @@ class FunctionBinderHelper { } #endregion + + #region IConvertibleMetaObject Members + + bool IConvertibleMetaObject.CanConvertTo(Type/*!*/ type, bool @explicit) { + return type.IsSubclassOf(typeof(Delegate)); + } + + #endregion } } diff --git a/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonOverloadResolver.cs b/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonOverloadResolver.cs index 9d961b2cd4..79143361bb 100644 --- a/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonOverloadResolver.cs +++ b/Merlin/Main/Languages/IronPython/IronPython/Runtime/Binding/PythonOverloadResolver.cs @@ -75,7 +75,7 @@ public PythonOverloadResolver(PythonBinder binder, IList args } } - public override bool CanConvertFrom(Type fromType, ParameterWrapper toParameter, NarrowingLevel level) { + public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArg, ParameterWrapper toParameter, NarrowingLevel level) { if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List)))) { if (toParameter.Type.IsGenericType && toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) && @@ -98,7 +98,7 @@ public PythonOverloadResolver(PythonBinder binder, IList args } } - return base.CanConvertFrom(fromType, toParameter, level); + return base.CanConvertFrom(fromType, fromArg, toParameter, level); } protected override BitArray MapSpecialParameters(ParameterMapping/*!*/ mapping) { diff --git a/Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj b/Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj index d0def9b3dc..c4095a64f1 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj +++ b/Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {811AC32C-11F3-4ED8-92A7-A7E39C2BB704} Exe @@ -14,7 +15,6 @@ SAK SAK ipy.ico - 2.0 618,1685 ..\..\..\Support\MSSharedLibKey.snk true @@ -23,6 +23,7 @@ Unsigned true x86 + v2.0 true diff --git a/Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj b/Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj index e482d7e012..cc0af6abfd 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj +++ b/Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {F1D861C5-D9D5-4CDA-968B-8275F5D9F6D2} Exe @@ -14,7 +15,6 @@ SAK SAK ..\IronPythonConsole\ipy.ico - 2.0 618,1685 ..\..\..\Support\MSSharedLibKey.snk true @@ -22,6 +22,7 @@ Signed Unsigned true + v2.0 true diff --git a/Merlin/Main/Languages/IronPython/IronPythonTest/BinderTest.cs b/Merlin/Main/Languages/IronPython/IronPythonTest/BinderTest.cs index aebb1645d3..5a4bdeab2a 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonTest/BinderTest.cs +++ b/Merlin/Main/Languages/IronPython/IronPythonTest/BinderTest.cs @@ -252,6 +252,12 @@ public class COtherOverloadConcern { // generics public void M130(Int32 arg) { Flag.Value = 130; } public void M130(T arg) { Flag.Value = 230; } + + // narrowing levels and __int__ conversion: + // If 2 instances of a Python subclass of C3 that implements __int__ are passed as arguments this + // the first overload should be preferred. + public void M140(C3 a, int b) { Flag.Value = 140; } + public void M140(int a, int b) { Flag.Value = 240; } } public interface I1 { void M(); } diff --git a/Merlin/Main/Languages/IronPython/IronPythonTest/IronPythonTest.csproj b/Merlin/Main/Languages/IronPython/IronPythonTest/IronPythonTest.csproj index 3204fc34df..36a29f4bb9 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonTest/IronPythonTest.csproj +++ b/Merlin/Main/Languages/IronPython/IronPythonTest/IronPythonTest.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {B6B42537-07F8-4F6C-A99A-B155CAEB124E} Library @@ -16,12 +17,12 @@ 618,1685 - 2.0 ..\..\..\Support\MSSharedLibKey.snk true SIGNED true ..\..\..\Utilities\Silverlight\x86ret\ + v2.0 true diff --git a/Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj b/Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj index 6f079ed498..0ad51a585d 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj +++ b/Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {81DA19C7-4FEC-47E7-981B-D9310D549F95} WinExe @@ -16,7 +17,7 @@ SAK SAK ipy.ico - 2.0 + v2.0 publish\ true Disk diff --git a/Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj b/Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj index 123db8b47a..1f2a84a420 100644 --- a/Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj +++ b/Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj @@ -1,8 +1,8 @@ - + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {7F6F9AB3-9943-4316-BD4C-A10F580BC75C} WinExe @@ -16,7 +16,7 @@ SAK SAK ..\IronPythonWindow\ipy.ico - 2.0 + v2.0 publish\ true Disk diff --git a/Merlin/Main/Languages/Ruby/ClassInitGenerator/ClassInitGenerator.csproj b/Merlin/Main/Languages/Ruby/ClassInitGenerator/ClassInitGenerator.csproj index 66f441d8bc..3416f635fd 100644 --- a/Merlin/Main/Languages/Ruby/ClassInitGenerator/ClassInitGenerator.csproj +++ b/Merlin/Main/Languages/Ruby/ClassInitGenerator/ClassInitGenerator.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30718 + 10.0.20624 2.0 {166940A1-2C91-4BD0-B72B-A517FBD8BF0B} Exe @@ -13,12 +14,12 @@ SAK SAK SAK - 2.0 4 ..\..\..\Support\MSSharedLibKey.snk true SIGNED true + v2.0 true @@ -69,4 +70,4 @@ --> - + \ No newline at end of file diff --git a/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs b/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs index 583db3fc12..ffcd3dd37b 100644 --- a/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs +++ b/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs @@ -140,6 +140,10 @@ private class ModuleDef { public IDictionary/*!*/ HiddenInstanceMethods = new SortedDictionary(); public IDictionary/*!*/ HiddenClassMethods = new SortedDictionary(); + // { new_name -> old_name } + public IDictionary/*!*/ ClassMethodAliases = new SortedDictionary(); + public IDictionary/*!*/ InstanceMethodAliases = new SortedDictionary(); + public List/*!*/ Factories = new List(); public List/*!*/ Mixins = new List(); @@ -206,7 +210,10 @@ private class ModuleDef { } public bool HasInstanceInitializer { - get { return InstanceMethods.Count > 0 || HiddenInstanceMethods.Count > 0 || HasCopyInclusions || IsPrimitive; } + get { + return InstanceMethods.Count > 0 || HiddenInstanceMethods.Count > 0 || InstanceMethodAliases.Count > 0 + || HasCopyInclusions || IsPrimitive; + } } public bool HasConstantsInitializer { @@ -214,7 +221,10 @@ private class ModuleDef { } public bool HasClassInitializer { - get { return ClassMethods.Count > 0 || HiddenClassMethods.Count > 0 || HasCopyInclusions || IsPrimitive; } + get { + return ClassMethods.Count > 0 || HiddenClassMethods.Count > 0 || ClassMethodAliases.Count > 0 + || HasCopyInclusions || IsPrimitive; + } } public const string/*!*/ ObjectClassRef = "Context.ObjectClass"; @@ -396,21 +406,35 @@ private class ConstantDef { // hidden CLR methods: foreach (HideMethodAttribute method in trait.GetCustomAttributes(typeof(HideMethodAttribute), false)) { - // TODO: warning, method already removed, method not found ... - if (method.IsStatic) { - def.HiddenClassMethods[method.Name] = HiddenMethod.ClrInvisible; + var dict = (method.IsStatic) ? def.HiddenClassMethods : def.HiddenInstanceMethods; + if (dict.ContainsKey(method.Name)) { + LogError("Method {0} is already hidden/removed", method.Name); } else { - def.HiddenInstanceMethods[method.Name] = HiddenMethod.ClrInvisible; + dict.Add(method.Name, HiddenMethod.ClrInvisible); } } // undefined methods: foreach (UndefineMethodAttribute method in trait.GetCustomAttributes(typeof(UndefineMethodAttribute), false)) { - // TODO: warning, method already removed, method not found ... - if (method.IsStatic) { - def.HiddenClassMethods[method.Name] = HiddenMethod.Undefined; + var dict = (method.IsStatic) ? def.HiddenClassMethods : def.HiddenInstanceMethods; + if (dict.ContainsKey(method.Name)) { + LogError("Method {0} is already hidden/removed", method.Name); + } else { + dict.Add(method.Name, HiddenMethod.Undefined); + } + } + + // aliased methods: + foreach (AliasMethodAttribute method in trait.GetCustomAttributes(typeof(AliasMethodAttribute), false)) { + var aliasDict = (method.IsStatic) ? def.ClassMethodAliases : def.InstanceMethodAliases; + var hiddenDict = (method.IsStatic) ? def.HiddenClassMethods : def.HiddenInstanceMethods; + + if (hiddenDict.ContainsKey(method.NewName)) { + LogError("Cannot alias hidden/removed method {0}", method.NewName); + } else if (aliasDict.ContainsKey(method.NewName)) { + LogError("Duplicate method alias {0} {1}", method.NewName, method.OldName); } else { - def.HiddenInstanceMethods[method.Name] = HiddenMethod.Undefined; + aliasDict.Add(method.NewName, method.OldName); } } } @@ -421,6 +445,10 @@ private class ConstantDef { // declaring modules, build configurations: foreach (ModuleDef def in _moduleDefs.Values) { if (!def.IsExtension) { + if (def.Extends.IsGenericTypeDefinition) { + LogError("Only extension modules or classes can be generic type definitions '{0}'", def.QualifiedName); + } + // finds the inner most Ruby module def containing this module def: ModuleDef declaringDef = GetDeclaringModuleDef(def); if (declaringDef != null) { @@ -497,6 +525,10 @@ private class ConstantDef { } else if (!mixin.Copy) { // define a module ref-variable for the type of the mixin: mixin.Module.RefName = MakeModuleReference(mixin.Module.Type); + } else { + LogError("Cannot copy-include a mixin not defined in this library ('{0}' includes '{1}')", + def.QualifiedName, mixin.Module.Type + ); } } } @@ -1102,6 +1134,7 @@ private class ConstantDef { GenerateIncludedTraitLoaders(moduleDef, isInstance); GenerateHiddenMethods(isInstance ? moduleDef.HiddenInstanceMethods : moduleDef.HiddenClassMethods); GenerateMethods(moduleDef.Trait, isInstance ? moduleDef.InstanceMethods : moduleDef.ClassMethods); + GenerateMethodAliases(isInstance ? moduleDef.InstanceMethodAliases : moduleDef.ClassMethodAliases); _output.Indent--; _output.WriteLine("}"); @@ -1177,6 +1210,12 @@ private class ConstantDef { } } + private void GenerateMethodAliases(IDictionary/*!*/ aliases) { + foreach (var alias in aliases) { + _output.WriteLine("module.AddMethodAlias(\"{0}\", \"{1}\");", alias.Key, alias.Value); + } + } + private void GenerateMethods(Type/*!*/ type, IDictionary/*!*/ methods) { foreach (MethodDef def in methods.Values) { if (def.BuildConfig != null) { diff --git a/Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj b/Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj index db622e3d0a..4c206da653 100644 --- a/Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj +++ b/Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {D6AB587D-A888-4B98-85AC-F15E36F53838} Exe @@ -22,6 +23,7 @@ Unsigned true x86 + v2.0 true diff --git a/Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj b/Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj index 273f383ecb..469a73f03d 100644 --- a/Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj +++ b/Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj @@ -1,8 +1,8 @@ - + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {6EE7A428-D803-41BC-8248-1297C3ACE369} Exe @@ -21,6 +21,7 @@ Signed Unsigned true + v2.0 true diff --git a/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj b/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj index 3e49712ed6..18be344541 100644 --- a/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj +++ b/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {8103D91B-89D8-4A18-9A40-426992602EA2} Exe @@ -23,6 +24,7 @@ Signed Unsigned true + v2.0 true diff --git a/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs b/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs index dc1f5e195d..90afe121ae 100644 --- a/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs +++ b/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs @@ -51,7 +51,8 @@ public partial class Tests { OverloadResolution_Block1, OverloadResolution_ParamArrays1, - AmbiguousMatch, + OverloadResolution_Numeric1, + AmbiguousMatch1, Interpreter1, Interpreter2, Interpreter3, @@ -406,6 +407,7 @@ public partial class Tests { ClrConstructor4, ClrPrimitiveNumericTypes1, ClrArrays1, + ClrArrays2, ClrChar1, ClrOperators1, ClrOperators2, @@ -617,7 +619,6 @@ public partial class Tests { Dlr_Convertible, Dlr_Indexable, Dlr_Number, - Dlr_Enumerable, Dlr_Comparable, Dlr_RubyObjects, Dlr_Methods, diff --git a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs index 18ed5c7545..b36a233363 100644 --- a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs +++ b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs @@ -1250,6 +1250,47 @@ p C.new.arity 2 InteropTests::Generics1::D[String] InteropTests::Generics1::C[Fixnum, Fixnum] +"); + + TestOutput(@" +include InteropTests::Generics1 +p C[0] +p C[1] +p C[2] +C[30] rescue p $! +p C[1][Fixnum] +p C[Fixnum][] +p C[Fixnum][0] +C[Fixnum][Fixnum] rescue p $! +C[Fixnum][1] rescue p $! +", @" +InteropTests::Generics1::C +InteropTests::Generics1::C[T] +InteropTests::Generics1::C[T, S] +# +InteropTests::Generics1::C[Fixnum] +InteropTests::Generics1::C[Fixnum] +InteropTests::Generics1::C[Fixnum] +# +# +"); + + // C instantiations are subclasses of C<>: + TestOutput(@" +include InteropTests::Generics1 +C[1].class_eval do + def foo + p self.class + end +end + +C[Fixnum].new.foo +C[String].new.foo +p C[Float].ancestors[0..2] +", @" +InteropTests::Generics1::C[Fixnum] +InteropTests::Generics1::C[String] +[InteropTests::Generics1::C[Float], InteropTests::Generics1::C[T], Object] "); } @@ -1984,16 +2025,15 @@ puts e.Initialize(1) /// Shelveset "Numerics-MetaOpsWithNarrowing" contains prototype implementation of the narrowing. /// public void ClrPrimitiveNumericTypes1() { - AssertOutput(delegate() { - CompilerTest(@" + TestOutput(@" [System::Byte, System::SByte, System::UInt16, System::Int16, System::UInt32, System::Int64, System::UInt64, System::Single].each_with_index do |t,i| p t.ancestors p t.new(i).class p x = t.new(i) + 1, x.class p t.new(i).size rescue puts 'no size method' end -"); - }, @" +", +@" [System::Byte, Integer, Precision, Numeric, Comparable, Object, Kernel] System::Byte 1 @@ -2039,8 +2079,7 @@ p t.ancestors public void ClrArrays1() { Context.SetGlobalConstant("A2", Context.GetClass(typeof(int[,]))); - AssertOutput(delegate() { - CompilerTest(@" + TestOutput(@" # multi-dim array: a2 = A2.new(2,4) a2[0,1] = 123 @@ -2051,11 +2090,7 @@ p t.ancestors p System::Array[Fixnum].new(3) p System::Array[Fixnum].new([1,2,3]) p System::Array[Fixnum].new(3, 12) - -# TODO: conversions: -# p System::Array[System::Char].new(3, 'x') -"); - }, @" +", @" 123 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [0, 0, 0] @@ -2063,14 +2098,41 @@ p t.ancestors [12, 12, 12] "); } - + + public void ClrArrays2() { + TestOutput(@" +class C + def to_str + 'c' + end +end + +a = System::Array[System::String].new(3) +a[0] = 'x' +a[1] = C.new +a[2] = :z + +# TODO: params array parameter of 'p' binds to the vector if passed alone +p a, + System::Array[System::String].new(3, C.new), + System::Array[System::String].new([C.new, C.new]), + System::Array[System::Byte].new(3) { |x| x }, + System::Array[System::Byte].new(3, 1) +", @" +['x', 'c', 'z'] +['c', 'c', 'c'] +['c', 'c'] +[0 (Byte), 1 (Byte), 2 (Byte)] +[1 (Byte), 1 (Byte), 1 (Byte)] +"); + } + public void ClrChar1() { - AssertOutput(delegate() { - CompilerTest(@" + TestOutput(@" p System::Char.ancestors p System::String.ancestors -a = System::Array[System::Char].new([System::Char.new('a'), System::Char.new('b')]) # TODO: implicit conversion +a = System::Array[System::Char].new(['a', 'b']) p System::Char.new(a) x = System::Char.new('foo') @@ -2079,8 +2141,7 @@ p x.index('f') p x + 'oo' p x == 'f' p System::Char.new('9').to_i -"); - }, @" +", @" [System::Char, IronRuby::Clr::String, Enumerable, Comparable, System::ValueType, Object, Kernel] [System::String, IronRuby::Clr::String, Enumerable, Comparable, Object, Kernel] 'a' @@ -2232,6 +2293,10 @@ public class Conversions1 { return d; } + public Delegate Delegate(int bogusOverload) { + return new Func((x) => x); + } + public int Foo(int a) { return a + 1; } @@ -2240,22 +2305,10 @@ public class Conversions1 { return (int)a; } - public int FixnumDefaultProtocol([DefaultProtocol]int a) { - return a + 2; - } - public string Bool([Optional]bool a) { return a ? "T" : "F"; } - public int ListOrString(IList a) { - return a.Count; - } - - public int ListOrString([DefaultProtocol]MutableString str) { - return 0; - } - public int ListAndStrings(IList a, MutableString str1) { return a.Count + str1.GetCharCount(); } @@ -2322,16 +2375,16 @@ p Inst.Double(2.0), Inst.Double(4), Inst.Double(System::Byte.new(8)), Inst.Doubl // primitive numerics: TestOutput(@" -p Inst.numerics(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) +p(*Inst.numerics(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) ", @" -1 -2 -3 -4 +1 (Byte) +2 (SByte) +3 (Int16) +4 (UInt16) 5 -6 -7 -8 +6 (UInt32) +7 (Int64) +8 (UInt64) 9 (10+0j) Convertible(11) @@ -2348,13 +2401,11 @@ def to_str 'xxx' end end -p Inst.ListOrString(C.new) p Inst.ListAndStrings(C.new, C.new) -p Inst.FixnumDefaultProtocol(Conv) +p Inst.Foo(Conv) ", @" -0 8 -13 +12 "); // protocol conversions: @@ -2372,11 +2423,15 @@ def to_int 101 "); // meta-object conversions: - TestOutput(@" -p Inst.delegate(Proc.new { |x| x + 1 }).invoke(123) -", @" -124 -"); + var r1 = Engine.Execute("Inst.delegate(Proc.new { |x| x + 1 }).invoke(123)"); + Assert(r1 == 124); + + // foreign meta-object conversion: + var py = Runtime.GetEngine("python"); + var scope = Runtime.CreateScope(); + py.Execute(@"def foo(x): return x + 2", scope); + var r2 = Engine.Execute(@"Inst.delegate(foo).invoke(123)", scope); + Assert(r2 == 125); } #endregion diff --git a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs index 11f04c9a34..49bb5af66a 100644 --- a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs +++ b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs @@ -216,7 +216,7 @@ public MyConvertBinder(Type type, object result) } - internal static T Invoke(object obj, T fallbackResult) { + internal static T Convert(object obj, T fallbackResult) { var site = CallSite>.Create(new MyConvertBinder(typeof(T), fallbackResult)); return site.Target(site, obj); } @@ -385,27 +385,6 @@ def to_s self.misc = Miscellaneous.new -#------------------------------------------------------------------------------ -class Convertible - def initialize v - @val = v - end - - def to_i - @val.to_i - end - - def to_f - @val.to_f - end - - def to_str - @val.to_str - end -end - -self.convertible = Convertible.new('0') - #------------------------------------------------------------------------------ class Indexable def initialize a=nil @@ -493,20 +472,6 @@ def ToString end end -#------------------------------------------------------------------------------ -class RubyEnumerable - include Enumerable - def initialize a - @array = a - end - - def each - @array.each {|elem| yield elem } - end -end - -self.ruby_enumerable = RubyEnumerable.new([1,2,3]) - #------------------------------------------------------------------------------ class RubyComparable include Comparable @@ -596,11 +561,6 @@ class SanityTest assert_equal main.misc.ruby_callable_called, true assert_equal main.misc.ToString(), 'to_s' - # main.convertible - assert_error lambda { System::GC.Collect(main.convertible) }, TypeError # convert to int - Bug!!!!!!!!!! - assert_equal System::Exception.new(main.convertible).class, Exception - # need to convert to float - # main.indexable assert_equal main.indexable[2], 2 main.indexable[10] = 100 @@ -613,9 +573,6 @@ class SanityTest assert_equal((main.number * 2), 200) assert_equal((main.number / 2), 50) - # RubyEnumerable - assert_equal main.ruby_enumerable.min, 1 - # RubyComparable assert_equal((main.ruby_comparable == 100), true) assert_equal((main.ruby_comparable > 100), false) @@ -725,13 +682,38 @@ SanityTest.sanity_test self AreEqual(MyInvokeMemberBinder.Invoke(misc_class, "ToString"), "FallbackInvokeMember"); } - // TODO: conversions public void Dlr_Convertible() { - var scope = CreateInteropScope(); - object convertible = scope.GetVariable("convertible"); - AreEqualBug(MyConvertBinder.Invoke(convertible, -1234), 0, -1234); - AreEqualBug(MyConvertBinder.Invoke(convertible, "FallbackConvert"), "0", "FallbackConvert"); - AreEqualBug(MyConvertBinder.Invoke(convertible, -1234.0f), 0.0, -1234.0f); + Engine.Execute(@" +class C + def to_int + 1 + end + + def to_f + 2.0 + end + + def to_str + 'str' + end + + def each + [1,2,3].each {|x| yield x } + end +end +"); + var classC = Runtime.Globals.GetVariable("C"); + var c = Engine.Operations.CreateInstance(classC); + + // TODO: + //AreEqual(MyConvertBinder.Convert(c, 10), 1); + //AreEqual(MyConvertBinder.Convert(c, 10), 1); + //AreEqual(MyConvertBinder.Convert(c, "FallbackConvert"), "str"); + //AreEqual(MyConvertBinder.Convert(c, -8.0), 2.0); + //AreEqual(MyConvertBinder.Convert(c, -8.0f), 2.0f); + //IEnumerable e = MyConvertBinder.Convert(c, null) + //Assert(e != null); + //new List(e); } public void Dlr_Indexable() { @@ -754,16 +736,6 @@ SanityTest.sanity_test self AreEqual(MyUnaryOperationBinder.Invoke(ExpressionType.OnesComplement, one_hundred), ~100); } - // TODO: conversion to IEnumerable - public void Dlr_Enumerable() { - var scope = CreateInteropScope(); - object ruby_enumerable = scope.GetVariable("ruby_enumerable"); - IEnumerable e = MyConvertBinder.Invoke(ruby_enumerable, null); - AreEqualBug(e != null, true, false); - IEnumerable e2 = MyConvertBinder.Invoke>(ruby_enumerable, null); - AreEqualBug(e2 != null, true, false); - } - public void Dlr_Comparable() { var scope = CreateInteropScope(); object ruby_comparable = scope.GetVariable("ruby_comparable"); diff --git a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/OverloadResolutionTests.cs b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/OverloadResolutionTests.cs index 1aa00315c3..b17f410e22 100644 --- a/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/OverloadResolutionTests.cs +++ b/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/OverloadResolutionTests.cs @@ -20,6 +20,9 @@ using IronRuby.Builtins; using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using Microsoft.Scripting; +using Microsoft.Scripting.Actions.Calls; +using Microsoft.Scripting.Math; using Microsoft.Scripting.Runtime; using Ast = System.Linq.Expressions.Expression; @@ -36,6 +39,10 @@ public partial class Tests { return Array.ConvertAll(type.GetMember(name, BindingFlags.Public | BindingFlags.Static), (mi) => (MethodInfo)mi); } + private static MethodInfo/*!*/[]/*!*/ GetInstanceMethods(Type/*!*/ type, string/*!*/ name) { + return Array.ConvertAll(type.GetMember(name, BindingFlags.Public | BindingFlags.Instance), (mi) => (MethodInfo)mi); + } + #region Block public class OverloadsWithBlock { @@ -81,10 +88,10 @@ public class OverloadsWithBlock { var metaBuilder = new MetaObjectBuilder(null); for (int i = 0; i < arguments.Length; i++) { - RubyOverloadResolver parameterBinder; + RubyOverloadResolver resolver; var bindingTarget = RubyMethodGroupInfo.ResolveOverload( metaBuilder, arguments[i], "times", GetStaticMethods(typeof(OverloadsWithBlock), "Times*"), SelfCallConvention.SelfIsParameter, - false, out parameterBinder + false, out resolver ); Assert(bindingTarget.Success); @@ -92,6 +99,95 @@ public class OverloadsWithBlock { } } + public class Overloads1 { + public class X { + } + + public void F1(int a) { } + public void F2(BigInteger a) { } + public void F3(double a) { } + + public void G1([DefaultProtocol]int a) { } + public void G2(BigInteger a) { } + public void G3(double a) { } + + public void I1(int a) { } + public void I2([NotNull]MutableString a) { } + public void I3([DefaultProtocol]Union a) { } + + public void J1(int a) { } + public void J2([NotNull]BigInteger a) { } + public void J3([DefaultProtocol]IntegerValue a) { } + + // This is rather useless overload combination: + // If DP parameter behaved exaclty like object it would be ambiguous. + // Since we try implicit conversions first, all types but numerics assignable to integer prefer K1. + // Therefore [DP] is irrelevant here. + public void K1(object a) { } + public void K2([DefaultProtocol]int a) { } + + // level 0: no overload applicable + // level 1: {L1, L3} applicable, MutableString <-/-> SymbolId + public void L1(SymbolId a, [DefaultProtocol, NotNull]string b) { } + public void L2([NotNull]string a, [DefaultProtocol, NotNull]string b) { } + public void L3([DefaultProtocol]MutableString a, [DefaultProtocol, NotNull]string b) { } + } + + public void OverloadResolution_Numeric1() { + var metaBuilder = new MetaObjectBuilder(null); + Context.ObjectClass.SetConstant("X", Context.GetClass(typeof(Overloads1.X))); + + var c = Engine.Execute(@"class C < X; new; end"); + var sym = SymbolTable.StringToId("x"); + var ms = MutableString.Create("x"); + + var cases = new[] { + // F + new { Args = new[] { MO(1) }, Overloads = "F*", Result = "F1" }, + new { Args = new[] { MO((byte)1) }, Overloads = "F*", Result = "F1" }, + new { Args = new[] { MO(1L) }, Overloads = "F*", Result = "F2" }, + new { Args = new[] { MO(1.2F) }, Overloads = "F*", Result = "F3" }, + + // G + new { Args = new[] { MO(1) }, Overloads = "G*", Result = "G1" }, + new { Args = new[] { MO((byte)1) }, Overloads = "G*", Result = "G1" }, + new { Args = new[] { MO(1L) }, Overloads = "G*", Result = "G2" }, + new { Args = new[] { MO(1.2F) }, Overloads = "G*", Result = "G3" }, + new { Args = new[] { MO(c) }, Overloads = "G*", Result = "G1" }, + + // I + new { Args = new[] { MO(c) }, Overloads = "I*", Result = "I3" }, + + // J + new { Args = new[] { MO(1) }, Overloads = "J*", Result = "J1" }, + new { Args = new[] { MO((BigInteger)1000) }, Overloads = "J*", Result = "J2" }, + new { Args = new[] { MO((byte)12) }, Overloads = "J*", Result = "J1" }, + new { Args = new[] { MO(c) }, Overloads = "J*", Result = "J3" }, + new { Args = new[] { MO(1.0) }, Overloads = "J*", Result = "J3" }, + + // K + new { Args = new[] { MO(1) }, Overloads = "K*", Result = "K2" }, + new { Args = new[] { MO(c) }, Overloads = "K*", Result = "K1" }, + new { Args = new[] { MO("x") }, Overloads = "K*", Result = "K1" }, + + // L + new { Args = new[] { MO(sym), MO(sym) }, Overloads = "L*", Result = "L1" }, + new { Args = new[] { MO("x"), MO(sym) }, Overloads = "L*", Result = "L2" }, + new { Args = new[] { MO(ms), MO(sym) }, Overloads = "L*", Result = "L3" }, + new { Args = new[] { MO(null), MO(sym) }, Overloads = "L*", Result = "L3" }, + new { Args = new[] { MO(c), MO(sym) }, Overloads = "L*", Result = "L3" }, + }; + + for (int i = 0; i < cases.Length; i++) { + var args = new CallArguments(Context, MO(new Overloads1()), cases[i].Args, RubyCallSignature.Simple(cases[i].Args.Length)); + var resolver = new RubyOverloadResolver(metaBuilder, args, SelfCallConvention.SelfIsInstance, false); + var overloads = GetInstanceMethods(typeof(Overloads1), cases[i].Overloads); + var result = resolver.ResolveOverload(i.ToString(), overloads, NarrowingLevel.None, NarrowingLevel.All); + + Assert(result.Success && result.Method.Name == cases[i].Result); + } + } + #endregion #region Param Arrays @@ -145,12 +241,12 @@ public class AmbiguousOverloads { return 2; } - public static int F(string p) { + public static int F(MutableString p) { return 3; } } - public void AmbiguousMatch() { + public void AmbiguousMatch1() { Context.SetGlobalConstant("C", Context.GetClass(typeof(AmbiguousOverloads))); AssertOutput(() => CompilerTest(@" [1, nil, 'foo'].each do |x| diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs index 5f1c44cea6..0fe667833a 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs @@ -23,6 +23,7 @@ using IronRuby.Compiler; using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using Microsoft.Scripting.Actions; using Microsoft.Scripting.Generation; using Microsoft.Scripting.Runtime; diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs index 55a1ee0ff7..9c5f52c358 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs @@ -38,7 +38,7 @@ public static class RubyFileOps { [RubyConstructor] public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, - [DefaultProtocol]Union descriptorOrPath, [Optional, DefaultProtocol]MutableString mode, [Optional]int permission) { + [DefaultProtocol, NotNull]Union descriptorOrPath, [Optional, DefaultProtocol]MutableString mode, [Optional]int permission) { if (descriptorOrPath.IsFixnum()) { // TODO: descriptor @@ -51,7 +51,7 @@ public static class RubyFileOps { [RubyConstructor] public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, - [DefaultProtocol]Union descriptorOrPath, int mode, [Optional]int permission) { + [DefaultProtocol, NotNull]Union descriptorOrPath, int mode, [Optional]int permission) { if (descriptorOrPath.IsFixnum()) { // TODO: descriptor @@ -63,17 +63,17 @@ public static class RubyFileOps { } [RubyConstructor] - public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path) { + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path) { return new RubyFile(self.Context, path.ConvertToString(), "r"); } [RubyConstructor] - public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, MutableString mode) { + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, MutableString mode) { return new RubyFile(self.Context, path.ConvertToString(), (mode != null) ? mode.ConvertToString() : "r"); } [RubyConstructor] - public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, int mode) { + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, int mode) { return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)mode); } diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs index 02b04fa228..03df73075a 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs @@ -24,6 +24,7 @@ using IronRuby.Compiler; using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using Microsoft.Scripting; using Microsoft.Scripting.Math; using Microsoft.Scripting.Runtime; @@ -565,12 +566,13 @@ public static class KernelOps { object self, [NotNull]params object[]/*!*/ args) { var inspect = inspectStorage.GetCallSite("inspect"); + var inspectedArgs = new object[args.Length]; for (int i = 0; i < args.Length; i++) { - args[i] = inspect.Target(inspect, args[i]); + inspectedArgs[i] = inspect.Target(inspect, args[i]); } // no dynamic dispatch to "puts": - RubyIOOps.Puts(writeStorage, tosConversion, writeStorage.Context.StandardOutput, args); + RubyIOOps.Puts(writeStorage, tosConversion, writeStorage.Context.StandardOutput, inspectedArgs); } [RubyMethod("print", RubyMethodAttributes.PrivateInstance)] diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs index e34d98bb4a..f3ebd64e6f 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs @@ -986,23 +986,45 @@ public static class ModuleOps { if (provided == 1 && type == typeof(Array)) { return self.Context.GetModule(Protocols.ToType(self.Context, typeArgs[0]).MakeArrayType()); - } + } - int required = type.GetGenericArguments().Length; - if (required == 0 && provided > 0) { - throw RubyExceptions.CreateArgumentError(String.Format("'{0}' is not a generic type", type.FullName)); + if (!type.IsGenericTypeDefinition) { + if (provided > 0) { + throw RubyExceptions.CreateArgumentError(String.Format("`{0}' is not a generic type definition", self.Name)); + } + return self; } + int required = type.GetGenericArguments().Length; if (required != provided) { - throw RubyExceptions.CreateArgumentError(String.Format("Type '{0}' requires {1} generic type arguments, {2} provided", type.FullName, required, provided)); + throw RubyExceptions.CreateArgumentError(String.Format("Type `{0}' requires {1} generic type arguments, {2} provided", self.Name, required, provided)); } - if (typeArgs.Length > 0) { - Type concreteType = type.MakeGenericType(Protocols.ToTypes(self.Context, typeArgs)); - return self.Context.GetModule(concreteType); - } else { + Type concreteType = type.MakeGenericType(Protocols.ToTypes(self.Context, typeArgs)); + return self.Context.GetModule(concreteType); + } + + [RubyMethod("of")] + [RubyMethod("[]")] + public static RubyModule/*!*/ Of(RubyModule/*!*/ self, int genericArity) { + if (self.TypeTracker == null) { + throw RubyExceptions.CreateArgumentError(String.Format("`{0}' is not a type", self.Name)); + } + + Type type = self.TypeTracker.Type; + + if (!type.IsGenericTypeDefinition) { + if (genericArity > 0) { + throw RubyExceptions.CreateArgumentError(String.Format("`{0}' is not a generic type definition", self.Name)); + } return self; } + + if (type.GetGenericArguments().Length != genericArity) { + throw RubyExceptions.CreateArgumentError(String.Format("`{0}' does not have generic arity {1}", self.Name, genericArity)); + } + + return self; } #endregion diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Numeric.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Numeric.cs index 3540613088..0713dd7b6e 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Numeric.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Numeric.cs @@ -17,11 +17,12 @@ using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Actions; using Microsoft.Scripting.Generation; -using IronRuby.Runtime; using System.Runtime.InteropServices; using System.Reflection; using System.Runtime.Serialization; +using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; namespace IronRuby.Builtins { diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs index fafb3fd034..1fd7b4d2d4 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs @@ -27,6 +27,7 @@ using System.Runtime.CompilerServices; using Microsoft.Scripting.Generation; using IronRuby.Compiler.Generation; +using IronRuby.Runtime.Conversions; namespace IronRuby.Builtins { diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StructOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StructOps.cs index e10bc669cb..0517109b1f 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StructOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StructOps.cs @@ -39,28 +39,21 @@ public static partial class RubyStructOps { } [RubyMethod("new", RubyMethodAttributes.PublicSingleton)] - public static object NewAnonymousStruct(BlockParam block, RubyClass/*!*/ self, int className, + public static object NewAnonymousStruct(BlockParam block, RubyClass/*!*/ self, SymbolId firstAttibuteName, [DefaultProtocol, NotNull, NotNullItems]params string/*!*/[]/*!*/ attributeNames) { - return CreateAnonymousWithFirstAttribute(block, self, RubyOps.ConvertFixnumToSymbol(self.Context, className), attributeNames); + return CreateAnonymousWithFirstAttribute(block, self, RubyOps.ConvertSymbolIdToSymbol(firstAttibuteName), attributeNames); } [RubyMethod("new", RubyMethodAttributes.PublicSingleton)] - public static object NewAnonymousStruct(BlockParam block, RubyClass/*!*/ self, SymbolId className, + public static object NewAnonymousStruct(BlockParam block, RubyClass/*!*/ self, [NotNull]string/*!*/ firstAttibuteName, [DefaultProtocol, NotNull, NotNullItems]params string/*!*/[]/*!*/ attributeNames) { - return CreateAnonymousWithFirstAttribute(block, self, RubyOps.ConvertSymbolIdToSymbol(className), attributeNames); + return CreateAnonymousWithFirstAttribute(block, self, firstAttibuteName, attributeNames); } [RubyMethod("new", RubyMethodAttributes.PublicSingleton)] - public static object NewAnonymousStruct(BlockParam block, RubyClass/*!*/ self, [NotNull]string/*!*/ className, - [DefaultProtocol, NotNull, NotNullItems]params string/*!*/[]/*!*/ attributeNames) { - - return CreateAnonymousWithFirstAttribute(block, self, className, attributeNames); - } - - [RubyMethod("new", RubyMethodAttributes.PublicSingleton)] - public static object NewStruct(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, Optional]MutableString className, + public static object NewStruct(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol]MutableString className, [DefaultProtocol, NotNull, NotNullItems]params string/*!*/[]/*!*/ attributeNames) { if (className == null) { diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Enumerator/Enumerator.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Enumerator/Enumerator.cs index 69aedd5d99..8a302eff9c 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Enumerator/Enumerator.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Enumerator/Enumerator.cs @@ -63,14 +63,24 @@ public Enumerator() } [RubyConstructor] - public static Enumerator/*!*/ Create(RubyClass/*!*/ self, object targetObject, [DefaultProtocol, Optional]string targetName, + public static Enumerator/*!*/ Create(RubyClass/*!*/ self, object targetObject) { + return Reinitialize(new Enumerator(), targetObject, null, ArrayUtils.EmptyObjects); + } + + [RubyConstructor] + public static Enumerator/*!*/ Create(RubyClass/*!*/ self, object targetObject, [DefaultProtocol]string targetName, [NotNull]params object[] targetArguments) { return Reinitialize(new Enumerator(), targetObject, targetName, targetArguments); } [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)] - public static Enumerator/*!*/ Reinitialize(Enumerator/*!*/ self, object targetObject, [DefaultProtocol, Optional]string targetName, + public static Enumerator/*!*/ Reinitialize(Enumerator/*!*/ self, object targetObject) { + return Reinitialize(self, targetObject, null, ArrayUtils.EmptyObjects); + } + + [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)] + public static Enumerator/*!*/ Reinitialize(Enumerator/*!*/ self, object targetObject, [DefaultProtocol]string targetName, [NotNull]params object[] targetArguments) { self._targetObject = targetObject; diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generated.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generated.cs index e4fcd95c29..09945ff6f2 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generated.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generated.cs @@ -84,6 +84,11 @@ public static partial class ByteOps { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (Byte)"); + } } public static partial class SByteOps { @@ -118,6 +123,11 @@ public static partial class SByteOps { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (SByte)"); + } } public static partial class Int16Ops { @@ -152,6 +162,11 @@ public static partial class Int16Ops { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (Int16)"); + } } public static partial class UInt16Ops { @@ -186,6 +201,11 @@ public static partial class UInt16Ops { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (UInt16)"); + } } public static partial class UInt32Ops { @@ -220,6 +240,11 @@ public static partial class UInt32Ops { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (UInt32)"); + } } public static partial class Int64Ops { @@ -254,6 +279,11 @@ public static partial class Int64Ops { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (Int64)"); + } } public static partial class UInt64Ops { @@ -288,6 +318,11 @@ public static partial class UInt64Ops { } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (UInt64)"); + } } // *** END GENERATED CODE *** diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generator.rb b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generator.rb index 56920378d0..9b12b9cc0f 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generator.rb +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/ClrInteger.Generator.rb @@ -63,4 +63,9 @@ def range_check_fixnum(type) } throw RubyExceptions.CreateRangeError(String.Format("Float {0} out of range of {1}", value, self.Name)); } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" ($Self)"); + } } diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IListOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IListOps.cs index 345e078428..4883d0a8b7 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IListOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IListOps.cs @@ -26,6 +26,7 @@ using Microsoft.Scripting.Utils; using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using EachSite = System.Func; @@ -49,6 +50,14 @@ public static class IListOps { return NormalizeIndex(list.Count, index); } + internal static int NormalizeIndexThrowIfNegative(IList/*!*/ list, int index) { + index = NormalizeIndex(list.Count, index); + if (index < 0) { + throw RubyExceptions.CreateIndexError(String.Format("index {0} out of array", index)); + } + return index; + } + internal static int NormalizeIndex(int count, int index) { return index < 0 ? index + count : index; } @@ -217,7 +226,9 @@ public static class IListOps { #region *, +, concat [RubyMethod("*")] - public static IList/*!*/ Repetition(CallSiteStorage>/*!*/ allocateStorage, IList/*!*/ self, int repeat) { + public static IList/*!*/ Repetition(CallSiteStorage>/*!*/ allocateStorage, + IList/*!*/ self, int repeat) { + if (repeat < 0) { throw RubyExceptions.CreateArgumentError("negative argument"); } @@ -236,12 +247,16 @@ public static class IListOps { } [RubyMethod("*")] - public static MutableString Repetition(ConversionStorage/*!*/ tosConversion, IList/*!*/ self, [NotNull]MutableString/*!*/ separator) { + public static MutableString Repetition(ConversionStorage/*!*/ tosConversion, + IList/*!*/ self, [NotNull]MutableString/*!*/ separator) { return Join(tosConversion, self, separator); } [RubyMethod("*")] - public static object Repetition(CallSiteStorage>/*!*/ allocateStorage, ConversionStorage/*!*/ tosConversion, IList/*!*/ self, [DefaultProtocol]Union repeat) { + public static object Repetition( + CallSiteStorage>/*!*/ allocateStorage, + ConversionStorage/*!*/ tosConversion, + IList/*!*/ self, [DefaultProtocol, NotNull]Union repeat) { if (repeat.IsFixnum()) { return Repetition(allocateStorage, self, repeat.Fixnum()); @@ -451,15 +466,21 @@ public static class IListOps { } [RubyMethod("[]=")] - public static object SetElement(IList/*!*/ self, [DefaultProtocol]int index, object value) { - index = NormalizeIndex(self, index); + public static object SetElement(RubyArray/*!*/ self, [DefaultProtocol]int index, object value) { + index = NormalizeIndexThrowIfNegative(self, index); - if (index < 0) { - throw RubyExceptions.CreateIndexError(String.Format("index {0} out of array", index)); + if (index >= self.Count) { + self.AddMultiple(index + 1 - self.Count, null); } + return self[index] = value; + } + + [RubyMethod("[]=")] + public static object SetElement(IList/*!*/ self, [DefaultProtocol]int index, object value) { + index = NormalizeIndexThrowIfNegative(self, index); + if (index < self.Count) { - // TODO: conversions self[index] = value; } else { ExpandList(self, index); @@ -475,10 +496,7 @@ public static class IListOps { throw RubyExceptions.CreateIndexError(String.Format("negative length ({0})", length)); } - index = NormalizeIndex(self, index); - if (index < 0) { - throw RubyExceptions.CreateIndexError(String.Format("index {0} out of array", index)); - } + index = NormalizeIndexThrowIfNegative(self, index); if (value == null) { DeleteItems(self, index, length); diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/MultiDimensionalArrayOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/MultiDimensionalArrayOps.cs index df95f9ffb2..defeda9cda 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/MultiDimensionalArrayOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/MultiDimensionalArrayOps.cs @@ -26,39 +26,6 @@ namespace IronRuby.Builtins { /// [RubyModule("MultiDimensionalArray", DefineIn = typeof(IronRubyOps.ClrOps), Extends = typeof(MultiDimensionalArray), Restrictions = ModuleRestrictions.None)] public static class MultiDimensionalArrayOps { - [RubyMethod("[]=")] - public static object SetElement(Array/*!*/ self, int index1, int index2, object value) { - self.SetValue(value, index1, index2); - return value; - } - - [RubyMethod("[]=")] - public static object SetElement(Array/*!*/ self, int index1, int index2, int index3, object value) { - self.SetValue(value, index1, index2, index3); - return value; - } - - // TODO: params array in the middle of parameters -> needs special attribute or a meta-implementation (meta-impl could call - // T[...].Get()/Set() directly). - [RubyMethod("[]=")] - public static object SetElement(Array/*!*/ self, /*params*/ int[] indices, object value) { - self.SetValue(value, indices); - return value; - } - - [RubyMethod("[]")] - public static object GetElement(Array/*!*/ self, int index1, int index2) { - return self.GetValue(index1, index2); - } - - [RubyMethod("[]")] - public static object GetElement(Array/*!*/ self, int index1, int index2, int index3) { - return self.GetValue(index1, index2, index3); - } - - [RubyMethod("[]")] - public static object GetElement(Array/*!*/ self, int[] indices) { - return self.GetValue(indices); - } + // [], []= methods are mapped to Get/Set methods } } diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/SingleOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/SingleOps.cs index 0d8345b3b9..c78abe7d9a 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/SingleOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/SingleOps.cs @@ -29,5 +29,10 @@ public static class SingleOps { public static float Create(RubyClass/*!*/ self, [DefaultProtocol]double value) { return (float)value; } + + [RubyMethod("inspect")] + public static MutableString/*!*/ Inspect(object/*!*/ self) { + return MutableString.CreateMutable().Append(self.ToString()).Append(" (Single)"); + } } } diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/TypeGroupOps.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/TypeGroupOps.cs index a312ad774f..7243ec833f 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/TypeGroupOps.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/TypeGroupOps.cs @@ -50,6 +50,17 @@ public class TypeGroupOps { return context.GetModule(concreteType); } + [RubyMethod("of")] + [RubyMethod("[]")] + public static RubyModule/*!*/ Of(RubyContext/*!*/ context, TypeGroup/*!*/ self, int genericArity) { + TypeTracker tracker = self.GetTypeForArity(genericArity); + if (tracker == null) { + throw RubyExceptions.CreateArgumentError(String.Format("Type group `{0}' does not contain a type of generic arity {1}", self.Name, genericArity)); + } + + return context.GetModule(tracker.Type); + } + [RubyMethod("each")] public static object EachType(RubyContext/*!*/ context, BlockParam/*!*/ block, TypeGroup/*!*/ self) { if (block == null) { diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs index 95ab61564d..1ee8f8d699 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs @@ -56,7 +56,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia IronRuby.Builtins.RubyModule def20 = DefineModule("IronRuby::Clr::FlagEnumeration", typeof(IronRuby.Builtins.FlagEnumeration), 0x00000000, LoadIronRuby__Clr__FlagEnumeration_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyModule def4 = DefineModule("IronRuby::Clr::Float", typeof(IronRuby.Builtins.ClrFloat), 0x00000103, LoadIronRuby__Clr__Float_Instance, LoadIronRuby__Clr__Float_Class, null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyModule def5 = DefineModule("IronRuby::Clr::Integer", typeof(IronRuby.Builtins.ClrInteger), 0x00000103, LoadIronRuby__Clr__Integer_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def23 = DefineModule("IronRuby::Clr::MultiDimensionalArray", typeof(IronRuby.Builtins.MultiDimensionalArray), 0x00000000, LoadIronRuby__Clr__MultiDimensionalArray_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def23 = DefineModule("IronRuby::Clr::MultiDimensionalArray", typeof(IronRuby.Builtins.MultiDimensionalArray), 0x00000000, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyModule def6 = DefineModule("IronRuby::Clr::String", typeof(IronRuby.Builtins.ClrString), 0x00000103, LoadIronRuby__Clr__String_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); // Skipped primitive: Kernel DefineGlobalModule("Marshal", typeof(IronRuby.Builtins.RubyMarshal), 0x00000103, null, LoadMarshal_Class, LoadMarshal_Constants, IronRuby.Builtins.RubyModule.EmptyArray); @@ -2384,21 +2384,6 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia } - private static void LoadIronRuby__Clr__MultiDimensionalArray_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { - module.DefineLibraryMethod("[]", 0x51, - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.GetElement), - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.GetElement), - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.GetElement) - ); - - module.DefineLibraryMethod("[]=", 0x51, - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.SetElement), - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.SetElement), - new System.Func(IronRuby.Builtins.MultiDimensionalArrayOps.SetElement) - ); - - } - private static void LoadIronRuby__Clr__Name_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("<=>", 0x51, new System.Func(IronRuby.Builtins.ClrNameOps.Compare), @@ -3581,7 +3566,8 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadMicrosoft__Scripting__Actions__TypeGroup_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("[]", 0x51, - new System.Func(IronRuby.Builtins.TypeGroupOps.Of) + new System.Func(IronRuby.Builtins.TypeGroupOps.Of), + new System.Func(IronRuby.Builtins.TypeGroupOps.Of) ); module.DefineLibraryMethod("clr_constructor", 0x51, @@ -3615,7 +3601,8 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia ); module.DefineLibraryMethod("of", 0x51, - new System.Func(IronRuby.Builtins.TypeGroupOps.Of) + new System.Func(IronRuby.Builtins.TypeGroupOps.Of), + new System.Func(IronRuby.Builtins.TypeGroupOps.Of) ); module.DefineLibraryMethod("superclass", 0x51, @@ -3641,7 +3628,8 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadModule_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("[]", 0x51, - new System.Func(IronRuby.Builtins.ModuleOps.Of) + new System.Func(IronRuby.Builtins.ModuleOps.Of), + new System.Func(IronRuby.Builtins.ModuleOps.Of) ); module.DefineLibraryMethod("<", 0x51, @@ -3844,7 +3832,8 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia ); module.DefineLibraryMethod("of", 0x51, - new System.Func(IronRuby.Builtins.ModuleOps.Of) + new System.Func(IronRuby.Builtins.ModuleOps.Of), + new System.Func(IronRuby.Builtins.ModuleOps.Of) ); module.DefineLibraryMethod("private", 0x52, @@ -4941,7 +4930,6 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadStruct_Class(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("new", 0x61, - new System.Func(IronRuby.Builtins.RubyStructOps.NewAnonymousStruct), new System.Func(IronRuby.Builtins.RubyStructOps.NewAnonymousStruct), new System.Func(IronRuby.Builtins.RubyStructOps.NewAnonymousStruct), new System.Func(IronRuby.Builtins.RubyStructOps.NewStruct) @@ -4990,6 +4978,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__Byte_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__Integer_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.ByteOps.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.ByteOps.Size) ); @@ -5213,6 +5205,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia ); module.DefineLibraryMethod("[]=", 0x51, + new System.Func(IronRuby.Builtins.IListOps.SetElement), new System.Func(IronRuby.Builtins.IListOps.SetElement), new System.Func, System.Collections.IList, System.Int32, System.Int32, System.Object, System.Object>(IronRuby.Builtins.IListOps.SetElement), new System.Func, IronRuby.Runtime.ConversionStorage, System.Collections.IList, IronRuby.Builtins.Range, System.Object, System.Object>(IronRuby.Builtins.IListOps.SetElement) @@ -5486,6 +5479,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__Int16_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__Integer_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.Int16Ops.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.Int16Ops.Size) ); @@ -5503,6 +5500,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__Int64_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__BigInteger_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.Int64Ops.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.Int64Ops.Size) ); @@ -5520,6 +5521,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__SByte_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__Integer_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.SByteOps.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.SByteOps.Size) ); @@ -5537,6 +5542,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__Single_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__Float_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.SingleOps.Inspect) + ); + } private static void LoadSystem__Single_Class(IronRuby.Builtins.RubyModule/*!*/ module) { @@ -5556,6 +5565,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__UInt16_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__Integer_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.UInt16Ops.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.UInt16Ops.Size) ); @@ -5573,6 +5586,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__UInt32_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__BigInteger_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.UInt32Ops.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.UInt32Ops.Size) ); @@ -5590,6 +5607,10 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia private static void LoadSystem__UInt64_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { LoadIronRuby__Clr__BigInteger_Instance(module); + module.DefineLibraryMethod("inspect", 0x51, + new System.Func(IronRuby.Builtins.UInt64Ops.Inspect) + ); + module.DefineLibraryMethod("size", 0x51, new System.Func(IronRuby.Builtins.UInt64Ops.Size) ); @@ -7636,6 +7657,7 @@ public sealed class EnumeratorLibraryInitializer : IronRuby.Builtins.LibraryInit IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("Enumerable", typeof(IronRuby.Builtins.Enumerable), 0x00000003, LoadEnumerable_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); ExtendModule(typeof(IronRuby.Builtins.Kernel), LoadIronRuby__Builtins__Kernel_Instance, null, null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyClass def2 = DefineClass("Enumerable::Enumerator", typeof(IronRuby.StandardLibrary.Enumerator.Enumerable.Enumerator), 0x00000103, classRef0, LoadEnumerable__Enumerator_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def1}, + new System.Func(IronRuby.StandardLibrary.Enumerator.Enumerable.Enumerator.Create), new System.Func(IronRuby.StandardLibrary.Enumerator.Enumerable.Enumerator.Create) ); def1.SetConstant("Enumerator", def2); @@ -7670,6 +7692,7 @@ public sealed class EnumeratorLibraryInitializer : IronRuby.Builtins.LibraryInit ); module.DefineLibraryMethod("initialize", 0x12, + new System.Func(IronRuby.StandardLibrary.Enumerator.Enumerable.Enumerator.Reinitialize), new System.Func(IronRuby.StandardLibrary.Enumerator.Enumerable.Enumerator.Reinitialize) ); diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj index d178a1f57e..3d08251b69 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {77323B06-15A2-4CF4-8A7A-86EAA2B66498} Library @@ -22,6 +23,7 @@ true 891289600 ..\..\..\Utilities\Silverlight\x86ret\ + v2.0 true @@ -195,4 +197,4 @@ - \ No newline at end of file + diff --git a/Merlin/Main/Languages/Ruby/Licenses/CHANGELOG.txt b/Merlin/Main/Languages/Ruby/Licenses/CHANGELOG.txt new file mode 100644 index 0000000000..0a27ab50e2 --- /dev/null +++ b/Merlin/Main/Languages/Ruby/Licenses/CHANGELOG.txt @@ -0,0 +1,1199 @@ +CHANGELOG +========= + +ironruby-0.6.0.0 - 2009-07-01 +----------------------------- + + 30-6 (sborde) + Added Hosting tutorial + Conditional execution of a task with :run_unless, typically to ensure + prerequite commands are executed + + 26-06 (jdeville) + Regression tests to close Codeplex bugs: + Access is allowed to internal fields + from + File.expand_path does not support a line number after filename + from + alias_method fails for :do + from + Proc.to_s should include line number where the block was declared + from + WinForms broken + from + $? is not always Process::Status + from + load_assembly() should work + from + System.Action.new does not work + from + Cannot call CLR constructor of builtin type + from + public(:foo) does not work correctly for mixed-in methods + from + Cannot call new on subtypes of builtin classes whose "new" method has + optional arguments + from + visibility of send :define_method + from + Passing a Ruby array to a .NET method that expects an IEnumerable + derivative fails with GetEnumerator call + from + Assert in SetMethodBasesNoLock when calling #== on Ruby class inheriting + from CLR class which overrides Equals + from + Wrong behavior when calling redefined methods on object instances + from + Can't call the BigIntegerOverload of a method with a DefaultProtocol Attrib + + 25-06 (tomat) + Replaces custom block delegates with Func delegates. + + 24-06 (tomat) + Implements FileTest and fixes race condition in a Rake test. + + 23-06 (tomat) + Improves implementation of RubyArray. + + 22-06 (jimmysch) + Fix ironruby_tutorial.rb where "require 'wpf.rb'" wasn't seen as a success + on the first attempt. The first execution results in "true" while the next + results in "false", and one attempt executed the code twice. The fix is a + bit hacky, but will suit unless we can handle detecting "require" better. + + 22-06 (tomat) + Disables adaptive compilation of Ruby sites in -X:NoAdaptiveCompilation is + set. + + 22-06 (jimmysch) + IronRuby Tutorial polish: + - Starting a tutorial jumps directly to the first task, but shows section + and chapter introductions above it (if they exist). + - FrameworkElement#set_or_collapse didn't show the element + - select_tree_view_item should only be used if the TreeView was + constructed with code + - "Move to next chapter" button is auto-focused + - Always scroll to the bottom on any repl activity + - Increase default window size to 640x700 + - Header now has a bottom shadow instead of a border, to make scrolling + text look cleaner. + - Section/Chapter navigation now fills vertical space, and is a 100px wider. + - No more tutorial introduction animation; it always shows on the first page. + + 20-06 (tomat) + Fixes implementation of Kernel#eql?, Kernel#==, Kernel#hash, Array#eql? and + Array#hash and improves CLR interop. + Improves performance of Array#- from quadratic algorithm to linear. + + CLR interop: + “hash” is mapped to “GetHashCode” and following below rules: + 1) A Ruby call to Kernel#hash on a CLR object that overrides GetHashCode + will call that override. + 2) A Ruby call to Kernel#hash on a Ruby subclass of a CLR type will call + the GetHashCode of the CLR type if the Ruby subclass doesn’t implement + “hash” method. + 3) A Ruby data structure (like Array) that calculates its hash code based + on hash codes of its items dynamically calls “hash” on those items. + 4) Any call from C# to GetHashCode on an instance of any Ruby class will + dynamically dispatch to either “hash”, “GetHashCode” or “get_hash_code” + whichever is found first in standard method resolution order. If multiple + of these methods are defined in the same class “hash” has highest priority + and “get_hash_code” the lowest. This implies that a Ruby method definition + with name “hash”, “GetHashCode” or “get_hash_code” in any Ruby class + overrides GetHashCode of the parent CLR class. + + Similarly is “eql?” mapped to “Equals”. + + Kernel#== is an alias for “eql?” and hence has the same behavior when invoked. + However, 4) doesn’t hold for “==”, i.e. method == defined in a Ruby class does + NOT override CLR Equals method. + + Adds /noadaptive option to unit test driver. + Fixes removal of CLR methods. + + Simplifies implementation of IsRemovable on RubyMemberInfo using IsRubyMethod. + IsRubyMethod returns true on all members that were defined by Ruby means, be + it explicit method definition (def keyword), alias, alias_method, define_method, + public/private/protected, overload, of, etc. CLR members used for definition of + a new method (via define_method, alias etc.) are called “detached” (as opposed + to “attached” CLR members, which represent the original CLR members). They + behave like any Ruby method with respect to method removal. + + 19-06 (sborde) + Alt-Enter fix for tutorial + Add support for multi-line input + + 18-06 (tomat) + DLR: Fixes bugs and implements new features in interpreter. + - Static field assignment. + - LessThan + - ConvertUnary – should re-box numeric values. + - Force compilation whenever ref/out parameters are encountered. + - Invocation expression with delegate target. + - Unbox – no-op. + - TypeEqual and TypeIs for sealed types. + + Ruby: + - Implements adaptively compiled rules: + - RubyMetaBinder (subclass of all Ruby binders) implements BindDelegate so that: + o It creates AST for the rule calling Bind and wraps the result into a lambda + exactly like call site binder does. + o If this lambda is interpretable (doesn’t contain loops or other constructs + that force compilation) it creates an InterpretedDispatcher that hooks the + lambda’s “Compiled” event so that it gets called back as soon as compiled + delegate is available. Until that happens it dispatches rule invocations + to the interpreter. + o If the lambda is forced-compiled it uses the resulting delegate right away. + o The dispatcher is a generic class generated for Func and Action delegates + with 0..15 generic parameters. + - Also Adds specs for “include?” used on ClrNames. + + Adds missing type test to singleton rules. + + 17-06 (sborde) + Adds WPF content to ironruby_tutorial + Improves the testing + + 17-06 (dinov) + Ruby’s MethodGroupInfo was doing MakeGenericMethod and then returning the + generic method.But the types it’s passing in are all generic parameters – + so the end result is Ruby produces a method for which + .IsGenericMethodDefinition is false but it contains all of the original + generic method parameters. Now we return the original target so + IsGenericMethodDefinition remains true. Also updated MissingBlockArgBuilder + so we can know that it doesn’t really prodive any parameters. Finally the + small set of tests verifying exceptions are throw are updated to expect + successful inference. + + 16-06 (sborde) + Fix non-deterministic Rake test for "multitask" by adding + semaphore.synchronize around array access + Changed default.mspec so that :core properly excludes the thread tests + Abstracts RubyUtils.FileSystemUsesDriveLetters + File.expand_path("c:/a..") should return "c:/a" + Fix Ruby snippet in DlrInteropTests.cs + Change system_spec to redirect output of a child process so that it does not + clutter the output + + 16-06 (jdeville) + adds a root directory rake file so rake commands can be run anywhere in the + git repo + removed old test tasks. All tests should be run via new tasks that will be + coming in, or via the mspec command line now + rewrite irtest.bat to use Ruby instead of Batch + making changes suggested by Ivan to allow compilation on Mono to work again. + refactor irtests into a ruby script + hook up test tasks, change default to run tests, make git:commit run tests, + namespace compilation, fix IronRuby.Test.exe + Most of IronPython now compiles with rake compile. We are only missing + IronPythonTest.dll, which may be ok + Adding more interop tests for delegate creation and invocation. Also adds + IronPython compilation to rake git:commit + Make legacy tests work from rake + split apps into two component tasks for granularity + add test to ensure that basic IronRuby works without ir.exe.config + move the no-config tests to mspec under interop\cli, -X tests will go here + eventually + code review fixes from Shri + more .net interop tests to get rid of test_basic + get rid of test_basic.rb + + 16-06 (jimmysch) + Auto-hide chapter/section navigation + Main screen with list of tutorials + Use test/spec + Totally change around wpf_tutorial.rb -- not perfect yet but it's a start + Move general wpf helpers into wpf.rb + Fix repl history margin + Fix reloading + + 16-06 (tomat) + Renames Method, UnboundMethod#overloads (plural) to Method, + UnboundMethod#overload (singular). + The old name is still available for now and throws an exception. + + Implements ClrName#==. + Groups CLR unit tests into regions. + + 13-06 (tomat) + Fixes bug in calls to base virtual methods. + + 12-06 (tomat) + Fixes bug in CLR method lookup failure caching. + Implements pre-compilation for rules of methods calls with a block targeting + Ruby methods. + + 11-06 (tomat) + Fixes bug http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1506: + -X:PrivateBinding does not enable referring to classes that have internal + visibility + + 11-06 (tomat) + Fixes http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1502: + alias_method fails for :do. + + 11-06 (tomat) + Implements CLR member enumeration: methods Module#instance_methods, etc. + now include CLR member names. + Adds IronRuby::Clr::Name class, which represents a pair of names of a CLR + method – the primary name is mangled (Ruby name) the alternative name + is the actual CLR name. + + Reflection methods like Module#instance_methods return instances of ClrName + whenever a CLR member is encountered that could be called by both names. + ClrName has methods to_s, to_sym, to_str, <=>, inspect, dump so that it can + be used wherever a string can be used. The display string for the name uses + single quotes so that you can easily distinguish CLR (dual) names from + regular names (plain mutable strings). + + >>> System::Byte.instance_methods(false) + => ["-", "%", "&", "*", "**", "/", "-@", "[]", "^", "|", "~", "+", "<", "<<", + "<=", "<=>", "==", ">", ">=", ">>", "abs", "div", "divmod", "modulo", + "quo", "to_f", "to_s", "zero?", "size", 'compare_to', 'equals', + 'get_hash_code', 'to_string' + , 'get_type_code'] + >>> l = System::Byte.instance_methods(false).last + => 'get_type_code' + >>> l.ruby_name + => "get_type_code" + >>> l.clr_name + => "GetTypeCode" + + Now this works with meta-programming as well: + + class System::Decimal + instance_methods(false).each do |name| + mangled = '__' + name + + alias_method(mangled, name) + private mangled + + define_method(name) do |*args| + puts "method called: #{name}" + send mangled, *args + end + end + end + + x, y = System::Decimal.new(1), System::Decimal.new(2) + p x + y # => “method called: +” + p x.CompareTo(y) # => “method called: compare_to” + + The trick here is in new set of define_method overloads strongly typed to + ClrName that define the real method using the ruby_name and alias it using + the clr_name. So both CompareTo and compare_to calls are intercepted. + + We might add similar overloads to other methods to improve meta-programming + experience for CLR types when needed. + + 10-06 (tomat) + Improves the implementation of singleton method dispatch. + + 1) The previous singleton related shelveset made IRubyObject singleton methods + as fast to call as regular methods. Since singletons of Object are frequently + used in specs, in fact any top level method calls are dispatched to a Object + singleton, it makes sense to optimize singletons of Object as well. So far + we mapped Object to System::Object and Object.new produced an instance of + System::Object. Since such instances are pretty useless in .NET – they are + essentially empty objects that you can’t do anything with - it is not + necessary to preserve this exact mapping. We still map the Object class + to System::Object CLR type, but the underlying CLR type of Object instances + is RubyObject. In pure Ruby program the difference is not observable. On + the other hand C# programs will see the instances typed to RubyObject. + 2) Fixes http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=761: + Wrong behavior when calling redefined methods on object instances. This + is actually fixed by 1) but the same issue applies on CLR singletons. + Let’s say we have a CLR class C. Once you create a singleton of any of its + instance all rules generated for method calls whose receiver is *any* + instance of C must check whether the receiver is a singleton object of C + or a regular instance of C. Previously we did this check only for calls to + singleton methods. This check is a pretty expensive weak dictionary lookup. + One way of optimizing this is to reduce the need of these checks. If we are + sure that no singleton method of the given name has been defined on any + singleton of C we don’t need to emit this check to the rule. Of course, we + need to invalidate such rule as soon as such method is defined. + 3) Fixes potential race conditions in singleton creation. + + These changes improve running time of specs significantly (2x): + + 10-06 (tomat) + Fixes allocation of structs. A struct can always be allocated by calling new + or allocate with no parameters or calling its constructor if available. + + 07-06 (tomat) + Initial work to improve singletons. + • Improves reflection cache generator – it searches IronRuby.dll for all + types marked by [ReflectionCache] attribute and generates ref-cache entries + for all their methods and properties marked with [Emitted] attribute. + • Merges RubyModule.Subclass into RubyModule, i.e. RubyModule now implements + IRubyObject. + • IRubyObjects now hold on their immediate class (not nominal class) and that + reference might change once from a non-singleton to a singleton class. + This change allows IRubyObject singletons (including modules and classes when + used in static method calls) to have the same rules as non-singleton objects. + The rule no longer needs to hold on such objects. + • Implements module freezing: methods, constants, instance and class variables, + mixins cannot be modified on a frozen module. Besides, if an object is frozen + its singleton class is (recursively) frozen as well. + • Fixes object freezing: instance variables cannot be modified on a frozen object + (we allowed it). + + 06-06 (tomat) + Fixes Ruby calls to protected generic methods. + + 05-06 (tomat) + Implements lazy method transformation. Previously a method was transformed to + DLR AST as soon as it was defined (def foo; …; end). We can postpone the + transformation until the method is called for the first time. This + significantly improves startup time. For example (not NGEN’d): + + require 'benchmark' + Benchmark.bm { |x| x.report { require 'rubygems' } } + + user system total real + eager transformation + 1.622410 0.031200 1.653611 ( 1.581316) + lazy transformation + 1.170008 0.031200 1.201208 ( 1.099220) + + Although Ruby methods (unlike block) don’t close over variables we still need + 2 closure variables: the parent lexical runtime scope and the module that the + method is declared in (for implementation of super). These were previously + DLR closure variables. They are live constants now. Ruby method + pre-compilation would require additional work, so we don’t support it for now. + + 04-06 (tomat) + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1509&ProjectName=ironruby: + Proc.to_s should include line number where the block was declared + + 03-06 (sborde) + Reimplemented File.expand_path such that it does not use System.IO.Path. + This allows us to get better compatibility with MRI. + The motivating reason was that RSpec does File.expand_path("filename:linenumber"), + and the old implementation complained that : is not valid in filenames, whereas + MRI allows such input + Fixed "[nil].uniq" - Cucumber was running into this. + Renamed scripts\ruby19.bat to ruby1.9.bat as "mspec -tr19" seems to have changed. + + Fix non-deterministic Rake test for "multitask" by adding + semaphore.synchronize around array access + Changed default.mspec so that :core properly excludes the thread tests + + 03-06 (jomes) + Make Expression.Type and Expression.NodeType virtual properties, and remove + TypeImpl & NodeTypeImpl. This fixes 4 fxcop warnings caused by the *Impl methods, + and results in a better API for end users. + + 02-06 (tomat) + Refactors AstGenerator so that we can use its new instance for each compiled + method. This is a preparation for lazy method compilation. + + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1184: + public(:foo) does not work correctly for mixed-in methods + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1060: + visibility of send :define_method Title is required + + Factors super-forwarders into a separate SuperForwarderInfo <: RubyMemberInfo + (it used to be just a flag on member info). The super-forwarder needs to + remember the name of the method to forward to since that can change if + it’s aliased (see Visibility2C test case). + + Fixes assertion in RubyOverloadResolver - it wasn't expecting DynamicMethod + stubs generated by super calls. + Also fixes the super stubs to throw an exception if the super method is abstract. + + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1345: + load_assembly() should work + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1501: + WinForms broken + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1344: + System.Action.new does not work + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=917: + Passing a Ruby array to a .NET method that expects an IEnumerable derivative + fails with GetEnumerator call + + + fixes incorrect caching of TypeGroup#new. + + Class#clr_member no longer throws an exception if called on Ruby class – it + returns a group of all inherited CLR methods of given name (if there are any). + Improves display name of generic types: e.g. Action displays as + System::Action[Fixnum]. + + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1470 : Can't call + the BigIntegerOverload of a method with a DefaultProtocol Attribute on the + BigInteger attribute + + + Bignum.new(1) should call method_missing: + + irb(main):001:0> Bignum.new(1) + NoMethodError: undefined method `new' for Bignum:Class + + 01-06 (jimmysch) + Allow Silverlight binary location to be adjusted based on a msbuild variable. + Merlin builds use the well-known SL path in the source tree by default. A + "SilverlightPath" msbuild variable can be passed to look for the SL binaries + there. For IronRuby and IronPython external SL builds either the + "SilverlightPath" variable can be set to Silverlight's install location, + or the necessary Silverlight binaries can be copied to + Merlin/Main/Utilities/Silverlight. + + Also scoots around aliases to Silverlight directories. + + 01-06 (jdeville) + * Added and modified tests to increase code coverage + * Rolls in cominteropfix shelveset to make the cominterop generic test + actually run COM interop tests + * Moves Rubygems tests to External\Languages\IronRuby\RubyGems-1_3_1-test + * Removes Rubygems 1.2 tests + * Fixes Rubygems test runner for the above. + * makes irtests run the core tests split up, adds cominterop + * splits out thread tests into a separate test list + * makes ir.cmd use TEST_OPTIONS + + 31-5 (tomat) + ClrMembers + + 29-5 (tomat) + Overrides4 + + 28-5 (jdeville) + * Remove temp.rb from IRPowershell, it was only needed to test the script + during development. + * Port minsysreq and minsysreq_ps. Next step will be to generalize them to + some different apps. + + 26-5 (tomat) + Fixes handling of CLR protected and private methods and properties. + Enables generic methods in ClsTypeEmitter. + Removes RubyCallFlag.TryCall – it’s not used anymore. + Fixes calls to Object.Equals instance/static methods. + + Notes on visibility: + Ruby visibility is orthogonal to CLR visibility. + Ruby visibility is mutable (can be changed using + Kernel#public/private/protected methods), CLR visibility is not. + A CLR method group can comprise of methods of different CLR visibility. + Ruby visibility applies on the group as a whole. + + Ruby-protected members can only be called from a scope whose self immediate + class is a descendant of the method owner. + CLR-protected members can only be called if the receiver is a descendant of + the method owner. + + Ruby-private members can only be called with an implicit receiver (self). + CLR-private members can only be called in PrivateBinding mode + (-X:PrivateBinding command line option), the receiver might be explicit or + implicit. + + Tests: + Since protected methods can only be called on a derived class instance the + specs need to be adjusted accordingly. + I’ve fixed generic_spec nad overload_spec and commented out a block in + protected_spec – all the cases there need to be changed to negative cases + (all should fail). + Removed ROWAN_BIN check in + External.LCA_RESTRICTED\Languages\IronRuby\mspec\default.mspec + so that mspec picks up IR_OPTIONS even if ROWAN_BIN is not set. + + 22-05 (jdevillle) + (jdeville) Regressions tests for the following CP bugs. + !!!!!Note that closing 1351 means we are upgrading redist-libs and rubygems!!!!: + ID Title + 374 irails Foo: undefined method for OpenSLL::Random.random_bytes + 459 throw FileNotFoundException => rescue Errno.NoEntryError + 466 ''.split(//, -1) returns [""] instead of [] + 572 Error when running Cucumber examples with IronRuby + 614 ci_files set needed in mspec config + 718 IronRuby ignores RUBYLIB environment variable + 727 to_proc not working + 814 Allocator underfined for (TypeError) + 940 Can't inherit from abstract classes + 1028 Missing conversion from Duration to Fixnum (ActiveSupport)? + 1351 redist-libs should have rubygems-1.3.1 + 1352 Test Defects + + Also: + * Categorizes uncategorized specs + * includes a TraceListener in default.mspec. + + 21-05 (tomat) + Improves DLR interop: adds support for GetMember/SetMember with + method_missing, Binary/Unary ops, indexers. + Fixes bugs in DLR interop. + +ironruby-0.5.0.0 - 2009-05-19 +----------------------------- + + 18-05 (jdeville) + From Jirapong: + * Fixed OpenSSL::Random.random_bypes and OpenSSL::Random.pseudo_bytes + (via cherry-pick from Jimmy's repro) + + From Shri: + * "ir.exe -Ifoo" should work. We were requiring "-I foo". + Removed critical tags in io\close that I noticed were working. + Miscellaneous new tests in File.basename + Our copy of unit\testcase.rb uses SubclassTracker which is defined in + "hacks" and so should require "hacks" + * Map #== and #hash to System.Object.Equals/GetHashCode + * With the memcache-client gem installed, the Rails tests fail to startup + as memcache does TCPSocket.new(addr, port, 0) and we were not handling + the third argument + * "numeric + someOtherObj" should call someOtherObj.method_missing(:coerce) + backtraces now include file names for builtin methods in + IronRuby.Libraries.dll in a DEBUG builds and with -X:ExceptionDetail + * Enables RubyGems tests in irtests.bat + * Add mocha gem + * Implement File.chown. It is a nop (on Windows) + * ObjectSpace.each_byte: + It was not throwing an exception for the unsupported cases. + Also, the unsupported cases should throw RuntimeError to match + ActiveSupport/JRuby conventions + The return value was also incorrect + * NameError should call #inspect on self, not #to_s + * #instance_method on singleton classes behaves a bit differently - it + puts a contraint of the nominal type. + * UnboundMethod#bind was doing an incorrect type check and not dealing with + singleton classes. Factored out RubyContext.IsKindOf for this + * Add flexmock gem + * Changed some uses of MutableString.Empty (like Array#join with empty array) + to create a new empty string as the user could validly mutate it. + - Renamed MutableString.Empty to MutableString.FixedEmpty to make it clear + that the instance should be shared in limited scenarios + * Fixes to Module#instance_method per Tomas's feedback from previous code review + * File.extname(".foo") should return "", not ".foo" + * Removes to_proc hack from Libs\hacks.rb + * Tutorial sample app + + From Shay: + * Fixing a File.print misbehavior when the global separator is not the default. + + From Jimmy: + * IronRack - Run Rack applications (Sinatra, Rails, etc) on IIS + (cherry picked from commit aba053caa5f5e10c9da360fd4f2d442406f59079) + * Load app by APP_ROOT and config.ru + (cherry picked from commit 3da7be50ee63e1fe3a437f95f9ab2220784f9141) + * Add "RackVersion" to web.config. + (cherry picked from commit 087ad7290217e18b41171e24866bf10c54d6ec0c) + * Add README + (cherry picked from commit 54edd25b3837a36714c67c5c44653b1b07bdb9f5) + * Load a version of Rack denoted by RACK_VERSION + (cherry picked from commit 85d98e68a6bb375820370cd8b724311e8ed2304e) + * Make readme .markdown + (cherry picked from commit 9f8c37e4d4935f51460501ec1526b350d6137397) + * Spring cleaning (aka merging Justin Rudd's version) + (cherry picked from commit 69916ceb04a3f8ecad570fb89549da7ef56d0a6c) + * IIS.Handle(request, response) now it pretty close to compliant with the Rack spec. + Added an Request/Response class, so most of the munging around in IIS.Handle + will be moved to those in the future. + (cherry picked from commit 025dc983062ae5d5c4d008532c94a5be9dcf925b) + * Adds irackup and fixes irake (Method#to_proc hack) + * Server name and server port + (cherry picked from commit d1257882642b06c0c71d05275d1ae5f84739ed23) + * Remove repl.rb from project ... + (cherry picked from commit dac7df55ce0217a77dc7f1c92c5b37b6dd0e14f7) + * rack.uri_scheme + (cherry picked from commit aeebcb0ec8247684a62e0a023a94fb3bb23e49b6) + * update sintra test + (cherry picked from commit 078aaaddd0c5468173ff1880b1c80091bb22dd80) + * Make sure the "env" has MutableString keys, and that Rackup() always + return a Rack app + (cherry picked from commit fe3517edb7fdecf6d5ecefd2f87d27d484ebc9f6) + * Set TOPLEVEL_BINDING if not already set + * Better logging + * Fix env vars for Sinatra (and completeness) + * TCPSocket#read patch for POST requests in WEBrick + (cherry picked from commit 77a060722592b26bb6fc91d47ceddf9ed90c775e) + * cleanup of ironruby-rack from railsconf + * Move to Merlin/Main/Hosts/IronRuby.Rack + * Log KCODE + * fix KCODE error message + * Add ngen install/uninstall scripts + (cherry picked from commit e9d15d93082e8ac8d32ce2a51939c32f8c0cfb03) + * require 'System.Windows.Forms' + (cherry picked from commit 92932a672921a03210c8aefe23ac0a7d6996ed2d) + + 18-05 (jdeville) + Initial COM interop tests for IronRuby. These are just a port of + IronPython's "app" interop tests. This also changes IronRuby to version 0.5 + + Ported IronPython's DiskUse sample to IronRuby + + 13-05 (tomat) + Adds support from nested types to Ruby – they are exposed as constants on + the declaring type. Also implements removal of namespace member and nested + type constants. + + Fixes a bug in autoload – the constant being loaded was removed on a + wrong module. + + Improves displaying of generic types and type groups: RubyContext.GetClassName + returns a name of the class without generic parameters or runtime id. + RubyContext.GetClassDisplayName includes both (runtime id only for classes + from foreign runtime). The latter is used for displaying errors and for + object inspection. + + 12-05 (tomat) + + Fixes class instantiation, including bug + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=1085. + + Several cases need to be distinguished in Class#new: + 1) The class defines or inherits an initializer (“initialize” method) that + is not the default Object#initializer. + a. The initializer is a Ruby method (written in Ruby). + => Use a default constructor to create the instance and invoke the + initializer on it. If the class derives from CLR class with no + default constructor an exception is thrown. + b. The initializer is defined in a built-in class/module. + i. The class being instantiated is a Ruby class. + Use default constructor and invoke the initializer. + ii. The class is a CLR class. + Use constructor or factory. Do not call the initializer + built-ins must initialize the object completely in + constructors/factories and provide initializers only for a direct + call. + 2) Otherwise. + => Use constructor or factory. Do not call the initializer. + + If the first parameter of a CLR constructor is of type RubyClass it is + considered optional and hidden (like RubyContext or RubyScope) and the + binder passes the class object that represents the class being + instantiated. + + Adds support for RubyContext hidden parameter to the constructor generator + in RubyTypeBuilder. The first RubyContext or RubyClass parameter is + considered a special hidden parameter. The built type needs to store + RubyClass instance to _class field. If the base constructor already has + RubyClass the derived ctor has the same signature. If the base constructor + takes RubyContext the derived ctor takes RubyClass in its place and passes + its context to the base ctor. If the base ctor doesn’t have RubyClass or + RubyContext parameter RubyClass parameter is injected. We also need to + ensure that we don’t create duplicate constructors (e.g. if there is a + parameter-less overload, an overload taking RubyContext and an overload + taking RubyClass). + + Fixes Ruby.sln so that System.Dynamic is not built in Silverlight configurations. + + 07-05 (tomat) + + Implements IsAscii() on MutableString – the bit is calculated along with + hashcode and invalidated each time a mutable operation is performed. + Enables combination of mutable strings with different encodings/KCoding. + If a string is k-coded it should be treated as byte array for all operations + since 1.8 doesn’t tag the strings with encodings. Hence any k-coded strings + can be combined regardless of their actual encodings. 1.9-encoded strings + must have the same encoding or one of them must have all characters in + range 0..127 (IsAscii == true) – MRI 1.9 allows combination of such strings. + + Fixes: + - “IronRuby ignores RUBYLIB environment variable” + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=718 + - Encoding wasn’t flowing correctly in eval (test Encoding4) + - Improves performance of String#*. + - MutableString.Content.GetCapacity was wrong. + + + 06-05 (tomat) + Improves performance for file IO#read method. + Previously we were 10x slower than MRI, now we are approx. 1.5-times faster + + 05-05 (tomat) + Implements Method#to_proc. + + Implements precompilation of simple Ruby method invocations. Adds + pre-generated rules for call sites that are: + 1) context bound + 2) without a block, splat or RHS argument + 3) with self of runtime type RubyObject strongly typed to Object in the + call site + 4) the method is resolved to an existing Ruby method or an “empty” + library method + 5) no context class checks are needed due to protected visibility + 6) the method doesn’t have optional or unsplatted parameters and the number + of mandatory parameters matches the call site + 7) the method has at most 5 parameters + + The rules are generated to MethodDispatcher.Generated.cs by + MethodDispatcher.Generator.rb. The generator finds blocks in C# code that + match this pattern: + + #if GENERATOR + + #else + + #end + #region Generated by … + + #endregion + + It creates a new class G < Generator for each such block end module-eval’s + in that class. Then it calls G.new.generate. The default + implementation takes the and replaces each occurrence of + /*$MethodName*/ or /*$MethodName{*/ … /*}*/ in the template by a value + returned by a call to MethodName on the generator class. The generator + replaces the content of “Generated by” region by the resulting code. The + is optional – the #else block can be omitted. + + There could be multiple templates in a single file. The generator also + searches the file for /*$$*/ comments before evaluating them. Text in + between such comment and following semicolon is evaluated as a Ruby global + variable definition. + + The shelveset also moves event sites (method added/removed/undefined, …) + to RubyModule and RubyClass so that they don’t become megamorphic. + Encapsulates class version into VersionHandle class. + + Changes perf stats output writer to a file 'perfstats.log'. + + Enables remaining Method specs. Fixes a couple of failures due to wrong arity calculation. + + 03-05 (tomat) + Fixes a bug in interpreter - if an exception was thrown in finally clause + the handler of that exception didn't get executed since the current + instruction index was already beyond "endIndex". We need to set endIndex + to _instructions.Length. + + Ruby: Removes old interpreter. + + 01-05 (tomat) + Fixes bugs in the new interpreter and implements more features to support + IronRuby. + + Fixes bug http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=572 + and other eval issues related to control flow. + + 28-04 (tomat) + RubyScope fixes and refactoring. + + This change enables top-level hosted code to define instance methods in + DLR scope. It is no longer necessary to define them as singleton methods. + Ruby engine executes the hosted code as if it was executed using + instance_eval on a proc. The behavior is the same except for control flow; + break or retry on top-level throws an exception as it does in MRI. + + This unit test illustrates the new behavior: + + // When executed without a scope top-level methods are defined on Object + // (as in MRI): + Engine.Execute("def foo; 1; end"); + Assert(Context.ObjectClass.GetMethod("foo") != null); + + // When executed against a scope top-level methods are defined on main + // singleton (not on Object) and also stored in the scope: + var scope = Engine.CreateScope(); + Engine.Execute("def bar; 1; end", scope); + Assert(Context.ObjectClass.GetMethod("bar") == null); + Assert(scope.GetVariable("bar") != null); + + Fixes bug in top-level scope compilation – variables from the scope were + not bound properly: + + var compiled = Engine.CreateScriptSourceFromString("some_variable").Compile(); + scope = Engine.CreateScope(); + scope.SetVariable("some_variable", "foo"); + Assert(compiled.Execute(scope) == "foo"); + + 25-04 (jdeville) + - Update to v0.4.0.0 + + 25-04 (jdeville) + From Danielle: + * IListOps.Difference now uses Object#hash and Object#eql? to check for + object equality, this fixes the failing spec "Array#- acts as if using an + intermediate hash to collect values" + * Modified IListOps.RecursiveJoin to make it flag the resulting string as + tainted if the given array, at least one of its elements or the separator + string are tainted. + * Changed IListOps.Repetition to return IList instances of the same type of + the given self argument (this fixes also "Array#* with an integer returns + subclass instance with Array subclasses") + * Various changes to IListOps.Join to clear all of the remaining tags for the + specs of Array#join. The tags marked as critical in join_tags.txt are not + related to pending bugs for Array#join. + * Added ArrayOps.ToAry as Array#to_a and Array#to_ary behave differently on + subclasses of arrays. + * Cleaning up tags removing expectations that do not fail anymore. + * Changed one overload of IListOps.Equals to make it try to call #to_ary on + the object argument of Array#== and use the resulting array as the actual + argument for the equality check. + * Changed IListOps.SetElement to make it try to invoke #to_ary on its argument + for multi-element sets. + * Changed IListOps.Reverse to return IList instances of the same type of the + given self argument (this change also fixes the following failing spec: + "Array#reverse returns subclass instance on Array subclasses") + * Fixed IListOps.ReverseIndex as Array#rindex should not fail if elements are + removed from the array during the iteration over its elements. + * Slightly modified IListOps.UniqueSelf as suggested upon review. + + From Jimmy: + * Allows symbols to be inside a YAML array + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=375 + * Fixes for File.dirname, makes all dirname specs pass. For Rails to find + log/development.log + http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=499 + * Uses [NotNull] instead of a explicit check. + * Makes __FILE__ and $PROGRAM_NAME (and $0) have canonicalized paths when + Ruby is hosted from ir.exe. However, __FILE__ is not messed with when including a file via require/load. + Fixes http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=545 + * autoload uses '/' to join load-path and autoload-path + Fixes http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=674 + * Code Review changes + - Moves command_line/fixtures/file* and language/fixtures/file* to fixtures/ + - Create RubyUtils.CanonicalizePath, to dependency on IronRuby.Builtins.Glob + from IronRuby.Hosting + * Code review updates: + - Don't combine paths with '/' if the base-path already ends with '/' or '\\' + - Remove Glob.CanonicalizePath (in favor of RubyUtils.CanonicalizePath) + + From Jim: + * remove Glob.CanonicalizePath as requested by Tomas for CR for Jimmy + * add ci_files to default.mspec so mspec ci works + * add a filtered function to mspec to simplify default.mspec + * categorizing uncategorized specs + * removing extra spec files + * update rubyspec and mspec + * add a file with the git sha1 hashes of current mspec and rubyspec + * implement File.umask in order to run the specs + * Implement Process.waitall (needed by Process specs) + Also implement Errno::ECHILD, Process.uid=, Process.wait and Process.wait2 + * rebuilt ironruby tags + * Code review fixes from Tomas + * fixing up some missing tags + + 23-04 (jdeville) + From Daniele: + * Array#first(n) and Array#last(n) on a subclass of Array should return an + instance of Array and not an instance of the subclass. + * The result of Array#compact must keep the tainted status of the source + array. + * A block passed to Array#delete should be executed only if no element + matches the given object + * Array#flatten returns subclass instance for Array subclasses + * Array#flatten does not call flatten on elements + * Array#fetch passes the original index argument object to the block, not + the converted Integer + * Removed unused allocateStorage argument from IListOps.First and + IListOps.Last; Removed the manual protocol conversion bits in IListOps.Fetch + * Fix IoOps.ToPrintedString to output a double converted to string using an + invariant culture (Issue #597 NumericLiterals1 test fails under french culture) + * IListOps.ValuesAt adds a null value to the result if the begin value of + the specified range instance(s) is <= the length of the array and the end + value is >= the length of the array. + * Array#uniq! raises a TypeError on a frozen array if modification would + take place. + * Fixed ArrayOps.ToArray to return a new RubyArray instance with the + elements of self if self is a RubyArray.Subclass. + * Array#initialize with (size, object=nil) uses the block value instead + of using the default value + * Fixed IListOps.Compare to work with recursive arrays. + + From Shri: + - Adding the RubyGems 1.2 tests + - Included the 1.3.1 tests as well. They can be used when IronRuby moves up + to RubyGems 1.3.1 (which is what MRI 1.8.6p287 uses) + - Added Scripts\RubyGemsTests.rb to run the RubyGems tests in the IronRuby + dev environment + - Added an optional task (use "irtests.bat -all") to irtests.bat to run the + RubyGems tests. We can enable it by default once more people can try it + out and make sure it works well + - irtest.bat now runs in series by default. Use "irtests.bat -par" to tasks + run in parallel + - Calling exit in at_exit should set the error code. This is required to + detect if RubyGemsTests.rb succeeded or not + - Fixes Array#hash to work with recursive arrays + - Also updated ArraySpecs.recursive_array to produce a cycle of length 3. + Previously, it was doing "a << a" multiple times, but this does not + increase the length of the cycle above 2. It just increase the number of + cycles. This change required an update to many files. + - Also added a new ArraySpecs.recursive_arrays function which should be used + when dealing with two arrays (comparisons, merge, etc). I have only used + it in equal_value_spec and eql_spec for now... + - Also removed entries from critical_tags.txt since recursive hashing and + comparison now works. + - Changed irtests.bat to not use "mspec -V" (unless you are using "irtests -par") + which was causing very verbose output + - Changed irtests.bat to only use two "mspec" tasks so that "irtest -par" + will spawn fewer processes. + - Changed IronRuby.Tests.exe to show dots for each test instead of printing a + new line which is very verbose + - Changed irtests.bat to continue running tests even if previous test task + failed. It remembers the failed results and prints the summary at the end. + - Added ruby19.bat so that "mspec -tr19" runs with Ruby 1.9. It requires + you to set RUBY19_EXE to point to your copy of the 1.9 version of ruby.exe + + From Jirapong: + - fix File.new by re-throw exception + - format indent style + - added RubyErrno.cs to IronRuby.dll, move EEXIST, EINVAL, and ENOENT + to IronRuby.dll + - move RubyErrno's exceptions to exceptions.cs + + 15-04 (jdeville) + Changes from Shri (Include changes from Jira and Daniele): + * Implemented Zlib::GzipWriter.open + * Added Kernel.abort + * Mapped Errno::EACCES to System.UnauthorizedAccessException + * File.delete catches IOException and rethrows Errno::EACCES to match MRI + * Adds Errno::EXDEV + * Updated rbconfig.rb to work with the dev environment. + Change RbConfig[:ruby_install_name] to "ir". Note that it is not "ironruby" + because RubyGems uses this to spawn new processes for running setup scripts + , and so it needs to match the executable name (ir.exe). + * Added Languages\Ruby\Tests\Interop\uncategorized_spec.rb as a place for devs + to add CLR tests. Jim can later move them into the right place in CLR interop + test suite. + * fix missleading FileMode refer to + http://rubyforge.org/tracker/index.php?func=detail&aid=25116&group_id=4359&atid=16798 + * Fixed another bug in String#% + * Bugs in File.rename + * Ruby should exit when main thread exits, even if other threads are still alive + * Mapped Errno::ENOENT to FleNotFoundException, and + ENOTDIR to DirectoryNotFoundException + * fix kernel.open with permission parameter + * Fixes on top of Jirapong's fix for Kernel.open + * Fixes File.expand_path to workaround a problem "igem i rails" was running into. + * Fixes File apis to throw correct exception type + * Implements Kernel.abort + * Adds Errno::ECONNREFUSED + * Exception#message should call Exception#to_s + * Fixes paths in rbconfig.rb to work in dev environment + * Fix the behaviour of Array#[]= with [start, length] + * Delete tags for Array[]= + + Changes by Jim: + * refactor method specs to use a shared behavior + * namespace mapping and method addition specs + * more namespace specs for adding and removing methods and classes + * adding specs mixing Namespaces into Ruby classes + * added specs for enums + * remove dependencies on ClrAssembly + * remove ClrAssembly from Ruby.sln. I'm leaving the ClrAssembly in the Git + repo so that I can reference it when doing my specs + * enum reflection specs + * spec IEnumerable maps to Enumerable + * spec IComparable maps to Comparable + * idictionary support specs + * Ilist specs + * class modification specs (method addition and removal + * spec comparable maps to icomparable + * specs that Int32 is Fixnum and System::DateTime is Time + * adding System::DateTime instantiation specs + * interface reflection spec + * implementing interfaces + + 15-04 (tomat) + Moves old interpreter to Ruby. + Cleans up scope factories (removes out parameters). + A couple of other small tweaks. + + 13-04 (tomat) + Adds support for .NET operators (op_* special methods). These methods + behave like extension methods so some adjustments were needed in + RubyOverloadResolver to handle “self” correctly. + + Implements bitwise operators on flag enums: each flag enum gets a + FlagEnumeration mixin that includes &, |, ^, and ~ methods. The + implementation is the same as Python have so I factored it out to + EnumUtils in DLR. + + Fixes implementation of RubyObject.ToString and Kernel#to_s so that + “to_s” is called from ToString on Ruby objects and ToString is called + from Kernel#to_s for .NET objects. Also implements ToString on built-ins + where it was missing and it makes sense to have it: range and regex. + Although Array and Hash implement to_s as well the result is a plain + concatenation of string representation of their items (entires). + E.g. [“a b”, “c”].to_s == “a bc”. + I don’t think adding RubyArray/Hash.ToString doing the same would be + useful for .NET users. + + Moves Protocols from libraries to IronRuby.dll. + + Implements more DLR interop binders and refactors existing ones. + Adds support for COM interop to interop binders and Kernel#methods. + Fixes a bug in Ruby AST that emitted wrong code for an empty AST. + + 08-04 (tomat) + Redesigns the default method binder. + Implements partially restricted splatting feature in Ruby. + Replaces calls to obsolete methods of default method binder with those using meta-objects. + + Fixes http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=18379. + + 04-04 (jdeville) + Jim: + - closing Rubyforge 15060 + - [#24589] $PROGRAM_NAME in 'English' not working now fixed + - making $0 the same object as $PROGRAM_NAME and adding specs for it. Closes + [#24589] $PROGRAM_NAME in 'English' not working + - closing Rubyforge [#15061] tracking: create generic interface type + - closing RubyForge [#15651] NoMethodError expected when calling the private + method 'initialize' of a ruby class + - added protected method invocation specs. Closes Rubyforge [#19118] + Protected members not available when inheriting from CLR type + - adding regression test for [#19872] IComparableOps.CompareTo throws argument + error when type is Decimal + - added reference support to csc.bat + - closing [#17467] Accessing IronRuby method from C# + - closing [#19950] Dir.glob doesn't handle ** + - closing [#20027] Formatting float to string produces incorrectly + "Infinity" + - closing [#20043] creating a generic type when the type is an interface + - closing [#20052] Calculating 3.0/2.0 produces NaN + - closing Rubyforge [#20263] Dir.glob doesn't handle missing folders + - closing [#20410] GetKCodeName + - adding test to ensure that File.stat returns a File::Stat object + - closing Rubyforge [#20640] Calling File.open with an integer (File descriptor + overload) causes the File.open site to be unusable + - closing Rubyforge [#20664] Respecting visibility of methods. Also fixes a + compilation error due to multiple IInterface definitions + - Closing RubyForge [#20665] Can't use an indexer on a WPF ResourceDictionary + - removing a tag for predefined + - closing Rubyforge [#21943] NullRef exception thrown while comparing a list + containing elements with overriden == + - closing Rubyforge [#21995] kind_of? not working with when extend is used + - recommiting some changes that were reverted by the merge. Methinks someone + in TFS changed them. This makes describe work with 2 strings for shared + behaviors, and it makes csc output #line pragmas + - fixing some more errors from the merge + - Adding class instantiation specs for regular classes with overloaded + constructors + - adding regression tests for [#22197] calling super throw Argument Error + - adding StringBuilder specs to get rid of test_basic.rb. Also added + equal_clr_string matcher + - refactor specs to use the equal_clr_string matcher + - basic string specs to remove test_basic.rb + - added more string specs to get rid of test_basic. Also adds field specs + - adding some basic event add and remove specs + - added event invocation specs + + Shri: + - YAML should allow spaces. eg the trailing \s\t in + YAML.load("!timestamp '2009-03-22 00:00:00\s\t'") is allowed + - Changed igem.bat, irake.bat, etc to work in dev environment where ir.exe + is not in the path + - File.expand_path("~") should throw ArgumentError is HOME is not set + - make orig_name, comment, and split close and finish + - compile error when pull form irmain, merge in zlib + - spec for finish, close, oriname, and trying to DRY orig_name and comment + - make orig_name, comment, close, and finish passed spec. + - Implements File.chmod + - File.readable? should return false if the given filename does not exist + - File.delete should be able to delete a read-only file. This is implemented + by making the file writable first. This is the only solution I could find. + - Added debugger visualizer for RubyObject so that VS will display the result + of to_s in the Watch window. + - Adds the wrapper script Merlin\Main\Test\Scritps\ir.cmd so that the Legacy + tests (Ruby\Scripts\test.bat) can pass without any failures. + + 28-03 (sborde) + - Adding unit tests for Ruby's IDMOP support. Failing scenarios are tagged + with AreEqualBug and AssertExceptionThrownBug + - Added Languages\Ruby\Scripts\ir_wrap.cmd as the replacement for + Test\Scripts\ir.cmd which does not exist in GIT. Most of the files are + changed because of this. + + 27-03 (jdeville) + - modify .gitignore to ignore Bin in addition to bin + - Adds ClrAssembly to Ruby.sln + - add dlr_config to IronRuby object + - csc describe handles shared specs (multiple arguments) and we now emit + #line pragmas instead of comments + - adding some generic tests and fixing tags, also make default.mspec load + ir.exe instead of ir.cmd + - adding some constrained generic specs + - added generic error messages specs. Fixed tag location + - split pragma warning to make sure I do not disable unintended warnings. + Refactor conflicting methods + - added class param and conflicting type param specs + - adding specs for ruby classes with type constraints + - array conversion specs + - array instantiation specs + - redid IronRuby.dlr_config after Tomas' IronRuby changes + - adding a default conversion spec and a little bit of refactoring + - more array tests + - spec for a static method caching bug i found + - spec method overriding maintains .NET supermethod + - refactor to add some metaclass helpers + - class instantiation specs + - some more class instantiation specs + - sealed class instantiation specs + - generic instantiation specs + - make GenericClass have a method so it isn't EmptyGenericClass + - more generic instantiation specs + + 26-03 (tomat) + Implements atomizer for Ruby call site binders: A new class + RubyMetaBinderFactory creates sites and caches them in dictionaries. Sites + are either bound to a runtime (RubyContext) or not. Bound sites don’t emit + context check, unbound need to. Bound sites don’t take RubyContext as the + first parameter any more. They can still take RubyScope if needed (such + sites have HasScope flag set). Replaces SiteLocalStorage with + RubyCallSiteStorage that holds on the context so that it is not necessary + to pass RubyContext to the sites stored in the storage. Updates all sites + in libraries accordingly. + + Adds –ER command line option that enables tracing of meta-objects (rules) + created by Ruby. + + Refactors MetaObjectBuilder to use type restrictions rather than expression + restrictions. + + Removes RubyClassAttribute.MixinInterfaces – it didn’t work correctly and + was almost unused. + + Also improves handling of BOM in 1.8 mode – we previously did exactly what + Ruby does, i.e. report a syntax error from which it is not obvious what’s + wrong. If –KU is not specified and UTF8 BOM is found at the beginning of + the source code, the tokenizer reports a level 2 warning, skips the BOM + as if it was whitespace and continues reading the file. + + 24-03 (tomat) + A couple of breaking changes: + - Removes ClrString constant. CLR string should be referred to as + System::String. + - Removes IronRuby library. “require ‘IronRuby’” is no longer needed, IronRuby + module is now a built-in module. + + Implements integer/float operations for all CLR primitive numeric types (byte, + sbyte, short, ushort, uint, long, ulong, float). Those integer types that fit + in 32-bit signed integer (Fixnum) are widened to Fixnum for all operations. The + other integer types are widened to BigInteger. Float is converted to double. + The operations on these types don’t narrow their results even if the values + fit. For example, (System::Byte.new(1) + 1).class == Fixnum, not System::Byte. + This might not be optimal for some scenarios. If we find it important we’ll fix + this in future. + + The implementation takes the operations from FixnumOps, BignumOps and FloatOps + and moves them to new modules IronRuby::Clr::Integer, IronRuby::Clr::BigInteger + and IronRuby::Clr::Float respectively. These are mixed back into the numeric + types. Some methods need to be specialized for each types, so we generated C# + code for them. Ruby 1.9 script ClrInteger.Generator.rb produces + ClrInteger.Generated.cs. + + Implements System::Char and System::String methods so that they behave like an + immutable UTF-8 encoded string (of size 1 character in the case of + System::Char). Many methods in MutableStringOps can share implementation with + CLR string. There is still a lot of work to be done here, especially to support + encodings. So for now, to make CLR strings work like Ruby frozen strings to a + large extent, I’ve implemented method-missing dispatch that forwards to a + MutableString. + + +ironruby-0.3.0.0 - 2009-03-20 +----------------------------- + + - Improves Ruby tokenizer and parser by 30% + - Moved source code repository to GIT, unsigned builds + - Thread library (Thread#stop, Kernel#sleep, Thread#raise, Thread#critical=) + - Fixes interpretation of UnaryExpresion cast with a custom method + - Implements generic methods parameters binding and explicit overload selection + - Makes operations on class hierarchy thread-safe + - Fixes binder error message given when an interface name is displayed. + - Adds additional RubySpec tests to language/regexp_specs.rb + - Fixes Zlib::Inflate#inflate and File#join (for gem install) + - Adds -e support to IronRuby using CommonConsoleOptions.Comand. + - Regexp literal support for /o + - Fixnum + Bignum should yield a Bignum, not a Float + - Implements Ruby protected visibility, fixes other bugs in Module (all specs pass now) and assignment in eval. + - Implements loading of assembly dependencies. diff --git a/Merlin/Main/Languages/Ruby/Licenses/CPL.txt b/Merlin/Main/Languages/Ruby/Licenses/LICENSE.CPL.txt similarity index 100% rename from Merlin/Main/Languages/Ruby/Licenses/CPL.txt rename to Merlin/Main/Languages/Ruby/Licenses/LICENSE.CPL.txt diff --git a/Merlin/Main/Languages/Ruby/Licenses/MSPL.html b/Merlin/Main/Languages/Ruby/Licenses/LICENSE.MSPL.html similarity index 100% rename from Merlin/Main/Languages/Ruby/Licenses/MSPL.html rename to Merlin/Main/Languages/Ruby/Licenses/LICENSE.MSPL.html diff --git a/Merlin/Main/Languages/Ruby/Licenses/RubyLicense.txt b/Merlin/Main/Languages/Ruby/Licenses/LICENSE.Ruby.txt similarity index 100% rename from Merlin/Main/Languages/Ruby/Licenses/RubyLicense.txt rename to Merlin/Main/Languages/Ruby/Licenses/LICENSE.Ruby.txt diff --git a/Merlin/Main/Languages/Ruby/Licenses/README.txt b/Merlin/Main/Languages/Ruby/Licenses/README.txt new file mode 100644 index 0000000000..48a3c8b33e --- /dev/null +++ b/Merlin/Main/Languages/Ruby/Licenses/README.txt @@ -0,0 +1,46 @@ +IronRuby - A .NET Implementation of the Ruby language + +Authors: + Daniele Alessandri, Shri Borde, Peter Bacon Darwin, Jim Deville, + Curt Hagenlocher, John Lam, Haibo Luo, Tomas Matousek, John Messerly, + Jirapong Nanta, Srivatsn Narayanan, Jimmy Schementi, Oleg Tkachenko, + Dino Viehland, and everyone else from the community who reports bugs, + builds libraries, and helps enrich IronRuby. + +Project Contact: Jimmy Schementi + +== About + +IronRuby is a Open Source implementation of the Ruby programming language +(http://www.ruby-lang.org) for .NET, heavily relying on Microsoft's +Dynamic Language Runtime (http://dlr.codeplex.com). + +The project's #1 goal is to be a true Ruby implementation, meaning it runs +existing Ruby code. See +http://ironruby.net/Documentation/Real_Ruby_Applications for information about +using the Ruby standard library and 3rd party libraries in IronRuby. + +IronRuby has tightly integration with .NET, so any .NET types can be used from +IronRuby, and the IronRuby runtime can be embedded into any .NET application. +See http://ironruby.net/documentation/.net for more information. + +== Running + +bin/ir.exe rubyfile.rb + +Will run rubyfile.rb with the IronRuby compiler. + +== Package + + /bin IronRuby binaries, ir.exe, iirb, irake, igem, iri, irdoc, etc. + /lib Ruby standard library, including RubyGems + CHANGELOG.txt Changes for each release + RELEASE.txt Release notes + LICENSE.Ruby.txt Ruby license + LICENSE.CPL.txt Common Public License + LICENSE.MSPL.html Microsoft Public License + README.txt This file + +== License + +Read the License.* files diff --git a/Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.cs b/Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.cs index 4caacd0df8..ba070cd018 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Builtins/MutableString.cs @@ -623,17 +623,24 @@ public MutableString() } // used by auto-conversions - [Obsolete("Do not use in code")] - public static implicit operator string(MutableString/*!*/ self) { + public static explicit operator string(MutableString/*!*/ self) { return self._content.ConvertToString(); } // used by auto-conversions - [Obsolete("Do not use in code")] - public static implicit operator byte[](MutableString/*!*/ self) { + public static explicit operator byte[](MutableString/*!*/ self) { return self._content.ConvertToBytes(); } + // used by auto-conversions + public static explicit operator char(MutableString/*!*/ self) { + try { + return self.GetChar(0); + } catch (IndexOutOfRangeException) { + throw RubyExceptions.CreateTypeConversionError("String", "System::Char"); + } + } + #endregion #region Comparisons (read-only) (TODO: Encodings) diff --git a/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs b/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs index fedbd06950..c8608bc1f7 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Builtins/Proc.Meta.cs @@ -33,7 +33,7 @@ public partial class Proc : IRubyDynamicMetaObjectProvider { return new Meta(parameter, BindingRestrictions.Empty, this); } - internal sealed class Meta : RubyMetaObject { + internal sealed class Meta : RubyMetaObject, IConvertibleMetaObject { public override RubyContext/*!*/ Context { get { return Value.LocalScope.RubyContext; } } @@ -47,6 +47,10 @@ public Meta(Expression/*!*/ expression, BindingRestrictions/*!*/ restrictions, P } // Conversion to a delegate. + public bool CanConvertTo(Type/*!*/ type, bool @explicit) { + return typeof(Delegate).IsAssignableFrom(type); + } + public override DynamicMetaObject/*!*/ BindConvert(ConvertBinder/*!*/ binder) { return InteropBinder.TryBindCovertToDelegate(this, binder, Methods.CreateDelegateFromProc) ?? base.BindConvert(binder); diff --git a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyArray.cs b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyArray.cs index 9598eda17e..be4c7a72a5 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyArray.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyArray.cs @@ -21,6 +21,7 @@ using Microsoft.Scripting; using Microsoft.Scripting.Utils; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; namespace IronRuby.Builtins { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs index 11f7d558ad..dca78c31fc 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs @@ -32,6 +32,7 @@ using Ast = System.Linq.Expressions.Expression; using AstUtils = Microsoft.Scripting.Ast.Utils; using Microsoft.Scripting.Generation; +using IronRuby.Runtime.Conversions; namespace IronRuby.Builtins { public sealed partial class RubyClass : RubyModule, IDuplicable { @@ -250,7 +251,7 @@ public sealed partial class RubyClass : RubyModule, IDuplicable { Interlocked.Exchange(ref _underlyingSystemType, RubyTypeDispenser.GetOrCreateType( _superClass.GetUnderlyingSystemType(), - GetClrInterfaces(), + GetImplementedInterfaces(), _superClass != null && (_superClass.Restrictions & ModuleRestrictions.NoOverrides) != 0 ) ); @@ -747,12 +748,19 @@ public RubyClass(RubyClass/*!*/ rubyClass) return true; } } else if (name == "[]" || name == "[]=") { - object[] attrs = type.GetCustomAttributes(typeof(DefaultMemberAttribute), false); - if (attrs.Length == 1) { - // default indexer accessor: + if (type.IsArray && !_isSingletonClass) { bool isSetter = name.Length == 3; - if (TryGetClrProperty(type, bindingFlags, isSetter, name, ((DefaultMemberAttribute)attrs[0]).MemberName, null, out method)) { - return true; + TryGetClrMethod(type, bindingFlags, false, name, null, isSetter ? "Set" : "Get", null, out method); + Debug.Assert(method != null); + return true; + } else { + object[] attrs = type.GetCustomAttributes(typeof(DefaultMemberAttribute), false); + if (attrs.Length == 1) { + // default indexer accessor: + bool isSetter = name.Length == 3; + if (TryGetClrProperty(type, bindingFlags, isSetter, name, ((DefaultMemberAttribute)attrs[0]).MemberName, null, out method)) { + return true; + } } } } else if (name.LastCharacter() == '=') { @@ -1249,7 +1257,7 @@ private sealed class ClrOverloadInfo { BuildDelegateConstructorCall(metaBuilder, args, type); return; } else if (type.IsArray && type.GetArrayRank() == 1) { - constructionOverloads = ClrVectorFactories; + constructionOverloads = GetClrVectorFactories(); } else if (_structInfo != null) { constructionOverloads = new MethodBase[] { Methods.CreateStructInstance }; } else if (_factories.Length != 0) { @@ -1386,16 +1394,19 @@ private sealed class ClrOverloadInfo { } } - private MethodBase/*!*/[]/*!*/ ClrVectorFactories { - get { - if (_clrVectorFactories == null) { - _clrVectorFactories = new[] { Methods.CreateVector, Methods.CreateVectorWithValues }; - } - return _clrVectorFactories; + private MethodBase/*!*/[]/*!*/ GetClrVectorFactories() { + if (_clrVectorFactories == null) { + Type elementType = GetUnderlyingSystemType().GetElementType(); + _clrVectorFactories = new[] { + Methods.CreateVector.MakeGenericMethod(elementType), + Methods.CreateVectorWithValues.MakeGenericMethod(elementType) + }; } + return _clrVectorFactories; } - private static MethodBase[] _clrVectorFactories; + // thread-safe (the latest write wins): + private MethodBase[] _clrVectorFactories; #endregion } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs index 990e48195e..9dd0cdef89 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs @@ -1669,8 +1669,8 @@ private enum ConstantLookupResult { private bool TryGetClrMember(string/*!*/ name, bool virtualLookup, out RubyMemberInfo method) { // Skip hidden CLR overloads. - // Skip lookup on types that are not visible or interfaces. - if (_typeTracker != null && !_typeTracker.Type.IsInterface) { + // Skip lookup on types that are not visible, that are interfaces or generic type definitions. + if (_typeTracker != null && !_typeTracker.Type.IsInterface && !_typeTracker.Type.IsGenericTypeDefinition) { // Note: Do not allow mangling for CLR virtual lookups - we want to match the overridden name exactly as is, // so that it corresponds to the base method call the override stub performs. bool tryUnmangle = !virtualLookup && (_restrictions & ModuleRestrictions.NoNameMangling) == 0; @@ -1904,14 +1904,6 @@ private enum ConstantLookupResult { foreach (RubyModule module in expanded) { if (module.IsInterface) { - // Can't include generic interfaces - if (module.TypeTracker.Type.ContainsGenericParameters) { - throw RubyExceptions.CreateTypeError(String.Format( - "{0}: cannot extend with open generic instantiation {1}. Only closed instantiations are supported.", - Name, module.Name - )); - } - if (!CanIncludeClrInterface) { bool alreadyIncluded = false; foreach (RubyModule includedModule in _mixins) { @@ -2006,11 +1998,11 @@ private enum ConstantLookupResult { get { return true; } } - internal List GetClrInterfaces() { + internal List GetImplementedInterfaces() { List interfaces = new List(); using (Context.ClassHierarchyLocker()) { foreach (RubyModule m in _mixins) { - if (m.IsInterface && !interfaces.Contains(m.TypeTracker.Type)) { + if (m.IsInterface && !m.TypeTracker.Type.IsGenericTypeDefinition && !interfaces.Contains(m.TypeTracker.Type)) { interfaces.Add(m.TypeTracker.Type); } } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/BlockReference.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/BlockReference.cs index 6ca72b36a0..f5db946ea7 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/BlockReference.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/BlockReference.cs @@ -17,6 +17,7 @@ using Microsoft.Scripting.Utils; using IronRuby.Builtins; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using MSA = System.Linq.Expressions; namespace IronRuby.Compiler.Ast { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Clauses/RescueClause.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Clauses/RescueClause.cs index 7b7339807d..0dfcbcfc76 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Clauses/RescueClause.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Clauses/RescueClause.cs @@ -13,7 +13,9 @@ * * ***************************************************************************/ -using System.Collections.Generic; +using System.Diagnostics; +using IronRuby.Runtime; +using IronRuby.Runtime.Conversions; using Microsoft.Scripting; using Microsoft.Scripting.Ast; using Microsoft.Scripting.Utils; @@ -22,10 +24,6 @@ namespace IronRuby.Compiler.Ast { using Ast = System.Linq.Expressions.Expression; - using System.Diagnostics; - using IronRuby.Runtime.Calls; - using System.Collections; - using IronRuby.Runtime; // rescue type // statements diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/MatchExpression.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/MatchExpression.cs index f818c2e9d2..5528842e15 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/MatchExpression.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/MatchExpression.cs @@ -20,12 +20,13 @@ using Microsoft.Scripting.Utils; using IronRuby.Builtins; using IronRuby.Runtime; +using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using AstUtils = Microsoft.Scripting.Ast.Utils; using MSA = System.Linq.Expressions; namespace IronRuby.Compiler.Ast { using Ast = System.Linq.Expressions.Expression; - using IronRuby.Runtime.Calls; public partial class MatchExpression : Expression { private readonly RegularExpression/*!*/ _regex; diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/StringConstructor.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/StringConstructor.cs index 27b28abb0e..cf7514f4c9 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/StringConstructor.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/Expressions/StringConstructor.cs @@ -22,12 +22,13 @@ using IronRuby.Runtime.Calls; using Microsoft.Scripting; using Microsoft.Scripting.Utils; +using System.Diagnostics; +using IronRuby.Runtime.Conversions; using AstUtils = Microsoft.Scripting.Ast.Utils; namespace IronRuby.Compiler.Ast { using Ast = System.Linq.Expressions.Expression; using MSA = System.Linq.Expressions; - using System.Diagnostics; public enum StringKind { Mutable, diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs index d42fac8524..b42cc7cf61 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Ast/SourceUnitTree.cs @@ -25,6 +25,7 @@ using IronRuby.Builtins; using IronRuby.Runtime; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using MSA = System.Linq.Expressions; using AstUtils = Microsoft.Scripting.Ast.Utils; diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeBuilder.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeBuilder.cs index 28144da75f..a8254a5c84 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeBuilder.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeBuilder.cs @@ -416,7 +416,7 @@ private sealed class ConstructorBuilderInfo { } private void DefineDynamicObjectImplementation() { - _tb.AddInterfaceImplementation(typeof(IDynamicMetaObjectProvider)); + _tb.AddInterfaceImplementation(typeof(IRubyDynamicMetaObjectProvider)); // MetaObject! IDynamicMetaObjectProvider.GetMetaObject(Expression! parameter) { // return RubyOps.GetMetaObject(this, parameter); diff --git a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs index caa2f8ec61..d6a709bfa6 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs @@ -24,6 +24,7 @@ using IronRuby.Runtime; using IronRuby.Runtime.Calls; using System.Linq.Expressions; +using IronRuby.Runtime.Conversions; namespace IronRuby.Compiler.Generation { public class RubyTypeEmitter : ClsTypeEmitter { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj b/Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj index c46dde392a..9c76d4b998 100644 Binary files a/Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj and b/Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj differ diff --git a/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj b/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj index a617c63ef7..dd495cce8b 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj +++ b/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD} Library @@ -22,6 +23,7 @@ true 887095296 ..\..\..\Utilities\Silverlight\x86ret\ + v2.0 pdbonly @@ -32,7 +34,8 @@ 4 true true - -Microsoft.Usage#CA2209;-!Microsoft.Design#CA1012;-!Microsoft.Design#CA2210;-!Microsoft.Design#CA1040;-!Microsoft.Design#CA1005;-!Microsoft.Design#CA1020;-!Microsoft.Design#CA1021;-!Microsoft.Design#CA1010;-!Microsoft.Design#CA1011;-!Microsoft.Design#CA1009;-!Microsoft.Design#CA1050;-!Microsoft.Design#CA1026;-!Microsoft.Design#CA1019;-!Microsoft.Design#CA1031;-!Microsoft.Design#CA1047;-!Microsoft.Design#CA1000;-!Microsoft.Design#CA1048;-!Microsoft.Design#CA1051;-!Microsoft.Design#CA1002;-!Microsoft.Design#CA1061;-!Microsoft.Design#CA1006;-!Microsoft.Design#CA1046;-!Microsoft.Design#CA1045;-!Microsoft.Design#CA1065;-!Microsoft.Design#CA1038;-!Microsoft.Design#CA1008;-!Microsoft.Design#CA1028;-!Microsoft.Design#CA1064;-!Microsoft.Design#CA1004;-!Microsoft.Design#CA1035;-!Microsoft.Design#CA1063;-!Microsoft.Design#CA1032;-!Microsoft.Design#CA1023;-!Microsoft.Design#CA1033;-!Microsoft.Design#CA1039;-!Microsoft.Design#CA1016;-!Microsoft.Design#CA1014;-!Microsoft.Design#CA1017;-!Microsoft.Design#CA1018;-!Microsoft.Design#CA1027;-!Microsoft.Design#CA1059;-!Microsoft.Design#CA1060;-!Microsoft.Design#CA1034;-!Microsoft.Design#CA1013;-!Microsoft.Design#CA1036;-!Microsoft.Design#CA1044;-!Microsoft.Design#CA1041;-!Microsoft.Design#CA1025;-!Microsoft.Design#CA1052;-!Microsoft.Design#CA1053;-!Microsoft.Design#CA1057;-!Microsoft.Design#CA1058;-!Microsoft.Design#CA1001;-!Microsoft.Design#CA1049;-!Microsoft.Design#CA1054;-!Microsoft.Design#CA1056;-!Microsoft.Design#CA1055;-!Microsoft.Design#CA1030;-!Microsoft.Design#CA1003;-!Microsoft.Design#CA1007;-!Microsoft.Design#CA1043;-!Microsoft.Design#CA1024;-!Microsoft.Globalization#CA1301;-!Microsoft.Globalization#CA1302;-!Microsoft.Globalization#CA1308;-!Microsoft.Globalization#CA1306;-!Microsoft.Globalization#CA1304;-!Microsoft.Globalization#CA1305;-!Microsoft.Globalization#CA2101;-!Microsoft.Globalization#CA1300;-!Microsoft.Globalization#CA1307;-!Microsoft.Globalization#CA1309;-!Microsoft.Interoperability#CA1403;-!Microsoft.Interoperability#CA1406;-!Microsoft.Interoperability#CA1413;-!Microsoft.Interoperability#CA1402;-!Microsoft.Interoperability#CA1407;-!Microsoft.Interoperability#CA1404;-!Microsoft.Interoperability#CA1410;-!Microsoft.Interoperability#CA1411;-!Microsoft.Interoperability#CA1405;-!Microsoft.Interoperability#CA1409;-!Microsoft.Interoperability#CA1415;-!Microsoft.Interoperability#CA1408;-!Microsoft.Interoperability#CA1414;-!Microsoft.Interoperability#CA1412;-!Microsoft.Interoperability#CA1400;-!Microsoft.Interoperability#CA1401;-!Microsoft.Maintainability#CA1506;-!Microsoft.Maintainability#CA1502;-!Microsoft.Maintainability#CA1501;-!Microsoft.Maintainability#CA1505;-!Microsoft.Maintainability#CA1504;-!Microsoft.Maintainability#CA1500;-!Microsoft.Mobility#CA1600;-!Microsoft.Mobility#CA1601;-!Microsoft.Naming#CA1702;-!Microsoft.Naming#CA1700;-!Microsoft.Naming#CA1712;-!Microsoft.Naming#CA1713;-!Microsoft.Naming#CA1714;-!Microsoft.Naming#CA1709;-!Microsoft.Naming#CA1704;-!Microsoft.Naming#CA1708;-!Microsoft.Naming#CA1715;-!Microsoft.Naming#CA1710;-!Microsoft.Naming#CA1720;-!Microsoft.Naming#CA1707;-!Microsoft.Naming#CA1722;-!Microsoft.Naming#CA1711;-!Microsoft.Naming#CA1716;-!Microsoft.Naming#CA1717;-!Microsoft.Naming#CA1725;-!Microsoft.Naming#CA1719;-!Microsoft.Naming#CA1721;-!Microsoft.Naming#CA1701;-!Microsoft.Naming#CA1703;-!Microsoft.Naming#CA1724;-!Microsoft.Naming#CA1726;-!Microsoft.Performance#CA1809;-!Microsoft.Performance#CA1811;-!Microsoft.Performance#CA1812;-!Microsoft.Performance#CA1813;+!Microsoft.Performance#CA1823;-!Microsoft.Performance#CA1800;-!Microsoft.Performance#CA1805;-!Microsoft.Performance#CA1810;+!Microsoft.Performance#CA1824;-!Microsoft.Performance#CA1822;-!Microsoft.Performance#CA1815;-!Microsoft.Performance#CA1814;-!Microsoft.Performance#CA1819;-!Microsoft.Performance#CA1821;-!Microsoft.Performance#CA1804;-!Microsoft.Performance#CA1820;-!Microsoft.Performance#CA1802;+!Microsoft.Portability#CA1903;+!Microsoft.Portability#CA1901;+!Microsoft.Portability#CA1900;+!Microsoft.Reliability#CA2001;+!Microsoft.Reliability#CA2002;+!Microsoft.Reliability#CA2003;+!Microsoft.Reliability#CA2004;+!Microsoft.Reliability#CA2006;+!Microsoft.Security#CA2116;+!Microsoft.Security#CA2117;+!Microsoft.Security#CA2105;+!Microsoft.Security#CA2115;+!Microsoft.Security#CA2102;-!Microsoft.Security#CA2104;+!Microsoft.Security#CA2122;+!Microsoft.Security#CA2114;+!Microsoft.Security#CA2123;+!Microsoft.Security#CA2111;+!Microsoft.Security#CA2108;+!Microsoft.Security#CA2107;+!Microsoft.Security#CA2103;+!Microsoft.Security#CA2118;+!Microsoft.Security#CA2109;+!Microsoft.Security#CA2119;+!Microsoft.Security#CA2106;+!Microsoft.Security#CA2112;+!Microsoft.Security#CA2120;+!Microsoft.Security#CA2121;+!Microsoft.Security#CA2126;+!Microsoft.Security#CA2124;+!Microsoft.Security#CA2127;+!Microsoft.Security#CA2128;+!Microsoft.Security#CA2129;-!Microsoft.Usage#CA2243;-!Microsoft.Usage#CA2236;-!Microsoft.Usage#CA1816;-!Microsoft.Usage#CA2227;-!Microsoft.Usage#CA2213;-!Microsoft.Usage#CA2216;-!Microsoft.Usage#CA2214;-!Microsoft.Usage#CA2222;-!Microsoft.Usage#CA1806;-!Microsoft.Usage#CA2217;-!Microsoft.Usage#CA2212;-!Microsoft.Usage#CA2219;-!Microsoft.Usage#CA2201;-!Microsoft.Usage#CA2228;-!Microsoft.Usage#CA2221;-!Microsoft.Usage#CA2220;-!Microsoft.Usage#CA2240;-!Microsoft.Usage#CA2229;-!Microsoft.Usage#CA2238;-!Microsoft.Usage#CA2207;-!Microsoft.Usage#CA2208;-!Microsoft.Usage#CA2235;-!Microsoft.Usage#CA2237;-!Microsoft.Usage#CA2232;-!Microsoft.Usage#CA2223;-!Microsoft.Usage#CA2211;-!Microsoft.Usage#CA2233;-!Microsoft.Usage#CA2225;-!Microsoft.Usage#CA2226;-!Microsoft.Usage#CA2231;-!Microsoft.Usage#CA2224;-!Microsoft.Usage#CA2218;-!Microsoft.Usage#CA2234;-!Microsoft.Usage#CA2239;-!Microsoft.Usage#CA2200;-!Microsoft.Usage#CA1801;-!Microsoft.Usage#CA2242;-!Microsoft.Usage#CA2205;-!Microsoft.Usage#CA2230 + -Microsoft.Usage#CA2209;-!Microsoft.Design#CA1012;-!Microsoft.Design#CA2210;-!Microsoft.Design#CA1040;-!Microsoft.Design#CA1005;-!Microsoft.Design#CA1020;-!Microsoft.Design#CA1021;-!Microsoft.Design#CA1010;-!Microsoft.Design#CA1011;-!Microsoft.Design#CA1009;-!Microsoft.Design#CA1050;-!Microsoft.Design#CA1026;-!Microsoft.Design#CA1019;-!Microsoft.Design#CA1031;-!Microsoft.Design#CA1047;-!Microsoft.Design#CA1000;-!Microsoft.Design#CA1048;-!Microsoft.Design#CA1051;-!Microsoft.Design#CA1002;-!Microsoft.Design#CA1061;-!Microsoft.Design#CA1006;-!Microsoft.Design#CA1046;-!Microsoft.Design#CA1045;-!Microsoft.Design#CA1065;-!Microsoft.Design#CA1038;-!Microsoft.Design#CA1008;-!Microsoft.Design#CA1028;-!Microsoft.Design#CA1064;-!Microsoft.Design#CA1004;-!Microsoft.Design#CA1035;-!Microsoft.Design#CA1063;-!Microsoft.Design#CA1032;-!Microsoft.Design#CA1023;-!Microsoft.Design#CA1033;-!Microsoft.Design#CA1039;-!Microsoft.Design#CA1016;-!Microsoft.Design#CA1014;-!Microsoft.Design#CA1017;-!Microsoft.Design#CA1018;-!Microsoft.Design#CA1027;-!Microsoft.Design#CA1059;-!Microsoft.Design#CA1060;-!Microsoft.Design#CA1034;-!Microsoft.Design#CA1013;-!Microsoft.Design#CA1036;-!Microsoft.Design#CA1044;-!Microsoft.Design#CA1041;-!Microsoft.Design#CA1025;-!Microsoft.Design#CA1052;-!Microsoft.Design#CA1053;-!Microsoft.Design#CA1057;-!Microsoft.Design#CA1058;-!Microsoft.Design#CA1001;-!Microsoft.Design#CA1049;-!Microsoft.Design#CA1054;-!Microsoft.Design#CA1056;-!Microsoft.Design#CA1055;-!Microsoft.Design#CA1030;-!Microsoft.Design#CA1003;-!Microsoft.Design#CA1007;-!Microsoft.Design#CA1043;-!Microsoft.Design#CA1024;-!Microsoft.Globalization#CA1301;-!Microsoft.Globalization#CA1302;-!Microsoft.Globalization#CA1308;-!Microsoft.Globalization#CA1306;-!Microsoft.Globalization#CA1304;-!Microsoft.Globalization#CA1305;-!Microsoft.Globalization#CA2101;-!Microsoft.Globalization#CA1300;-!Microsoft.Globalization#CA1307;-!Microsoft.Globalization#CA1309;-!Microsoft.Interoperability#CA1403;-!Microsoft.Interoperability#CA1406;-!Microsoft.Interoperability#CA1413;-!Microsoft.Interoperability#CA1402;-!Microsoft.Interoperability#CA1407;-!Microsoft.Interoperability#CA1404;-!Microsoft.Interoperability#CA1410;-!Microsoft.Interoperability#CA1411;-!Microsoft.Interoperability#CA1405;-!Microsoft.Interoperability#CA1409;-!Microsoft.Interoperability#CA1415;-!Microsoft.Interoperability#CA1408;-!Microsoft.Interoperability#CA1414;-!Microsoft.Interoperability#CA1412;-!Microsoft.Interoperability#CA1400;-!Microsoft.Interoperability#CA1401;-!Microsoft.Maintainability#CA1506;-!Microsoft.Maintainability#CA1502;-!Microsoft.Maintainability#CA1501;-!Microsoft.Maintainability#CA1505;-!Microsoft.Maintainability#CA1504;-!Microsoft.Maintainability#CA1500;-!Microsoft.Mobility#CA1600;-!Microsoft.Mobility#CA1601;-!Microsoft.Naming#CA1702;-!Microsoft.Naming#CA1700;-!Microsoft.Naming#CA1712;-!Microsoft.Naming#CA1713;-!Microsoft.Naming#CA1714;-!Microsoft.Naming#CA1709;-!Microsoft.Naming#CA1704;-!Microsoft.Naming#CA1708;-!Microsoft.Naming#CA1715;-!Microsoft.Naming#CA1710;-!Microsoft.Naming#CA1720;-!Microsoft.Naming#CA1707;-!Microsoft.Naming#CA1722;-!Microsoft.Naming#CA1711;-!Microsoft.Naming#CA1716;-!Microsoft.Naming#CA1717;-!Microsoft.Naming#CA1725;-!Microsoft.Naming#CA1719;-!Microsoft.Naming#CA1721;-!Microsoft.Naming#CA1701;-!Microsoft.Naming#CA1703;-!Microsoft.Naming#CA1724;-!Microsoft.Naming#CA1726;-!Microsoft.Performance#CA1809;-!Microsoft.Performance#CA1811;-!Microsoft.Performance#CA1812;-!Microsoft.Performance#CA1813;+!Microsoft.Performance#CA1823;-!Microsoft.Performance#CA1800;-!Microsoft.Performance#CA1805;-!Microsoft.Performance#CA1810;+!Microsoft.Performance#CA1824;-!Microsoft.Performance#CA1822;-!Microsoft.Performance#CA1815;-!Microsoft.Performance#CA1814;-!Microsoft.Performance#CA1819;-!Microsoft.Performance#CA1821;-!Microsoft.Performance#CA1804;-!Microsoft.Performance#CA1820;-!Microsoft.Performance#CA1802;+!Microsoft.Portability#CA1903;+!Microsoft.Portability#CA1901;+!Microsoft.Portability#CA1900;+!Microsoft.Reliability#CA2001;+!Microsoft.Reliability#CA2002;+!Microsoft +.Reliability#CA2003;+!Microsoft.Reliability#CA2004;+!Microsoft.Reliability#CA2006;+!Microsoft.Security#CA2116;+!Microsoft.Security#CA2117;+!Microsoft.Security#CA2105;+!Microsoft.Security#CA2115;+!Microsoft.Security#CA2102;-!Microsoft.Security#CA2104;+!Microsoft.Security#CA2122;+!Microsoft.Security#CA2114;+!Microsoft.Security#CA2123;+!Microsoft.Security#CA2111;+!Microsoft.Security#CA2108;+!Microsoft.Security#CA2107;+!Microsoft.Security#CA2103;+!Microsoft.Security#CA2118;+!Microsoft.Security#CA2109;+!Microsoft.Security#CA2119;+!Microsoft.Security#CA2106;+!Microsoft.Security#CA2112;+!Microsoft.Security#CA2120;+!Microsoft.Security#CA2121;+!Microsoft.Security#CA2126;+!Microsoft.Security#CA2124;+!Microsoft.Security#CA2127;+!Microsoft.Security#CA2128;+!Microsoft.Security#CA2129;-!Microsoft.Usage#CA2243;-!Microsoft.Usage#CA2236;-!Microsoft.Usage#CA1816;-!Microsoft.Usage#CA2227;-!Microsoft.Usage#CA2213;-!Microsoft.Usage#CA2216;-!Microsoft.Usage#CA2214;-!Microsoft.Usage#CA2222;-!Microsoft.Usage#CA1806;-!Microsoft.Usage#CA2217;-!Microsoft.Usage#CA2212;-!Microsoft.Usage#CA2219;-!Microsoft.Usage#CA2201;-!Microsoft.Usage#CA2228;-!Microsoft.Usage#CA2221;-!Microsoft.Usage#CA2220;-!Microsoft.Usage#CA2240;-!Microsoft.Usage#CA2229;-!Microsoft.Usage#CA2238;-!Microsoft.Usage#CA2207;-!Microsoft.Usage#CA2208;-!Microsoft.Usage#CA2235;-!Microsoft.Usage#CA2237;-!Microsoft.Usage#CA2232;-!Microsoft.Usage#CA2223;-!Microsoft.Usage#CA2211;-!Microsoft.Usage#CA2233;-!Microsoft.Usage#CA2225;-!Microsoft.Usage#CA2226;-!Microsoft.Usage#CA2231;-!Microsoft.Usage#CA2224;-!Microsoft.Usage#CA2218;-!Microsoft.Usage#CA2234;-!Microsoft.Usage#CA2239;-!Microsoft.Usage#CA2200;-!Microsoft.Usage#CA1801;-!Microsoft.Usage#CA2242;-!Microsoft.Usage#CA2205;-!Microsoft.Usage#CA2230 true @@ -176,10 +179,10 @@ - + - - + + @@ -219,7 +222,7 @@ - + @@ -251,8 +254,8 @@ - - + + @@ -339,7 +342,6 @@ - @@ -359,7 +361,7 @@ - + @@ -377,8 +379,9 @@ + - + diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Attributes.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Attributes.cs index c89d4744bd..ec4448983a 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Attributes.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Attributes.cs @@ -307,6 +307,23 @@ public sealed class UndefineMethodAttribute : Attribute { } } + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)] + public sealed class AliasMethodAttribute : Attribute { + private readonly string/*!*/ _oldName, _newName; + private bool _isStatic; + + public string/*!*/ NewName { get { return _newName; } } + public string/*!*/ OldName { get { return _oldName; } } + public bool IsStatic { get { return _isStatic; } set { _isStatic = value; } } + + public AliasMethodAttribute(string/*!*/ newName, string/*!*/ oldName) { + ContractUtils.RequiresNotNull(newName, "newName"); + ContractUtils.RequiresNotNull(oldName, "oldName"); + _newName = newName; + _oldName = oldName; + } + } + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class RubyStackTraceHiddenAttribute : Attribute { } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/BinaryContentProvider.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/BinaryContentProvider.cs index 74678775ee..a710947585 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/BinaryContentProvider.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/BinaryContentProvider.cs @@ -1,9 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Text; +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System.IO; using Microsoft.Scripting; using Microsoft.Scripting.Utils; -using System.IO; namespace IronRuby.Runtime { internal sealed class BinaryContentProvider : StreamContentProvider { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/CallSiteStorages.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/CallSiteStorages.cs index 4cb488ed02..0da03acbf6 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/CallSiteStorages.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/CallSiteStorages.cs @@ -14,25 +14,12 @@ * ***************************************************************************/ using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq.Expressions; -using System.Reflection; -using System.Runtime.Serialization; -using System.Text; -using System.Threading; -using Microsoft.Scripting; -using Microsoft.Scripting.Actions; -using Microsoft.Scripting.Runtime; -using Microsoft.Scripting.Utils; -using IronRuby.Builtins; -using IronRuby.Compiler; -using IronRuby.Runtime.Calls; -using System.Dynamic; -using Microsoft.Scripting.Math; using System.Runtime.CompilerServices; -using Microsoft.Scripting.Generation; using IronRuby.Compiler.Generation; +using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; +using Microsoft.Scripting; +using Microsoft.Scripting.Utils; namespace IronRuby.Runtime { @@ -98,5 +85,10 @@ public sealed class ConversionStorage : CallSiteStorage>/*!*/ GetSite(RubyConversionAction/*!*/ conversion) { return RubyUtils.GetCallSite(ref Site, conversion); } + + internal CallSite>/*!*/ GetDefaultConversionSite() { + return RubyUtils.GetCallSite(ref Site, ProtocolConversionAction.GetConversionAction(Context, typeof(TResult), true)); + + } } } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs index 32276e9eb9..db4a357657 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs @@ -596,6 +596,16 @@ public Convert(RubyContext/*!*/ context, Type/*!*/ type, bool isExplicit) ); } + public static DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, ConvertBinder/*!*/ binder, + DynamicMetaObject/*!*/ target, Func/*!*/ fallback) { + + // TODO: + return null; + //return InvokeMember.Bind(context, RubyUtils.MapOperator(binder.Operation), _CallInfo, binder, target, new[] { arg }, + // (trgt, args) => fallback(trgt, args[0]) + //); + } + public override string/*!*/ ToString() { return String.Format("Interop.Convert({0}, {1}){2}", Type.Name, diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs index 22bb43fcb4..45d0fe5a12 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs @@ -21,6 +21,7 @@ using Microsoft.Scripting.Utils; using System.Threading; using System.Diagnostics; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime.Calls { public sealed class RubyBinder : DefaultBinder { @@ -46,7 +47,7 @@ internal RubyBinder(RubyContext/*!*/ context) } public override bool CanConvertFrom(Type/*!*/ fromType, Type/*!*/ toType, bool toNotNullable, NarrowingLevel level) { - return Converter.CanConvertFrom(fromType, toType, level, true); + return Converter.CanConvertFrom(null, fromType, toType, toNotNullable, level, false, false); } public override Candidate PreferConvert(Type t1, Type t2) { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyFieldInfo.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyFieldInfo.cs index 42b1110d6d..06de4bb2fe 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyFieldInfo.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyFieldInfo.cs @@ -22,6 +22,7 @@ using IronRuby.Builtins; using IronRuby.Compiler; using AstUtils = Microsoft.Scripting.Ast.Utils; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime.Calls { using Ast = System.Linq.Expressions.Expression; diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaBinderFactory.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaBinderFactory.cs index 6b49bb2ff4..5aa177ff74 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaBinderFactory.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaBinderFactory.cs @@ -4,6 +4,7 @@ using Microsoft.Scripting.Utils; using System.Threading; using System.Dynamic; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime.Calls { internal sealed class RubyMetaBinderFactory { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaObject.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaObject.cs index 23cc46fe8a..95fa2595b8 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaObject.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMetaObject.cs @@ -29,7 +29,7 @@ namespace IronRuby.Runtime.Calls { using Ast = System.Linq.Expressions.Expression; - interface IRubyDynamicMetaObjectProvider : IDynamicMetaObjectProvider { + public interface IRubyDynamicMetaObjectProvider : IDynamicMetaObjectProvider { } public abstract class RubyMetaObject : DynamicMetaObject { @@ -72,6 +72,11 @@ internal RubyMetaObject(Expression/*!*/ expression, BindingRestrictions/*!*/ res public override DynamicMetaObject/*!*/ BindBinaryOperation(BinaryOperationBinder/*!*/ binder, DynamicMetaObject/*!*/ arg) { return InteropBinder.BinaryOperation.Bind(CreateMetaContext(), binder, this, arg, binder.FallbackBinaryOperation); } + + // TODO: + //public override DynamicMetaObject/*!*/ BindConvert(ConvertBinder/*!*/ binder) { + // return InteropBinder.Convert.Bind(CreateMetaContext(), binder, this, binder.FallbackConvert); + //} } public abstract class RubyMetaObject : RubyMetaObject { diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyOverloadResolver.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyOverloadResolver.cs index cfbb1acb8a..93e6873966 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyOverloadResolver.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyOverloadResolver.cs @@ -23,6 +23,7 @@ using System.Text; using IronRuby.Builtins; using IronRuby.Compiler; +using IronRuby.Runtime.Conversions; using Microsoft.Scripting.Actions.Calls; using Microsoft.Scripting.Generation; using Microsoft.Scripting.Runtime; @@ -38,14 +39,11 @@ internal sealed class RubyOverloadResolver : OverloadResolver { // // We want to perform Ruby protocol conversions when binding to CLR methods. - // However, Ruby some libraries don't allow protocol conversions on their parameters. + // However, some Ruby libraries don't allow protocol conversions on their parameters. // Hence in libraries protocol conversions should only be performed when DefaultProtocol attribute is present. // This flag is set if protocol conversions should be applied on all parameters regardless of DefaultProtocol attribute. - // - // Note that using DefaultProtocol explicitly is not the same as performing implicit protocol conversions. - // A parameter marked with DP is treated as accepting any type of object for overload resolution purposes. - // On the other hand, implicit protocol conversions are only applied on narrowing level 2. Hence the overload resolution - // uses the real parameter types in first 2 steps and only then falls back to dynamic conversions. + // This also implies a different narrowing level of the protocol conversions for library methods and other CLR methods + // (see Converter.CanConvertFrom). // private readonly bool _implicitProtocolConversions; @@ -416,85 +414,70 @@ internal sealed class RubyOverloadResolver : OverloadResolver { #region Step 4: Argument Building, Conversions - public override bool CanConvertFrom(Type/*!*/ fromType, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) { - Type toType = toParameter.Type; - - if (toType == fromType) { - return true; - } - - if (fromType == typeof(DynamicNull)) { - if (toParameter.ProhibitNull) { - return false; - } - - if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { - return true; - } - - if (!toType.IsValueType) { - return true; - } - } - - // blocks: - if (fromType == typeof(MissingBlockParam)) { - return toType == typeof(BlockParam) && !toParameter.ProhibitNull; - } - - if (fromType == typeof(BlockParam) && toType == typeof(MissingBlockParam)) { - return true; - } - - // protocol conversions: - if (toParameter.ParameterInfo != null && toParameter.ParameterInfo.IsDefined(typeof(DefaultProtocolAttribute), false) && - // default protocol doesn't apply on param-array/dict itself, only on the expanded parameters: - !toParameter.IsParamsArray) { - - // any type is potentially convertible, except for nil if [NotNull] is used or the target type is a value type: - return fromType != typeof(DynamicNull) || !(toParameter.ProhibitNull || toType.IsValueType); - } + /// + /// Returns true if fromArg of type fromType can be assigned to toParameter with a conversion on given narrowing level. + /// + public override bool CanConvertFrom(Type/*!*/ fromType, DynamicMetaObject fromArg, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) { + return Converter.CanConvertFrom(fromArg, fromType, toParameter.Type, toParameter.ProhibitNull, level, + HasExplicitProtocolConversion(toParameter), _implicitProtocolConversions + ); + } - if (Converter.CanConvertFrom(fromType, toType, level, _implicitProtocolConversions)) { - return true; - } + public override bool CanConvertFrom(ParameterWrapper/*!*/ fromParameter, ParameterWrapper/*!*/ toParameter) { + return Converter.CanConvertFrom(null, fromParameter.Type, toParameter.Type, toParameter.ProhibitNull, NarrowingLevel.None, false, false); + } - return false; + private bool HasExplicitProtocolConversion(ParameterWrapper/*!*/ parameter) { + return + parameter.ParameterInfo != null && + parameter.ParameterInfo.IsDefined(typeof(DefaultProtocolAttribute), false) && + !parameter.IsParamsArray; // default protocol doesn't apply on param-array/dict itself, only on the expanded parameters } - public override Candidate SelectBestConversionFor(Type/*!*/ actualType, ParameterWrapper/*!*/ candidateOne, ParameterWrapper/*!*/ candidateTwo, NarrowingLevel level) { + public override Candidate SelectBestConversionFor(DynamicMetaObject/*!*/ arg, ParameterWrapper/*!*/ candidateOne, + ParameterWrapper/*!*/ candidateTwo, NarrowingLevel level) { + Type typeOne = candidateOne.Type; Type typeTwo = candidateTwo.Type; + Type actualType = arg.GetLimitType(); + // if nil is passed as a block argument prefer BlockParam over missing block: if (actualType == typeof(DynamicNull)) { - // if nil is passed as a block argument prefer BlockParam over missing block; if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) { + Debug.Assert(!candidateOne.ProhibitNull); return Candidate.One; } if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) { + Debug.Assert(!candidateTwo.ProhibitNull); return Candidate.Two; } - } else { - if (actualType == typeOne && candidateOne.ProhibitNull) { + } else if (actualType == typeof(MissingBlockParam)) { + if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) { + return Candidate.Two; + } + + if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) { + return Candidate.One; + } + } else if (actualType == typeof(BlockParam)) { + if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) { return Candidate.One; } - if (actualType == typeTwo && candidateTwo.ProhibitNull) { + if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) { return Candidate.Two; } - } - if (actualType == typeOne) { - return Candidate.One; - } - - if (actualType == typeTwo) { - return Candidate.Two; + if (typeOne == typeof(BlockParam) && typeTwo == typeof(BlockParam)) { + if (candidateOne.ProhibitNull) { + return Candidate.One; + } else if (candidateTwo.ProhibitNull) { + return Candidate.Two; + } + } } - - - return Candidate.Equivalent; + return base.SelectBestConversionFor(arg, candidateOne, candidateTwo, level); } public override Expression/*!*/ Convert(DynamicMetaObject/*!*/ metaObject, Type restrictedType, ParameterInfo info, Type/*!*/ toType) { @@ -519,7 +502,8 @@ internal sealed class RubyOverloadResolver : OverloadResolver { return Ast.Dynamic(action, toType, expr); } - throw new InvalidOperationException(String.Format("No default protocol conversion for type {0}.", toType)); + // Do not throw an exception here to allow generic type parameters to be used with D.P. attribute. + // The semantics should be to use DP if available for the current instantiation and ignore it otherwise. } if (restrictedType != null) { @@ -538,7 +522,7 @@ internal sealed class RubyOverloadResolver : OverloadResolver { // if there is a simple conversion from restricted type, convert the expression to the restricted type and use that conversion: Type visibleRestrictedType = CompilerHelpers.GetVisibleType(restrictedType); - if (Converter.CanConvertFrom(visibleRestrictedType, toType, NarrowingLevel.One, false)) { + if (Converter.CanConvertFrom(metaObject, visibleRestrictedType, toType, false, NarrowingLevel.None, false, false)) { expr = AstUtils.Convert(expr, visibleRestrictedType); } } @@ -765,9 +749,18 @@ public MissingBlockArgBuilder(int index) return Methods.CreateArgumentsErrorForMissingBlock.OpCall(); } + string toType; + if (cr.To.IsGenericType && cr.To.GetGenericTypeDefinition() == typeof(Union<,>)) { + var g = cr.To.GetGenericArguments(); + toType = Binder.GetTypeName(g[0]) + " or " + Binder.GetTypeName(g[1]); + } else { + toType = Binder.GetTypeName(cr.To); + } + return Methods.CreateTypeConversionError.OpCall( - AstUtils.Constant(cr.GetArgumentTypeName(Binder)), - AstUtils.Constant(Binder.GetTypeName(cr.To))); + AstUtils.Constant(cr.GetArgumentTypeName(Binder)), + AstUtils.Constant(toType) + ); } } break; diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/CompositeConversionAction.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/CompositeConversionAction.cs similarity index 98% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/CompositeConversionAction.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/CompositeConversionAction.cs index 0626df21d2..7090f8adf8 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/CompositeConversionAction.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/CompositeConversionAction.cs @@ -24,8 +24,9 @@ using Ast = System.Linq.Expressions.Expression; using System.Diagnostics; using AstUtils = Microsoft.Scripting.Ast.Utils; +using IronRuby.Runtime.Calls; -namespace IronRuby.Runtime.Calls { +namespace IronRuby.Runtime.Conversions { public enum CompositeConversion { ToFixnumToStr, ToStrToFixnum, diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ConvertToSAction.cs similarity index 98% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ConvertToSAction.cs index 1a6cb6c5bd..f6d9d28c46 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ConvertToSAction.cs @@ -26,8 +26,9 @@ using System.Reflection; using System.Diagnostics; using System.Collections.Generic; +using IronRuby.Runtime.Calls; -namespace IronRuby.Runtime.Calls { +namespace IronRuby.Runtime.Conversions { // 1) implicit conversion to MutableString // 2) calls to_s diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.Generated.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.Generated.cs similarity index 99% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.Generated.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.Generated.cs index 71f2915ee7..85e8674906 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.Generated.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.Generated.cs @@ -16,7 +16,7 @@ using System; using Microsoft.Scripting.Math; -namespace IronRuby.Runtime { +namespace IronRuby.Runtime.Conversions { internal enum NumericTypeCode { Invalid = 0, diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.Generator.rb b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.Generator.rb similarity index 100% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.Generator.rb rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.Generator.rb diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.cs similarity index 77% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.cs index 2afbe4a63e..b64eb31d35 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Converter.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/Converter.cs @@ -26,17 +26,54 @@ using Microsoft.Scripting.Utils; using Ast = System.Linq.Expressions.Expression; using AstUtils = Microsoft.Scripting.Ast.Utils; +using Microsoft.Scripting.Runtime; -namespace IronRuby.Runtime { +namespace IronRuby.Runtime.Conversions { internal static partial class Converter { - internal static bool CanConvertFrom(Type/*!*/ fromType, Type/*!*/ toType, NarrowingLevel level, bool implicitProtocolConversions) { + internal static bool CanConvertFrom(DynamicMetaObject fromArg, Type/*!*/ fromType, Type/*!*/ toType, bool toNotNullable, + NarrowingLevel level, bool explicitProtocolConversions, bool implicitProtocolConversions) { ContractUtils.RequiresNotNull(fromType, "fromType"); ContractUtils.RequiresNotNull(toType, "toType"); + var metaConvertible = fromArg as IConvertibleMetaObject; + // // narrowing level 0: // + if (toType == fromType) { + return true; + } + + if (fromType == typeof(DynamicNull)) { + if (toNotNullable) { + return false; + } + + if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { + return true; + } + + if (!toType.IsValueType) { + // null convertible to any reference type: + return true; + } else if (toType == typeof(bool)) { + return true; + } else if (!ProtocolConversionAction.HasDefaultConversion(toType)) { + // null not convertible to a value type unless a protocol conversion is allowed: + return false; + } + } + + // blocks: + if (fromType == typeof(MissingBlockParam)) { + return toType == typeof(BlockParam) && !toNotNullable; + } + + if (fromType == typeof(BlockParam) && toType == typeof(MissingBlockParam)) { + return true; + } + if (toType.IsAssignableFrom(fromType)) { return true; } @@ -54,6 +91,10 @@ internal static partial class Converter { return true; } + if (metaConvertible != null) { + return metaConvertible.CanConvertTo(toType, false); + } + // // narrowing level 1: // @@ -62,6 +103,18 @@ internal static partial class Converter { return false; } + if (explicitProtocolConversions && ProtocolConversionAction.HasDefaultConversion(toType)) { + return true; + } + + // + // narrowing level 2: + // + + if (level < NarrowingLevel.Two) { + return false; + } + if (HasExplicitNumericConversion(fromType, toType)) { return true; } @@ -82,36 +135,31 @@ internal static partial class Converter { return true; } - // - // narrowing level 2: - // + if (metaConvertible != null) { + return metaConvertible.CanConvertTo(toType, true); + } - if (level < NarrowingLevel.Two) { + // + // narrowing level 3: + // + + if (level < NarrowingLevel.Three) { return false; } - // we can convert any object to any type for which we have a default protocol: if (implicitProtocolConversions && ProtocolConversionAction.HasDefaultConversion(toType)) { return true; } - // any dynamic object is potentially convertible to any type: - if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(fromType)) { - return true; - } - return false; } - internal static Expression ConvertExpression(Expression/*!*/ expr, Type/*!*/ toType, RubyContext/*!*/ context, Expression/*!*/ contextExpression, + internal static Expression/*!*/ ConvertExpression(Expression/*!*/ expr, Type/*!*/ toType, RubyContext/*!*/ context, Expression/*!*/ contextExpression, bool implicitProtocolConversions) { return - // narrowing level 0: ImplicitConvert(expr, expr.Type, toType) ?? - // narrowing level 1: ExplicitConvert(expr, expr.Type, toType) ?? - // narrowing level 2: Ast.Dynamic(ProtocolConversionAction.GetConversionAction(context, toType, implicitProtocolConversions), toType, expr); } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/GenericConversionAction.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/GenericConversionAction.cs similarity index 90% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/GenericConversionAction.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/GenericConversionAction.cs index 3744b95bce..6674f13eb2 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/GenericConversionAction.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/GenericConversionAction.cs @@ -24,8 +24,9 @@ using IronRuby.Compiler.Generation; using System.Linq.Expressions; using System.Diagnostics; +using IronRuby.Runtime.Calls; -namespace IronRuby.Runtime.Calls { +namespace IronRuby.Runtime.Conversions { public sealed class GenericConversionAction : RubyConversionAction { private readonly Type/*!*/ _type; @@ -86,6 +87,7 @@ internal GenericConversionAction(RubyContext context, Type/*!*/ type) } internal bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { + // TODO: include this into ImplicitConvert? if (args.Target == null) { if (!_type.IsValueType || _type.IsGenericType && _type.GetGenericTypeDefinition() == typeof(Nullable<>)) { metaBuilder.Result = AstUtils.Constant(null, _type); @@ -95,12 +97,11 @@ internal GenericConversionAction(RubyContext context, Type/*!*/ type) } } - if (_type.IsAssignableFrom(args.Target.GetType())) { - metaBuilder.Result = Ast.Convert(args.MetaTarget.Expression, _type); - return true; - } - - return false; + Type fromType = args.Target.GetType(); + return null != (metaBuilder.Result = + Converter.ImplicitConvert(args.TargetExpression, fromType, _type) ?? + Converter.ExplicitConvert(args.TargetExpression, fromType, _type) + ); } } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ProtocolConversionAction.cs similarity index 99% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ProtocolConversionAction.cs index 9d096aef98..df7e95bbaa 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Conversions/ProtocolConversionAction.cs @@ -31,8 +31,9 @@ using AstFactory = IronRuby.Compiler.Ast.AstFactory; using AstUtils = Microsoft.Scripting.Ast.Utils; using Microsoft.Scripting.Generation; +using IronRuby.Runtime.Calls; -namespace IronRuby.Runtime.Calls { +namespace IronRuby.Runtime.Conversions { public abstract class RubyConversionAction : RubyMetaBinder { protected RubyConversionAction() : base(null) { @@ -345,7 +346,7 @@ public abstract class ConvertToReferenceTypeAction : Protoco internal static bool TryImplicitConversionInternal(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { if (args.Target == null) { - metaBuilder.Result = AstUtils.Constant(null); + metaBuilder.Result = AstUtils.Constant(null, typeof(TTargetType)); return true; } diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs index af0dfc8170..b100640929 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs @@ -28,6 +28,7 @@ using Microsoft.Scripting; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime { [Flags] diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Protocols.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Protocols.cs index fd6d0d55c5..d73dce074c 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/Protocols.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/Protocols.cs @@ -26,6 +26,7 @@ using IronRuby.Builtins; using IronRuby.Runtime.Calls; using IronRuby.Compiler; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime { /// diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyCallTargets.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyCallTargets.cs deleted file mode 100644 index d6427881ee..0000000000 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyCallTargets.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* **************************************************************************** - * - * Copyright (c) Microsoft Corporation. - * - * This source code is subject to terms and conditions of the Microsoft Public License. A - * copy of the license can be found in the License.html file at the root of this distribution. If - * you cannot locate the Microsoft Public License, please send an email to - * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - * by the terms of the Microsoft Public License. - * - * You must not remove this notice, or any other, from this software. - * - * - * ***************************************************************************/ - -using System; -using Microsoft.Scripting; -using Microsoft.Scripting.Utils; - -namespace IronRuby.Runtime { - // - // Ruby call targets - // - - /// - /// The delegate representing the Ruby code entry point - /// - public delegate object RubyMainDelegate(); - - /// - /// Generic delegate type for block with >RubyCallTargets.MaxSignatureSize parameters - /// - public delegate object RubyCallTargetN(params object[] args); - - static class RubyCallTargets { - - internal const int MaxSignatureSize = 10; - - internal static Type GetDelegateType(Type[] arguments, Type returnType) { - Assert.NotNull(arguments, returnType); - Type result; - - if (returnType == typeof(void)) { - switch (arguments.Length) { - case 0: return typeof(Action); - case 1: result = typeof(Action<>); break; - case 2: result = typeof(Action<,>); break; - case 3: result = typeof(Action<,,>); break; - case 4: result = typeof(Action<,,,>); break; - case 5: result = typeof(Action<,,,,>); break; - case 6: result = typeof(Action<,,,,,>); break; - case 7: result = typeof(Action<,,,,,,>); break; - case 8: result = typeof(Action<,,,,,,,>); break; - case 9: result = typeof(Action<,,,,,,,,>); break; - case 10: result = typeof(Action<,,,,,,,,,>); break; - default: - throw new NotImplementedException("Action delegate not implemented for " + arguments.Length + " arguments."); - } - } else { - arguments = ArrayUtils.Append(arguments, returnType); - switch (arguments.Length) { - case 0: throw Assert.Unreachable; - case 1: result = typeof(Func<>); break; - case 2: result = typeof(Func<,>); break; - case 3: result = typeof(Func<,,>); break; - case 4: result = typeof(Func<,,,>); break; - case 5: result = typeof(Func<,,,,>); break; - case 6: result = typeof(Func<,,,,,>); break; - case 7: result = typeof(Func<,,,,,,>); break; - case 8: result = typeof(Func<,,,,,,,>); break; - case 9: result = typeof(Func<,,,,,,,,>); break; - case 10: result = typeof(Func<,,,,,,,,,>); break; - case 11: result = typeof(Func<,,,,,,,,,,>); break; - default: - throw new NotImplementedException("Function delegate not implemented for " + arguments.Length + " arguments."); - } - } - - return result.MakeGenericType(arguments); - } - - } -} diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs index 5a29225690..7566ee8c24 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs @@ -16,22 +16,22 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Dynamic; using System.IO; using System.Runtime.CompilerServices; -using System.Dynamic; using System.Security; using System.Text; using System.Threading; using IronRuby.Builtins; using IronRuby.Compiler; +using IronRuby.Compiler.Ast; using IronRuby.Compiler.Generation; using IronRuby.Runtime.Calls; +using IronRuby.Runtime.Conversions; using Microsoft.Scripting; using Microsoft.Scripting.Actions; -using Microsoft.Scripting.Generation; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; -using IronRuby.Compiler.Ast; using MSA = System.Linq.Expressions; namespace IronRuby.Runtime { @@ -718,7 +718,16 @@ public RubyContext(ScriptDomainManager/*!*/ manager, IDictionary } TypeTracker tracker = (TypeTracker)TypeTracker.FromMemberInfo(interfaceType); - result = CreateModule(GetQualifiedNameNoLock(interfaceType), null, null, null, null, null, tracker, ModuleRestrictions.None); + + RubyModule[] mixins; + if (interfaceType.IsGenericType && !interfaceType.IsGenericTypeDefinition) { + // I mixes in its generic definition I<,..,> + mixins = new[] { GetOrCreateModuleNoLock(interfaceType.GetGenericTypeDefinition()) }; + } else { + mixins = null; + } + + result = CreateModule(GetQualifiedNameNoLock(interfaceType), null, null, null, mixins, null, tracker, ModuleRestrictions.None); _moduleCache[interfaceType] = result; return result; } @@ -731,7 +740,15 @@ public RubyContext(ScriptDomainManager/*!*/ manager, IDictionary return result; } - RubyClass baseClass = GetOrCreateClassNoLock(type.BaseType); + RubyClass baseClass; + + if (type.IsGenericType && !type.IsGenericTypeDefinition) { + // C's super class is its generic definition C<,..,> + baseClass = GetOrCreateClassNoLock(type.GetGenericTypeDefinition()); + } else { + baseClass = GetOrCreateClassNoLock(type.BaseType); + } + TypeTracker tracker = (TypeTracker)TypeTracker.FromMemberInfo(type); RubyModule[] interfaceMixins = GetDeclaredInterfaceModulesNoLock(type); RubyModule[] expandedMixins; diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RuntimeFlowControl.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.FlowControl.cs similarity index 100% rename from Merlin/Main/Languages/Ruby/Ruby/Runtime/RuntimeFlowControl.cs rename to Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.FlowControl.cs diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs index 6744f3e462..0cc3852ce1 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs @@ -34,6 +34,7 @@ using Microsoft.Scripting.Utils; using IronRuby.Compiler.Ast; using MSA = System.Linq.Expressions; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime { [ReflectionCached, CLSCompliant(false)] @@ -849,70 +850,70 @@ public static partial class RubyOps { #region CLR Vectors (factories mimic Ruby Array factories) [Emitted, RubyConstructor] - public static object/*!*/ CreateVector(ConversionStorage>/*!*/ toAryToInt, BlockParam block, RubyClass/*!*/ self, - [NotNull]object/*!*/ arrayOrSize) { + public static object/*!*/ CreateVector( + ConversionStorage/*!*/ elementConversion, + ConversionStorage>/*!*/ toAryToInt, + BlockParam block, RubyClass/*!*/ self, [NotNull]object/*!*/ arrayOrSize) { - var elementType = self.GetUnderlyingSystemType().GetElementType(); - Debug.Assert(elementType != null); + Debug.Assert(typeof(TElement) == self.GetUnderlyingSystemType().GetElementType()); var site = toAryToInt.GetSite(CompositeConversionAction.Make(self.Context, CompositeConversion.ToAryToInt)); var union = site.Target(site, arrayOrSize); if (union.First != null) { // block ignored - return CreateVectorInternal(self.Context, elementType, union.First); + return CreateVectorInternal(elementConversion, union.First); } else if (block != null) { - return PopulateVector(self.Context, CreateVectorInternal(elementType, union.Second), block); + return PopulateVector(elementConversion, CreateVectorInternal(union.Second), block); } else { - return CreateVectorInternal(elementType, union.Second); + return CreateVectorInternal(union.Second); } } [Emitted, RubyConstructor] - public static Array/*!*/ CreateVectorWithValues(RubyClass/*!*/ self, [DefaultProtocol]int size, object value) { - var elementType = self.GetUnderlyingSystemType().GetElementType(); - Debug.Assert(elementType != null); + public static Array/*!*/ CreateVectorWithValues(ConversionStorage/*!*/ elementConversion, + RubyClass/*!*/ self, [DefaultProtocol]int size, [DefaultProtocol]TElement value) { + Debug.Assert(typeof(TElement) == self.GetUnderlyingSystemType().GetElementType()); - var result = CreateVectorInternal(elementType, size); - for (int i = 0; i < size; i++) { - SetVectorItem(self.Context, result, i, value); + TElement[] result = CreateVectorInternal(size); + for (int i = 0; i < result.Length; i++) { + result[i] = value; } return result; } - public static Array/*!*/ CreateVectorInternal(Type/*!*/ elementType, int size) { + private static TElement[]/*!*/ CreateVectorInternal(int size) { if (size < 0) { throw RubyExceptions.CreateArgumentError("negative array size"); } - return Array.CreateInstance(elementType, size); + return new TElement[size]; } - private static Array/*!*/ CreateVectorInternal(RubyContext/*!*/ context, Type/*!*/ elementType, IList/*!*/ list) { - var result = Array.CreateInstance(elementType, list.Count); + private static Array/*!*/ CreateVectorInternal(ConversionStorage/*!*/ elementConversion, IList/*!*/ list) { + var site = elementConversion.GetDefaultConversionSite(); + + var result = new TElement[list.Count]; for (int i = 0; i < result.Length; i++) { - SetVectorItem(context, result, i, list[i]); + result[i] = site.Target(site, list[i]); } return result; } - private static object PopulateVector(RubyContext/*!*/ context, Array/*!*/ array, BlockParam/*!*/ block) { + private static object PopulateVector(ConversionStorage/*!*/ elementConversion, TElement[]/*!*/ array, BlockParam/*!*/ block) { + var site = elementConversion.GetDefaultConversionSite(); + for (int i = 0; i < array.Length; i++) { object item; if (block.Yield(i, out item)) { return item; } - SetVectorItem(context, array, i, item); + array[i] = site.Target(site, item); } return array; } - private static void SetVectorItem(RubyContext/*!*/ context, Array/*!*/ array, int index, object value) { - // TODO: convert to the element type: - array.SetValue(value, index); - } - #endregion #region Global Variables diff --git a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs index 58dce126af..98c2879ce5 100644 --- a/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs +++ b/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs @@ -30,6 +30,7 @@ using Microsoft.Scripting.Math; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime { using EvalEntryPointDelegate = Func; diff --git a/Merlin/Main/Languages/Ruby/Ruby4.sln b/Merlin/Main/Languages/Ruby/Ruby4.sln new file mode 100644 index 0000000000..6648d5e54b --- /dev/null +++ b/Merlin/Main/Languages/Ruby/Ruby4.sln @@ -0,0 +1,208 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 10 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Tests", "IronRuby.Tests\IronRuby.Tests.csproj", "{8103D91B-89D8-4A18-9A40-426992602EA2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ruby", "Ruby\Ruby.csproj", "{7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ruby.Console", "Console\Ruby.Console.csproj", "{D6AB587D-A888-4B98-85AC-F15E36F53838}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassInitGenerator", "ClassInitGenerator\ClassInitGenerator.csproj", "{166940A1-2C91-4BD0-B72B-A517FBD8BF0B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting.Core", "..\..\..\..\ndp\fx\src\Core\Microsoft\Scripting\Microsoft.Scripting.Core.csproj", "{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Dynamic", "..\..\..\..\ndp\fx\src\Dynamic\System\Dynamic\Microsoft.Dynamic.csproj", "{D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries", "Libraries.LCA_RESTRICTED\IronRuby.Libraries.csproj", "{77323B06-15A2-4CF4-8A7A-86EAA2B66498}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting", "..\..\Runtime\Microsoft.Scripting\Microsoft.Scripting.csproj", "{EB66B766-6354-4208-A3D4-AACBDCB5C3B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronRuby.Libraries.Yaml", "..\..\..\External.LCA_RESTRICTED\Languages\IronRuby\yaml\IronRuby.Libraries.Yaml\IronRuby.Libraries.Yaml.csproj", "{AA18A245-E342-4368-A474-83178311A742}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting.ExtensionAttribute", "..\..\..\..\ndp\fx\src\Core\Microsoft\Scripting\Microsoft.Scripting.ExtensionAttribute.csproj", "{8B0F1074-750E-4D64-BF23-A1E0F54261E5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A6B6A5B5-335A-4515-8535-954DE8A953EF}" + ProjectSection(SolutionItems) = preProject + Scripts\CodeGenerator.rb = Scripts\CodeGenerator.rb + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RubySpec", "Tests\RubySpec\RubySpec.csproj", "{534A82C6-3EB0-4888-ABD2-A15284683E8D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ruby.ConsoleAny", "Console\Ruby.ConsoleAny.csproj", "{6EE7A428-D803-41BC-8248-1297C3ACE369}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Scripting.Debugging", "..\..\Debugging\Microsoft.Scripting.Debugging\Microsoft.Scripting.Debugging.csproj", "{ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}" +EndProject +Global + GlobalSection(TeamFoundationVersionControl) = preSolution + SccNumberOfProjects = 14 + SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} + SccTeamFoundationServer = http://vstfdevdiv:8080/ + SccLocalPath0 = . + SccProjectUniqueName1 = IronRuby.Tests\\IronRuby.Tests.csproj + SccProjectName1 = IronRuby.Tests + SccLocalPath1 = IronRuby.Tests + SccProjectUniqueName2 = Ruby\\Ruby.csproj + SccProjectName2 = Ruby + SccLocalPath2 = Ruby + SccProjectUniqueName3 = Console\\Ruby.Console.csproj + SccProjectName3 = Console + SccLocalPath3 = Console + SccProjectUniqueName4 = ClassInitGenerator\\ClassInitGenerator.csproj + SccProjectName4 = ClassInitGenerator + SccLocalPath4 = ClassInitGenerator + SccProjectUniqueName5 = Libraries.LCA_RESTRICTED\\IronRuby.Libraries.csproj + SccProjectName5 = Libraries.LCA_RESTRICTED + SccLocalPath5 = Libraries.LCA_RESTRICTED + SccProjectUniqueName6 = ..\\..\\Runtime\\Microsoft.Scripting\\Microsoft.Scripting.csproj + SccProjectName6 = ../../Runtime/Microsoft.Scripting + SccLocalPath6 = ..\\..\\Runtime\\Microsoft.Scripting + SccProjectUniqueName7 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting\\Microsoft.Scripting.Core.csproj + SccProjectName7 = ../../../../ndp/fx/src/Core/Microsoft/Scripting + SccLocalPath7 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting + SccProjectUniqueName8 = ..\\..\\..\\External.LCA_RESTRICTED\\Languages\\IronRuby\\yaml\\IronRuby.Libraries.Yaml\\IronRuby.Libraries.Yaml.csproj + SccProjectName8 = ../../../External.LCA_RESTRICTED/Languages/IronRuby/yaml/IronRuby.Libraries.Yaml + SccLocalPath8 = ..\\..\\..\\External.LCA_RESTRICTED\\Languages\\IronRuby\\yaml\\IronRuby.Libraries.Yaml + SccProjectUniqueName9 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting\\Microsoft.Scripting.ExtensionAttribute.csproj + SccProjectName9 = ../../../../ndp/fx/src/Core/Microsoft/Scripting + SccLocalPath9 = ..\\..\\..\\..\\ndp\\fx\\src\\Core\\Microsoft\\Scripting + SccProjectUniqueName10 = Tests\\RubySpec\\RubySpec.csproj + SccProjectName10 = Tests/RubySpec + SccLocalPath10 = Tests\\RubySpec + SccProjectUniqueName11 = ..\\..\\..\\..\\ndp\\fx\\src\\Dynamic\\System\\Dynamic\\Microsoft.Dynamic.csproj + SccProjectName11 = ../../../../ndp/fx/src/Dynamic/System/Dynamic + SccLocalPath11 = ..\\..\\..\\..\\ndp\\fx\\src\\Dynamic\\System\\Dynamic + SccProjectUniqueName12 = Console\\Ruby.ConsoleAny.csproj + SccProjectName12 = Console + SccLocalPath12 = Console + SccProjectUniqueName13 = ..\\..\\Debugging\\Microsoft.Scripting.Debugging\\Microsoft.Scripting.Debugging.csproj + SccProjectName13 = ../../Debugging/Microsoft.Scripting.Debugging + SccLocalPath13 = ..\\..\\Debugging\\Microsoft.Scripting.Debugging + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + FxCop|Any CPU = FxCop|Any CPU + Release|Any CPU = Release|Any CPU + Silverlight Debug|Any CPU = Silverlight Debug|Any CPU + Silverlight Release|Any CPU = Silverlight Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8103D91B-89D8-4A18-9A40-426992602EA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.FxCop|Any CPU.Build.0 = Release|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.Release|Any CPU.Build.0 = Release|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8103D91B-89D8-4A18-9A40-426992602EA2}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.FxCop|Any CPU.Build.0 = FxCop|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Release|Any CPU.Build.0 = Release|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {7F6984B4-EE6D-4E6F-ABB1-E210D7DC4FDD}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.FxCop|Any CPU.Build.0 = Release|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Release|Any CPU.Build.0 = Release|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6AB587D-A888-4B98-85AC-F15E36F53838}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.FxCop|Any CPU.Build.0 = Release|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Release|Any CPU.Build.0 = Release|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {166940A1-2C91-4BD0-B72B-A517FBD8BF0B}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.FxCop|Any CPU.Build.0 = FxCop|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Release|Any CPU.Build.0 = Release|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.FxCop|Any CPU.Build.0 = FxCop|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Release|Any CPU.Build.0 = Release|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.FxCop|Any CPU.Build.0 = Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Release|Any CPU.Build.0 = Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {77323B06-15A2-4CF4-8A7A-86EAA2B66498}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.FxCop|Any CPU.Build.0 = FxCop|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Release|Any CPU.Build.0 = Release|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {EB66B766-6354-4208-A3D4-AACBDCB5C3B3}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.FxCop|Any CPU.Build.0 = Release|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Release|Any CPU.Build.0 = Release|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA18A245-E342-4368-A474-83178311A742}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.FxCop|Any CPU.ActiveCfg = FxCop|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.FxCop|Any CPU.Build.0 = FxCop|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Release|Any CPU.Build.0 = Release|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {8B0F1074-750E-4D64-BF23-A1E0F54261E5}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + {534A82C6-3EB0-4888-ABD2-A15284683E8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {534A82C6-3EB0-4888-ABD2-A15284683E8D}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {534A82C6-3EB0-4888-ABD2-A15284683E8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {534A82C6-3EB0-4888-ABD2-A15284683E8D}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {534A82C6-3EB0-4888-ABD2-A15284683E8D}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.FxCop|Any CPU.ActiveCfg = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.FxCop|Any CPU.Build.0 = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Release|Any CPU.Build.0 = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Debug|Any CPU.Build.0 = Debug|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Release|Any CPU.ActiveCfg = Release|Any CPU + {6EE7A428-D803-41BC-8248-1297C3ACE369}.Silverlight Release|Any CPU.Build.0 = Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.FxCop|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.FxCop|Any CPU.Build.0 = Silverlight Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Release|Any CPU.Build.0 = Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Silverlight Debug|Any CPU.ActiveCfg = Silverlight Debug|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Silverlight Debug|Any CPU.Build.0 = Silverlight Debug|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Silverlight Release|Any CPU.ActiveCfg = Silverlight Release|Any CPU + {ED82A346-1CD9-4CB0-9C00-4CDD4CF577CF}.Silverlight Release|Any CPU.Build.0 = Silverlight Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Merlin/Main/Languages/Ruby/Scripts/Dev.bat b/Merlin/Main/Languages/Ruby/Scripts/Dev.bat index fbd3bd54fa..1ecf147185 100644 --- a/Merlin/Main/Languages/Ruby/Scripts/Dev.bat +++ b/Merlin/Main/Languages/Ruby/Scripts/Dev.bat @@ -42,10 +42,29 @@ if exist "%PROGRAM_FILES_32%\Microsoft.NET\SDK\v2.0\Bin\sdkvars.bat" ( set PATH=%PATH%;%MERLIN_ROOT%\Languages\Ruby\Scripts;%MERLIN_ROOT%\Languages\Ruby\Scripts\bin;%RUBY18_BIN%;%MERLIN_ROOT%\..\External.LCA_RESTRICTED\Languages\IronRuby\mspec\mspec\bin +if not DEFINED HOME_FOR_MSPECRC ( + if DEFINED HOME ( + set HOME_FOR_MSPECRC=%HOME% + goto SetRubyEnv + ) + + if DEFINED HOMEDRIVE ( + if DEFINED HOMEPATH ( + set HOME_FOR_MSPECRC=%HOMEDRIVE%%HOMEPATH% + goto SetRubyEnv + ) + ) + if not DEFINED USERPROFILE ( + echo Error: One of HOME, HOMEDRIVE,HOMEPATH, or USERPROFILE needs to be set + goto END + ) + set HOME_FOR_MSPECRC=%USERPROFILE% +) + :SetRubyEnv -if NOT exist "%HOME%\.mspecrc" ( - copy "%MERLIN_ROOT%\Languages\Ruby\default.mspec" "%HOME%\.mspecrc" +if NOT EXIST "%HOME_FOR_MSPECRC%\.mspecrc" ( + copy "%MERLIN_ROOT%\Languages\Ruby\default.mspec" "%HOME_FOR_MSPECRC%\.mspecrc" ) call doskey /macrofile=%MERLIN_ROOT%\Scripts\Bat\%Alias.txt diff --git a/Merlin/Main/Languages/Ruby/Tests/Interop/net/bcl/array/modification_spec.rb b/Merlin/Main/Languages/Ruby/Tests/Interop/net/bcl/array/modification_spec.rb index 49a1889d16..7f86ed2159 100644 --- a/Merlin/Main/Languages/Ruby/Tests/Interop/net/bcl/array/modification_spec.rb +++ b/Merlin/Main/Languages/Ruby/Tests/Interop/net/bcl/array/modification_spec.rb @@ -6,6 +6,6 @@ end it "doesn't dynamicly resize" do - lambda {@array[10] = 1}.should raise_error(System::NotSupportedException) + lambda {@array[10] = 1}.should raise_error(IndexError) end end diff --git a/Merlin/Main/Languages/Ruby/Tests/RubySpec/RubySpec.csproj b/Merlin/Main/Languages/Ruby/Tests/RubySpec/RubySpec.csproj index b331919ec2..1d0a1cc6e0 100644 --- a/Merlin/Main/Languages/Ruby/Tests/RubySpec/RubySpec.csproj +++ b/Merlin/Main/Languages/Ruby/Tests/RubySpec/RubySpec.csproj @@ -1,16 +1,16 @@  - + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {534A82C6-3EB0-4888-ABD2-A15284683E8D} Exe Properties RubySpec RubySpec - v3.5 + v2.0 512 SAK SAK diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/Actions/Calls/OverloadResolver.cs b/Merlin/Main/Runtime/Microsoft.Scripting/Actions/Calls/OverloadResolver.cs index a24a6641fa..c8eb5ef5de 100644 --- a/Merlin/Main/Runtime/Microsoft.Scripting/Actions/Calls/OverloadResolver.cs +++ b/Merlin/Main/Runtime/Microsoft.Scripting/Actions/Calls/OverloadResolver.cs @@ -363,7 +363,7 @@ public abstract partial class OverloadResolver { return MakeSuccessfulBindingTarget(applicable[0], potential, level, targetSet); } - var bestCandidate = SelectBestCandidate(applicable); + var bestCandidate = SelectBestCandidate(applicable, level); if (bestCandidate != null) { return MakeSuccessfulBindingTarget(bestCandidate, potential, level, targetSet); } else { @@ -472,7 +472,7 @@ public abstract partial class OverloadResolver { bool success = true; for (int i = 0; i < _actualArguments.Count; i++) { - success &= (hasConversion[i] = CanConvertFrom(_actualArguments[i].GetLimitType(), candidate.GetParameter(i, namesBinding), narrowingLevel)); + success &= (hasConversion[i] = CanConvertFrom(_actualArguments[i].GetLimitType(), _actualArguments[i], candidate.GetParameter(i, namesBinding), narrowingLevel)); } if (!success) { @@ -499,7 +499,7 @@ public abstract partial class OverloadResolver { object value = GetCollapsedArgumentValue(i); Type argType = CompilerHelpers.GetType(value); - if (!CanConvertFrom(argType, parameter, narrowingLevel)) { + if (!CanConvertFrom(argType, null, parameter, narrowingLevel)) { failure = new CallFailure(candidate, new[] { new ConversionResult(value, argType, parameter.Type, false) }); return false; } @@ -598,21 +598,21 @@ public abstract partial class OverloadResolver { return false; } - private bool IsBest(ApplicableCandidate candidate, List candidates) { + private bool IsBest(ApplicableCandidate candidate, List candidates, NarrowingLevel level) { foreach (ApplicableCandidate other in candidates) { if (candidate == other) { continue; } - if (GetPreferredCandidate(candidate, other) != Candidate.One) { + if (GetPreferredCandidate(candidate, other, level) != Candidate.One) { return false; } } return true; } - internal Candidate GetPreferredCandidate(ApplicableCandidate one, ApplicableCandidate two) { - Candidate cmpParams = GetPreferredParameters(one, two); + internal Candidate GetPreferredCandidate(ApplicableCandidate one, ApplicableCandidate two, NarrowingLevel level) { + Candidate cmpParams = GetPreferredParameters(one, two, level); if (cmpParams.Chosen()) { return cmpParams; } @@ -692,13 +692,13 @@ public abstract partial class OverloadResolver { return max; } - internal Candidate GetPreferredParameters(ApplicableCandidate one, ApplicableCandidate two) { + private Candidate GetPreferredParameters(ApplicableCandidate one, ApplicableCandidate two, NarrowingLevel level) { Debug.Assert(one.Method.ParameterCount == two.Method.ParameterCount); var args = GetActualArguments(); Candidate result = Candidate.Equivalent; for (int i = 0; i < args.Count; i++) { - Candidate preferred = GetPreferredParameter(one.GetParameter(i), two.GetParameter(i), args[i].GetLimitType()); + Candidate preferred = GetPreferredParameter(one.GetParameter(i), two.GetParameter(i), args[i], level); switch (result) { case Candidate.Equivalent: @@ -729,46 +729,32 @@ public abstract partial class OverloadResolver { return result; } - internal Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo, Type argType) { - Assert.NotNull(candidateOne, candidateTwo, argType); - - if (ParametersEquivalent(candidateOne, candidateTwo)) { - return Candidate.Equivalent; - } - - for (NarrowingLevel curLevel = NarrowingLevel.None; curLevel <= NarrowingLevel.All; curLevel++) { - Candidate candidate = SelectBestConversionFor(argType, candidateOne, candidateTwo, curLevel); - if (candidate.Chosen()) { - return candidate; - } - } - - return GetPreferredParameter(candidateOne, candidateTwo); - } - - internal Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo) { + private Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo, DynamicMetaObject arg, NarrowingLevel level) { Assert.NotNull(candidateOne, candidateTwo); if (ParametersEquivalent(candidateOne, candidateTwo)) { return Candidate.Equivalent; } - Type t1 = candidateOne.Type; - Type t2 = candidateTwo.Type; + Candidate candidate = SelectBestConversionFor(arg, candidateOne, candidateTwo, level); + if (candidate.Chosen()) { + return candidate; + } - if (CanConvertFrom(t2, candidateOne, NarrowingLevel.None)) { - if (CanConvertFrom(t1, candidateTwo, NarrowingLevel.None)) { + if (CanConvertFrom(candidateTwo, candidateOne)) { + if (CanConvertFrom(candidateOne, candidateTwo)) { return Candidate.Ambiguous; } else { return Candidate.Two; } - } - - if (CanConvertFrom(t1, candidateTwo, NarrowingLevel.None)) { + } else if (CanConvertFrom(candidateOne, candidateTwo)) { return Candidate.One; } // Special additional rules to order numeric value types + Type t1 = candidateOne.Type; + Type t2 = candidateTwo.Type; + Candidate preferred = PreferConvert(t1, t2); if (preferred.Chosen()) { return preferred; @@ -779,12 +765,38 @@ public abstract partial class OverloadResolver { return preferred; } - return Candidate.Ambiguous; + // consider the actual argument type: + Type argType = arg.GetLimitType(); + NarrowingLevel levelOne = NarrowingLevel.None; + while (levelOne < level && !CanConvertFrom(argType, arg, candidateOne, levelOne)) { + if (levelOne == NarrowingLevel.All) { + Debug.Assert(false, "Each argument should be convertible to the corresponding parameter"); + break; + } + levelOne++; + } + + NarrowingLevel levelTwo = NarrowingLevel.None; + while (levelTwo < level && !CanConvertFrom(argType, arg, candidateTwo, levelTwo)) { + if (levelTwo == NarrowingLevel.All) { + Debug.Assert(false, "Each argument should be convertible to the corresponding parameter"); + break; + } + levelTwo++; + } + + if (levelOne < levelTwo) { + return Candidate.One; + } else if (levelOne > levelTwo) { + return Candidate.Two; + } else { + return Candidate.Ambiguous; + } } - private ApplicableCandidate SelectBestCandidate(List candidates) { + private ApplicableCandidate SelectBestCandidate(List candidates, NarrowingLevel level) { foreach (var candidate in candidates) { - if (IsBest(candidate, candidates)) { + if (IsBest(candidate, candidates, level)) { return candidate; } } @@ -824,7 +836,11 @@ public abstract partial class OverloadResolver { return parameter1.Type == parameter2.Type && parameter1.ProhibitNull == parameter2.ProhibitNull; } - public virtual bool CanConvertFrom(Type fromType, ParameterWrapper toParameter, NarrowingLevel level) { + public virtual bool CanConvertFrom(ParameterWrapper parameter1, ParameterWrapper parameter2) { + return CanConvertFrom(parameter1.Type, null, parameter2, NarrowingLevel.None); + } + + public virtual bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument, ParameterWrapper toParameter, NarrowingLevel level) { Assert.NotNull(fromType, toParameter); Type toType = toParameter.Type; @@ -853,7 +869,7 @@ public abstract partial class OverloadResolver { /// /// Selects the best (of two) candidates for conversion from actualType /// - public virtual Candidate SelectBestConversionFor(Type actualType, ParameterWrapper candidateOne, ParameterWrapper candidateTwo, NarrowingLevel level) { + public virtual Candidate SelectBestConversionFor(DynamicMetaObject arg, ParameterWrapper candidateOne, ParameterWrapper candidateTwo, NarrowingLevel level) { return Candidate.Equivalent; } diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/ComInterop/ComTypeLibDesc.cs b/Merlin/Main/Runtime/Microsoft.Scripting/ComInterop/ComTypeLibDesc.cs index 6072e4e458..5be8819acd 100644 --- a/Merlin/Main/Runtime/Microsoft.Scripting/ComInterop/ComTypeLibDesc.cs +++ b/Merlin/Main/Runtime/Microsoft.Scripting/ComInterop/ComTypeLibDesc.cs @@ -25,6 +25,10 @@ namespace Microsoft.Scripting.ComInterop { + /// + /// Cached information from a TLB. Only information that is required is saved. CoClasses are used + /// for event hookup. Enums are stored for accessing symbolic names from scripts. + /// public sealed class ComTypeLibDesc : IDynamicMetaObjectProvider { // typically typelibs contain very small number of coclasses @@ -120,14 +124,31 @@ public sealed class ComTypeLibDesc : IDynamicMetaObjectProvider { typeLib.GetTypeInfoType(i, out typeKind); ComTypes.ITypeInfo typeInfo; + typeLib.GetTypeInfo(i, out typeInfo); if (typeKind == ComTypes.TYPEKIND.TKIND_COCLASS) { - typeLib.GetTypeInfo(i, out typeInfo); ComTypeClassDesc classDesc = new ComTypeClassDesc(typeInfo, typeLibDesc); typeLibDesc._classes.AddLast(classDesc); } else if (typeKind == ComTypes.TYPEKIND.TKIND_ENUM) { - typeLib.GetTypeInfo(i, out typeInfo); ComTypeEnumDesc enumDesc = new ComTypeEnumDesc(typeInfo, typeLibDesc); typeLibDesc._enums.Add(enumDesc.TypeName, enumDesc); + } + else if (typeKind == ComTypes.TYPEKIND.TKIND_ALIAS) { + ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo); + if (typeAttr.tdescAlias.vt == (short)VarEnum.VT_USERDEFINED) { + string aliasName, documentation; + ComRuntimeHelpers.GetInfoFromType(typeInfo, out aliasName, out documentation); + + ComTypes.ITypeInfo referencedTypeInfo; + typeInfo.GetRefTypeInfo(typeAttr.tdescAlias.lpValue.ToInt32(), out referencedTypeInfo); + + ComTypes.TYPEATTR referencedTypeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(referencedTypeInfo); + ComTypes.TYPEKIND referencedTypeKind = referencedTypeAttr.typekind; + + if (referencedTypeKind == ComTypes.TYPEKIND.TKIND_ENUM) { + ComTypeEnumDesc enumDesc = new ComTypeEnumDesc(referencedTypeInfo, typeLibDesc); + typeLibDesc._enums.Add(aliasName, enumDesc); + } + } } } @@ -157,7 +178,6 @@ public sealed class ComTypeLibDesc : IDynamicMetaObjectProvider { public string[] GetMemberNames() { string[] retval = new string[_enums.Count + _classes.Count]; int i = 0; - foreach (ComTypeClassDesc coclass in _classes) { retval[i++] = coclass.TypeName; } diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.Build.csproj b/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.Build.csproj index 3c84f569cd..53781fa9b6 100644 Binary files a/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.Build.csproj and b/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.Build.csproj differ diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.csproj b/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.csproj index e9fa65bddf..9f075ed059 100644 --- a/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.csproj +++ b/Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.30729 + 10.0.20624 2.0 {EB66B766-6354-4208-A3D4-AACBDCB5C3B3} Library @@ -16,13 +17,13 @@ ..\..\Bin\Release\Microsoft.Scripting.XML 1685 1591 - 2.0 ..\..\Support\MSSharedLibKey.snk true SIGNED true 857735168 ..\..\Utilities\Silverlight\x86ret\ + v2.0 pdbonly @@ -241,6 +242,7 @@ + diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/Runtime/IConvertibleMetaObject.cs b/Merlin/Main/Runtime/Microsoft.Scripting/Runtime/IConvertibleMetaObject.cs new file mode 100644 index 0000000000..6095dd8046 --- /dev/null +++ b/Merlin/Main/Runtime/Microsoft.Scripting/Runtime/IConvertibleMetaObject.cs @@ -0,0 +1,25 @@ +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; + +namespace Microsoft.Scripting.Runtime { + /// + /// Indicates that a DynamicMetaObject might be convertible to a CLR type. + /// + public interface IConvertibleMetaObject { + bool CanConvertTo(Type type, bool @explicit); + } +} diff --git a/Merlin/Main/Runtime/Microsoft.Scripting/Utils/ReflectionUtils.cs b/Merlin/Main/Runtime/Microsoft.Scripting/Utils/ReflectionUtils.cs index 38e35c99a2..2e9bbeab77 100644 --- a/Merlin/Main/Runtime/Microsoft.Scripting/Utils/ReflectionUtils.cs +++ b/Merlin/Main/Runtime/Microsoft.Scripting/Utils/ReflectionUtils.cs @@ -95,7 +95,15 @@ public static class ReflectionUtils { string genericName = type.GetGenericTypeDefinition().FullName.Replace('+', '.'); int tickIndex = genericName.IndexOf('`'); result.Append(tickIndex != -1 ? genericName.Substring(0, tickIndex) : genericName); - FormatTypeArgs(result, type.GetGenericArguments()); + + Type[] typeArgs = type.GetGenericArguments(); + if (type.IsGenericTypeDefinition) { + result.Append('<'); + result.Append(',', typeArgs.Length - 1); + result.Append('>'); + } else { + FormatTypeArgs(result, typeArgs); + } } else if (type.IsGenericParameter) { result.Append(type.Name); } else { diff --git a/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.Core.csproj b/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.Core.csproj index 478fbebce7..4cbaf33d5d 100644 --- a/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.Core.csproj +++ b/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.Core.csproj @@ -1,8 +1,9 @@ - + + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {2AE75F5A-CD1F-4925-9647-AF4D1C282FB4} Library @@ -16,13 +17,13 @@ SAK ..\..\..\..\..\..\Merlin\Main\Bin\Release\Microsoft.Scripting.Core.XML 1591 - 2.0 ..\..\..\..\..\..\Merlin\Main\Support\MSSharedLibKey.snk true SIGNED true ..\..\..\..\..\..\Merlin\Main\Utilities\Silverlight\x86ret\ 855638016 + v2.0 pdbonly @@ -248,4 +249,4 @@ - + \ No newline at end of file diff --git a/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.ExtensionAttribute.csproj b/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.ExtensionAttribute.csproj index 0b4aac36ed..bd6232d34c 100644 --- a/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.ExtensionAttribute.csproj +++ b/ndp/fx/src/Core/Microsoft/Scripting/Microsoft.Scripting.ExtensionAttribute.csproj @@ -1,8 +1,8 @@ - + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {8B0F1074-750E-4D64-BF23-A1E0F54261E5} Library @@ -13,13 +13,13 @@ SAK SAK SAK - 2.0 ..\..\..\..\..\..\Merlin\Main\Support\MSSharedLibKey.snk true SIGNED true 866123776 ..\..\..\..\..\..\Merlin\Main\Utilities\Silverlight\x86ret\ + v2.0 pdbonly diff --git a/ndp/fx/src/Dynamic/System/Dynamic/Microsoft.Dynamic.csproj b/ndp/fx/src/Dynamic/System/Dynamic/Microsoft.Dynamic.csproj index acb607d6ec..82ec5b9592 100644 --- a/ndp/fx/src/Dynamic/System/Dynamic/Microsoft.Dynamic.csproj +++ b/ndp/fx/src/Dynamic/System/Dynamic/Microsoft.Dynamic.csproj @@ -1,8 +1,8 @@ - + Debug AnyCPU - 9.0.21022 + 10.0.20624 2.0 {D4AE44AD-07B9-41DC-BB3B-1FDCDE3C987D} Library @@ -20,6 +20,7 @@ true SIGNED true + v2.0 pdbonly