edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonContext.cs;C669190 File: PythonContext.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonContext.cs;C669190 (server) 12/5/2008 9:41 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/PythonContext.cs;ScopesAndCrossRuntime @@ -718,7 +718,7 @@ } internal PythonModule GetPythonModule(Scope scope) { - return (PythonModule)GetScopeExtension(scope); + return (PythonModule)scope.GetExtension(ContextId); } internal PythonModule EnsurePythonModule(Scope scope) { @@ -879,7 +879,7 @@ internal PythonModule GetReloadableModule(Scope/*!*/ scope) { Assert.NotNull(scope); - PythonModule module = (PythonModule)GetScopeExtension(scope); + PythonModule module = (PythonModule)scope.GetExtension(ContextId); if (module == null || !module.IsPythonCreatedModule) { throw PythonOps.TypeError("can only reload Python modules"); @@ -903,20 +903,20 @@ /// Python's global scope includes looking at built-ins. First check built-ins, and if /// not there then fallback to any DLR globals. /// - public override bool TryLookupGlobal(CodeContext context, SymbolId name, out object value) { + public override bool TryLookupGlobal(Scope scope, SymbolId name, out object value) { object builtins; - if (!context.GlobalScope.TryGetName(Symbols.Builtins, out builtins)) { + if (!scope.ModuleScope.TryGetName(Symbols.Builtins, out builtins)) { value = null; return false; } - Scope scope = builtins as Scope; - if (scope != null && scope.TryGetName(name, out value)) return true; + Scope builtinsScope = builtins as Scope; + if (builtinsScope != null && builtinsScope.TryGetName(name, out value)) return true; IAttributesCollection dict = builtins as IAttributesCollection; if (dict != null && dict.TryGetValue(name, out value)) return true; - return base.TryLookupGlobal(context, name, out value); + return base.TryLookupGlobal(scope, name, out value); } protected override Exception MissingName(SymbolId name) { @@ -932,14 +932,6 @@ return res; } - public override object Call(CodeContext context, object function, object[] args) { - return Call(function, args); - } - - public override bool EqualReturnBool(CodeContext context, object x, object y) { - return PythonOps.EqualRetBool(context, x, y); - } - #region Assembly Loading public override Assembly LoadAssemblyFromFile(string file) { =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/ReflectedEvent.cs;C633889 File: ReflectedEvent.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/ReflectedEvent.cs;C633889 (server) 12/5/2008 9:55 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/IronPython/IronPython/Runtime/Types/ReflectedEvent.cs;ScopesAndCrossRuntime @@ -369,7 +369,7 @@ object key = copyOfHandlers[i].Key; object value = copyOfHandlers[i].Value; - if (context.LanguageContext.EqualReturnBool(context, key, callableObject)) { + if (PythonOps.EqualRetBool(context, key, callableObject)) { Delegate handler = (Delegate)value; _handlers.RemoveAt(i); return handler; @@ -407,7 +407,7 @@ object key = copyOfHandlers[i].Key.Target; object value = copyOfHandlers[i].Value.Target; - if (key != null && value != null && context.LanguageContext.EqualReturnBool(context, key, callableObject)) { + if (key != null && value != null && PythonOps.EqualRetBool(context, key, callableObject)) { Delegate handler = (Delegate)value; _handlers.RemoveAt(i); return handler; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs;C667395 File: LibraryDef.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs;C667395 (server) 12/5/2008 1:03 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Libraries/LibraryDef.cs;ScopesAndCrossRuntime @@ -933,10 +933,11 @@ (def.HasClassInitializer) ? String.Format("new {0}(Load{1}_Class)", TypeActionOfRubyModule, def.Id) : "null" ); } else { - _output.Write("Define{0}Module(\"{1}\", typeof({2}), {3}, {4}, ", + _output.Write("Define{0}Module(\"{1}\", typeof({2}), {3}, {4}, {5}, ", def.IsGlobal ? "Global" : "", def.QualifiedName, TypeName(def.Extends), + def.Extends == def.Trait ? "true" : "false", (def.HasInstanceInitializer) ? String.Format("new {0}(Load{1}_Instance)", TypeActionOfRubyModule, def.Id) : "null", (def.HasClassInitializer) ? String.Format("new {0}(Load{1}_Class)", TypeActionOfRubyModule, def.Id) : "null" ); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C667392 File: RubyTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C667392 (server) 12/5/2008 12:51 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;ScopesAndCrossRuntime @@ -286,6 +286,8 @@ RubyHosting2, RubyHosting3, RubyHosting4, + CrossRuntime1, + CrossRuntime2, Scenario_RubyConsole1, // TODO: interop, hosting: Scenario_RubyConsole2, =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;C656578 File: HostingTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;C656578 (server) 12/5/2008 12:52 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/HostingTests.cs;ScopesAndCrossRuntime @@ -113,7 +113,38 @@ => nil "); } + + public void CrossRuntime1() { + AssertOutput(() => { + CompilerTest(@" +load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.IronRubyModule' +engine = IronRuby.create_engine +puts engine.execute('1+1') +puts engine.execute('Fixnum') +engine.execute('class Fixnum; def + other; 123; end; end') +puts 1+1 +puts engine.execute('1+1') +"); + }, @" +2 +Fixnum@* +2 +123 +", OutputFlags.Match); + } + public void CrossRuntime2() { + var engine2 = Ruby.CreateEngine(); + Engine.Runtime.Globals.SetVariable("C", engine2.Execute("class C; def bar; end; self; end")); + AssertExceptionThrown(() => Engine.Execute("class C; def foo; end; end")); + AssertExceptionThrown(() => Engine.Execute("class C; alias foo bar; end")); + AssertExceptionThrown(() => Engine.Execute("class C; define_method(:goo) {}; end")); + AssertExceptionThrown(() => Engine.Execute(@" +module M; end +class C; include M; end +")); + } + public void Scenario_RubyConsole2() { #if OBSOLETE // TODO: interop =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C633889 File: LoaderTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C633889 (server) 12/5/2008 1:04 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;ScopesAndCrossRuntime @@ -142,7 +142,7 @@ public class TestLibraryInitializer1 : LibraryInitializer { protected override void LoadModules() { Context.ObjectClass.SetConstant("TEST_LIBRARY", "hello from library"); - DefineGlobalModule("Object", typeof(Object), ObjectMonkeyPatch, null, RubyModule.EmptyArray); + DefineGlobalModule("Object", typeof(Object), true, ObjectMonkeyPatch, null, RubyModule.EmptyArray); } private void ObjectMonkeyPatch(RubyModule/*!*/ module) { =================================================================== delete: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Clr;C633889 edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/GenerateInitializers.cmd;C633889 File: GenerateInitializers.cmd =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/GenerateInitializers.cmd;C633889 (server) 12/5/2008 3:04 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/GenerateInitializers.cmd;ScopesAndCrossRuntime @@ -1,1 +1,1 @@ -"%MERLIN_ROOT%\Bin\Debug\ClassInitGenerator" "%MERLIN_ROOT%\Bin\Debug\IronRuby.Libraries.dll" /libraries:IronRuby.Builtins;IronRuby.StandardLibrary.Threading;IronRuby.StandardLibrary.Sockets;IronRuby.StandardLibrary.OpenSsl;IronRuby.StandardLibrary.Digest;IronRuby.StandardLibrary.Zlib;IronRuby.StandardLibrary.StringIO;IronRuby.StandardLibrary.StringScanner;IronRuby.StandardLibrary.Enumerator;IronRuby.StandardLibrary.FunctionControl;IronRuby.StandardLibrary.FileControl;IronRuby.StandardLibrary.BigDecimal;IronRuby.StandardLibrary.Iconv;IronRuby.StandardLibrary.Clr;IronRuby.StandardLibrary.ParseTree /out:%~dp0\Initializers.Generated.cs +"%MERLIN_ROOT%\Bin\Debug\ClassInitGenerator" "%MERLIN_ROOT%\Bin\Debug\IronRuby.Libraries.dll" /libraries:IronRuby.Builtins;IronRuby.StandardLibrary.Threading;IronRuby.StandardLibrary.Sockets;IronRuby.StandardLibrary.OpenSsl;IronRuby.StandardLibrary.Digest;IronRuby.StandardLibrary.Zlib;IronRuby.StandardLibrary.StringIO;IronRuby.StandardLibrary.StringScanner;IronRuby.StandardLibrary.Enumerator;IronRuby.StandardLibrary.FunctionControl;IronRuby.StandardLibrary.FileControl;IronRuby.StandardLibrary.BigDecimal;IronRuby.StandardLibrary.Iconv;IronRuby.StandardLibrary.IronRubyModule;IronRuby.StandardLibrary.ParseTree /out:%~dp0\Initializers.Generated.cs =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C669565 File: Initializers.Generated.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C669565 (server) 12/5/2008 2:20 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;ScopesAndCrossRuntime @@ -26,7 +26,7 @@ [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.FileControl.FileControlLibraryInitializer))] [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.BigDecimal.BigDecimalLibraryInitializer))] [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.Iconv.IconvLibraryInitializer))] -[assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.Clr.ClrLibraryInitializer))] +[assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.IronRubyModule.IronRubyModuleLibraryInitializer))] [assembly: IronRuby.Runtime.RubyLibraryAttribute(typeof(IronRuby.StandardLibrary.ParseTree.ParseTreeLibraryInitializer))] namespace IronRuby.Builtins { @@ -50,22 +50,22 @@ // Skipped primitive: __ClassSingleton // Skipped primitive: __MainSingleton - IronRuby.Builtins.RubyModule def30 = DefineGlobalModule("Comparable", typeof(IronRuby.Builtins.Comparable), new System.Action(LoadComparable_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def21 = DefineGlobalModule("Enumerable", typeof(IronRuby.Builtins.Enumerable), new System.Action(LoadEnumerable_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def3 = DefineGlobalModule("Errno", typeof(IronRuby.Builtins.Errno), null, null, IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def17 = DefineModule("File::Constants", typeof(IronRuby.Builtins.RubyFileOps.Constants), new System.Action(LoadFile__Constants_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); - DefineGlobalModule("GC", typeof(IronRuby.Builtins.RubyGC), new System.Action(LoadGC_Instance), new System.Action(LoadGC_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def30 = DefineGlobalModule("Comparable", typeof(IronRuby.Builtins.Comparable), true, new System.Action(LoadComparable_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def21 = DefineGlobalModule("Enumerable", typeof(IronRuby.Builtins.Enumerable), true, new System.Action(LoadEnumerable_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def3 = DefineGlobalModule("Errno", typeof(IronRuby.Builtins.Errno), true, null, null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def17 = DefineModule("File::Constants", typeof(IronRuby.Builtins.RubyFileOps.Constants), true, new System.Action(LoadFile__Constants_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("GC", typeof(IronRuby.Builtins.RubyGC), true, new System.Action(LoadGC_Instance), new System.Action(LoadGC_Class), IronRuby.Builtins.RubyModule.EmptyArray); // Skipped primitive: Kernel - DefineGlobalModule("Marshal", typeof(IronRuby.Builtins.RubyMarshal), new System.Action(LoadMarshal_Instance), new System.Action(LoadMarshal_Class), IronRuby.Builtins.RubyModule.EmptyArray); - DefineGlobalModule("Math", typeof(IronRuby.Builtins.RubyMath), new System.Action(LoadMath_Instance), new System.Action(LoadMath_Class), IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("Marshal", typeof(IronRuby.Builtins.RubyMarshal), true, new System.Action(LoadMarshal_Instance), new System.Action(LoadMarshal_Class), IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("Math", typeof(IronRuby.Builtins.RubyMath), true, new System.Action(LoadMath_Instance), new System.Action(LoadMath_Class), IronRuby.Builtins.RubyModule.EmptyArray); ExtendClass(typeof(Microsoft.Scripting.Actions.TypeTracker), new System.Action(LoadMicrosoft__Scripting__Actions__TypeTracker_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, null); - DefineGlobalModule("ObjectSpace", typeof(IronRuby.Builtins.ObjectSpace), null, new System.Action(LoadObjectSpace_Class), IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def26 = DefineGlobalModule("Precision", typeof(IronRuby.Builtins.Precision), new System.Action(LoadPrecision_Instance), new System.Action(LoadPrecision_Class), IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("ObjectSpace", typeof(IronRuby.Builtins.ObjectSpace), true, null, new System.Action(LoadObjectSpace_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def26 = DefineGlobalModule("Precision", typeof(IronRuby.Builtins.Precision), true, new System.Action(LoadPrecision_Instance), new System.Action(LoadPrecision_Class), IronRuby.Builtins.RubyModule.EmptyArray); #if !SILVERLIGHT - IronRuby.Builtins.RubyModule def18 = DefineGlobalModule("Process", typeof(IronRuby.Builtins.RubyProcess), new System.Action(LoadProcess_Instance), new System.Action(LoadProcess_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def18 = DefineGlobalModule("Process", typeof(IronRuby.Builtins.RubyProcess), true, new System.Action(LoadProcess_Instance), new System.Action(LoadProcess_Class), IronRuby.Builtins.RubyModule.EmptyArray); #endif #if !SILVERLIGHT - DefineGlobalModule("Signal", typeof(IronRuby.Builtins.Signal), null, new System.Action(LoadSignal_Class), IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("Signal", typeof(IronRuby.Builtins.Signal), true, null, new System.Action(LoadSignal_Class), IronRuby.Builtins.RubyModule.EmptyArray); #endif ExtendClass(typeof(System.Type), new System.Action(LoadSystem__Type_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, null); // Skipped primitive: __ClassSingletonSingleton @@ -3193,7 +3193,7 @@ }); module.DefineLibraryMethod("to_s", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.MethodOps.ToS), + new System.Func(IronRuby.Builtins.MethodOps.ToS), }); module.DefineLibraryMethod("unbind", 0x51, new System.Delegate[] { @@ -3280,7 +3280,7 @@ }); module.DefineLibraryMethod("alias_method", 0x52, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.AliasMethod), + new System.Func(IronRuby.Builtins.ModuleOps.AliasMethod), }); module.DefineLibraryMethod("ancestors", 0x51, new System.Delegate[] { @@ -3360,8 +3360,8 @@ }); module.DefineLibraryMethod("define_method", 0x52, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), - new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), + new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), + new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), new System.Func(IronRuby.Builtins.ModuleOps.DefineMethod), }); @@ -3438,7 +3438,7 @@ }); module.DefineLibraryMethod("name", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.GetName), + new System.Func(IronRuby.Builtins.ModuleOps.GetName), }); module.DefineLibraryMethod("of", 0x51, new System.Delegate[] { @@ -3450,7 +3450,7 @@ }); module.DefineLibraryMethod("private_class_method", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.MakeClassMethodsPrivate), + new System.Func(IronRuby.Builtins.ModuleOps.MakeClassMethodsPrivate), }); module.DefineLibraryMethod("private_instance_methods", 0x51, new System.Delegate[] { @@ -3480,7 +3480,7 @@ }); module.DefineLibraryMethod("public_class_method", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.MakeClassMethodsPublic), + new System.Func(IronRuby.Builtins.ModuleOps.MakeClassMethodsPublic), }); module.DefineLibraryMethod("public_instance_methods", 0x51, new System.Delegate[] { @@ -3509,7 +3509,7 @@ }); module.DefineLibraryMethod("to_s", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ModuleOps.ToS), + new System.Func(IronRuby.Builtins.ModuleOps.ToS), }); module.DefineLibraryMethod("undef_method", 0x52, new System.Delegate[] { @@ -5493,7 +5493,7 @@ }); module.DefineLibraryMethod("to_s", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.UnboundMethod.ToS), + new System.Func(IronRuby.Builtins.UnboundMethod.ToS), }); } @@ -5767,7 +5767,7 @@ IronRuby.Builtins.RubyClass def3 = DefineGlobalClass("BasicSocket", typeof(IronRuby.StandardLibrary.Sockets.RubyBasicSocket), true, classRef0, new System.Action(LoadBasicSocket_Instance), new System.Action(LoadBasicSocket_Class), IronRuby.Builtins.RubyModule.EmptyArray, null); #endif #if !SILVERLIGHT && !SILVERLIGHT - IronRuby.Builtins.RubyModule def2 = DefineModule("Socket::Constants", typeof(IronRuby.StandardLibrary.Sockets.RubySocket.SocketConstants), new System.Action(LoadSocket__Constants_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def2 = DefineModule("Socket::Constants", typeof(IronRuby.StandardLibrary.Sockets.RubySocket.SocketConstants), true, new System.Action(LoadSocket__Constants_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); #endif #if !SILVERLIGHT DefineGlobalClass("SocketError", typeof(System.Net.Sockets.SocketException), false, classRef1, new System.Action(LoadSocketError_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { @@ -6308,14 +6308,14 @@ IronRuby.Builtins.RubyClass classRef0 = GetClass(typeof(System.Object)); - IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("OpenSSL", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl), new System.Action(LoadOpenSSL_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("OpenSSL", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl), true, new System.Action(LoadOpenSSL_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyClass def2 = DefineClass("OpenSSL::BN", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.BN), true, classRef0, null, new System.Action(LoadOpenSSL__BN_Class), IronRuby.Builtins.RubyModule.EmptyArray, null); - IronRuby.Builtins.RubyModule def3 = DefineModule("OpenSSL::Digest", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory), null, null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def3 = DefineModule("OpenSSL::Digest", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory), true, null, null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyClass def4 = DefineClass("OpenSSL::Digest::Digest", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest), true, classRef0, new System.Action(LoadOpenSSL__Digest__Digest_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new System.Func(IronRuby.StandardLibrary.OpenSsl.OpenSsl.DigestFactory.Digest.CreateDigest), }); IronRuby.Builtins.RubyClass def5 = DefineClass("OpenSSL::HMAC", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.HMAC), true, classRef0, null, new System.Action(LoadOpenSSL__HMAC_Class), IronRuby.Builtins.RubyModule.EmptyArray, null); - IronRuby.Builtins.RubyModule def6 = DefineModule("OpenSSL::Random", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.RandomModule), null, new System.Action(LoadOpenSSL__Random_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def6 = DefineModule("OpenSSL::Random", typeof(IronRuby.StandardLibrary.OpenSsl.OpenSsl.RandomModule), true, null, new System.Action(LoadOpenSSL__Random_Class), IronRuby.Builtins.RubyModule.EmptyArray); def1.SetConstant("BN", def2); def1.SetConstant("Digest", def3); def3.SetConstant("Digest", def4); @@ -6368,8 +6368,8 @@ IronRuby.Builtins.RubyClass classRef0 = GetClass(typeof(System.Object)); - IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("Digest", typeof(IronRuby.StandardLibrary.Digest.Digest), null, new System.Action(LoadDigest_Class), IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def4 = DefineModule("Digest::Instance", typeof(IronRuby.StandardLibrary.Digest.Digest.Instance), new System.Action(LoadDigest__Instance_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("Digest", typeof(IronRuby.StandardLibrary.Digest.Digest), true, null, new System.Action(LoadDigest_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def4 = DefineModule("Digest::Instance", typeof(IronRuby.StandardLibrary.Digest.Digest.Instance), true, new System.Action(LoadDigest__Instance_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyClass def3 = DefineClass("Digest::Class", typeof(IronRuby.StandardLibrary.Digest.Digest.Class), true, classRef0, null, new System.Action(LoadDigest__Class_Class), new IronRuby.Builtins.RubyModule[] {def4, }, null); IronRuby.Builtins.RubyClass def2 = DefineClass("Digest::Base", typeof(IronRuby.StandardLibrary.Digest.Digest.Base), true, def3, new System.Action(LoadDigest__Base_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, null); #if !SILVERLIGHT @@ -6483,7 +6483,7 @@ IronRuby.Builtins.RubyClass classRef1 = GetClass(typeof(System.Object)); - IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("Zlib", typeof(IronRuby.StandardLibrary.Zlib.Zlib), new System.Action(LoadZlib_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("Zlib", typeof(IronRuby.StandardLibrary.Zlib.Zlib), true, new System.Action(LoadZlib_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); IronRuby.Builtins.RubyClass def2 = DefineClass("Zlib::DataError", typeof(IronRuby.StandardLibrary.Zlib.Zlib.DataError), true, classRef0, null, null, IronRuby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new System.Func(ZlibLibraryInitializer.ExceptionFactory__Zlib__DataError) }); IronRuby.Builtins.RubyClass def3 = DefineClass("Zlib::GzipFile", typeof(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile), true, classRef1, null, null, IronRuby.Builtins.RubyModule.EmptyArray, null); IronRuby.Builtins.RubyClass def4 = DefineClass("Zlib::GzipFile::Error", typeof(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile.Error), true, classRef0, null, null, IronRuby.Builtins.RubyModule.EmptyArray, null); @@ -6935,7 +6935,7 @@ protected override void LoadModules() { - DefineGlobalModule("Fcntl", typeof(IronRuby.StandardLibrary.FileControl.Fcntl), new System.Action(LoadFcntl_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + DefineGlobalModule("Fcntl", typeof(IronRuby.StandardLibrary.FileControl.Fcntl), true, new System.Action(LoadFcntl_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); } private void LoadFcntl_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { @@ -7373,18 +7373,20 @@ } } -namespace IronRuby.StandardLibrary.Clr { - public sealed class ClrLibraryInitializer : IronRuby.Builtins.LibraryInitializer { +namespace IronRuby.StandardLibrary.IronRubyModule { + public sealed class IronRubyModuleLibraryInitializer : IronRuby.Builtins.LibraryInitializer { protected override void LoadModules() { - DefineGlobalModule("Clr", typeof(IronRuby.StandardLibrary.Clr.ClrOps), null, new System.Action(LoadClr_Class), IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("IronRuby", typeof(IronRuby.Ruby), false, null, null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def2 = DefineModule("IronRuby::Clr", typeof(IronRuby.StandardLibrary.IronRubyModule.IronRubyOps.ClrOps), true, null, new System.Action(LoadIronRuby__Clr_Class), IronRuby.Builtins.RubyModule.EmptyArray); + def1.SetConstant("Clr", def2); } - private void LoadClr_Class(IronRuby.Builtins.RubyModule/*!*/ module) { + private void LoadIronRuby__Clr_Class(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("profile", 0x21, new System.Delegate[] { - new System.Func(IronRuby.StandardLibrary.Clr.ClrOps.GetProfile), - new System.Func(IronRuby.StandardLibrary.Clr.ClrOps.GetProfile), + new System.Func(IronRuby.StandardLibrary.IronRubyModule.IronRubyOps.ClrOps.GetProfile), + new System.Func(IronRuby.StandardLibrary.IronRubyModule.IronRubyOps.ClrOps.GetProfile), }); } @@ -7397,8 +7399,8 @@ protected override void LoadModules() { - IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("IronRuby", typeof(IronRuby.StandardLibrary.ParseTree.IronRubyOps), null, null, IronRuby.Builtins.RubyModule.EmptyArray); - IronRuby.Builtins.RubyModule def2 = DefineModule("IronRuby::ParseTree", typeof(IronRuby.StandardLibrary.ParseTree.IronRubyOps.ParseTreeOps), new System.Action(LoadIronRuby__ParseTree_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def1 = DefineGlobalModule("IronRuby", typeof(IronRuby.Ruby), false, null, null, IronRuby.Builtins.RubyModule.EmptyArray); + IronRuby.Builtins.RubyModule def2 = DefineModule("IronRuby::ParseTree", typeof(IronRuby.StandardLibrary.ParseTree.IronRubyOps.ParseTreeOps), true, new System.Action(LoadIronRuby__ParseTree_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray); def1.SetConstant("ParseTree", def2); } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;C633889 File: IronRuby.Libraries.csproj =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;C633889 (server) 12/5/2008 2:55 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;ScopesAndCrossRuntime @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30703 + 9.0.30729 2.0 {77323B06-15A2-4CF4-8A7A-86EAA2B66498} Library @@ -126,7 +126,6 @@ - @@ -139,6 +138,7 @@ + =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C659171 File: KernelOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C659171 (server) 12/6/2008 1:24 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;ScopesAndCrossRuntime @@ -1015,7 +1015,7 @@ [NotNull]params RubyModule/*!*/[]/*!*/ modules) { Assert.NotNull(self, modules); - RubyUtils.RequireNonClasses(modules); + RubyUtils.RequireMixins(module.SingletonClass, modules); var extendObject = extendObjectStorage.GetCallSite("extend_object", 1); var extended = extendedStorage.GetCallSite("extended", 1); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;C659171 File: Marshal.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;C659171 (server) 12/5/2008 2:20 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;ScopesAndCrossRuntime @@ -275,7 +275,7 @@ private void TestForAnonymous(RubyModule/*!*/ theModule) { if (theModule.Name == null) { string objectType = (theModule is RubyClass) ? "class" : "module"; - string displayName = theModule.GetDisplayName(false).ConvertToString(); + string displayName = theModule.GetDisplayName(_context, false).ConvertToString(); string message = String.Format("can't dump anonymous {0} {1}", objectType, displayName); throw RubyExceptions.CreateTypeError(message); } @@ -415,7 +415,7 @@ // "_dump" doesn't write "extend" info but "marshal_dump" does RubyClass theClass = _context.GetImmediateClassOf(obj); if (theClass.IsSingletonClass) { - foreach (var mixin in theClass.Mixins) { + foreach (var mixin in theClass.GetMixins()) { _writer.Write((byte)'e'); WriteSymbol(mixin.Name); } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MethodOps.cs;C641155 File: MethodOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MethodOps.cs;C641155 (server) 12/5/2008 4:29 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MethodOps.cs;ScopesAndCrossRuntime @@ -52,8 +52,8 @@ } [RubyMethod("to_s")] - public static MutableString/*!*/ ToS(RubyMethod/*!*/ self) { - return UnboundMethod.ToS(self.Name, self.Info.DeclaringModule, self.GetTargetClass(), "Method"); + public static MutableString/*!*/ ToS(RubyContext/*!*/ context, RubyMethod/*!*/ self) { + return UnboundMethod.ToS(context, self.Name, self.Info.DeclaringModule, self.GetTargetClass(), "Method"); } [RubyMethod("to_proc")] =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;C659171 File: ModuleOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;C659171 (server) 12/5/2008 2:20 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;ScopesAndCrossRuntime @@ -111,7 +111,7 @@ SiteLocalStorage>>/*!*/ includedStorage, RubyModule/*!*/ self, [NotNull]params RubyModule[]/*!*/ modules) { - RubyUtils.RequireNonClasses(modules); + RubyUtils.RequireMixins(self, modules); var appendFeatures = appendFeaturesStorage.GetCallSite("append_features", 1); var included = includedStorage.GetCallSite("included", 1); @@ -221,9 +221,9 @@ } if ((attributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction) { - module.AddModuleFunction(methodName, method); + module.AddModuleFunction(scope.RubyContext, methodName, method); } else { - module.SetMethodVisibility(methodName, method, (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask)); + module.SetMethodVisibility(scope.RubyContext, methodName, method, (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask)); } } } @@ -234,33 +234,33 @@ #region define_method [RubyMethod("define_method", RubyMethodAttributes.PrivateInstance)] - public static RubyMethod/*!*/ DefineMethod(RubyModule/*!*/ self, + public static RubyMethod/*!*/ DefineMethod(RubyContext/*!*/ context, RubyModule/*!*/ self, [DefaultProtocol]string/*!*/ methodName, [NotNull]RubyMethod/*!*/ method) { // MRI 1.8 does the check when the method is called, 1.9 checks it upfront as we do: var targetClass = method.GetTargetClass(); if (!self.HasAncestor(targetClass)) { throw RubyExceptions.CreateTypeError( - String.Format("bind argument must be a subclass of {0}", targetClass.Name) + String.Format("bind argument must be a subclass of {0}", targetClass.GetName(context)) ); } - self.AddDefinedMethod(methodName, method.Info); + self.AddDefinedMethod(context, methodName, method.Info); return method; } [RubyMethod("define_method", RubyMethodAttributes.PrivateInstance)] - public static UnboundMethod/*!*/ DefineMethod(RubyModule/*!*/ self, + public static UnboundMethod/*!*/ DefineMethod(RubyContext/*!*/ context, RubyModule/*!*/ self, [DefaultProtocol]string/*!*/ methodName, [NotNull]UnboundMethod/*!*/ method) { // MRI 1.8 does the check when the method is called, 1.9 checks it upfront as we do: if (!self.HasAncestor(method.TargetConstraint)) { throw RubyExceptions.CreateTypeError( - String.Format("bind argument must be a subclass of {0}", method.TargetConstraint.Name) + String.Format("bind argument must be a subclass of {0}", method.TargetConstraint.GetName(context)) ); } - self.AddDefinedMethod(methodName, method.Info); + self.AddDefinedMethod(context, methodName, method.Info); return method; } @@ -280,7 +280,7 @@ // MFI 1.9: uses public visibility as we do, unless the name is special. var visibility = RubyUtils.GetSpecialMethodVisibility(scope.Visibility, methodName); - self.AddMethod(methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self)); + self.AddMethod(scope.RubyContext, methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self)); return method; } @@ -368,7 +368,7 @@ #region alias_method, remove_method, undef_method [RubyMethod("alias_method", RubyMethodAttributes.PrivateInstance)] - public static RubyModule/*!*/ AliasMethod(RubyModule/*!*/ self, + public static RubyModule/*!*/ AliasMethod(RubyContext/*!*/ context, RubyModule/*!*/ self, [DefaultProtocol]string/*!*/ newName, [DefaultProtocol]string/*!*/ oldName) { RubyMemberInfo method = self.ResolveMethodFallbackToObject(oldName, true); @@ -376,7 +376,7 @@ throw RubyExceptions.CreateUndefinedMethodError(self, oldName); } - self.AddMethodAlias(newName, method); + self.AddMethodAlias(context, newName, method); return self; } @@ -504,7 +504,9 @@ [RubyMethod("include?")] public static bool IncludesModule(RubyModule/*!*/ self, [NotNull]RubyModule/*!*/ other) { - RubyUtils.RequireNonClasses(other); + if (other.IsClass) { + throw RubyExceptions.CreateTypeError("wrong argument type Class (expected Module)"); + } return other != self && self.HasAncestor(other); } @@ -703,7 +705,7 @@ return new UnboundMethod(self, methodName, method); } - private static void SetClassMethodsVisibility(RubyModule/*!*/ module, string[]/*!*/ methodNames, RubyMethodVisibility visibility) { + private static void SetClassMethodsVisibility(RubyContext/*!*/ context, RubyModule/*!*/ module, string[]/*!*/ methodNames, RubyMethodVisibility visibility) { var methods = new RubyMemberInfo[methodNames.Length]; for (int i = 0; i < methods.Length; i++) { RubyMemberInfo method = module.SingletonClass.ResolveMethod(methodNames[i], true); @@ -714,19 +716,19 @@ } for (int i = 0; i < methods.Length; i++) { - module.SingletonClass.SetMethodVisibility(methodNames[i], methods[i], visibility); + module.SingletonClass.SetMethodVisibility(context, methodNames[i], methods[i], visibility); } } [RubyMethodAttribute("private_class_method")] - public static RubyModule/*!*/ MakeClassMethodsPrivate(RubyModule/*!*/ self, [NotNull]params object[]/*!*/ methodNames) { - SetClassMethodsVisibility(self, Protocols.CastToSymbols(self.Context, methodNames), RubyMethodVisibility.Private); + public static RubyModule/*!*/ MakeClassMethodsPrivate(RubyContext/*!*/ context, RubyModule/*!*/ self, [NotNull]params object[]/*!*/ methodNames) { + SetClassMethodsVisibility(context, self, Protocols.CastToSymbols(context, methodNames), RubyMethodVisibility.Private); return self; } [RubyMethodAttribute("public_class_method")] - public static RubyModule/*!*/ MakeClassMethodsPublic(RubyModule/*!*/ self, [NotNull]params object[]/*!*/ methodNames) { - SetClassMethodsVisibility(self, Protocols.CastToSymbols(self.Context, methodNames), RubyMethodVisibility.Public); + public static RubyModule/*!*/ MakeClassMethodsPublic(RubyContext/*!*/ context, RubyModule/*!*/ self, [NotNull]params object[]/*!*/ methodNames) { + SetClassMethodsVisibility(context, self, Protocols.CastToSymbols(context, methodNames), RubyMethodVisibility.Public); return self; } @@ -757,13 +759,13 @@ } [RubyMethod("to_s")] - public static MutableString/*!*/ ToS(RubyModule/*!*/ self) { - return self.GetDisplayName(false); + public static MutableString/*!*/ ToS(RubyContext/*!*/ context, RubyModule/*!*/ self) { + return self.GetDisplayName(context, false); } [RubyMethod("name")] - public static MutableString/*!*/ GetName(RubyModule/*!*/ self) { - return self.GetDisplayName(true); + public static MutableString/*!*/ GetName(RubyContext/*!*/ context, RubyModule/*!*/ self) { + return self.GetDisplayName(context, true); } [RubyMethod("of")] =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/SingletonOps.cs;C633889 File: SingletonOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/SingletonOps.cs;C633889 (server) 12/6/2008 1:25 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/SingletonOps.cs;ScopesAndCrossRuntime @@ -63,9 +63,6 @@ [RubyMethod("include", RubyMethodAttributes.PublicInstance)] public static RubyClass/*!*/ Include(RubyContext/*!*/ context, object/*!*/ self, params RubyModule[]/*!*/ modules) { - ContractUtils.RequiresNotNullItems(modules, "modules"); - RubyUtils.RequireNonClasses(modules); - RubyClass result = context.GetClassOf(self); result.IncludeModules(modules); return result; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadOps.cs;C660056 edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/UnboundMethod.cs;C641155 File: UnboundMethod.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/UnboundMethod.cs;C641155 (server) 12/5/2008 4:23 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/UnboundMethod.cs;ScopesAndCrossRuntime @@ -67,11 +67,11 @@ [RubyMethod("bind")] public static RubyMethod/*!*/ Bind(UnboundMethod/*!*/ self, object target) { - RubyContext ec = self._targetConstraint.Context; + RubyContext context = self._targetConstraint.Context; - if (!ec.GetClassOf(target).HasAncestor(self._targetConstraint)) { + if (!context.GetClassOf(target).HasAncestor(self._targetConstraint)) { throw RubyExceptions.CreateTypeError( - String.Format("bind argument must be an instance of {0}", self._targetConstraint.Name) + String.Format("bind argument must be an instance of {0}", self._targetConstraint.GetName(context)) ); } @@ -84,11 +84,11 @@ } [RubyMethod("to_s")] - public static MutableString/*!*/ ToS(UnboundMethod/*!*/ self) { - return ToS(self.Name, self._info.DeclaringModule, self._targetConstraint, "UnboundMethod"); + public static MutableString/*!*/ ToS(RubyContext/*!*/ context, UnboundMethod/*!*/ self) { + return ToS(context, self.Name, self._info.DeclaringModule, self._targetConstraint, "UnboundMethod"); } - internal static MutableString/*!*/ ToS(string/*!*/ methodName, RubyModule/*!*/ declaringModule, RubyModule/*!*/ targetModule, + internal static MutableString/*!*/ ToS(RubyContext/*!*/ context, string/*!*/ methodName, RubyModule/*!*/ declaringModule, RubyModule/*!*/ targetModule, string/*!*/ classDisplayName) { MutableString result = MutableString.CreateMutable(); @@ -97,11 +97,11 @@ result.Append(": "); if (ReferenceEquals(targetModule, declaringModule)) { - result.Append(declaringModule.Name); + result.Append(declaringModule.GetName(context)); } else { - result.Append(targetModule.Name); + result.Append(targetModule.GetName(context)); result.Append('('); - result.Append(declaringModule.Name); + result.Append(declaringModule.GetName(context)); result.Append(')'); } =================================================================== branch, edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby/IronRubyOps.cs File: IronRubyOps.cs =================================================================== --- ClrOps.cs (server) 12/5/2008 2:55 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby/IronRubyOps.cs;ScopesAndCrossRuntime @@ -17,47 +17,51 @@ using IronRuby.Compiler.Generation; using IronRuby.Runtime; -namespace IronRuby.StandardLibrary.Clr { - [RubyModule("Clr")] - public static class ClrOps { +namespace IronRuby.StandardLibrary.IronRubyModule { + [RubyModule("IronRuby", Extends = typeof(Ruby))] + public static class IronRubyOps { - [RubyMethod("profile", RubyMethodAttributes.PublicSingleton)] - public static Hash/*!*/ GetProfile(RubyContext/*!*/ context, object self) { - if (!((RubyOptions)context.Options).Profile) { - throw RubyExceptions.CreateSystemCallError("You must enable profiling to use Clr.profile"); - } + [RubyModule("Clr")] + public static class ClrOps { - Hash result = new Hash(context); - foreach (var entry in Profiler.Instance.GetProfile()) { - result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(entry.Value)); - } - return result; - } + [RubyMethod("profile", RubyMethodAttributes.PublicSingleton)] + public static Hash/*!*/ GetProfile(RubyContext/*!*/ context, object self) { + if (!((RubyOptions)context.Options).Profile) { + throw RubyExceptions.CreateSystemCallError("You must enable profiling to use Clr.profile"); + } - [RubyMethod("profile", RubyMethodAttributes.PublicSingleton)] - public static object GetProfile(RubyContext/*!*/ context, BlockParam/*!*/ block, object self) { - if (!((RubyOptions)context.Options).Profile) { - throw RubyExceptions.CreateSystemCallError("You must enable profiling to use Clr.profile"); + Hash result = new Hash(context); + foreach (var entry in Profiler.Instance.GetProfile()) { + result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(entry.Value)); + } + return result; } - var start = Profiler.Instance.GetProfile(); - object blockResult; - if (block.Yield(out blockResult)) { - return blockResult; - } + [RubyMethod("profile", RubyMethodAttributes.PublicSingleton)] + public static object GetProfile(RubyContext/*!*/ context, BlockParam/*!*/ block, object self) { + if (!((RubyOptions)context.Options).Profile) { + throw RubyExceptions.CreateSystemCallError("You must enable profiling to use Clr.profile"); + } - Hash result = new Hash(context); - foreach (var entry in Profiler.Instance.GetProfile()) { - long startTime; - if (!start.TryGetValue(entry.Key, out startTime)) { - startTime = 0; + var start = Profiler.Instance.GetProfile(); + object blockResult; + if (block.Yield(out blockResult)) { + return blockResult; } - long elapsed = entry.Value - startTime; - if (elapsed > 0) { - result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(elapsed)); + + Hash result = new Hash(context); + foreach (var entry in Profiler.Instance.GetProfile()) { + long startTime; + if (!start.TryGetValue(entry.Key, out startTime)) { + startTime = 0; + } + long elapsed = entry.Value - startTime; + if (elapsed > 0) { + result[entry.Key] = Protocols.Normalize(Utils.DateTimeTicksFromStopwatch(elapsed)); + } } + return result; } - return result; } } } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/ParseTree/IronRubyParseTreeOps.cs;C667392 File: IronRubyParseTreeOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/ParseTree/IronRubyParseTreeOps.cs;C667392 (server) 12/5/2008 12:54 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/ParseTree/IronRubyParseTreeOps.cs;ScopesAndCrossRuntime @@ -27,7 +27,7 @@ using Microsoft.Scripting.Utils; namespace IronRuby.StandardLibrary.ParseTree { - [RubyModule("IronRuby")] + [RubyModule("IronRuby", Extends = typeof(Ruby))] public static class IronRubyOps { [RubyModule("ParseTree")] =================================================================== delete: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libs/clr.rb;C633889 File: clr.rb =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libs/clr.rb;C633889 (server) 12/5/2008 2:54 PM +++ [no target file] @@ -1,16 +1,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. -# -# -# **************************************************************************** - -load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.Clr' =================================================================== branch, edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libs/IronRuby.rb File: IronRuby.rb =================================================================== --- clr.rb (server) 12/5/2008 2:24 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libs/IronRuby.rb;ScopesAndCrossRuntime @@ -13,4 +13,4 @@ # # **************************************************************************** -load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.Clr' +load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.IronRubyModule' =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;C667395 File: Initializer.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;C667395 (server) 12/5/2008 1:01 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/Initializer.cs;ScopesAndCrossRuntime @@ -56,9 +56,9 @@ return _context.DefineLibraryClass(null, type, instanceTrait, classTrait, null, mixins, factories, false, _builtin); } - protected RubyModule/*!*/ DefineGlobalModule(string/*!*/ name, Type/*!*/ type, Action instanceTrait, + protected RubyModule/*!*/ DefineGlobalModule(string/*!*/ name, Type/*!*/ type, bool isSelfContained, Action instanceTrait, Action classTrait, RubyModule[]/*!*/ mixins) { - RubyModule module = _context.DefineLibraryModule(name, type, instanceTrait, classTrait, mixins); + RubyModule module = _context.DefineLibraryModule(name, type, instanceTrait, classTrait, mixins, isSelfContained); _context.ObjectClass.SetConstant(module.Name, module); return module; } @@ -72,14 +72,14 @@ // - Interface modules: // "type" parameter specifies the CLR interface being extended. // - protected RubyModule/*!*/ DefineModule(string/*!*/ name, Type/*!*/ type, Action instanceTrait, + protected RubyModule/*!*/ DefineModule(string/*!*/ name, Type/*!*/ type, bool isSelfContained, Action instanceTrait, Action classTrait, RubyModule[]/*!*/ mixins) { - return _context.DefineLibraryModule(name, type, instanceTrait, classTrait, mixins); + return _context.DefineLibraryModule(name, type, instanceTrait, classTrait, mixins, isSelfContained); } protected RubyModule/*!*/ ExtendModule(Type/*!*/ type, Action instanceTrait, Action classTrait, RubyModule[]/*!*/ mixins) { - return _context.DefineLibraryModule(null, type, instanceTrait, classTrait, mixins); + return _context.DefineLibraryModule(null, type, instanceTrait, classTrait, mixins, false); } protected object/*!*/ DefineSingleton(Action instanceTrait, Action classTrait, RubyModule[]/*!*/ mixins) { =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs;C656583 File: RubyModule.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs;C656583 (server) 12/5/2008 2:21 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyModule.cs;ScopesAndCrossRuntime @@ -29,6 +29,7 @@ using MSA = System.Linq.Expressions; using Ast = System.Linq.Expressions.Expression; using AstFactory = IronRuby.Compiler.Ast.AstFactory; +using System.Collections.ObjectModel; namespace IronRuby.Builtins { @@ -112,6 +113,8 @@ get { return ReferenceEquals(_singletonClass, this); } } + // TODO: We hold on RubyModule in rules. That keeps the module alive until the rule dies. + // We can allocate version in a separate object and let rule point to that object. [Emitted] public int Version { get { return _version; } @@ -126,6 +129,10 @@ internal set { _name = value; } } + public string GetName(RubyContext/*!*/ context) { + return context == _context ? _name : _name + "@" + _context.RuntimeId; + } + public virtual bool IsSingletonClass { get { return false; } } @@ -151,10 +158,6 @@ get { return null; } } - public RubyModule[]/*!*/ Mixins { - get { return _mixins; } - } - // default allocator: public RubyModule(RubyClass/*!*/ rubyClass) : this(rubyClass, null) { @@ -666,40 +669,45 @@ }); } - public void AddMethodAlias(string/*!*/ name, RubyMemberInfo/*!*/ method) { + public void AddMethodAlias(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method) { // Alias preserves visibility and declaring module even though the alias is declared in a different module (e.g. subclass) => // we can share method info (in fact, sharing is sound with Method#== semantics - it returns true on aliased methods). - AddMethod(name, method); + AddMethod(callerContext, name, method); } // adds method alias via define_method: - public void AddDefinedMethod(string/*!*/ name, RubyMemberInfo/*!*/ method) { + public void AddDefinedMethod(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method) { // copy method, Method#== returns false on defined methods: - AddMethod(name, method.Copy(method.Flags, this)); + AddMethod(callerContext, name, method.Copy(method.Flags, this)); } // adds instance and singleton methods of a module function: - public void AddModuleFunction(string/*!*/ name, RubyMemberInfo/*!*/ method) { - AddMethod(name, method.Copy(RubyMemberFlags.Private, this)); - SingletonClass.AddMethod(name, method.Copy(RubyMemberFlags.Public, SingletonClass)); + public void AddModuleFunction(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method) { + AddMethod(callerContext, name, method.Copy(RubyMemberFlags.Private, this)); + SingletonClass.AddMethod(callerContext, name, method.Copy(RubyMemberFlags.Public, SingletonClass)); } - public void SetMethodVisibility(string/*!*/ name, RubyMemberInfo/*!*/ method, RubyMethodVisibility visibility) { + public void SetMethodVisibility(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method, RubyMethodVisibility visibility) { if (method.Visibility != visibility) { - AddMethod(name, method.Copy((RubyMemberFlags)visibility, this)); + AddMethod(callerContext, name, method.Copy((RubyMemberFlags)visibility, this)); } } - public void AddMethod(string/*!*/ name, RubyMemberInfo/*!*/ method) { + public void AddMethod(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method) { Assert.NotNull(name, method); - SetMethodNoEvent(name, method); + SetMethodNoEvent(callerContext, name, method); _context.MethodAdded(this, name); } - internal void SetMethodNoEvent(string/*!*/ name, RubyMemberInfo/*!*/ method) { + internal void SetMethodNoEvent(RubyContext/*!*/ callerContext, string/*!*/ name, RubyMemberInfo/*!*/ method) { Assert.NotNull(name, method); + if (callerContext != _context) { + throw RubyExceptions.CreateTypeError(String.Format("Cannot define a method on a {0} `{1}' defined in a foreign runtime #{2}", + IsClass ? "class" : "module", _name, _context.RuntimeId)); + } + // Update only if the current method overrides/redefines another one in the inheritance hierarchy. // Method lookup failures are not cached in dynamic sites. // Therefore a future invocation of the method will trigger resolution in binder that will find just added method. @@ -777,9 +785,9 @@ public void SetLibraryMethod(string/*!*/ name, RubyMemberInfo/*!*/ method, bool noEvent) { // trigger event only for non-builtins: if (noEvent) { - SetMethodNoEvent(name, method); + SetMethodNoEvent(_context, name, method); } else { - AddMethod(name, method); + AddMethod(_context, name, method); } } @@ -1036,9 +1044,13 @@ }); } + public ReadOnlyCollection/*!*/ GetMixins() { + return new ReadOnlyCollection(_mixins); + } + internal void SetMixins(IList/*!*/ modules) { Debug.Assert(_mixins.Length == 0); - Debug.Assert(modules != null && CollectionUtils.TrueForAll(modules, delegate(RubyModule m) { return m != null && !m.IsClass; })); + Debug.Assert(modules != null && CollectionUtils.TrueForAll(modules, (m) => m != null && !m.IsClass && m.Context == _context)); // do not initialize modules: _mixins = MakeNewMixins(EmptyArray, modules); @@ -1047,7 +1059,7 @@ } public void IncludeModules(params RubyModule[]/*!*/ modules) { - Debug.Assert(CollectionUtils.TrueForAll(modules, delegate(RubyModule m) { return m != null && !m.IsClass; })); + RubyUtils.RequireMixins(this, modules); RubyModule[] tmp = MakeNewMixins(_mixins, modules); @@ -1190,20 +1202,9 @@ #endregion - internal void AddFullVersionTest(MetaObjectBuilder/*!*/ metaBuilder, MSA.Expression/*!*/ contextExpression) { - Assert.NotNull(metaBuilder); - EnsureInitialized(); // Initialization changes the version number, so ensure that the module is initialized - - // check for runtime: - metaBuilder.AddRestriction(Ast.Equal(contextExpression, Ast.Constant(_context))); - - // check for version: - metaBuilder.AddCondition(Ast.Equal(Ast.Property(Ast.Constant(this), VersionProperty), Ast.Constant(_version))); - } - #region Utils - public MutableString/*!*/ GetDisplayName(bool showEmptyName) { + public MutableString/*!*/ GetDisplayName(RubyContext/*!*/ context, bool showEmptyName) { if (IsSingletonClass) { RubyClass c = (RubyClass)this; object singletonOf; @@ -1221,14 +1222,14 @@ if (module == null) { nestings++; result.Append("#<"); - result.Append(c.SuperClass.Name); + result.Append(c.SuperClass.GetName(context)); result.Append(':'); RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(_context, singletonOf)); break; } if (!module.IsSingletonClass) { - result.Append(module.Name); + result.Append(module.GetName(context)); break; } @@ -1241,14 +1242,14 @@ } else { MutableString result = MutableString.CreateMutable(); result.Append("#<"); - result.Append(_context.GetClassOf(this).Name); + result.Append(_context.GetClassOf(this).GetName(context)); result.Append(':'); RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(_context, this)); result.Append('>'); return result; } } else { - return MutableString.Create(_name); + return MutableString.CreateMutable(GetName(context)); } } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C667395 File: RubyContext.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C667395 (server) 12/4/2008 5:29 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;ScopesAndCrossRuntime @@ -41,7 +41,8 @@ /// public sealed class RubyContext : LanguageContext { internal static readonly Guid RubyLanguageGuid = new Guid("F03C4640-DABA-473f-96F1-391400714DAB"); - + private static int _RuntimeIdGenerator = 0; + // MRI compliance: public static readonly string/*!*/ MriVersion = "1.8.6"; public static readonly string/*!*/ MriReleaseDate = "2008-05-28"; @@ -56,6 +57,7 @@ // TODO: remove internal static RubyContext _Default; + private readonly int _runtimeId; private readonly RubyScope/*!*/ _emptyScope; private RubyOptions/*!*/ _options; @@ -342,6 +344,10 @@ get { return RubyLanguageGuid; } } + public int RuntimeId { + get { return _runtimeId; } + } + #region Initialization public RubyContext(ScriptDomainManager/*!*/ manager, IDictionary options) @@ -349,6 +355,7 @@ ContractUtils.RequiresNotNull(manager, "manager"); _options = new RubyOptions(options); + _runtimeId = Interlocked.Increment(ref _RuntimeIdGenerator); _upTime = new Stopwatch(); _upTime.Start(); @@ -842,7 +849,7 @@ #region Libraries internal RubyModule/*!*/ DefineLibraryModule(string name, Type/*!*/ type, Action instanceTrait, - Action classTrait, RubyModule[]/*!*/ mixins) { + Action classTrait, RubyModule[]/*!*/ mixins, bool isSelfContained) { Assert.NotNull(type); Assert.NotNullItems(mixins); @@ -858,8 +865,9 @@ name = RubyUtils.GetQualifiedName(type); } - // setting tracker for interfaces: - TypeTracker tracker = type.IsInterface ? ReflectionCache.GetTypeTracker(type) : null; + // Setting tracker on the module makes CLR methods visible. + // Hide CLR methods if the type itself defines RubyMethods and is not an extension of another type. + TypeTracker tracker = isSelfContained ? null : ReflectionCache.GetTypeTracker(type); module = CreateModule(name, instanceTrait, classTrait, null, tracker); module.SetMixins(mixins); @@ -1688,14 +1696,19 @@ /// Creates a scope extension for DLR scopes that haven't been created by Ruby. /// These scopes adds method_missing and const_missing methods to handle lookups to the DLR scope. /// - public override ScopeExtension/*!*/ CreateScopeExtension(Scope/*!*/ globalScope) { + internal GlobalScopeExtension/*!*/ InitializeGlobalScope(Scope/*!*/ globalScope) { Assert.NotNull(globalScope); + var scopeExtension = globalScope.GetExtension(ContextId); + if (scopeExtension != null) { + return (GlobalScopeExtension)scopeExtension; + } + object mainObject = new Object(); RubyClass singletonClass = CreateMainSingleton(mainObject); // method_missing: - singletonClass.SetMethodNoEvent(Symbols.MethodMissing, new RubyMethodGroupInfo(new Delegate[] { + singletonClass.SetMethodNoEvent(this, Symbols.MethodMissing, new RubyMethodGroupInfo(new Delegate[] { new Func(RubyTopLevelScope.TopMethodMissing) }, RubyMemberFlags.Private, singletonClass)); @@ -1708,6 +1721,7 @@ GlobalScopeExtension result = new GlobalScopeExtension(this, globalScope, mainObject, true); singletonClass.SetGlobalScope(result); + globalScope.SetExtension(ContextId, result); return result; } @@ -1938,16 +1952,6 @@ #region Language Context Overrides - public override void SetName(CodeContext context, SymbolId name, object value) { - RubyScope scope = (RubyScope)context; - RubyOps.SetLocalVariable(value, scope, SymbolTable.IdToString(name)); - } - - public override bool TryLookupName(CodeContext context, SymbolId name, out object value) { - value = RubyOps.GetLocalVariable((RubyScope)context, SymbolTable.IdToString(name)); - return true; - } - public override TService GetService(params object[] args) { if (typeof(TService) == typeof(TokenizerService)) { return (TService)(object)new Tokenizer(); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C669565 File: RubyOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C669565 (server) 12/5/2008 3:39 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;ScopesAndCrossRuntime @@ -56,7 +56,7 @@ out object self, out RuntimeFlowControl/*!*/ rfc, string dataPath, int dataOffset) { Assert.NotNull(locals, globalScope, language); - GlobalScopeExtension rubyGlobalScope = (GlobalScopeExtension)language.EnsureScopeExtension(globalScope); + GlobalScopeExtension rubyGlobalScope = ((RubyContext)language).InitializeGlobalScope(globalScope); RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals); scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject); @@ -90,7 +90,7 @@ public static RubyTopLevelScope/*!*/ CreateTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc) { - RubyTopLevelScope scope = CreateTopLevelScopeInternal(locals, globalScope, language); + RubyTopLevelScope scope = CreateTopLevelScopeInternal(locals, globalScope, (RubyContext)language); self = scope.SelfObject; rfc = scope.RuntimeFlowControl; return scope; @@ -100,7 +100,7 @@ public static RubyTopLevelScope/*!*/ CreateWrappedTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc) { - RubyTopLevelScope scope = CreateTopLevelScopeInternal(locals, globalScope, language); + RubyTopLevelScope scope = CreateTopLevelScopeInternal(locals, globalScope, (RubyContext)language); RubyModule module = scope.RubyGlobalScope.Context.CreateModule(null, null, null, null, null); @@ -116,8 +116,8 @@ return scope; } - private static RubyTopLevelScope/*!*/ CreateTopLevelScopeInternal(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language) { - GlobalScopeExtension rubyGlobalScope = (GlobalScopeExtension)language.EnsureScopeExtension(globalScope); + private static RubyTopLevelScope/*!*/ CreateTopLevelScopeInternal(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, RubyContext/*!*/ context) { + GlobalScopeExtension rubyGlobalScope = context.InitializeGlobalScope(globalScope); RubyTopLevelScope result = new RubyTopLevelScope(rubyGlobalScope, null, locals); result.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject); result.SetDebugName("top-level"); @@ -530,13 +530,13 @@ RubyMethodInfo instanceMethod = null, singletonMethod = null; if (instanceOwner != null) { - SetMethod(instanceMethod = + SetMethod(scope.RubyContext, instanceMethod = new RubyMethodInfo(ast, clrMethod, instanceOwner, name, mandatory, optional, hasUnsplatParameter, instanceFlags) ); } if (singletonOwner != null) { - SetMethod(singletonMethod = + SetMethod(scope.RubyContext, singletonMethod = new RubyMethodInfo(ast, clrMethod, singletonOwner, name, mandatory, optional, hasUnsplatParameter, singletonFlags) ); } @@ -545,12 +545,12 @@ return instanceMethod ?? singletonMethod; } - private static void SetMethod(RubyMethodInfo/*!*/ method) { + private static void SetMethod(RubyContext/*!*/ callerContext, RubyMethodInfo/*!*/ method) { var owner = method.DeclaringModule; // Do not trigger the add-method event just yet, we need to assign the result into closure before executing any user code. // If the method being defined is "method_added" itself, we would call that method before the info gets assigned to the closure. - owner.SetMethodNoEvent(method.DefinitionName, method); + owner.SetMethodNoEvent(callerContext, method.DefinitionName, method); // expose RubyMethod in the scope (the method is bound to the main singleton instance): if (owner.GlobalScope != null) { @@ -582,7 +582,7 @@ RubyModule owner = scope.GetMethodDefinitionOwner(); RubyMemberInfo method = owner.ResolveMethodFallbackToObject(oldName, true); if (method != null) { - owner.AddMethodAlias(newName, method); + owner.AddMethodAlias(scope.RubyContext, newName, method); return; } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;C641155 File: RubyScope.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;C641155 (server) 12/4/2008 5:28 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyScope.cs;ScopesAndCrossRuntime @@ -40,13 +40,13 @@ #if !SILVERLIGHT [DebuggerTypeProxy(typeof(RubyScope.DebugView))] #endif - public abstract class RubyScope : CodeContext { + public abstract class RubyScope { internal static readonly LocalsDictionary _EmptyLocals = new LocalsDictionary(new IStrongBox[0], new SymbolId[0]); private readonly IAttributesCollection/*!*/ _frame; + private readonly RubyTopLevelScope/*!*/ _top; + private readonly RubyScope _parent; - private RubyTopLevelScope/*!*/ _top; - private object _selfObject; private RuntimeFlowControl/*!*/ _runtimeFlowControl; // TODO: merge? @@ -78,7 +78,7 @@ get { return _runtimeFlowControl; } } - public sealed override Scope GlobalScope { + public Scope GlobalScope { get { return _top.RubyGlobalScope.Scope; } } @@ -87,24 +87,30 @@ } public RubyContext/*!*/ RubyContext { - get { return (RubyContext)LanguageContext; } + get { return _top.RubyContext; } } public IAttributesCollection/*!*/ Frame { get { return _frame; } } + public RubyScope Parent { + get { return _parent; } + } + // top scope: - protected RubyScope(LanguageContext/*!*/ language, IAttributesCollection/*!*/ frame) - : base(null, language, null) { + protected RubyScope(IAttributesCollection/*!*/ frame) { + Assert.NotNull(frame); _frame = frame; _top = (RubyTopLevelScope)this; + _parent = null; } // other scopes: - protected RubyScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame) - : base(null, parent.Top.LanguageContext, parent) { + protected RubyScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame) { + Assert.NotNull(parent, frame); _frame = frame; + _parent = parent; _top = parent.Top; } @@ -341,7 +347,7 @@ public DebugView(RubyScope/*!*/ scope) { Assert.NotNull(scope); _scope = scope; - _selfClassName = _scope.RubyContext.GetImmediateClassOf(_scope._selfObject).GetDisplayName(true).ConvertToString(); + _selfClassName = _scope.RubyContext.GetImmediateClassOf(_scope._selfObject).GetDisplayName(_scope.RubyContext, true).ConvertToString(); } [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] @@ -353,7 +359,7 @@ foreach (KeyValuePair variable in scope._frame.SymbolAttributes) { string name = SymbolTable.IdToString(variable.Key); if (!name.StartsWith("#")) { - string className = _scope.RubyContext.GetImmediateClassOf(variable.Value).GetDisplayName(true).ConvertToString(); + string className = _scope.RubyContext.GetImmediateClassOf(variable.Value).GetDisplayName(_scope.RubyContext, true).ConvertToString(); if (scope != _scope) { name += " (outer)"; } @@ -424,8 +430,8 @@ private object _lastInputLine; // TODO: per method scope and top level scope, not block scope // top scope: - protected RubyClosureScope(LanguageContext/*!*/ language, IAttributesCollection/*!*/ frame) - : base(language, frame) { + protected RubyClosureScope(IAttributesCollection/*!*/ frame) + : base(frame) { } // other scopes: @@ -563,6 +569,7 @@ public override bool InheritsLocalVariables { get { return false; } } private readonly GlobalScopeExtension/*!*/ _globalScope; + private readonly RubyContext/*!*/ _context; private RubyModule _definitionsModule; public GlobalScopeExtension/*!*/ RubyGlobalScope { @@ -574,6 +581,10 @@ } } + internal new RubyContext/*!*/ RubyContext { + get { return _context; } + } + public override RubyModule Module { get { return _definitionsModule; } } @@ -587,14 +598,16 @@ } // empty scope: - internal RubyTopLevelScope(LanguageContext/*!*/ context) - : base(context, _EmptyLocals) { + internal RubyTopLevelScope(RubyContext/*!*/ context) + : base(_EmptyLocals) { + _context = context; } internal RubyTopLevelScope(GlobalScopeExtension/*!*/ globalScope, RubyModule definitionsModule, IAttributesCollection/*!*/ frame) - : base(globalScope.Context, frame) { + : base(frame) { Assert.NotNull(globalScope); _globalScope = globalScope; + _context = globalScope.Context; _definitionsModule = definitionsModule; } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs;C659171 File: RubyUtils.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs;C659171 (server) 12/5/2008 2:21 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs;ScopesAndCrossRuntime @@ -89,14 +89,15 @@ return MutableString.Create("..."); } + RubyClass objClass = context.GetClassOf(obj); MutableString str = MutableString.CreateMutable(); str.Append("#<"); - str.Append(context.GetClassOf(obj).Name); + str.Append(objClass.GetName(context)); // Ruby prints 2*object_id for objects str.Append(':'); AppendFormatHexObjectId(str, GetObjectId(context, obj)); - + // display instance variables RubyInstanceData data = context.TryGetInstanceData(obj); if (data != null) { @@ -455,7 +456,7 @@ return module; } - public static void RequireNonClasses(params RubyModule[]/*!*/ modules) { + public static void RequireMixins(RubyModule/*!*/ target, params RubyModule[]/*!*/ modules) { foreach (RubyModule module in modules) { if (module == null) { throw RubyExceptions.CreateTypeError("wrong argument type nil (expected Module)"); @@ -464,6 +465,12 @@ if (module.IsClass) { throw RubyExceptions.CreateTypeError("wrong argument type Class (expected Module)"); } + + if (module.Context != target.Context) { + throw RubyExceptions.CreateTypeError(String.Format("cannot mix a foreign module `{0}' into `{1}' (runtime mismatch)", + module.GetName(target.Context), target.GetName(module.Context) + )); + } } } @@ -804,5 +811,6 @@ } #endregion + } } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/MetaObjectBuilder.cs;C669565 File: MetaObjectBuilder.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/MetaObjectBuilder.cs;C669565 (server) 12/5/2008 2:21 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/MetaObjectBuilder.cs;ScopesAndCrossRuntime @@ -146,7 +146,7 @@ // singleton nil: if (target == null) { AddRestriction(Ast.Equal(targetParameter, Ast.Constant(null))); - context.NilClass.AddFullVersionTest(this, contextExpression); + AddFullVersionTest(context.NilClass, context, contextExpression); return; } @@ -158,9 +158,9 @@ )); if ((bool)target) { - context.TrueClass.AddFullVersionTest(this, contextExpression); + AddFullVersionTest(context.TrueClass, context, contextExpression); } else { - context.FalseClass.AddFullVersionTest(this, contextExpression); + AddFullVersionTest(context.FalseClass, context, contextExpression); } return; @@ -178,7 +178,7 @@ ); // we need to check for a runtime (e.g. "foo" .NET string instance could be shared accross runtimes): - immediateClass.AddFullVersionTest(this, contextExpression); + AddFullVersionTest(immediateClass, context, contextExpression); return; } @@ -203,10 +203,21 @@ throw new NotSupportedException("Type implementing IRubyObject should have RubyClass getter"); } else { // CLR objects: - immediateClass.AddFullVersionTest(this, contextExpression); + AddFullVersionTest(immediateClass, context, contextExpression); } } + internal void AddFullVersionTest(RubyModule/*!*/ module, RubyContext/*!*/ context, Expression/*!*/ contextExpression) { + Assert.NotNull(module, context, contextExpression); + module.EnsureInitialized(); // Initialization changes the version number, so ensure that the module is initialized + + // check for runtime (note that the module's runtime could be different from the call-site runtime): + AddRestriction(Ast.Equal(contextExpression, Ast.Constant(context))); + + // check for version: + AddCondition(Ast.Equal(Ast.Property(Ast.Constant(module), RubyModule.VersionProperty), Ast.Constant(module.Version))); + } + internal bool AddSplattedArgumentTest(object value, Expression/*!*/ expression, out int listLength, out ParameterExpression/*!*/ listVariable) { if (value == null) { AddRestriction(Ast.Equal(expression, Ast.Constant(null))); ===================================================================