edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Program.cs;C429806
File: Program.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Program.cs;C429806 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/ClassInitGenerator/Program.cs;Loader9
@@ -671,8 +671,6 @@
_output.Write("Context.FalseClass = ");
} else if (def.QualifiedName == "Exception") {
_output.Write("Context.ExceptionClass = ");
- } else if (def.QualifiedName == "RuntimeError") {
- _output.Write("Context.RuntimeErrorClass = ");
} else if (def.QualifiedName == "StandardError") {
_output.Write("Context.StandardErrorClass = ");
}
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Driver.cs;C420856
File: Driver.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Driver.cs;C420856 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Driver.cs;Loader9
@@ -59,6 +59,7 @@
_engine = IronRuby.GetEngine(_env);
_executionContext = IronRuby.GetExecutionContext(_engine);
_engine.Options.InterpretedMode = _driver.InterpretedMode;
+ ((RubyEngineOptions)_engine.Options).ShowWarnings = true;
}
}
@@ -278,5 +279,11 @@
Snippets.Shared.Dump();
}
}
+
+ internal string/*!*/ MakeTempDir() {
+ string dir = Path.Combine(Path.GetTempPath(), _testRuntime.TestName);
+ Directory.CreateDirectory(dir);
+ return dir;
+ }
}
}
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;C429806
File: IronRuby.Tests.csproj
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;C429806 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;Loader9
@@ -70,7 +70,7 @@
-
+
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C429806
File: RubyTests.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C429806 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;Loader9
@@ -187,9 +187,14 @@
// TODO: interop, hosting: Scenario_RubyConsole2,
Scenario_RubyConsole3,
Scenario_RubyConsole4,
- Scenario_RubyRequire1,
- // TODO: Ctlr+F5 doesn't work: Scenario_RubyRequire2,
- // TODO: interop, file loading: Scenario_RubyRequire3,
+
+ Loader_Assemblies1,
+
+ Require1,
+ RequireInterop1,
+ Load1,
+ LibraryLoader1,
+
Scenario_ClrFields1,
Scenario_ClrTypes1,
Scenario_ClrMethods1,
===================================================================
rename, edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C417101
File: LoaderTests.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;C417101 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/LoaderTests.cs;Loader9
@@ -27,14 +27,56 @@
using Ruby.Compiler;
using Ruby.Compiler.Ast;
using Ruby.Runtime;
+using System.Reflection;
+using Ruby.Builtins;
namespace Ruby.Tests {
public partial class Tests {
- public void Scenario_RubyRequire1() {
+
+ public void Loader_Assemblies1() {
+ string assembly;
+ string type;
+ string str;
+ bool b;
+
+ str = "a.rb";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == false);
+
+ str = "IronRuby";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == false);
+
+ str = @"..\foo\bar\a,b.rb";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == false);
+
+ str = "Ruby.Runtime.RubyContext, IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == true &&
+ assembly == "IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" &&
+ type == "Ruby.Runtime.RubyContext"
+ );
+
+ str = "IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == true && assembly == str && type == null);
+
+ str = "IronRuby, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == true && assembly == str && type == null);
+
+ str = "IronRuby, Version=1.0.0.0";
+ b = Loader.TryParseAssemblyName(str, out type, out assembly);
+ Assert(b == true && assembly == str && type == null);
+ }
+
+ public void Require1() {
try {
- File.WriteAllText("a.rb", @"
-C = 123
-");
+ string temp = _driver.MakeTempDir();
+ ExecutionContext.Loader.SetLoadPaths(temp);
+ File.WriteAllText(Path.Combine(temp, "a.rb"), @"C = 123");
+
AssertOutput(delegate() {
CompilerTest(@"
puts(require('a'))
@@ -44,51 +86,81 @@
true
123
");
+
+ AssertOutput(delegate() {
+ CompilerTest(@"
+puts(require('a.rb'))
+puts C
+");
+ }, @"
+false
+123
+");
} finally {
File.Delete("a.rb");
}
}
- public void Scenario_RubyRequire2() {
+ public void Load1() {
try {
- File.WriteAllText("a.rb", @"
-C = 123
+ string temp = _driver.MakeTempDir();
+ ExecutionContext.Loader.SetLoadPaths(temp);
+
+ File.WriteAllText(Path.Combine(temp, "a.rb"), @"C = 123");
+
+ AssertOutput(delegate() {
+ CompilerTest(@"
+puts(load('a.rb', true))
+puts C rescue puts 'error'
");
- AssertExceptionThrown(delegate() {
- CompilerTest(@"
-puts(load('a',true))
-puts C
+ }, @"
+true
+error
");
- });
} finally {
File.Delete("a.rb");
}
}
- public void Scenario_RubyRequire3() {
+ public void RequireInterop1() {
try {
- File.WriteAllText("b.py", @"
-def format(format, *args):
- return format % (args)
+ string temp = _driver.MakeTempDir();
+ ExecutionContext.Loader.SetLoadPaths(temp);
-x = 'Python'
+ File.WriteAllText(Path.Combine(temp, "a.py"), @"
+print 'Hello from Python'
");
AssertOutput(delegate() {
CompilerTest(@"
-#TODO: maybe we don't need to return a module, we can mix it in instead (load 'foo', true will do)
-a = require('b')
-puts a
-puts a.x
-puts a.format('Hello from %s on %s!', 'Ruby', 'Silverlight')
+require('a')
");
}, @"
-Microsoft.Scripting.ScriptModule
-Python
-Hello from Ruby on Silverlight!");
+Hello from Python
+");
} finally {
File.Delete("b.py");
}
}
+
+ public class TestLibraryInitializer1 : LibraryInitializer {
+ protected override void LoadModules() {
+ Context.ObjectClass.SetConstant("TEST_LIBRARY", "hello from library");
+ }
+ }
+
+ public void LibraryLoader1() {
+ ExecutionContext.DefineGlobalVariable("lib_name", MutableString.Create(typeof(TestLibraryInitializer1).AssemblyQualifiedName));
+
+ AssertOutput(delegate() {
+ CompilerTest(@"
+require($lib_name)
+puts TEST_LIBRARY
+");
+ }, @"
+hello from library
+");
+
+ }
}
}
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;C435539
File: Initializer.Generated.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;C435539 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;Loader9
@@ -189,7 +189,7 @@
DefineGlobalClass("RegexpError", typeof(Ruby.Builtins.RegexpError), typeof(Ruby.Builtins.RegexpErrorOps), null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] {
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.RegexpErrorOps.Factory),
});
- Ruby.Builtins.RubyClass def45 = Context.RuntimeErrorClass = DefineGlobalClass("RuntimeError", typeof(Ruby.Builtins.RuntimeError), null, null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, null);
+ Ruby.Builtins.RubyClass def45 = DefineGlobalClass("RuntimeError", typeof(Ruby.Builtins.RuntimeError), null, null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, null);
DefineGlobalClass("SecurityError", typeof(System.Security.SecurityException), typeof(Ruby.Builtins.SecurityErrorOps), null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] {
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.SecurityErrorOps.Factory),
});
@@ -1910,6 +1910,10 @@
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.Load),
});
+ module.DefineMethod("load_assembly", 0xa, new System.Delegate[] {
+ new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.LoadAssembly),
+ });
+
module.DefineMethod("local_variables", 0xa, new System.Delegate[] {
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.GetLocalVariableNames),
});
@@ -2070,6 +2074,10 @@
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.Load),
});
+ module.DefineMethod("load_assembly", 0x11, new System.Delegate[] {
+ new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.LoadAssembly),
+ });
+
module.DefineMethod("local_variables", 0x11, new System.Delegate[] {
new Microsoft.Scripting.Utils.Function(Ruby.Builtins.Kernel.GetLocalVariableNames),
});
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;C435539
File: Kernel.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;C435539 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Kernel.cs;Loader9
@@ -236,16 +236,22 @@
[RubyMethod("load", RubyMethodAttributes.PrivateInstance)]
[RubyMethod("load", RubyMethodAttributes.PublicSingleton)]
- public static bool Load(CodeContext/*!*/ context, object self, MutableString/*!*/ libraryName) {
- return RubyUtils.GetExecutionContext(context).Loader.LoadModule(context, self, libraryName.ConvertToString(), LoadFlags.None);
+ public static bool Load(CodeContext/*!*/ context, object self, [NotNull]MutableString/*!*/ libraryName) {
+ return RubyUtils.GetExecutionContext(context).Loader.LoadFile(context, self, libraryName, LoadFlags.None);
}
[RubyMethod("load", RubyMethodAttributes.PrivateInstance)]
[RubyMethod("load", RubyMethodAttributes.PublicSingleton)]
- public static bool Load(CodeContext/*!*/ context, object self, MutableString/*!*/ libraryName, bool wrap) {
- return RubyUtils.GetExecutionContext(context).Loader.LoadModule(context, self, libraryName.ConvertToString(), wrap ? LoadFlags.LoadIsolated : LoadFlags.None);
+ public static bool Load(CodeContext/*!*/ context, object self, [NotNull]MutableString/*!*/ libraryName, bool wrap) {
+ return RubyUtils.GetExecutionContext(context).Loader.LoadFile(context, self, libraryName, wrap ? LoadFlags.LoadIsolated : LoadFlags.None);
}
+ [RubyMethod("load_assembly", RubyMethodAttributes.PrivateInstance)]
+ [RubyMethod("load_assembly", RubyMethodAttributes.PublicSingleton)]
+ public static bool LoadAssembly(CodeContext/*!*/ context, object self, [NotNull]MutableString/*!*/ assemblyName, [Optional, NotNull]MutableString typeName) {
+ return RubyUtils.GetExecutionContext(context).Loader.LoadAssembly(assemblyName.ConvertToString(), typeName != null ? typeName.ConvertToString() : null, true);
+ }
+
[RubyMethod("local_variables", RubyMethodAttributes.PrivateInstance)]
[RubyMethod("local_variables", RubyMethodAttributes.PublicSingleton)]
public static RubyArray/*!*/ GetLocalVariableNames(CodeContext/*!*/ context, object self) {
@@ -833,7 +839,7 @@
[RubyMethod("require")]
[RubyMethod("require", RubyMethodAttributes.PublicSingleton)]
public static bool Require(CodeContext/*!*/ context, object self, [NotNull]MutableString/*!*/ libraryName) {
- return RubyUtils.GetExecutionContext(context).Loader.LoadModule(context, self, libraryName.ConvertToString(), LoadFlags.LoadOnce);
+ return RubyUtils.GetExecutionContext(context).Loader.LoadFile(context, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions);
}
#endregion
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C429806
File: Symbols.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C429806 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;Loader9
@@ -29,6 +29,7 @@
public static readonly SymbolId MethodMissing = SymbolTable.StringToId("method_missing");
public static readonly SymbolId RespondTo = SymbolTable.StringToId("respond_to?");
public static readonly SymbolId ToProc = SymbolTable.StringToId("to_proc");
+ public static readonly SymbolId ToStr = SymbolTable.StringToId("to_str");
public static readonly SymbolId Initialize = SymbolTable.StringToId("initialize");
public static readonly SymbolId Object = SymbolTable.StringToId("Object");
public static readonly SymbolId Kernel = SymbolTable.StringToId("Kernel");
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C435539
File: Loader.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;C435539 (server) 5/9/2008 2:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Loader.cs;Loader9
@@ -30,6 +30,10 @@
using Ruby.Builtins;
using Microsoft.Scripting.Utils;
using Microsoft.Scripting.Runtime;
+using System.Reflection;
+using System.Text.RegularExpressions;
+using Microsoft.Scripting.Actions;
+using Ruby.Runtime.Calls;
namespace Ruby.Runtime {
[Flags]
@@ -37,14 +41,16 @@
None = 0,
LoadOnce = 1,
LoadIsolated = 2,
+ AppendExtensions = 4,
}
public sealed class Loader {
- private enum FileKind {
+ internal enum FileKind {
RubySourceFile,
NonRubySourceFile,
Assembly,
+ Type,
Unknown,
}
@@ -57,19 +63,27 @@
private readonly RubyArray/*!*/ _loadedFiles;
///
- /// Thread safety: the user of this object is responsible for locking it.
+ /// TODO: Thread safety: the user of this object is responsible for locking it.
///
public RubyArray/*!*/ LoadPaths {
get { return _loadPaths; }
}
///
- /// Thread safety: the user of this object is responsible for locking it.
+ /// TODO: Thread safety: the user of this object is responsible for locking it.
///
- public List