Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Syncing to head of TFS for 0.9.2

  • Loading branch information...
commit 6b6e2981a9037d8232663bd83063c5e68f6e0b9f 1 parent abdb256
Jim Deville jredville authored

Showing 58 changed files with 938 additions and 894 deletions. Show diff stats Hide diff stats

  1. +2 0  Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj
  2. +2 0  Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj
  3. +2 0  Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj
  4. +2 0  Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj
  5. +2 0  Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj
  6. +2 0  Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj
  7. +2 0  Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj
  8. +4 1 Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs
  9. +194 2 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs
  10. +13 3 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs
  11. +11 0 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs
  12. +3 10 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs
  13. +1 1  Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs
  14. +15 3 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs
  15. +1 1  Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ObjectOps.cs
  16. +2 2 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs
  17. +4 2 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs
  18. +1 1  Merlin/Main/Languages/Ruby/Ruby/Builtins/LibraryInitializer.cs
  19. +11 11 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs
  20. +32 0 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyMethod.cs
  21. +34 31 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs
  22. +36 220 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/ClsTypeEmitter.cs
  23. +29 0 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/IRubyType.cs
  24. +16 4 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/InterfacesBuilder.cs
  25. +0 190 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/OverriddenMembers.cs
  26. +97 85 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeBuilder.cs
  27. +6 4 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeDispenser.cs
  28. +15 27 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/RubyTypeEmitter.cs
  29. +4 2 Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.Generated.cs
  30. BIN  Merlin/Main/Languages/Ruby/Ruby/Ruby.Build.csproj
  31. +1 1  Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj
  32. +14 1 Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs
  33. +19 4 Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyBinder.cs
  34. +88 11 Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMethodGroupBase.cs
  35. +1 170 Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyMethodGroupInfo.cs
  36. +16 5 Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyOverloadResolver.cs
  37. +13 3 Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs
  38. +1 1  Merlin/Main/Languages/Ruby/Ruby/Runtime/Protocols.cs
  39. +36 39 Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs
  40. +18 9 Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyGlobalScope.cs
  41. +8 0 Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs
  42. +3 1 Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs
  43. +9 3 Merlin/Main/Languages/Ruby/Tests/Interop/net/class/mapping_spec.rb
  44. +1 1  Merlin/Main/Languages/Ruby/Tests/Interop/net/class/shared/uninstantiable.rb
  45. +5 0 Merlin/Main/Runtime/Microsoft.Dynamic/Actions/Calls/BindingResult.cs
  46. +4 0 Merlin/Main/Runtime/Microsoft.Dynamic/Actions/Calls/CallFailureReason.cs
  47. +12 1 Merlin/Main/Runtime/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs
  48. +1 1  Merlin/Main/Runtime/Microsoft.Dynamic/Hosting/Shell/CommandLine.cs
  49. +23 3 Merlin/Main/Runtime/Microsoft.Scripting/Hosting/Providers/HostingHelpers.cs
  50. +20 4 Merlin/Main/Runtime/Microsoft.Scripting/Hosting/ScriptEngine.cs
  51. +13 2 Merlin/Main/Runtime/Microsoft.Scripting/Hosting/ScriptRuntime.cs
  52. +11 14 Merlin/Main/Runtime/Microsoft.Scripting/Hosting/ScriptScope.cs
  53. BIN  Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.Build.csproj
  54. +1 1  Merlin/Main/Runtime/Microsoft.Scripting/Microsoft.Scripting.csproj
  55. +3 3 Merlin/Main/Runtime/Microsoft.Scripting/Runtime/DynamicOperations.cs
  56. +25 6 Merlin/Main/Runtime/Microsoft.Scripting/Runtime/Scope.cs
  57. +19 10 Merlin/Main/Runtime/Microsoft.Scripting/Runtime/ScopeStorage.cs
  58. +30 0 Merlin/Main/Runtime/Microsoft.Scripting/Utils/ExpressionUtils.cs
2  Merlin/Main/Languages/IronPython/IronPythonConsole/IronPythonConsole.csproj
@@ -66,6 +66,7 @@
66 66 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
67 67 <UseVSHostingProcess>true</UseVSHostingProcess>
68 68 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  69 + <UseVSHostingProcess>false</UseVSHostingProcess>
69 70 </PropertyGroup>
70 71 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
71 72 <DebugType>pdbonly</DebugType>
@@ -77,6 +78,7 @@
77 78 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
78 79 <DelaySigned>true</DelaySigned>
79 80 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  81 + <UseVSHostingProcess>false</UseVSHostingProcess>
80 82 </PropertyGroup>
81 83 <ItemGroup>
82 84 <Compile Include="AssemblyInfo.cs" />
2  Merlin/Main/Languages/IronPython/IronPythonConsoleAny/IronPythonConsoleAny.csproj
@@ -65,6 +65,7 @@
65 65 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66 66 <UseVSHostingProcess>true</UseVSHostingProcess>
67 67 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  68 + <UseVSHostingProcess>false</UseVSHostingProcess>
68 69 </PropertyGroup>
69 70 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
70 71 <DebugType>pdbonly</DebugType>
@@ -76,6 +77,7 @@
76 77 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77 78 <DelaySigned>true</DelaySigned>
78 79 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  80 + <UseVSHostingProcess>false</UseVSHostingProcess>
79 81 </PropertyGroup>
80 82 <ItemGroup>
81 83 <Compile Include="..\IronPythonConsole\AssemblyInfo.cs" />
2  Merlin/Main/Languages/IronPython/IronPythonWindow/IronPythonWindow.csproj
@@ -74,6 +74,7 @@
74 74 <DefineConstants>TRACE;DEBUG;IRONPYTHON_WINDOW;CLR4;$(SignedSym)</DefineConstants>
75 75 <ErrorReport>prompt</ErrorReport>
76 76 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  77 + <UseVSHostingProcess>false</UseVSHostingProcess>
77 78 </PropertyGroup>
78 79 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
79 80 <DebugType>pdbonly</DebugType>
@@ -82,6 +83,7 @@
82 83 <DefineConstants>TRACE;IRONPYTHON_WINDOW;CLR4;$(SignedSym)</DefineConstants>
83 84 <ErrorReport>prompt</ErrorReport>
84 85 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  86 + <UseVSHostingProcess>false</UseVSHostingProcess>
85 87 </PropertyGroup>
86 88 <ItemGroup>
87 89 <Reference Include="System" />
2  Merlin/Main/Languages/IronPython/IronPythonWindowAny/IronPythonWindowAny.csproj
@@ -72,6 +72,7 @@
72 72 <DefineConstants>TRACE;DEBUG;IRONPYTHON_WINDOW;CLR4;$(SignedSym)</DefineConstants>
73 73 <ErrorReport>prompt</ErrorReport>
74 74 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  75 + <UseVSHostingProcess>false</UseVSHostingProcess>
75 76 </PropertyGroup>
76 77 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
77 78 <DebugType>pdbonly</DebugType>
@@ -80,6 +81,7 @@
80 81 <DefineConstants>TRACE;IRONPYTHON_WINDOW;CLR4;$(SignedSym)</DefineConstants>
81 82 <ErrorReport>prompt</ErrorReport>
82 83 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  84 + <UseVSHostingProcess>false</UseVSHostingProcess>
83 85 </PropertyGroup>
84 86 <ItemGroup>
85 87 <Compile Include="..\IronPythonWindow\IronPythonWindow.cs" />
2  Merlin/Main/Languages/Ruby/Console/Ruby.Console.csproj
@@ -52,6 +52,7 @@
52 52 <WarningLevel>4</WarningLevel>
53 53 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
54 54 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  55 + <UseVSHostingProcess>false</UseVSHostingProcess>
55 56 </PropertyGroup>
56 57 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
57 58 <DebugType>pdbonly</DebugType>
@@ -61,6 +62,7 @@
61 62 <ErrorReport>prompt</ErrorReport>
62 63 <WarningLevel>4</WarningLevel>
63 64 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  65 + <UseVSHostingProcess>false</UseVSHostingProcess>
64 66 </PropertyGroup>
65 67 <ItemGroup>
66 68 <Compile Include="Program.cs" />
2  Merlin/Main/Languages/Ruby/Console/Ruby.ConsoleAny.csproj
@@ -50,6 +50,7 @@
50 50 <WarningLevel>4</WarningLevel>
51 51 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
52 52 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  53 + <UseVSHostingProcess>false</UseVSHostingProcess>
53 54 </PropertyGroup>
54 55 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Release|AnyCPU' ">
55 56 <DebugType>pdbonly</DebugType>
@@ -59,6 +60,7 @@
59 60 <ErrorReport>prompt</ErrorReport>
60 61 <WarningLevel>4</WarningLevel>
61 62 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  63 + <UseVSHostingProcess>false</UseVSHostingProcess>
62 64 </PropertyGroup>
63 65 <ItemGroup>
64 66 <Compile Include="Program.cs" />
2  Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj
@@ -47,6 +47,7 @@
47 47 <DefineConstants>TRACE;CLR4;$(SignedSym)</DefineConstants>
48 48 <ErrorReport>prompt</ErrorReport>
49 49 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  50 + <UseVSHostingProcess>false</UseVSHostingProcess>
50 51 </PropertyGroup>
51 52 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'V4 Debug|AnyCPU' ">
52 53 <DebugSymbols>true</DebugSymbols>
@@ -56,6 +57,7 @@
56 57 <DefineConstants>TRACE;DEBUG;CLR4;$(SignedSym)</DefineConstants>
57 58 <ErrorReport>prompt</ErrorReport>
58 59 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  60 + <UseVSHostingProcess>false</UseVSHostingProcess>
59 61 </PropertyGroup>
60 62 <ItemGroup>
61 63 <Compile Include="Driver.cs" />
5 Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs
@@ -406,6 +406,7 @@ public partial class Tests {
406 406 ClrNamespaces2,
407 407 ClrGenerics1,
408 408 ClrGenerics2,
  409 + ClrGenerics3,
409 410 ClrMethods1,
410 411 ClrMethods2,
411 412 ClrMethods3,
@@ -444,7 +445,9 @@ public partial class Tests {
444 445 ClrOverride1,
445 446 ClrOverride2,
446 447 ClrOverride3,
447   - //TODO: Fix ClrOverride4,
  448 + ClrOverride4,
  449 + ClrOverride5,
  450 + ClrOverride6,
448 451 ClrEventImpl1,
449 452 ClrDetachedVirtual1,
450 453 ClrConstructor1,
196 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs
@@ -45,6 +45,19 @@ public class D : C {
45 45 public class D<T> : C<T> {
46 46 public override int Arity { get { return 11; } }
47 47 }
  48 +
  49 + public interface J<T> {
  50 + void MethodOnJ();
  51 + }
  52 +
  53 + public interface I<T> : J<T> {
  54 + void MethodOnI();
  55 + }
  56 +
  57 + public class E<T> : I<T>, J<T> {
  58 + void I<T>.MethodOnI() { }
  59 + void J<T>.MethodOnJ() { }
  60 + }
48 61 }
49 62
50 63 namespace InteropTests.Namespaces2 {
@@ -1388,7 +1401,7 @@ p C.new.arity
1388 1401 #<ArgumentError: `InteropTests::Generics1::C[Fixnum]' is not a generic type definition>
1389 1402 ");
1390 1403
1391   - // C<T> instantiations are subclasses of C<>:
  1404 + // C<> is a mixin for all its instantiations:
1392 1405 TestOutput(@"
1393 1406 include InteropTests::Generics1
1394 1407 C[1].class_eval do
@@ -1405,6 +1418,65 @@ p self.class
1405 1418 InteropTests::Generics1::C[String]
1406 1419 [InteropTests::Generics1::C[Float], InteropTests::Generics1::C[T], Object]
1407 1420 ");
  1421 +
  1422 + // It is possible to include a generic type definition into another class. It behaves like a Ruby module.
  1423 + // Besides inclusion of a generic interface instantiation transitively includes its generic type definition.
  1424 + TestOutput(@"
  1425 +include InteropTests::Generics1
  1426 +
  1427 +class ClassA
  1428 + include C[1]
  1429 + include I[1]
  1430 + p ancestors
  1431 + new
  1432 +end
  1433 +
  1434 +class ClassB
  1435 + include C[Fixnum] rescue p $!
  1436 + include I[Fixnum]
  1437 + p ancestors
  1438 + new
  1439 +end
  1440 +", @"
  1441 +[ClassA, InteropTests::Generics1::I[T], InteropTests::Generics1::C[T], Object, InteropTests::Generics1, Kernel]
  1442 +#<TypeError: wrong argument type Class (expected Module)>
  1443 +[ClassB, InteropTests::Generics1::I[Fixnum], InteropTests::Generics1::I[T], Object, InteropTests::Generics1, Kernel]
  1444 +");
  1445 +
  1446 + // generic type definitions cannot be instantiated and don't expose their methods:
  1447 + TestOutput(@"
  1448 +include InteropTests::Generics1
  1449 +p C[Fixnum].new.method(:Arity)
  1450 +C[1].new rescue p $!
  1451 +C[1].instance_method(:Arity) rescue p $!
  1452 +", @"
  1453 +#<Method: InteropTests::Generics1::C[Fixnum]#Arity>
  1454 +#<NoMethodError: undefined method `new' for InteropTests::Generics1::C[T]:Module>
  1455 +#<NameError: undefined method `Arity' for module `InteropTests::Generics1::C[T]'>
  1456 +");
  1457 + }
  1458 +
  1459 + public class GenericClass1<T> {
  1460 + public int Foo(T item) {
  1461 + return 1;
  1462 + }
  1463 + }
  1464 +
  1465 + public class GenericSubclass1<T> : GenericClass1<T> {
  1466 + }
  1467 +
  1468 + public void ClrGenerics2() {
  1469 + Context.ObjectClass.SetConstant("T", Context.GetClass(GetType()));
  1470 +
  1471 + // CLR methods with generic arguments defined on a generic type don't get duplicated:
  1472 + // (C<T> inherits from C<> but the generic type definition should be ignored when looking for CLR method overloads):
  1473 + TestOutput(@"
  1474 +p T::GenericClass1[Fixnum].new.foo(1)
  1475 +p T::GenericSubclass1[Fixnum].new.foo(1)
  1476 +", @"
  1477 +1
  1478 +1
  1479 +");
1408 1480 }
1409 1481
1410 1482 public class ClassWithNestedGenericTypes1 {
@@ -1430,7 +1502,7 @@ public class C<T, S> {
1430 1502 }
1431 1503 }
1432 1504
1433   - public void ClrGenerics2() {
  1505 + public void ClrGenerics3() {
1434 1506 Context.ObjectClass.SetConstant("C1", Context.GetClass(typeof(ClassWithNestedGenericTypes1)));
1435 1507 Context.ObjectClass.SetConstant("C2", Context.GetClass(typeof(ClassWithNestedGenericTypes2)));
1436 1508
@@ -1765,6 +1837,126 @@ p E.new.virtual_method
1765 1837 ");
1766 1838 }
1767 1839
  1840 + public class ClassWithProperties {
  1841 + private int _prop;
  1842 + private int[] _values = new int[1];
  1843 +
  1844 + public virtual int Prop {
  1845 + get { return _prop; }
  1846 + set { _prop = value; }
  1847 + }
  1848 +
  1849 + public virtual int this[int i] {
  1850 + get { return _values[i]; }
  1851 + set { _values[i] = value; }
  1852 + }
  1853 +
  1854 + public int[] Report() {
  1855 + Prop = 10;
  1856 + this[0] = 20;
  1857 + return new int[] { Prop, _prop, this[0], _values[0] };
  1858 + }
  1859 + }
  1860 +
  1861 + public void ClrOverride5() {
  1862 + Context.ObjectClass.SetConstant("C", Context.GetClass(typeof(ClassWithProperties)));
  1863 + TestOutput(@"
  1864 +class D < C
  1865 +end
  1866 +
  1867 +p D.new.report
  1868 +
  1869 +class D < C
  1870 + def prop
  1871 + 4
  1872 + end
  1873 +
  1874 + def prop= value
  1875 + super(5)
  1876 + end
  1877 +
  1878 + def [] index
  1879 + 6
  1880 + end
  1881 +
  1882 + def []= index, value
  1883 + super(index, 7)
  1884 + end
  1885 +end
  1886 +
  1887 +p D.new.report
  1888 +", @"
  1889 +[10, 10, 20, 20]
  1890 +[4, 5, 6, 7]
  1891 +");
  1892 + }
  1893 +
  1894 + public class ClassWithVirtuals1 {
  1895 + public virtual int Foo() { return 1; }
  1896 + public virtual int Goo() { return 20; }
  1897 + protected int Prot() { return 1000; }
  1898 +
  1899 + public virtual int Bar() { return 1; }
  1900 + }
  1901 +
  1902 + public class ClassWithVirtuals2 : ClassWithVirtuals1 {
  1903 + public int Report() {
  1904 + return Foo() + Goo();
  1905 + }
  1906 +
  1907 + public sealed override int Goo() { return 30; }
  1908 +
  1909 + public override int Bar() { return 2; }
  1910 + }
  1911 +
  1912 + public class ClassWithVirtuals3 : ClassWithVirtuals2 {
  1913 + public override int Bar() { return 3; }
  1914 + }
  1915 +
  1916 + public interface I1 { int f(); }
  1917 + public interface I2 { int g(); }
  1918 +
  1919 + public void ClrOverride6() {
  1920 + Context.ObjectClass.SetConstant("C", Context.GetClass(typeof(ClassWithVirtuals2)));
  1921 + Context.ObjectClass.SetConstant("I1", Context.GetModule(typeof(I1)));
  1922 + Context.ObjectClass.SetConstant("I2", Context.GetModule(typeof(I2)));
  1923 + TestOutput(@"
  1924 +class D < C
  1925 + include I1
  1926 +end
  1927 +
  1928 +class E < D
  1929 + include I2
  1930 +
  1931 + def foo
  1932 + super + 100
  1933 + end
  1934 +
  1935 + def goo
  1936 + super + prot
  1937 + end
  1938 +end
  1939 +
  1940 +p E.new.report
  1941 +p E.new.goo
  1942 +", @"
  1943 +131
  1944 +1030
  1945 +");
  1946 +
  1947 + AssertOutput(() => CompilerTest(@"
  1948 +class C
  1949 + def bar
  1950 + super + 100
  1951 + end
  1952 +end
  1953 +
  1954 +C.new.bar rescue p $!
  1955 +"), @"
  1956 +#<NoMethodError: Virtual CLR method `bar' called via super from *; Super calls to virtual CLR methods can only be used in a Ruby subclass of the class declaring the method>
  1957 +", OutputFlags.Match);
  1958 + }
  1959 +
1768 1960 /// <summary>
1769 1961 /// See RubyMethodGroupBase.BuildCallNoFlow.
1770 1962 /// </summary>
16 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/DlrInteropTests.cs
@@ -15,12 +15,15 @@
15 15
16 16 #if !CLR2
17 17 using System.Linq.Expressions;
  18 +using CsBinder = Microsoft.CSharp.RuntimeBinder.Binder;
  19 +using CSharpBinderFlags = Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags;
18 20 #else
19 21 using Microsoft.Scripting.Ast;
20 22 using dynamic = System.Object;
21 23 #endif
22 24
23 25 using System;
  26 +using System.Diagnostics;
24 27 using System.Dynamic;
25 28 using System.Runtime.CompilerServices;
26 29 using IronRuby.Builtins;
@@ -30,6 +33,7 @@
30 33 using Microsoft.Scripting.Utils;
31 34 using System.Collections;
32 35 using IronRuby.Runtime;
  36 +using System.Collections.Generic;
33 37
34 38 namespace IronRuby.Tests {
35 39 #region Custom binders
@@ -496,9 +500,8 @@ class SanityTest
496 500 def self.sanity_test main
497 501 # $ruby_array_list
498 502 assert_equal main.ruby_array_list.Count, 2
499   - assert_error lambda { main.ruby_array_list[0] }, NameError # Bug !!!!!!!!!!!! Should equal 100
500   -
501   - assert_error lambda { main.ruby_array_list.Count = 1 }, NoMethodError
  503 + main.ruby_array_list[0]
  504 +
502 505 assert_equal main.ruby_array_list.ruby_method, 'Hi from Ruby'.to_clr_string
503 506 assert_equal main.ruby_array_list.IndexOf(nil), 123456789
504 507
@@ -601,6 +604,13 @@ SanityTest.sanity_test self
601 604 // Ruby attributes are invoked directly via SetMember/GetMember:
602 605 AreEqual(MySetMemberBinder.Invoke(ruby_array_list, "ruby_attribute", 123), 123);
603 606 AreEqual(MyGetMemberBinder.Invoke(ruby_array_list, "ruby_attribute"), 123);
  607 +#if !CLR2
  608 + List<object> result = new List<object>();
  609 + foreach (object item in (dynamic)ruby_array_list) {
  610 + result.Add(item);
  611 + }
  612 + Assert(result.Count == 2 && (int)result[0] == 100 && (int)result[1] == 200);
  613 +#endif
604 614 }
605 615
606 616 public void Dlr_MethodMissing() {
11 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs
@@ -263,6 +263,17 @@ puts h.foo
263 263 IronRuby.globals.z = IronRuby.globals.x + FooBar
264 264 ");
265 265 Assert(Runtime.Globals.GetVariable<int>("z") == 3);
  266 +
  267 +#if !CLR2
  268 + dynamic scope = Engine.CreateScope();
  269 + Engine.Execute(@"def foo; 1; end", scope);
  270 +
  271 + RubyMethod method = (RubyMethod)scope.foo;
  272 + Assert(method.Name == "foo");
  273 +
  274 + object value = scope.foo();
  275 + Assert((int)value == 1);
  276 +#endif
266 277 }
267 278
268 279 public void RubyHosting_Scopes1() {
13 Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs
@@ -128,14 +128,7 @@ puts C
128 128 File.WriteAllText(Path.Combine(temp, "a.py"), @"
129 129 print 'Hello from Python'
130 130 ");
131   - AssertOutput(delegate() {
132   - CompilerTest(@"
133   -require('a')
134   -");
135   - }, @"
136   -Hello from Python
137   -");
138   -
  131 + AssertExceptionThrown<LoadError>(() => CompilerTest(@"require('a')"));
139 132 } finally {
140 133 File.Delete("b.py");
141 134 }
@@ -162,9 +155,9 @@ print Foo
162 155 TestOutput(@"
163 156 a = IronRuby.require('a')
164 157 scopes = IronRuby.loaded_scripts.collect { |z| z.value }
165   -a.who_is_this.call
  158 +a.who_is_this
166 159 a.foo += 1
167   -a.bar.new.baz
  160 +a.bar.baz # a Python class is callable so we get Bar's instance from a.bar
168 161 puts scopes[0].Foo
169 162 ", @"
170 163 Python
2  Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs
@@ -892,7 +892,7 @@ public static class ModuleOps {
892 892
893 893 using (self.Context.ClassHierarchyLocker()) {
894 894 self.ForEachMember(inherited, attributes, foreignMembers, (name, module, member) => {
895   - if (member.IsInteropMember && (module.Restrictions & ModuleRestrictions.NoNameMangling) == 0 && RubyUtils.HasMangledName(name)) {
  895 + if (member.IsInteropMember && (module.Restrictions & ModuleRestrictions.NoNameMapping) == 0 && RubyUtils.HasMangledName(name)) {
896 896 result.Add(new ClrName(name));
897 897 } else {
898 898 result.Add(CreateMethodName(name, symbolicNames));
18 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs
@@ -47,6 +47,11 @@ public class MutableStringOps {
47 47 return MutableString.Create(value);
48 48 }
49 49
  50 + [RubyConstructor]
  51 + public static MutableString/*!*/ Create(RubyClass/*!*/ self, [NotNull]byte[]/*!*/ value) {
  52 + return MutableString.CreateBinary(value);
  53 + }
  54 +
50 55 #region Helpers
51 56
52 57 internal static bool InExclusiveRangeNormalized(int length, ref int index) {
@@ -343,6 +348,12 @@ public class RangeParser {
343 348
344 349 #region initialize, initialize_copy
345 350
  351 + // Reinitialization. Not called when a factory/non-default ctor is called.
  352 + [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)]
  353 + public static MutableString/*!*/ Reinitialize(MutableString/*!*/ self) {
  354 + return self;
  355 + }
  356 +
346 357 // "initialize" not called when a factory/non-default ctor is called.
347 358 // "initialize_copy" called from "dup" and "clone"
348 359 [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)]
@@ -350,10 +361,11 @@ public class RangeParser {
350 361 public static MutableString/*!*/ Reinitialize(MutableString/*!*/ self, [DefaultProtocol, NotNull]MutableString other) {
351 362 return Replace(self, other);
352 363 }
353   -
354   - // Reinitialization. Not called when a factory/non-default ctor is called.
  364 +
355 365 [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)]
356   - public static MutableString/*!*/ Reinitialize(MutableString/*!*/ self) {
  366 + public static MutableString/*!*/ Reinitialize(MutableString/*!*/ self, [NotNull]byte[] other) {
  367 + self.Clear();
  368 + self.Append(other);
357 369 return self;
358 370 }
359 371
2  Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ObjectOps.cs
@@ -17,7 +17,7 @@
17 17
18 18 namespace IronRuby.Builtins {
19 19
20   - [RubyClass("Object", Extends = typeof(object), Restrictions = ModuleRestrictions.NoNameMangling | ModuleRestrictions.NotPublished)]
  20 + [RubyClass("Object", Extends = typeof(object), Restrictions = ModuleRestrictions.NoNameMapping | ModuleRestrictions.NotPublished)]
21 21 [Includes(typeof(Kernel))]
22 22 public static class ObjectOps {
23 23 [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance | RubyMethodAttributes.Empty)]
4 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Extensions/IronRubyOps.cs
@@ -59,7 +59,7 @@ public static class IronRubyOps {
59 59 object loaded;
60 60
61 61 scope.RubyContext.Loader.LoadFile(
62   - null, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions | LoadFlags.ResolveLoaded, out loaded
  62 + null, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions | LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded
63 63 );
64 64
65 65 Debug.Assert(loaded != null);
@@ -72,7 +72,7 @@ public static class IronRubyOps {
72 72 [RubyMethod("load", RubyMethodAttributes.PublicSingleton)]
73 73 public static object/*!*/ Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName) {
74 74 object loaded;
75   - scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded, out loaded);
  75 + scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded);
76 76 Debug.Assert(loaded != null);
77 77 return loaded;
78 78 }
6 Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs
@@ -155,7 +155,8 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia
155 155 );
156 156 DefineGlobalClass("String", typeof(IronRuby.Builtins.MutableString), 0x00000007, Context.ObjectClass, LoadString_Instance, null, null, new IronRuby.Builtins.RubyModule[] {def36, def45},
157 157 new Func<IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Create),
158   - new Func<IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Create)
  158 + new Func<IronRuby.Builtins.RubyClass, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Create),
  159 + new Func<IronRuby.Builtins.RubyClass, System.Byte[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Create)
159 160 );
160 161 DefineGlobalClass("Struct", typeof(IronRuby.Builtins.RubyStruct), 0x00000007, Context.ObjectClass, LoadStruct_Instance, LoadStruct_Class, LoadStruct_Constants, new IronRuby.Builtins.RubyModule[] {def36},
161 162 new Action<IronRuby.Builtins.RubyClass, System.Object[]>(IronRuby.Builtins.RubyStructOps.AllocatorUndefined)
@@ -4797,8 +4798,9 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia
4797 4798 );
4798 4799
4799 4800 DefineLibraryMethod(module, "initialize", 0x52,
  4801 + new Func<IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Reinitialize),
4800 4802 new Func<IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Reinitialize),
4801   - new Func<IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Reinitialize)
  4803 + new Func<IronRuby.Builtins.MutableString, System.Byte[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Reinitialize)
4802 4804 );
4803 4805
4804 4806 DefineLibraryMethod(module, "initialize_copy", 0x52,
2  Merlin/Main/Languages/Ruby/Ruby/Builtins/LibraryInitializer.cs
@@ -201,7 +201,7 @@ public abstract class LibraryInitializer {
201 201 #endregion
202 202
203 203 protected RubyClass/*!*/ GetClass(Type/*!*/ type) {
204   - Debug.Assert(type != null && !type.IsInterface);
  204 + Debug.Assert(type != null && !RubyModule.IsModuleType(type));
205 205 // TODO: CLR class vs library class:
206 206 return _context.GetOrCreateClass(type);
207 207 }
22 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyClass.cs
@@ -697,7 +697,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
697 697 }
698 698
699 699 Type type = cls.TypeTracker.Type;
700   - Debug.Assert(!type.IsInterface);
  700 + Debug.Assert(!RubyModule.IsModuleType(type));
701 701
702 702 // Note: We don't cache results as this API is not used so frequently (e.g. for regular method dispatch).
703 703
@@ -707,13 +707,13 @@ public RubyClass(RubyClass/*!*/ rubyClass)
707 707
708 708 // TODO: should declaring module of the resulting method rather be the base class?
709 709 method = null;
710   - return cls.TryGetClrMember(asType ?? type, name, true, 0, out method);
  710 + return cls.TryGetClrMember(asType ?? type, name, true, true, 0, out method);
711 711 }
712 712
713 713 // thread safe: doesn't need any lock since it only accesses immutable state
714 714 public bool TryGetClrConstructor(out RubyMemberInfo method) {
715 715 ConstructorInfo[] ctors;
716   - if (TypeTracker != null && !TypeTracker.Type.IsInterface && (ctors = GetConstructors(TypeTracker.Type)).Length > 0) {
  716 + if (TypeTracker != null && (ctors = GetConstructors(TypeTracker.Type)).Length > 0) {
717 717 method = new RubyMethodGroupInfo(ctors, this, true);
718 718 return true;
719 719 }
@@ -722,7 +722,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
722 722 return false;
723 723 }
724 724
725   - protected override bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool tryUnmangle, out RubyMemberInfo method) {
  725 + protected override bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool mapNames, bool unmangleNames, out RubyMemberInfo method) {
726 726 Context.RequiresClassHierarchyLock();
727 727
728 728 if (IsFailureCached(type, name, _isSingletonClass)) {
@@ -730,7 +730,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
730 730 return false;
731 731 }
732 732
733   - if (TryGetClrMember(type, name, tryUnmangle, BindingFlags.DeclaredOnly, out method)) {
  733 + if (TryGetClrMember(type, name, mapNames, unmangleNames, BindingFlags.DeclaredOnly, out method)) {
734 734 return true;
735 735 }
736 736
@@ -743,7 +743,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
743 743 /// Returns a fresh instance of RubyMemberInfo each time it is called. The caller needs to cache it if appropriate.
744 744 /// May add or use method groups to/from super-clases if BindingFlags.DeclaredOnly is used.
745 745 /// </summary>
746   - private bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool tryUnmangle, BindingFlags basicBindingFlags, out RubyMemberInfo method) {
  746 + private bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool mapNames, bool unmangleNames, BindingFlags basicBindingFlags, out RubyMemberInfo method) {
747 747 basicBindingFlags |= BindingFlags.Public | BindingFlags.NonPublic;
748 748
749 749 // We look only for members directly declared on the type and handle method overloads inheritance manually.
@@ -755,12 +755,12 @@ public RubyClass(RubyClass/*!*/ rubyClass)
755 755 }
756 756
757 757 string operatorName;
758   - if (tryUnmangle && !_isSingletonClass && (operatorName = RubyUtils.MapOperator(name)) != null) {
  758 + if (mapNames && !_isSingletonClass && (operatorName = RubyUtils.MapOperator(name)) != null) {
759 759 // instance invocation of an operator:
760 760 if (TryGetClrMethod(type, basicBindingFlags | BindingFlags.Static, true, name, null, operatorName, null, out method)) {
761 761 return true;
762 762 }
763   - } else if (tryUnmangle && (name == "[]" || name == "[]=")) {
  763 + } else if (mapNames && (name == "[]" || name == "[]=")) {
764 764 if (type.IsArray && !_isSingletonClass) {
765 765 bool isSetter = name.Length == 3;
766 766 TryGetClrMethod(type, bindingFlags, false, name, null, isSetter ? "Set" : "Get", null, out method);
@@ -778,7 +778,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
778 778 }
779 779 } else if (name.LastCharacter() == '=') {
780 780 string propertyName = name.Substring(0, name.Length - 1);
781   - string altName = tryUnmangle ? RubyUtils.TryUnmangleMethodName(propertyName) : null;
  781 + string altName = unmangleNames ? RubyUtils.TryUnmangleMethodName(propertyName) : null;
782 782
783 783 // property setter:
784 784 if (TryGetClrProperty(type, bindingFlags, true, name, propertyName, altName, out method)) return true;
@@ -786,7 +786,7 @@ public RubyClass(RubyClass/*!*/ rubyClass)
786 786 // writeable field:
787 787 if (TryGetClrField(type, bindingFlags, true, propertyName, altName, out method)) return true;
788 788 } else {
789   - string altName = tryUnmangle ? RubyUtils.TryUnmangleMethodName(name) : null;
  789 + string altName = unmangleNames ? RubyUtils.TryUnmangleMethodName(name) : null;
790 790
791 791 // method:
792 792 if (TryGetClrMethod(type, bindingFlags, false, name, null, name, altName, out method)) return true;
@@ -929,7 +929,7 @@ private sealed class ClrOverloadInfo {
929 929 }
930 930
931 931 // Skip classes that have no tracker, e.g. Fixnum(tracker) <: Integer(null) <: Numeric(null) <: Object(tracker).
932   - // Skip interfaces, their methods are not callable => do not include them into a method group.
  932 + // Skip CLR modules, their methods are not callable => do not include them into a method group.
933 933 // Skip all classes once hidden sentinel is encountered (no CLR overloads are visible since then).
934 934 if (!skipHidden && module.TypeTracker != null && module.IsClass) {
935 935 ancestors.Add((RubyClass)module);
32 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyMethod.cs
@@ -22,6 +22,7 @@
22 22 using System;
23 23 using System.Diagnostics;
24 24 using System.Runtime.CompilerServices;
  25 +using System.Text;
25 26 using IronRuby.Runtime;
26 27 using IronRuby.Runtime.Calls;
27 28 using Microsoft.Scripting.Utils;
@@ -32,6 +33,7 @@ namespace IronRuby.Builtins {
32 33 using Ast = Expression;
33 34 using BlockCallTargetUnsplatN = Func<BlockParam, object, object[], RubyArray, object>;
34 35
  36 + [DebuggerDisplay("{GetDebugView(), nq}")]
35 37 public partial class RubyMethod {
36 38 private readonly object _target;
37 39 private readonly string/*!*/ _name;
@@ -115,6 +117,7 @@ public partial class RubyMethod {
115 117 #region Curried
116 118
117 119 // TODO: currently used only to curry a method name for method_missing, but could be easily extended to support general argument currying
  120 + [DebuggerDisplay("{GetDebugView(), nq}")]
118 121 public sealed class Curried : RubyMethod {
119 122 private readonly string/*!*/ _methodNameArg;
120 123
@@ -131,6 +134,35 @@ internal Curried(object target, RubyMemberInfo/*!*/ info, string/*!*/ methodName
131 134 public override Proc/*!*/ ToProc(RubyScope/*!*/ scope) {
132 135 throw new NotSupportedException();
133 136 }
  137 +
  138 + private new string/*!*/ GetDebugView() {
  139 + var result = new StringBuilder();
  140 + result.Append("missing ");
  141 + result.Append(GetTargetClass().Name);
  142 + result.Append('#');
  143 + result.Append(_methodNameArg);
  144 +
  145 + result.Append("(?)");
  146 + return result.ToString();
  147 + }
  148 + }
  149 +
  150 + #endregion
  151 +
  152 + #region Debug View
  153 +
  154 + private string/*!*/ GetDebugView() {
  155 + var result = new StringBuilder();
  156 + result.Append(_info.Visibility.ToString().ToLowerInvariant());
  157 + result.Append(' ');
  158 +
  159 + result.Append(GetTargetClass().Name);
  160 + result.Append('#');
  161 + result.Append(_name);
  162 +
  163 + // TODO: parameter names?
  164 + result.Append("()");
  165 + return result.ToString();
134 166 }
135 167
136 168 #endregion
65 Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs
@@ -40,10 +40,10 @@ public enum ModuleRestrictions {
40 40 NoOverrides = 1,
41 41
42 42 /// <summary>
43   - /// Module doesn't allow its methods to be called by mangled names.
  43 + /// Module doesn't allow its methods to be called by mangled (FooBar -> foo_bar) or mapped ([] -> get_Item) names.
44 44 /// Used for built-ins.
45 45 /// </summary>
46   - NoNameMangling = 2,
  46 + NoNameMapping = 2,
47 47
48 48 /// <summary>
49 49 /// Module is not published in the runtime global scope.
@@ -53,7 +53,7 @@ public enum ModuleRestrictions {
53 53 /// <summary>
54 54 /// Default restrictions for built-in modules.
55 55 /// </summary>
56   - Builtin = NoOverrides | NoNameMangling | NotPublished,
  56 + Builtin = NoOverrides | NoNameMapping | NotPublished,
57 57
58 58 All = Builtin
59 59 }
@@ -63,7 +63,7 @@ public enum RubyModuleAttributes {
63 63 None = 0,
64 64
65 65 NoOverrides = ModuleRestrictions.NoOverrides,
66   - NoNameMangling = ModuleRestrictions.NoNameMangling,
  66 + NoNameMangling = ModuleRestrictions.NoNameMapping,
67 67 NotPublished = ModuleRestrictions.NotPublished,
68 68 RestrictionsMask = ModuleRestrictions.All,
69 69
@@ -229,8 +229,12 @@ private enum MemberTableState {
229 229 get { return _typeTracker != null && _typeTracker.Type.IsInterface; }
230 230 }
231 231
  232 + public bool IsClrModule {
  233 + get { return _typeTracker != null && IsModuleType(_typeTracker.Type); }
  234 + }
  235 +
232 236 public virtual Type/*!*/ GetUnderlyingSystemType() {
233   - if (IsInterface) {
  237 + if (IsClrModule) {
234 238 return _typeTracker.Type;
235 239 } else {
236 240 throw new InvalidOperationException();
@@ -349,7 +353,7 @@ protected RubyModule(RubyClass/*!*/ metaModuleClass, string name)
349 353 Utils.Log(_name ?? "<anonymous>", "CT_INIT");
350 354 // TODO: use lock-free operations in initializers
351 355 _constantsInitializer(this);
352   - } else if (!IsInterface && _typeTracker != null) {
  356 + } else if (_typeTracker != null && !_typeTracker.Type.IsInterface) {
353 357 // Load types eagerly. We do this only for CLR types that have no constant initializer (not builtins) and
354 358 // a constant access is performed (otherwise this method wouldn't be called).
355 359 //
@@ -1142,9 +1146,9 @@ private enum ConstantLookupResult {
1142 1146
1143 1147 ForEachAncestor(inherited, delegate(RubyModule/*!*/ module) {
1144 1148
1145   - // skip interfaces (methods declared on interfaces have already been looked for in the class);
1146   - // if 'this' is an interface, we want to visit all interface methods:
1147   - if (module.IsInterface && !this.IsInterface) return false;
  1149 + // Skip CLR modules (methods declared on CLR modules have already been looked for in the class).
  1150 + // If 'this' is a CLR module, we want to visit all mixed-in methods.
  1151 + if (module.IsClrModule && !this.IsClrModule) return false;
1148 1152
1149 1153 // notification that we entered the module (it could have no method):
1150 1154 if (action(module, null, null)) return true;
@@ -1539,7 +1543,7 @@ private enum ConstantLookupResult {
1539 1543
1540 1544 if (virtualLookup) {
1541 1545 string mangled;
1542   - // TODO: set/get_FooBar??
  1546 + // Note: property and default indexers getters and setters use FooBar, FooBar= and [], []= names, respectively, in virtual sites:
1543 1547 if ((mangled = RubyUtils.TryMangleMethodName(name)) != null && TryGetDefinedMethod(mangled, ref skipHidden, out method)
1544 1548 && method.IsRubyMember) {
1545 1549 return true;
@@ -1564,12 +1568,13 @@ private enum ConstantLookupResult {
1564 1568 private bool TryGetClrMember(string/*!*/ name, bool virtualLookup, out RubyMemberInfo method) {
1565 1569 // Skip hidden CLR overloads.
1566 1570 // Skip lookup on types that are not visible, that are interfaces or generic type definitions.
1567   - if (_typeTracker != null && !_typeTracker.Type.IsInterface && !_typeTracker.Type.IsGenericTypeDefinition) {
  1571 + if (_typeTracker != null && !IsModuleType(_typeTracker.Type)) {
1568 1572 // Note: Do not allow mangling for CLR virtual lookups - we want to match the overridden name exactly as is,
1569 1573 // so that it corresponds to the base method call the override stub performs.
1570   - bool tryUnmangle = !virtualLookup && (_restrictions & ModuleRestrictions.NoNameMangling) == 0;
  1574 + bool mapNames = (Restrictions & ModuleRestrictions.NoNameMapping) == 0;
  1575 + bool unmangleNames = !virtualLookup && mapNames;
1571 1576
1572   - if (TryGetClrMember(_typeTracker.Type, name, tryUnmangle, out method)) {
  1577 + if (TryGetClrMember(_typeTracker.Type, name, mapNames, unmangleNames, out method)) {
1573 1578 _methods.Add(name, method);
1574 1579 return true;
1575 1580 }
@@ -1579,7 +1584,7 @@ private enum ConstantLookupResult {
1579 1584 return false;
1580 1585 }
1581 1586
1582   - protected virtual bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool tryUnmangle, out RubyMemberInfo method) {
  1587 + protected virtual bool TryGetClrMember(Type/*!*/ type, string/*!*/ name, bool mapNames, bool unmangleNames, out RubyMemberInfo method) {
1583 1588 method = null;
1584 1589 return false;
1585 1590 }
@@ -1600,7 +1605,7 @@ private enum ConstantLookupResult {
1600 1605 }
1601 1606
1602 1607 // CLR members (do not include interface members - they are not callable methods, just metadata):
1603   - if (_typeTracker != null && !_typeTracker.Type.IsInterface) {
  1608 + if (_typeTracker != null && !IsModuleType(_typeTracker.Type)) {
1604 1609 foreach (string name in EnumerateClrMembers(_typeTracker.Type)) {
1605 1610 if (action(this, name, RubyMemberInfo.InteropMember)) {
1606 1611 return true;
@@ -1762,6 +1767,13 @@ private enum ConstantLookupResult {
1762 1767
1763 1768 #region Mixins (thread-safe)
1764 1769
  1770 + /// <summary>
  1771 + /// Returns true if the CLR type is treated as Ruby module (as opposed to a Ruby class)
  1772 + /// </summary>
  1773 + public static bool IsModuleType(Type/*!*/ type) {
  1774 + return type.IsInterface || type.IsGenericTypeDefinition;
  1775 + }
  1776 +
1765 1777 // thread-safe:
1766 1778 public bool HasAncestor(RubyModule/*!*/ module) {
1767 1779 using (Context.ClassHierarchyLocker()) {
@@ -1797,23 +1809,14 @@ private enum ConstantLookupResult {
1797 1809 RubyModule[] expanded = ExpandMixinsNoLock(GetSuperClass(), _mixins, modules);
1798 1810
1799 1811 foreach (RubyModule module in expanded) {
1800   - if (module.IsInterface) {
1801   - if (!CanIncludeClrInterface) {
1802   - bool alreadyIncluded = false;
1803   - foreach (RubyModule includedModule in _mixins) {
1804   - if (includedModule == module) {
1805   - alreadyIncluded = true;
1806   - break;
1807   - }
1808   - }
1809   - if (!alreadyIncluded) {
1810   - throw new InvalidOperationException(String.Format(
1811   - "Interface {0} cannot be included in class {1} because its underlying type has already been created.",
1812   - module.Name, Name
1813   - ));
1814   - }
  1812 + if (module.IsInterface && !CanIncludeClrInterface) {
  1813 + if (Array.IndexOf(_mixins, module) == -1) {
  1814 + throw new InvalidOperationException(String.Format(
  1815 + "Interface `{0}' cannot be included in class `{1}' because its underlying type has already been created",
  1816 + module.Name, Name
  1817 + ));
1815 1818 }
1816   - }
  1819 + }
1817 1820 }
1818 1821
1819 1822 MixinsUpdated(_mixins, _mixins = expanded);
256 Merlin/Main/Languages/Ruby/Ruby/Compiler/Generation/ClsTypeEmitter.cs
@@ -35,42 +35,7 @@
35 35
36 36 namespace IronRuby.Compiler.Generation {
37 37
38   - public abstract partial class ClsTypeEmitter {
39   - class SpecialNames {
40   - private readonly Dictionary<string/*!*/, List<string/*!*/>/*!*/>/*!*/ _specialNames;
41   -
42   - internal SpecialNames() {
43   - _specialNames = new Dictionary<string, List<string>>();
44   - }
45   -
46   - internal void SetSpecialName(string/*!*/ specialName, List<string/*!*/>/*!*/ names) {
47   - _specialNames[specialName] = names;
48   - }
49   -
50   - internal void SetSpecialName(string/*!*/ name) {
51   - List<string> names = new List<string>(1);
52   - names.Add(name);
53   - _specialNames[name] = names;
54   - }
55   -
56   - internal IEnumerable<string> GetBaseName(MethodInfo/*!*/ mi) {
57   - string newName;
58   - if (mi.Name.StartsWith(BaseMethodPrefix)) {
59   - newName = mi.Name.Substring(BaseMethodPrefix.Length);
60   - } else if (mi.Name.StartsWith(FieldGetterPrefix)) {
61   - newName = mi.Name.Substring(FieldGetterPrefix.Length);
62   - } else if (mi.Name.StartsWith(FieldSetterPrefix)) {
63   - newName = mi.Name.Substring(FieldSetterPrefix.Length);
64   - } else {
65   - throw new InvalidOperationException();
66   - }
67   -
68   - Debug.Assert(_specialNames.ContainsKey(newName));
69   -
70   - return _specialNames[newName];
71   - }
72   - }
73   -
  38 + public abstract class ClsTypeEmitter {
74 39 public const string VtableNamesField = "#VTableNames#";
75 40 public const string BaseMethodPrefix = "#base#";
76 41 public const string FieldGetterPrefix = "#field_get#", FieldSetterPrefix = "#field_set#";
@@ -79,20 +44,14 @@ class SpecialNames {
79 44 private readonly TypeBuilder _tb;
80 45 private readonly Type _baseType;
81 46 private int _site;
82   - private readonly SpecialNames _specialNames;
83 47 private readonly List<Expression> _dynamicSiteFactories;
84 48
85 49 protected ClsTypeEmitter(TypeBuilder tb) {
86 50 _tb = tb;
87 51 _baseType = tb.BaseType;
88   - _specialNames = new SpecialNames();
89 52 _dynamicSiteFactories = new List<Expression>();
90 53 }
91 54
92   - private static bool ShouldOverrideVirtual(MethodInfo/*!*/ mi) {
93   - return true;
94   - }
95   -
96 55 private static bool CanOverrideMethod(MethodInfo/*!*/ mi) {
97 56 #if !SILVERLIGHT
98 57 return true;
@@ -111,9 +70,6 @@ class SpecialNames {
111 70 protected abstract MethodInfo GetGenericConversionSiteFactory(Type toType);
112 71 protected abstract void EmitClassObjectFromInstance(ILGen il);
113 72
114   - protected abstract bool TryGetName(Type clrType, MethodInfo mi, out string name);
115   - protected abstract bool TryGetName(Type clrType, EventInfo ei, MethodInfo mi, out string name);
116   - protected abstract bool TryGetName(Type clrType, PropertyInfo pi, MethodInfo mi, out string name);
117 73 protected abstract Type/*!*/[]/*!*/ MakeSiteSignature(int nargs);
118 74 protected abstract Type/*!*/ ContextType { get; }
119 75
@@ -247,8 +203,6 @@ class SpecialNames {
247 203
248 204 fieldAccessorNames.Add(method.Name);
249 205 }
250   -
251   - _specialNames.SetSpecialName(fi.Name, fieldAccessorNames);
252 206 }
253 207 }
254 208
@@ -257,10 +211,19 @@ class SpecialNames {
257 211 /// including statics and non-statics.
258 212 /// </summary>
259 213 internal void OverrideMethods(Type type) {