add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Tokenizer/ParseInteger.rb File: ParseInteger.rb =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Experimental/Tokenizer/ParseInteger.rb;CompositeConversions3 @@ -1,0 +1,42 @@ +puts '- MRI bugs -' +p "0b1010".oct +p "0xFF".oct +p "0d500".oct +p "__12___3".to_i +p "__12___3".to_i(0) +p "__12___3".to_i(16) + +puts '---' + +p "-1234".hex == -4660 +p "+1234".hex == 4660 + +puts '---' +p " 0x2 ".to_i # default param value is 10 +p "".to_i +p " 2 ".to_i +puts '---' +p " 0x2 ".to_i(10) +p " 9 ".oct +p " -20 ".hex +p " -2 ".to_i +puts '---' +p " 0078 ".to_i(0) +p " 200\0100".to_i +puts '---' +p Integer(" 0x2_2_2122222222222222222222222222222222 ") +p Integer(" 2_2__2 ") rescue p $! +p Integer(" 2123123.12323 ") rescue p $! +p Integer(" 2123123 # ") rescue p $! +p Integer(" ") rescue p $! +p Integer(" - ") rescue p $! +p Integer(" - 1") rescue p $! +p Integer(" - 0x1") rescue p $! +p Integer(" \" - 0x1") rescue p $! +p Integer("") rescue p $! +p Integer("200\0100") rescue p $! +puts '---' +p "0b1010".hex +p "0d500".hex +p "abcdefG".hex +puts '---' =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;C698276 File: IronRuby.Tests.csproj =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;C698276 (server) 1/8/2009 2:13 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/IronRuby.Tests.csproj;CompositeConversions3 @@ -71,6 +71,7 @@ + =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C695629 File: RubyTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;C695629 (server) 1/7/2009 2:25 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/RubyTests.cs;CompositeConversions3 @@ -27,6 +27,7 @@ Identifiers1, Identifiers2, Scenario_ParseBigInts1, + ParseIntegers1, Scenario_ParseNumbers1, Scenario_ParseInstanceClassVariables1, ParseGlobalVariables1, @@ -423,7 +424,9 @@ Scenario_RubyThreads1, Scenario_YieldCodeGen, - Methods, + Methods1, + ToIntegerConversion1, + ToIntToStrConversion1, MethodAliasExpression, ClassDuplication1, ClassDuplication2, =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Parser/ParserTests.cs;C667392 File: ParserTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Parser/ParserTests.cs;C667392 (server) 1/8/2009 8:38 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Parser/ParserTests.cs;CompositeConversions3 @@ -149,9 +149,11 @@ public void Scenario_RubyCategorizer1() { TestCategorizer(Engine, "print 'foo' #bar", -1, new TokenInfo[] { new TokenInfo(new SourceSpan(new SourceLocation(0, 1, 1), new SourceLocation(5, 1, 6)), TokenCategory.Identifier, TokenTriggers.None), + new TokenInfo(new SourceSpan(new SourceLocation(5, 1, 6), new SourceLocation(6, 1, 7)), TokenCategory.WhiteSpace, TokenTriggers.None), new TokenInfo(new SourceSpan(new SourceLocation(6, 1, 7), new SourceLocation(7, 1, 8)), TokenCategory.StringLiteral, TokenTriggers.None), new TokenInfo(new SourceSpan(new SourceLocation(7, 1, 8), new SourceLocation(10, 1, 11)), TokenCategory.StringLiteral, TokenTriggers.None), new TokenInfo(new SourceSpan(new SourceLocation(10, 1, 11), new SourceLocation(11, 1, 12)), TokenCategory.StringLiteral, TokenTriggers.None), + new TokenInfo(new SourceSpan(new SourceLocation(11, 1, 12), new SourceLocation(12, 1, 13)), TokenCategory.WhiteSpace, TokenTriggers.None), new TokenInfo(new SourceSpan(new SourceLocation(12, 1, 13), new SourceLocation(16, 1, 17)), TokenCategory.LineComment, TokenTriggers.None), }); @@ -170,12 +172,16 @@ new TokenInfo(new SourceSpan(new SourceLocation(0, 1, 1), new SourceLocation(6, 1, 7)), TokenCategory.Identifier, TokenTriggers.None), // canvas new TokenInfo(new SourceSpan(new SourceLocation(6, 1, 7), new SourceLocation(7, 1, 8)), TokenCategory.Delimiter, TokenTriggers.MemberSelect), // . new TokenInfo(new SourceSpan(new SourceLocation(7, 1, 8), new SourceLocation(12, 1, 13)), TokenCategory.Identifier, TokenTriggers.None), // Event + new TokenInfo(new SourceSpan(new SourceLocation(12, 1, 13), new SourceLocation(13, 1, 14)), TokenCategory.WhiteSpace, TokenTriggers.None), // new TokenInfo(new SourceSpan(new SourceLocation(13, 1, 14), new SourceLocation(14, 1, 15)), TokenCategory.Grouping, TokenTriggers.MatchBraces), // { + new TokenInfo(new SourceSpan(new SourceLocation(14, 1, 15), new SourceLocation(15, 1, 16)), TokenCategory.WhiteSpace, TokenTriggers.None), // new TokenInfo(new SourceSpan(new SourceLocation(15, 1, 16), new SourceLocation(16, 1, 17)), TokenCategory.Grouping, TokenTriggers.MatchBraces), // | new TokenInfo(new SourceSpan(new SourceLocation(16, 1, 17), new SourceLocation(17, 1, 18)), TokenCategory.Identifier, TokenTriggers.None), // x new TokenInfo(new SourceSpan(new SourceLocation(17, 1, 18), new SourceLocation(18, 1, 19)), TokenCategory.Grouping, TokenTriggers.MatchBraces), // | + new TokenInfo(new SourceSpan(new SourceLocation(18, 1, 19), new SourceLocation(19, 1, 20)), TokenCategory.WhiteSpace, TokenTriggers.None), // \n // line 2 new TokenInfo(new SourceSpan(new SourceLocation(19, 2, 1), new SourceLocation(23, 2, 5)), TokenCategory.Identifier, TokenTriggers.None), // puts + new TokenInfo(new SourceSpan(new SourceLocation(23, 2, 5), new SourceLocation(24, 2, 6)), TokenCategory.WhiteSpace, TokenTriggers.None), // new TokenInfo(new SourceSpan(new SourceLocation(24, 2, 6), new SourceLocation(25, 2, 7)), TokenCategory.StringLiteral, TokenTriggers.None), // ' new TokenInfo(new SourceSpan(new SourceLocation(25, 2, 7), new SourceLocation(31, 2, 13)), TokenCategory.StringLiteral, TokenTriggers.None), // string new TokenInfo(new SourceSpan(new SourceLocation(31, 2, 13), new SourceLocation(32, 2, 14)), TokenCategory.StringLiteral, TokenTriggers.None), // ' @@ -279,6 +285,35 @@ } } + public void ParseIntegers1() { + IntegerValue x; + Assert((x = Tokenizer.ParseInteger("", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("", 16)).Equals(0)); + Assert((x = Tokenizer.ParseInteger(" ", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("-", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("+", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("0", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("00", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("0x", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("0x", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("-0x", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("+0x", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger(" 1234 ", 0)).Equals(1234)); + Assert((x = Tokenizer.ParseInteger(" 1_2_3_4 ", 0)).Equals(1234)); + Assert((x = Tokenizer.ParseInteger(" _1234 ", 0)).Equals(0)); + Assert((x = Tokenizer.ParseInteger(" 12a34 ", 0)).Equals(12)); + Assert((x = Tokenizer.ParseInteger(" 1_2__34 ", 0)).Equals(12)); + Assert((x = Tokenizer.ParseInteger(" -1_2", 0)).Equals(-12)); + Assert((x = Tokenizer.ParseInteger("0x1234", 0)).Equals(0x1234)); + Assert((x = Tokenizer.ParseInteger("0x1234", 10)).Equals(0)); + Assert((x = Tokenizer.ParseInteger("0b102", 0)).Equals(2)); + Assert((x = Tokenizer.ParseInteger("1000_000000_0000000000", 0)).Bignum.ToString() == "10000000000000000000"); + Assert((x = Tokenizer.ParseInteger("1000000_000000_0000000", 16)).Bignum.ToString() == "75557863725914323419136"); + Assert((x = Tokenizer.ParseInteger("0x1000000_000000_0000000", 0)).Bignum.ToString() == "75557863725914323419136"); + Assert((x = Tokenizer.ParseInteger("0b1000000_000000_0000000", 0)).Equals(524288)); + Assert((x = Tokenizer.ParseInteger("-0b1000000_000000_0000000", 0)).Equals(-524288)); + } + private void Scenario_ParseNumbers1() { AssertTokenizer t = AssertTokens(); @@ -884,9 +919,6 @@ foreach (TokenInfo info in actual) { Assert(i < expected.Length); if (!info.Equals(expected[i])) { -#if DEBUG - Console.WriteLine(""); // TODO: Fix Ruby -#endif Assert(false); } i++; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/MiscTests.cs;C633889 File: MiscTests.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/MiscTests.cs;C633889 (server) 1/7/2009 2:23 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/MiscTests.cs;CompositeConversions3 @@ -912,7 +912,7 @@ "); } - public void Methods() { + public void Methods1() { AssertOutput(delegate() { CompilerTest(@" class C =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ProtocolTests.cs File: ProtocolTests.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/IronRuby.Tests/Runtime/ProtocolTests.cs;CompositeConversions3 @@ -1,0 +1,164 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using IronRuby.Builtins; +using IronRuby.Runtime; + +namespace IronRuby.Tests { + + public class DefaultProtocolTester : LibraryInitializer { + protected override void LoadModules() { + DefineGlobalModule("Tests", typeof(DefaultProtocolTester), true, null, (module) => { + module.DefineLibraryMethod("to_int_to_str", (int)RubyMethodAttributes.PublicSingleton, new System.Delegate[] { + new Func, RubyArray>(ToIntToStr), + }); + module.DefineLibraryMethod("to_str_to_int", (int)RubyMethodAttributes.PublicSingleton, new System.Delegate[] { + new Func, RubyArray>(ToStrToInt), + }); + }, + RubyModule.EmptyArray); + } + + public static RubyArray ToIntToStr(RubyModule/*!*/ self, [DefaultProtocol]Union value) { + return RubyOps.MakeArray2(value.First, value.Second); + } + + public static RubyArray ToStrToInt(RubyModule/*!*/ self, [DefaultProtocol]Union value) { + return RubyOps.MakeArray2(value.First, value.Second); + } + } + + public partial class Tests { + public void ToIntegerConversion1() { + AssertOutput(delegate() { + CompilerTest(@" +class C + def to_i + 1000000000000 + end +end + +class D + def to_int + 1 + end +end + +class E + def respond_to? name + puts name + false + end +end + +puts Integer(123) +puts Integer(1230000000000000) +puts Integer(C.new) +puts Integer(D.new) +puts Integer(E.new) rescue puts $! +"); + }, @" +123 +1230000000000000 +1000000000000 +1 +to_int +to_i +can't convert E into Integer +"); + } + + private const string StrIntDeclarations = @" +require $protocol_tester + +class A + def to_str + 'A' + end +end + +class B + def to_int + 1 + end +end + +class C + def to_str + 'C' + end + + def to_int + 2 + end +end + +class E + def respond_to? name + puts name + false + end +end +"; + public void ToIntToStrConversion1() { + Context.DefineGlobalVariable("protocol_tester", MutableString.Create(typeof(DefaultProtocolTester).AssemblyQualifiedName)); + + Engine.Execute(StrIntDeclarations); + + AssertOutput(delegate() { + CompilerTest(@" +p Tests.to_int_to_str(123) +p Tests.to_int_to_str('xxx') +p Tests.to_int_to_str(A.new) +p Tests.to_int_to_str(B.new) +p Tests.to_int_to_str(C.new) +p Tests.to_int_to_str(E.new) rescue puts $! +"); + }, @" +[123, nil] +[0, ""xxx""] +[0, ""A""] +[1, nil] +[2, nil] +to_int +to_str +can't convert E into String +"); + + AssertOutput(delegate() { + CompilerTest(@" +p Tests.to_str_to_int(123) +p Tests.to_str_to_int('xxx') +p Tests.to_str_to_int(A.new) +p Tests.to_str_to_int(B.new) +p Tests.to_str_to_int(C.new) +p Tests.to_str_to_int(E.new) rescue puts $! +"); + }, @" +[nil, 123] +[""xxx"", 0] +[""A"", 0] +[nil, 1] +[""C"", 0] +to_str +to_int +can't convert E into Fixnum +"); + } + } +} =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C695629 File: Initializers.Generated.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C695629 (server) 1/7/2009 1:10 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;CompositeConversions3 @@ -79,16 +79,16 @@ new System.Action(IronRuby.Builtins.RubyStructOps.AllocatorUndefined), }); ExtendModule(typeof(System.Collections.Generic.IDictionary), new System.Action(LoadSystem__Collections__Generic__IDictionary_Instance), null, new IronRuby.Builtins.RubyModule[] {def21, }); - IronRuby.Builtins.RubyModule def35 = ExtendModule(typeof(System.Collections.IEnumerable), new System.Action(LoadSystem__Collections__IEnumerable_Instance), null, new IronRuby.Builtins.RubyModule[] {def21, }); + IronRuby.Builtins.RubyModule def36 = ExtendModule(typeof(System.Collections.IEnumerable), new System.Action(LoadSystem__Collections__IEnumerable_Instance), null, new IronRuby.Builtins.RubyModule[] {def21, }); ExtendModule(typeof(System.Collections.IList), new System.Action(LoadSystem__Collections__IList_Instance), null, new IronRuby.Builtins.RubyModule[] {def21, }); - ExtendModule(typeof(System.IComparable), new System.Action(LoadSystem__IComparable_Instance), null, new IronRuby.Builtins.RubyModule[] {def30, }); + IronRuby.Builtins.RubyModule def35 = ExtendModule(typeof(System.IComparable), new System.Action(LoadSystem__IComparable_Instance), null, new IronRuby.Builtins.RubyModule[] {def30, }); DefineGlobalClass("Array", typeof(IronRuby.Builtins.RubyArray), false, Context.ObjectClass, new System.Action(LoadArray_Instance), new System.Action(LoadArray_Class), new IronRuby.Builtins.RubyModule[] {def21, }, new System.Delegate[] { new System.Func(IronRuby.Builtins.ArrayOps.CreateArray), new System.Func, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Object, System.Object>(IronRuby.Builtins.ArrayOps.CreateArray), new System.Func(IronRuby.Builtins.ArrayOps.CreateArray), }); DefineGlobalClass("Binding", typeof(IronRuby.Builtins.Binding), false, Context.ObjectClass, null, null, IronRuby.Builtins.RubyModule.EmptyArray, null); - DefineGlobalClass("ClrString", typeof(System.String), false, Context.ObjectClass, new System.Action(LoadClrString_Instance), null, new IronRuby.Builtins.RubyModule[] {def35, }, null); + DefineGlobalClass("ClrString", typeof(System.String), false, Context.ObjectClass, new System.Action(LoadClrString_Instance), null, new IronRuby.Builtins.RubyModule[] {def35, def36, }, null); DefineGlobalClass("Dir", typeof(IronRuby.Builtins.RubyDir), true, Context.ObjectClass, new System.Action(LoadDir_Instance), new System.Action(LoadDir_Class), new IronRuby.Builtins.RubyModule[] {def21, }, null); #if !SILVERLIGHT DefineGlobalClass("Encoding", typeof(IronRuby.Builtins.RubyEncoding), false, Context.ObjectClass, new System.Action(LoadEncoding_Instance), new System.Action(LoadEncoding_Class), IronRuby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { @@ -108,7 +108,7 @@ new System.Func(IronRuby.Builtins.HashOps.CreateHash), new System.Func(IronRuby.Builtins.HashOps.CreateHash), }); - IronRuby.Builtins.RubyClass def32 = DefineGlobalClass("IO", typeof(IronRuby.Builtins.RubyIO), false, Context.ObjectClass, new System.Action(LoadIO_Instance), new System.Action(LoadIO_Class), new IronRuby.Builtins.RubyModule[] {def17, }, new System.Delegate[] { + IronRuby.Builtins.RubyClass def32 = DefineGlobalClass("IO", typeof(IronRuby.Builtins.RubyIO), false, Context.ObjectClass, new System.Action(LoadIO_Instance), new System.Action(LoadIO_Class), new IronRuby.Builtins.RubyModule[] {def17, def21, }, new System.Delegate[] { new System.Func(IronRuby.Builtins.RubyIOOps.CreateIO), new System.Func(IronRuby.Builtins.RubyIOOps.CreateIO), }); @@ -147,11 +147,11 @@ DefineGlobalClass("UnboundMethod", typeof(IronRuby.Builtins.UnboundMethod), true, Context.ObjectClass, new System.Action(LoadUnboundMethod_Instance), null, IronRuby.Builtins.RubyModule.EmptyArray, null); // Skipped primitive: Class IronRuby.Builtins.RubyClass def16 = DefineGlobalClass("File", typeof(IronRuby.Builtins.RubyFile), false, def32, new System.Action(LoadFile_Instance), new System.Action(LoadFile_Class), IronRuby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { - new System.Func(IronRuby.Builtins.RubyFileOps.CreateIO), - new System.Func(IronRuby.Builtins.RubyFileOps.CreateIO), - new System.Func(IronRuby.Builtins.RubyFileOps.CreateIO), - new System.Func(IronRuby.Builtins.RubyFileOps.CreateIO), - new System.Func(IronRuby.Builtins.RubyFileOps.CreateIO), + new System.Func, IronRuby.Builtins.MutableString, System.Int32, IronRuby.Builtins.RubyFile>(IronRuby.Builtins.RubyFileOps.CreateFile), + new System.Func, System.Int32, System.Int32, IronRuby.Builtins.RubyFile>(IronRuby.Builtins.RubyFileOps.CreateFile), + new System.Func(IronRuby.Builtins.RubyFileOps.CreateFile), + new System.Func(IronRuby.Builtins.RubyFileOps.CreateFile), + new System.Func(IronRuby.Builtins.RubyFileOps.CreateFile), }); DefineGlobalClass("Float", typeof(System.Double), false, def25, new System.Action(LoadFloat_Instance), new System.Action(LoadFloat_Class), new IronRuby.Builtins.RubyModule[] {def26, }, null); IronRuby.Builtins.RubyClass def33 = DefineGlobalClass("Integer", typeof(IronRuby.Builtins.Integer), true, def25, new System.Action(LoadInteger_Instance), new System.Action(LoadInteger_Class), new IronRuby.Builtins.RubyModule[] {def26, }, null); @@ -326,7 +326,7 @@ }); module.DefineLibraryMethod("pack", 0x51, new System.Delegate[] { - new System.Func, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyArray, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.ArrayOps.Pack), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyArray, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString>(IronRuby.Builtins.ArrayOps.Pack), }); module.DefineLibraryMethod("reverse!", 0x51, new System.Delegate[] { @@ -378,7 +378,7 @@ module.DefineLibraryMethod("&", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.BignumOps.And), new System.Func(IronRuby.Builtins.BignumOps.And), - new System.Func(IronRuby.Builtins.BignumOps.And), + new System.Func(IronRuby.Builtins.BignumOps.And), }); module.DefineLibraryMethod("*", 0x51, new System.Delegate[] { @@ -412,13 +412,13 @@ module.DefineLibraryMethod("^", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.BignumOps.Xor), new System.Func(IronRuby.Builtins.BignumOps.Xor), - new System.Func(IronRuby.Builtins.BignumOps.Xor), + new System.Func(IronRuby.Builtins.BignumOps.Xor), }); module.DefineLibraryMethod("|", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.BignumOps.BitwiseOr), new System.Func(IronRuby.Builtins.BignumOps.BitwiseOr), - new System.Func(IronRuby.Builtins.BignumOps.BitwiseOr), + new System.Func(IronRuby.Builtins.BignumOps.BitwiseOr), }); module.DefineLibraryMethod("~", 0x51, new System.Delegate[] { @@ -434,7 +434,7 @@ module.DefineLibraryMethod("<<", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.BignumOps.LeftShift), new System.Func(IronRuby.Builtins.BignumOps.LeftShift), - new System.Func(IronRuby.Builtins.BignumOps.LeftShift), + new System.Func(IronRuby.Builtins.BignumOps.LeftShift), }); module.DefineLibraryMethod("<=>", 0x51, new System.Delegate[] { @@ -452,7 +452,7 @@ module.DefineLibraryMethod(">>", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.BignumOps.RightShift), new System.Func(IronRuby.Builtins.BignumOps.RightShift), - new System.Func(IronRuby.Builtins.BignumOps.RightShift), + new System.Func(IronRuby.Builtins.BignumOps.RightShift), }); module.DefineLibraryMethod("abs", 0x51, new System.Delegate[] { @@ -1182,16 +1182,7 @@ new System.Func(IronRuby.Builtins.RubyFileOps.ModifiedTime), }); - module.DefineLibraryMethod("open", 0x61, new System.Delegate[] { - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - new System.Func(IronRuby.Builtins.RubyFileOps.Open), - }); + module.DefineRuleGenerator("open", 0x61, IronRuby.Builtins.RubyFileOps.Open()); module.DefineLibraryMethod("owned?", 0x61, new System.Delegate[] { new System.Func(IronRuby.Builtins.RubyFileOps.IsUserOwned), @@ -1304,9 +1295,6 @@ module.SetConstant("NONBLOCK", IronRuby.Builtins.RubyFileOps.Constants.NONBLOCK); module.SetConstant("RDONLY", IronRuby.Builtins.RubyFileOps.Constants.RDONLY); module.SetConstant("RDWR", IronRuby.Builtins.RubyFileOps.Constants.RDWR); - module.SetConstant("SEEK_CUR", IronRuby.Builtins.RubyFileOps.Constants.SEEK_CUR); - module.SetConstant("SEEK_END", IronRuby.Builtins.RubyFileOps.Constants.SEEK_END); - module.SetConstant("SEEK_SET", IronRuby.Builtins.RubyFileOps.Constants.SEEK_SET); module.SetConstant("TRUNC", IronRuby.Builtins.RubyFileOps.Constants.TRUNC); module.SetConstant("WRONLY", IronRuby.Builtins.RubyFileOps.Constants.WRONLY); @@ -1506,7 +1494,7 @@ module.DefineLibraryMethod("&", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.FixnumOps.BitwiseAnd), new System.Func(IronRuby.Builtins.FixnumOps.BitwiseAnd), - new System.Func(IronRuby.Builtins.FixnumOps.BitwiseAnd), + new System.Func(IronRuby.Builtins.FixnumOps.BitwiseAnd), }); module.DefineLibraryMethod("*", 0x51, new System.Delegate[] { @@ -1539,13 +1527,13 @@ module.DefineLibraryMethod("^", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.FixnumOps.BitwiseXor), new System.Func(IronRuby.Builtins.FixnumOps.BitwiseXor), - new System.Func(IronRuby.Builtins.FixnumOps.BitwiseXor), + new System.Func(IronRuby.Builtins.FixnumOps.BitwiseXor), }); module.DefineLibraryMethod("|", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.FixnumOps.BitwiseOr), new System.Func(IronRuby.Builtins.FixnumOps.BitwiseOr), - new System.Func(IronRuby.Builtins.FixnumOps.BitwiseOr), + new System.Func(IronRuby.Builtins.FixnumOps.BitwiseOr), }); module.DefineLibraryMethod("~", 0x51, new System.Delegate[] { @@ -1565,7 +1553,7 @@ module.DefineLibraryMethod("<<", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.FixnumOps.LeftShift), - new System.Func(IronRuby.Builtins.FixnumOps.LeftShift), + new System.Func(IronRuby.Builtins.FixnumOps.LeftShift), }); module.DefineLibraryMethod("<=", 0x51, new System.Delegate[] { @@ -1595,7 +1583,7 @@ module.DefineLibraryMethod(">>", 0x51, new System.Delegate[] { new System.Func(IronRuby.Builtins.FixnumOps.RightShift), - new System.Func(IronRuby.Builtins.FixnumOps.RightShift), + new System.Func(IronRuby.Builtins.FixnumOps.RightShift), }); module.DefineLibraryMethod("abs", 0x51, new System.Delegate[] { @@ -2106,7 +2094,7 @@ }); module.DefineLibraryMethod("printf", 0x51, new System.Delegate[] { - new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.RubyIOOps.PrintFormatted), + new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyIO, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.RubyIOOps.PrintFormatted), }); module.DefineLibraryMethod("putc", 0x51, new System.Delegate[] { @@ -2185,9 +2173,7 @@ } private void LoadIO_Class(IronRuby.Builtins.RubyModule/*!*/ module) { - module.DefineLibraryMethod("for_fd", 0x61, new System.Delegate[] { - new System.Func(IronRuby.Builtins.RubyIOOps.ForFd), - }); + module.DefineRuleGenerator("for_fd", 0x61, IronRuby.Builtins.RubyIOOps.ForFileDescriptor()); module.DefineLibraryMethod("foreach", 0x61, new System.Delegate[] { new System.Action(IronRuby.Builtins.RubyIOOps.ForEach), @@ -2354,7 +2340,7 @@ }); module.DefineLibraryMethod("format", 0x52, new System.Delegate[] { - new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), }); module.DefineLibraryMethod("freeze", 0x51, new System.Delegate[] { @@ -2421,7 +2407,8 @@ }); module.DefineLibraryMethod("Integer", 0x52, new System.Delegate[] { - new System.Func(IronRuby.Builtins.KernelOps.ToInteger), + new System.Func(IronRuby.Builtins.KernelOps.ToInteger), + new System.Func, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object>(IronRuby.Builtins.KernelOps.ToInteger), }); module.DefineLibraryMethod("is_a?", 0x51, new System.Delegate[] { @@ -2500,8 +2487,8 @@ }); module.DefineLibraryMethod("printf", 0x52, new System.Delegate[] { - new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), - new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), + new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), + new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), }); module.DefineLibraryMethod("private_methods", 0x51, new System.Delegate[] { @@ -2555,7 +2542,7 @@ }); module.DefineLibraryMethod("respond_to?", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.KernelOps.RespondTo), + new System.Func(IronRuby.Builtins.KernelOps.RespondTo), }); module.DefineLibraryMethod("select", 0x52, new System.Delegate[] { @@ -2605,7 +2592,7 @@ }); module.DefineLibraryMethod("sprintf", 0x52, new System.Delegate[] { - new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), }); module.DefineLibraryMethod("String", 0x52, new System.Delegate[] { @@ -2726,7 +2713,7 @@ }); module.DefineLibraryMethod("format", 0x61, new System.Delegate[] { - new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), }); module.DefineLibraryMethod("getc", 0x61, new System.Delegate[] { @@ -2743,7 +2730,8 @@ }); module.DefineLibraryMethod("Integer", 0x61, new System.Delegate[] { - new System.Func(IronRuby.Builtins.KernelOps.ToInteger), + new System.Func(IronRuby.Builtins.KernelOps.ToInteger), + new System.Func, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object>(IronRuby.Builtins.KernelOps.ToInteger), }); module.DefineLibraryMethod("lambda", 0x61, new System.Delegate[] { @@ -2794,8 +2782,8 @@ }); module.DefineLibraryMethod("printf", 0x61, new System.Delegate[] { - new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), - new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), + new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), + new System.Action, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.RubyContext, System.Object, System.Object, System.Object, System.Object[]>(IronRuby.Builtins.KernelOps.PrintFormatted), }); module.DefineLibraryMethod("proc", 0x61, new System.Delegate[] { @@ -2849,7 +2837,7 @@ }); module.DefineLibraryMethod("sprintf", 0x61, new System.Delegate[] { - new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, System.Object, IronRuby.Builtins.MutableString, System.Object[], IronRuby.Builtins.MutableString>(IronRuby.Builtins.KernelOps.Sprintf), }); module.DefineLibraryMethod("String", 0x61, new System.Delegate[] { @@ -4035,7 +4023,7 @@ module.HideMethod("clone"); module.HideMethod("version"); module.DefineLibraryMethod("%", 0x51, new System.Delegate[] { - new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, IronRuby.Builtins.MutableString, System.Object, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Format), + new System.Func, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.ConversionStorage, IronRuby.Runtime.RubyContext, IronRuby.Builtins.MutableString, System.Object, IronRuby.Builtins.MutableString>(IronRuby.Builtins.MutableStringOps.Format), }); module.DefineLibraryMethod("*", 0x51, new System.Delegate[] { @@ -4176,9 +4164,9 @@ }); module.DefineLibraryMethod("gsub", 0x51, new System.Delegate[] { + new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceAll), new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), - new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceAll), }); module.DefineLibraryMethod("gsub!", 0x51, new System.Delegate[] { @@ -4187,7 +4175,7 @@ }); module.DefineLibraryMethod("hex", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.MutableStringOps.ToIntegerHex), + new System.Func(IronRuby.Builtins.MutableStringOps.ToIntegerHex), }); module.DefineLibraryMethod("include?", 0x51, new System.Delegate[] { @@ -4253,7 +4241,7 @@ }); module.DefineLibraryMethod("oct", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.MutableStringOps.ToIntegerOctal), + new System.Func(IronRuby.Builtins.MutableStringOps.ToIntegerOctal), }); module.DefineLibraryMethod("replace", 0x51, new System.Delegate[] { @@ -4378,8 +4366,7 @@ }); module.DefineLibraryMethod("to_i", 0x51, new System.Delegate[] { - new System.Func(IronRuby.Builtins.MutableStringOps.ToInteger), - new System.Func(IronRuby.Builtins.MutableStringOps.ToInteger), + new System.Func(IronRuby.Builtins.MutableStringOps.ToInteger), }); module.DefineLibraryMethod("to_s", 0x51, new System.Delegate[] { =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;C674241 File: Protocols.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;C674241 (server) 1/7/2009 1:10 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;CompositeConversions3 @@ -41,8 +41,6 @@ private static readonly CallSite>/*!*/ _ToF = CallSite>.Create(RubySites.InstanceCallAction("to_f")), - _ToI = CallSite>.Create(RubySites.InstanceCallAction("to_i")), - _ToInt = CallSite>.Create(RubySites.InstanceCallAction("to_int")), _ToStr = CallSite>.Create(RubySites.InstanceCallAction("to_str")), _ToA = CallSite>.Create(RubySites.InstanceCallAction("to_a")), _ToAry = CallSite>.Create(RubySites.InstanceCallAction("to_ary")); @@ -59,7 +57,7 @@ /// /// Use this helper to downgrade BigIntegers as necessary. /// - public static object Normalize(BigInteger x) { + public static object/*!*/ Normalize(BigInteger/*!*/ x) { int result; if (x.AsInt32(out result)) { return ScriptingRuntimeHelpers.Int32ToObject(result); @@ -156,11 +154,11 @@ /// Throws if conversion fails /// public static double ConvertToFloat(RubyContext/*!*/ context, object value) { - if (value == null) { - throw RubyExceptions.CreateTypeError("can't convert nil into Float"); + if (value is double) { + return (double)value; } - if (value is int || value is double) { - return Converter.ConvertToDouble(value); + if (value is int) { + return (double)(int)value; } if (value is BigInteger) { return ((BigInteger)value).ToFloat64(); @@ -169,6 +167,10 @@ return ConvertStringToFloat(context, (MutableString)value); } + if (value == null) { + throw RubyExceptions.CreateTypeError("can't convert nil into Float"); + } + if (RubySites.RespondTo(context, value, "to_f")) { object obj = _ToF.Target(_ToF, context, value); if (!(obj is double)) { @@ -193,131 +195,61 @@ #endregion - #region ConvertToInteger, CastToInteger, CastToFixnum + #region ConvertToInteger, CastToInteger, CastToFixnum, CastToUInt32Unchecked, CastToUInt64Unchecked - private static bool AsPrimitiveInteger(object obj, out int intValue, out BigInteger bigValue) { - // TODO: All CLR primitive numeric types? - - if (obj is int) { - intValue = (int)obj; - bigValue = null; - return true; - } - - var big = obj as BigInteger; - if ((object)big != null) { - intValue = 0; - bigValue = big; - return true; - } - - intValue = 0; - bigValue = null; - return false; + public static IntegerValue ConvertToInteger(ConversionStorage/*!*/ integerConversion, RubyContext/*!*/ context, object value) { + var site = integerConversion.GetSite(CompositeConversionAction.ToIntToI); + return site.Target(site, context, value); } - /// - /// Standard way to convert to a Ruby Integer, using to_int and to_i - /// Trys to call to_int, followed by to_i (if implemented). - /// If neither is callable, throws a type error. - /// - public static void ConvertToInteger(RubyContext/*!*/ context, object obj, out int fixnum, out BigInteger bignum) { - // Don't call to_int, to_i on primitive types: - if (AsPrimitiveInteger(obj, out fixnum, out bignum)) { - return; - } - - if (RubySites.RespondTo(context, obj, "to_int")) { - object result = _ToInt.Target(_ToInt, context, obj); - if (AsPrimitiveInteger(result, out fixnum, out bignum)) { - return; - } - - throw RubyExceptions.MethodShouldReturnType(context, obj, "to_int", "Integer"); - } - - if (RubySites.RespondTo(context, obj, "to_i")) { - object result = _ToI.Target(_ToI, context, obj); - if (AsPrimitiveInteger(result, out fixnum, out bignum)) { - return; - } - - throw RubyExceptions.MethodShouldReturnType(context, obj, "to_i", "Integer"); - } - - throw RubyExceptions.CannotConvertTypeToTargetType(context, obj, "Integer"); + public static IntegerValue CastToInteger(ConversionStorage/*!*/ integerConversion, RubyContext/*!*/ context, object value) { + var site = integerConversion.GetSite(ConvertToIntAction.Instance); + return site.Target(site, context, value); } - /// - /// Try to cast the object to an Integer using to_int - /// Throws if the cast fails - /// Can return either Bignum or Fixnum - /// - public static void CastToInteger(RubyContext/*!*/ context, object obj, out int fixnum, out BigInteger bignum) { - // Don't call to_int on types derived from Integer - if (AsPrimitiveInteger(obj, out fixnum, out bignum)) { - return; - } - - if (RubySites.RespondTo(context, obj, "to_int")) { - object result = _ToInt.Target(_ToInt, context, obj); - if (AsPrimitiveInteger(result, out fixnum, out bignum)) { - return; - } - - throw RubyExceptions.InvalidValueForType(context, result, "Integer"); - } - - throw RubyExceptions.CannotConvertTypeToTargetType(context, obj, "Integer"); - } - - public static int CastToFixnum(ConversionStorage/*!*/ conversionStorage, RubyContext/*!*/ context, object obj) { + public static int CastToFixnum(ConversionStorage/*!*/ conversionStorage, RubyContext/*!*/ context, object value) { var site = conversionStorage.GetSite(ConvertToFixnumAction.Instance); - return site.Target(site, context, obj); + return site.Target(site, context, value); } /// /// Like CastToInteger, but converts the result to an unsigned int. /// - public static uint CastToUInt32Unchecked(RubyContext/*!*/ context, object obj) { + public static uint CastToUInt32Unchecked(ConversionStorage/*!*/ integerConversion, RubyContext/*!*/ context, object obj) { if (obj == null) { throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer"); } - int fixnum; - BigInteger bignum; - CastToInteger(context, obj, out fixnum, out bignum); - if ((object)bignum != null) { - uint u; - if (bignum.AsUInt32(out u)) { - return u; - } - throw RubyExceptions.CreateRangeError("bignum too big to convert into `unsigned long'"); + IntegerValue integer = CastToInteger(integerConversion, context, obj); + if (integer.IsFixnum) { + return unchecked((uint)integer.Fixnum); + } + + uint u; + if (integer.Bignum.AsUInt32(out u)) { + return u; } - - return unchecked((uint)fixnum); + throw RubyExceptions.CreateRangeError("bignum too big to convert into `unsigned long'"); } /// /// Like CastToInteger, but converts the result to an unsigned int. /// - public static ulong CastToUInt64Unchecked(RubyContext/*!*/ context, object obj) { + public static ulong CastToUInt64Unchecked(ConversionStorage/*!*/ integerConversion, RubyContext/*!*/ context, object obj) { if (obj == null) { throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer"); } - int fixnum; - BigInteger bignum; - CastToInteger(context, obj, out fixnum, out bignum); - if ((object)bignum != null) { - ulong u; - if (bignum.AsUInt64(out u)) { - return u; - } - throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad long'"); + IntegerValue integer = CastToInteger(integerConversion, context, obj); + if (integer.IsFixnum) { + return unchecked((ulong)integer.Fixnum); } - return unchecked((ulong)fixnum); + ulong u; + if (integer.Bignum.AsUInt64(out u)) { + return u; + } + throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad long'"); } #endregion =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs;C674241 File: ArrayOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs;C674241 (server) 1/7/2009 7:34 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ArrayOps.cs;CompositeConversions3 @@ -229,7 +229,9 @@ #region pack [RubyMethod("pack")] - public static MutableString/*!*/ Pack(ConversionStorage/*!*/ stringCast, + public static MutableString/*!*/ Pack( + ConversionStorage/*!*/ integerConversion, + ConversionStorage/*!*/ stringCast, RubyContext/*!*/ context, RubyArray/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format) { using (MutableStringStream stream = new MutableStringStream()) { @@ -271,61 +273,61 @@ case 'Q': case 'q': for (int j = 0; j < count; j++) { - writer.Write(Protocols.CastToUInt64Unchecked(context, self[i + j])); + writer.Write(Protocols.CastToUInt64Unchecked(integerConversion, context, self[i + j])); } break; case 'l': case 'i': for (int j = 0; j < count; j++) { - writer.Write(unchecked((int)Protocols.CastToUInt32Unchecked(context, self[i + j]))); + writer.Write(unchecked((int)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]))); } break; case 'L': case 'I': for (int j = 0; j < count; j++) { - writer.Write(Protocols.CastToUInt32Unchecked(context, self[i + j])); + writer.Write(Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j])); } break; case 'N': // unsigned 4-byte big-endian - WriteUInt32(writer, self, context, i, count, BitConverter.IsLittleEndian); + WriteUInt32(integerConversion, writer, self, context, i, count, BitConverter.IsLittleEndian); break; case 'n': // unsigned 2-byte big-endian - WriteUInt16(writer, self, context, i, count, BitConverter.IsLittleEndian); + WriteUInt16(integerConversion, writer, self, context, i, count, BitConverter.IsLittleEndian); break; case 'V': // unsigned 4-byte little-endian - WriteUInt32(writer, self, context, i, count, !BitConverter.IsLittleEndian); + WriteUInt32(integerConversion, writer, self, context, i, count, !BitConverter.IsLittleEndian); break; case 'v': // unsigned 2-byte little-endian - WriteUInt16(writer, self, context, i, count, !BitConverter.IsLittleEndian); + WriteUInt16(integerConversion, writer, self, context, i, count, !BitConverter.IsLittleEndian); break; case 's': for (int j = 0; j < count; j++) { - writer.Write(unchecked((short)Protocols.CastToUInt32Unchecked(context, self[i + j]))); + writer.Write(unchecked((short)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]))); } break; case 'S': for (int j = 0; j < count; j++) { - writer.Write(unchecked((ushort)Protocols.CastToUInt32Unchecked(context, self[i + j]))); + writer.Write(unchecked((ushort)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]))); } break; case 'c': for (int j = 0; j < count; j++) { - writer.Write(unchecked((sbyte)Protocols.CastToUInt32Unchecked(context, self[i + j]))); + writer.Write(unchecked((sbyte)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]))); } break; case 'C': for (int j = 0; j < count; j++) { - writer.Write(unchecked((byte)Protocols.CastToUInt32Unchecked(context, self[i + j]))); + writer.Write(unchecked((byte)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]))); } break; @@ -346,7 +348,7 @@ case 'U': char[] buffer = new char[count]; for (int j = 0; j < count; j++) { - buffer[j] = unchecked((char)Protocols.CastToUInt32Unchecked(context, self[i + j])); + buffer[j] = unchecked((char)Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j])); } writer.Write(Encoding.UTF8.GetBytes(buffer)); break; @@ -391,9 +393,10 @@ } } - private static void WriteUInt64(BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { + private static void WriteUInt64(ConversionStorage/*!*/ integerConversion, + BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { for (int j = 0; j < count; j++) { - uint n = Protocols.CastToUInt32Unchecked(context, self[i + j]); + uint n = Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]); if (swap) { writer.Write((byte)(n >> 24)); writer.Write((byte)((n >> 16) & 0xff)); @@ -405,9 +408,10 @@ } } - private static void WriteUInt32(BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { + private static void WriteUInt32(ConversionStorage/*!*/ integerConversion, + BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { for (int j = 0; j < count; j++) { - uint n = Protocols.CastToUInt32Unchecked(context, self[i + j]); + uint n = Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]); if (swap) { writer.Write((byte)(n >> 24)); writer.Write((byte)((n >> 16) & 0xff)); @@ -419,9 +423,10 @@ } } - private static void WriteUInt16(BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { + private static void WriteUInt16(ConversionStorage/*!*/ integerConversion, + BinaryWriter/*!*/ writer, RubyArray/*!*/ self, RubyContext/*!*/ context, int i, int count, bool swap) { for (int j = 0; j < count; j++) { - uint n = Protocols.CastToUInt32Unchecked(context, self[i + j]); + uint n = Protocols.CastToUInt32Unchecked(integerConversion, context, self[i + j]); if (swap) { writer.Write((byte)((n >> 8) & 0xff)); writer.Write((byte)(n & 0xff)); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;C674241 File: BigNumOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;C674241 (server) 1/7/2009 1:27 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;CompositeConversions3 @@ -540,14 +540,14 @@ /// This is because Bignum is supposed to look like it is stored in 2s complement format. /// [RubyMethod("<<")] - public static object LeftShift(BigInteger/*!*/ self, int other) { + public static object/*!*/ LeftShift(BigInteger/*!*/ self, int other) { BigInteger result = self << other; result = ShiftOverflowCheck(self, result); return Protocols.Normalize(result); } [RubyMethod("<<")] - public static object LeftShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ LeftShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { // Dodgy error message but matches MRI throw RubyExceptions.CreateRangeError("bignum too big to convert into long"); } @@ -558,11 +558,8 @@ /// self << other, as Bignum or Fixnum /// other is converted to an Integer by dynamically invoking self.to_int [RubyMethod("<<")] - public static object LeftShift(RubyContext/*!*/ context, BigInteger/*!*/ self, object other) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, other, out fixnum, out bignum); - return ((object)bignum != null) ? LeftShift(self, bignum) : LeftShift(self, fixnum); + public static object/*!*/ LeftShift(RubyContext/*!*/ context, BigInteger/*!*/ self, [DefaultProtocol]IntegerValue other) { + return other.IsFixnum ? LeftShift(self, other.Fixnum) : LeftShift(self, other.Bignum); } #endregion @@ -578,14 +575,14 @@ /// This is because Bignum is supposed to look like it is stored in 2s complement format. /// [RubyMethod(">>")] - public static object RightShift(BigInteger/*!*/ self, int other) { + public static object/*!*/ RightShift(BigInteger/*!*/ self, int other) { BigInteger result = self >> other; result = ShiftOverflowCheck(self, result); return Protocols.Normalize(result); } [RubyMethod(">>")] - public static object RightShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ RightShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { if (self.IsNegative()) { return -1; } @@ -598,11 +595,8 @@ /// self >> other, as Bignum or Fixnum /// other is converted to an Integer by dynamically invoking self.to_int [RubyMethod(">>")] - public static object RightShift(RubyContext/*!*/ context, BigInteger/*!*/ self, object other) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, other, out fixnum, out bignum); - return ((object)bignum != null) ? RightShift(self, bignum) : RightShift(self, fixnum); + public static object/*!*/ RightShift(RubyContext/*!*/ context, BigInteger/*!*/ self, [DefaultProtocol]IntegerValue other) { + return other.IsFixnum ? RightShift(self, other.Fixnum) : RightShift(self, other.Bignum); } #endregion @@ -610,12 +604,12 @@ #region | [RubyMethod("|")] - public static object BitwiseOr(BigInteger/*!*/ self, int other) { + public static object/*!*/ BitwiseOr(BigInteger/*!*/ self, int other) { return Protocols.Normalize(self | other); } [RubyMethod("|")] - public static object BitwiseOr(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ BitwiseOr(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { return Protocols.Normalize(self | other); } @@ -624,11 +618,8 @@ /// /// other is dynamically converted to an Integer by other.to_int then | is invoked dynamically. E.g. self | (index.to_int) [RubyMethod("|")] - public static object BitwiseOr(RubyContext/*!*/ context, BigInteger/*!*/ self, object other) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, other, out fixnum, out bignum); - return ((object)bignum != null) ? BitwiseOr(self, bignum) : BitwiseOr(self, fixnum); + public static object/*!*/ BitwiseOr(RubyContext/*!*/ context, BigInteger/*!*/ self, [DefaultProtocol]IntegerValue other) { + return other.IsFixnum ? BitwiseOr(self, other.Fixnum) : BitwiseOr(self, other.Bignum); } #endregion @@ -636,12 +627,12 @@ #region & [RubyMethod("&")] - public static object And(BigInteger/*!*/ self, int other) { + public static object/*!*/ And(BigInteger/*!*/ self, int other) { return Protocols.Normalize(self & other); } [RubyMethod("&")] - public static object And(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ And(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { return Protocols.Normalize(self & other); } @@ -650,11 +641,8 @@ /// /// other is dynamically converted to an Integer by other.to_int then & is invoked dynamically. E.g. self & (index.to_int) [RubyMethod("&")] - public static object And(RubyContext/*!*/ context, BigInteger/*!*/ self, object other) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, other, out fixnum, out bignum); - return ((object)bignum != null) ? And(self, bignum) : And(self, fixnum); + public static object/*!*/ And(RubyContext/*!*/ context, BigInteger/*!*/ self, [DefaultProtocol]IntegerValue other) { + return other.IsFixnum ? And(self, other.Fixnum) : And(self, other.Bignum); } #endregion @@ -662,12 +650,12 @@ #region ^ [RubyMethod("^")] - public static object Xor(BigInteger/*!*/ self, int other) { + public static object/*!*/ Xor(BigInteger/*!*/ self, int other) { return Protocols.Normalize(self ^ other); } [RubyMethod("^")] - public static object Xor(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ Xor(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { return Protocols.Normalize(self ^ other); } @@ -676,11 +664,8 @@ /// /// other is dynamically converted to an Integer by other.to_int then ^ is invoked dynamically. E.g. self ^ (index.to_int) [RubyMethod("^")] - public static object Xor(RubyContext/*!*/ context, BigInteger/*!*/ self, object other) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, other, out fixnum, out bignum); - return ((object)bignum != null) ? Xor(self, bignum) : Xor(self, fixnum); + public static object/*!*/ Xor(RubyContext/*!*/ context, BigInteger/*!*/ self, [DefaultProtocol]IntegerValue other) { + return other.IsFixnum ? Xor(self, other.Fixnum) : Xor(self, other.Bignum); } #endregion =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs;C674241 File: FileOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs;C674241 (server) 1/7/2009 10:23 AM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FileOps.cs;CompositeConversions3 @@ -14,13 +14,13 @@ * ***************************************************************************/ using System; +using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using IronRuby.Runtime; +using IronRuby.Runtime.Calls; using Microsoft.Scripting; using Microsoft.Scripting.Runtime; -using IronRuby.Runtime; -using IronRuby.Runtime.Calls; -using System.Diagnostics; namespace IronRuby.Builtins { @@ -30,41 +30,58 @@ [RubyClass("File", Extends = typeof(RubyFile))] public class RubyFileOps { + #region Construction + [RubyConstructor] - public static RubyIO CreateIO(RubyClass/*!*/ self, MutableString/*!*/ path) { - return new RubyFile(self.Context, path.ConvertToString(), "r"); + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, + [DefaultProtocol]Union descriptorOrPath, [Optional, DefaultProtocol]MutableString mode, [Optional]int permission) { + + if (descriptorOrPath.IsFixnum()) { + // TODO: descriptor + throw new NotImplementedException(); + } else { + // TODO: permissions + return CreateFile(self, descriptorOrPath.Second, mode); + } } [RubyConstructor] - public static RubyIO CreateIO(RubyClass/*!*/ self, MutableString/*!*/ path, MutableString modeString) { - return new RubyFile(self.Context, path.ConvertToString(), - (modeString != null) ? modeString.ConvertToString() : "r"); + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, + [DefaultProtocol]Union descriptorOrPath, int mode, [Optional]int permission) { + + if (descriptorOrPath.IsFixnum()) { + // TODO: descriptor + throw new NotImplementedException(); + } else { + // TODO: permissions + return CreateFile(self, descriptorOrPath.Second, mode); + } } [RubyConstructor] - public static RubyIO CreateIO(RubyClass/*!*/ self, MutableString/*!*/ path, MutableString modeString, int permissions) { - // TODO: make this actually do something with permissions - return new RubyFile(self.Context, path.ConvertToString(), - (modeString != null) ? modeString.ConvertToString() : "r"); + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path) { + return new RubyFile(self.Context, path.ConvertToString(), "r"); } [RubyConstructor] - public static RubyIO CreateIO(RubyClass/*!*/ self, MutableString/*!*/ path, int fileMode) { - return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)fileMode); + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, MutableString mode) { + return new RubyFile(self.Context, path.ConvertToString(), (mode != null) ? mode.ConvertToString() : "r"); } [RubyConstructor] - public static RubyIO CreateIO(RubyClass/*!*/ self, MutableString/*!*/ path, int fileMode, int permissions) { - // TODO: make this actually do something with permissions - return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)fileMode); + public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, int mode) { + return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)mode); } - #region Private Singleton Methods - #endregion #region Public Singleton Methods + [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] + public static RuleGenerator/*!*/ Open() { + return RubyIOOps.Open(); + } + [RubyMethod("atime", RubyMethodAttributes.PublicSingleton)] public static DateTime AccessTime(RubyClass/*!*/ self, [DefaultProtocol]MutableString/*!*/ path) { return RubyStatOps.AccessTime(RubyStatOps.Create(self.Context, path)); @@ -397,54 +414,6 @@ return RubyStatOps.ModifiedTime(RubyStatOps.Create(self.Context, path)); } - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, [NotNull]MutableString/*!*/ mode) { - RubyIO io = RubyIOOps._CreateIOSharedSite2.Target(RubyIOOps._CreateIOSharedSite2, self.Context, self, path, mode); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, object path, object mode) { - RubyIO io = RubyIOOps._CreateIOSharedSite2.Target(RubyIOOps._CreateIOSharedSite2, self.Context, self, Protocols.CastToString(self.Context, path), Protocols.CastToString(self.Context, mode)); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path) { - RubyIO io = RubyIOOps._CreateIOSharedSite3.Target(RubyIOOps._CreateIOSharedSite3, self.Context, self, path); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, object path) { - RubyIO io = RubyIOOps._CreateIOSharedSite3.Target(RubyIOOps._CreateIOSharedSite3, self.Context, self, Protocols.CastToString(self.Context, path)); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, [NotNull]MutableString/*!*/ path, int fileMode) { - RubyIO io = RubyIOOps._CreateIOSharedSite4.Target(RubyIOOps._CreateIOSharedSite4, self.Context, self, path, fileMode); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, object path, int fileMode) { - RubyIO io = RubyIOOps._CreateIOSharedSite4.Target(RubyIOOps._CreateIOSharedSite4, self.Context, self, Protocols.CastToString(self.Context, path), fileMode); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, object path, int fileMode, int permissions) { - RubyIO io = RubyIOOps._CreateIOSharedSite5.Target(RubyIOOps._CreateIOSharedSite5, self.Context, self, Protocols.CastToString(self.Context, path), fileMode, permissions); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - - [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] - public static object Open(BlockParam/*!*/ block, RubyClass/*!*/ self, MutableString/*!*/ path, MutableString/*!*/ mode, int permissions) { - RubyIO io = RubyIOOps._CreateIOSharedSite7.Target(RubyIOOps._CreateIOSharedSite7, self.Context, self, path, mode, permissions); - return RubyIOOps.TryInvokeOpenBlock(self.Context, block, io); - } - [RubyMethod("owned?", RubyMethodAttributes.PublicSingleton)] public static bool IsUserOwned(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) { return RubyStatOps.IsUserOwned(RubyStatOps.Create(self.Context, path)); @@ -699,12 +668,6 @@ [RubyConstant] public readonly static int RDWR = (int)RubyFileMode.RDWR; [RubyConstant] - public readonly static int SEEK_CUR = 0x01; - [RubyConstant] - public readonly static int SEEK_END = 0x02; - [RubyConstant] - public readonly static int SEEK_SET = 0x00; - [RubyConstant] public readonly static int TRUNC = (int)RubyFileMode.TRUNC; [RubyConstant] public readonly static int WRONLY = (int)RubyFileMode.WRONLY; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;C674241 File: FixnumOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;C674241 (server) 1/7/2009 1:28 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;CompositeConversions3 @@ -105,7 +105,7 @@ /// The value after the shift /// Converts to Bignum if the result cannot fit into Fixnum [RubyMethod("<<")] - public static object LeftShift(RubyContext/*!*/ context, int self, object other) { + public static object LeftShift(RubyContext/*!*/ context, int self, [DefaultProtocol]IntegerValue other) { return BignumOps.LeftShift(context, self, other); } @@ -140,7 +140,7 @@ /// The value after the shift /// Converts to Bignum if the result cannot fit into Fixnum [RubyMethod(">>")] - public static object RightShift(RubyContext/*!*/ context, int self, object other) { + public static object RightShift(RubyContext/*!*/ context, int self, [DefaultProtocol]IntegerValue other) { return BignumOps.RightShift(context, self, other); } @@ -199,30 +199,35 @@ #endregion #region ^ + /// /// Performs bitwise XOR on self and other /// [RubyMethod("^")] - public static object BitwiseXor(int self, int other) { + public static object/*!*/ BitwiseXor(int self, int other) { return self ^ other; } + /// /// Performs bitwise XOR on self and other /// [RubyMethod("^")] - public static object BitwiseXor(int self, [NotNull]BigInteger/*!*/ other) { + public static object/*!*/ BitwiseXor(int self, [NotNull]BigInteger/*!*/ other) { return other ^ self; } + /// /// Performs bitwise XOR on self and other, where other is not Fixnum or Bignum /// [RubyMethod("^")] - public static object BitwiseXor(RubyContext/*!*/ context, int self, object other) { + public static object/*!*/ BitwiseXor(RubyContext/*!*/ context, int self, [DefaultProtocol]IntegerValue other) { return BignumOps.Xor(context, self, other); } + #endregion #region & + /// /// Performs bitwise AND on self and other, where other is Fixnum /// @@ -230,6 +235,7 @@ public static object BitwiseAnd(int self, int other) { return self & other; } + /// /// Performs bitwise AND on self and other, where other is Bignum /// @@ -237,16 +243,19 @@ public static object BitwiseAnd(int self, [NotNull]BigInteger/*!*/ other) { return other & self; } + /// /// Performs bitwise AND on self and other, where other is not Fixnum or Bignum /// [RubyMethod("&")] - public static object BitwiseAnd(RubyContext/*!*/ context, int self, object other) { + public static object BitwiseAnd(RubyContext/*!*/ context, int self, [DefaultProtocol]IntegerValue other) { return BignumOps.And(context, self, other); } + #endregion #region | + /// /// Performs bitwise OR on self and other /// @@ -254,6 +263,7 @@ public static object BitwiseOr(int self, int other) { return self | other; } + /// /// Performs bitwise OR on self and other /// @@ -261,13 +271,15 @@ public static object BitwiseOr(int self, [NotNull]BigInteger/*!*/ other) { return other | self; } + /// /// Performs bitwise OR on self and other, where other is not Fixnum or Bignum /// [RubyMethod("|")] - public static object BitwiseOr(RubyContext/*!*/ context, int self, object other) { + public static object BitwiseOr(RubyContext/*!*/ context, int self, [DefaultProtocol]IntegerValue other) { return BignumOps.BitwiseOr(context, self, other); } + #endregion #region ~ =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FloatOps.cs;C674241 File: FloatOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FloatOps.cs;C674241 (server) 1/7/2009 1:26 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FloatOps.cs;CompositeConversions3 @@ -593,7 +593,7 @@ /// [RubyMethod("to_s")] public static MutableString ToS(RubyContext/*!*/ context, double self) { - StringFormatter sf = new StringFormatter(null, null, context, "%.15g", new object[] { self }); + StringFormatter sf = new StringFormatter(context, "%.15g", new object[] { self }); sf.TrailingZeroAfterWholeFloat = true; return sf.Format(); } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;C695629 File: IoOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;C695629 (server) 1/7/2009 10:11 AM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;CompositeConversions3 @@ -15,17 +15,16 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +using IronRuby.Compiler.Generation; using IronRuby.Runtime; +using IronRuby.Runtime.Calls; using Microsoft.Scripting.Math; using Microsoft.Scripting.Runtime; -using IronRuby.Runtime.Calls; -using System.Diagnostics; -using Microsoft.Scripting.Generation; -using IronRuby.Compiler.Generation; using Ast = System.Linq.Expressions.Expression; namespace IronRuby.Builtins { @@ -33,11 +32,9 @@ /// /// Implementation of IO builtin class. /// - [RubyClass("IO", Extends = typeof(RubyIO)), Includes(typeof(RubyFileOps.Constants))] + [RubyClass("IO", Extends = typeof(RubyIO)), Includes(typeof(RubyFileOps.Constants)), Includes(typeof(Enumerable))] public class RubyIOOps { - // Mixins: File::Constants,Enumerable - #region Constants [RubyConstant] @@ -55,7 +52,7 @@ [RubyConstructor] public static RubyIO/*!*/ CreateIO(RubyClass/*!*/ self) { - // TODO: should create an IO object with uninitialize stream + // TODO: should create an IO object with an uninitialized stream throw new NotImplementedException(); } @@ -88,59 +85,15 @@ //initialize_copy + [RubyMethod("for_fd", RubyMethodAttributes.PublicSingleton)] + public static RuleGenerator/*!*/ ForFileDescriptor() { + return new RuleGenerator(RuleGenerators.InstanceConstructor); + } + #endregion #region Public singleton methods - [RubyMethod("for_fd", RubyMethodAttributes.PublicSingleton)] - public static RubyIO ForFd(RubyClass/*!*/ self, int fileDescriptor, [DefaultProtocol, NotNull]MutableString/*!*/ modeString) { - return CreateIO(self, fileDescriptor, modeString); - } - - [RubyMethod("foreach", RubyMethodAttributes.PublicSingleton)] - public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) { - ForEach(block, self, path, self.Context.InputSeparator); - } - - [RubyMethod("foreach", RubyMethodAttributes.PublicSingleton)] - public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, MutableString separator) { - - using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), "r")) { - Each(block, io, separator); - } - } - - // Explicit overloads - - private readonly static CallSite> _CreateIOSharedSite1 = - CallSite>.Create(RubySites.InstanceCallAction("new", 1)); - - private readonly static CallSite> _CreateIOSharedSite11 = - CallSite>.Create(RubySites.InstanceCallAction("new", 2)); - - // TODO: these static fields are marked as internal since they are referenced from FileOps.cs. There is a static initialization problem where _Default.Binder in RubyContext - // isn't being initialized if these sites are stored in the RubyFileOps class. Perhaps we should do the wholesale consolidation of all sites into LibrarySites.cs? - - internal readonly static CallSite> _CreateIOSharedSite2 = - CallSite>.Create(RubySites.InstanceCallAction("new", 2)); - - internal readonly static CallSite> _CreateIOSharedSite3 = - CallSite>.Create(RubySites.InstanceCallAction("new", 1)); - - internal readonly static CallSite> _CreateIOSharedSite4 = - CallSite>.Create(RubySites.InstanceCallAction("new", 2)); - - internal readonly static CallSite> _CreateIOSharedSite5 = - CallSite>.Create(RubySites.InstanceCallAction("new", 3)); - - // TCPSocket.open(host, port) - internal readonly static CallSite> _CreateIOSharedSite6 = - CallSite>.Create(RubySites.InstanceCallAction("new", 2)); - - // File.open(path, mode, perms) - internal readonly static CallSite> _CreateIOSharedSite7 = - CallSite>.Create(RubySites.InstanceCallAction("new", 3)); - internal static object TryInvokeOpenBlock(RubyContext/*!*/ context, BlockParam/*!*/ block, RubyIO/*!*/ io) { if (block == null) return io; @@ -153,6 +106,24 @@ } } + #region foreach + + [RubyMethod("foreach", RubyMethodAttributes.PublicSingleton)] + public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path) { + ForEach(block, self, path, self.Context.InputSeparator); + } + + [RubyMethod("foreach", RubyMethodAttributes.PublicSingleton)] + public static void ForEach(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ path, MutableString separator) { + using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), "r")) { + Each(block, io, separator); + } + } + + #endregion + + #region open + [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] public static RuleGenerator/*!*/ Open() { return new RuleGenerator((metaBuilder, args, name) => { @@ -186,22 +157,18 @@ public static object InvokeOpenBlock(RubyContext/*!*/ context, BlockParam/*!*/ block, object obj) { RubyIO io; if (!RubyOps.IsRetrySingleton(obj) && block != null && (io = obj as RubyIO) != null) { - block.Yield(io, out obj); - if (!block.BlockJumped(obj)) { + try { + block.Yield(io, out obj); + } finally { io.Close(); } } return obj; } - private static RubyIO OpenFileForRead(RubyContext/*!*/ context, MutableString/*!*/ path) { - string strPath = path.ConvertToString(); - if (!File.Exists(strPath)) { - throw new Errno.NoEntryError(String.Format("No such file or directory - {0}", strPath)); - } - return new RubyIO(context, File.OpenRead(strPath), "r"); - } + #endregion + #region pipe, popen #if !SILVERLIGHT //pipe @@ -253,8 +220,10 @@ return new RubyIO(context, reader, writer, modeString.ConvertToString()); } +#endif + #endregion -#endif + #region select [RubyMethod("select", RubyMethodAttributes.PublicSingleton)] public static RubyArray Select(RubyContext/*!*/ context, object self, RubyArray read, [Optional]RubyArray write, [Optional]RubyArray error) { @@ -374,6 +343,8 @@ return io; } + #endregion + //sysopen #endregion @@ -699,11 +670,15 @@ } [RubyMethod("printf")] - public static void PrintFormatted(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, + public static void PrintFormatted( + ConversionStorage/*!*/ integerConversion, + ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, + ConversionStorage/*!*/ stringCast, BinaryOpStorage/*!*/ writeStorage, RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format, [NotNull]params object[]/*!*/ args) { - KernelOps.PrintFormatted(fixnumCast, tosConversion, writeStorage, context, null, self, format, args); + KernelOps.PrintFormatted(integerConversion, fixnumCast, tosConversion, stringCast, writeStorage, context, null, self, format, args); } #endregion @@ -731,7 +706,15 @@ #region read, read_nonblock - private static byte[] ReadAllBytes(RubyIO/*!*/ io) { + private static RubyIO/*!*/ OpenFileForRead(RubyContext/*!*/ context, MutableString/*!*/ path) { + string strPath = path.ConvertToString(); + if (!File.Exists(strPath)) { + throw new Errno.NoEntryError(String.Format("No such file or directory - {0}", strPath)); + } + return new RubyIO(context, File.OpenRead(strPath), "r"); + } + + private static byte[]/*!*/ ReadAllBytes(RubyIO/*!*/ io) { var fixedBuffer = new byte[io.Length]; io.ReadBytes(fixedBuffer, 0, (int)io.Length); return fixedBuffer; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C695629 File: KernelOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C695629 (server) 1/7/2009 1:16 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;CompositeConversions3 @@ -28,6 +28,8 @@ using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; using Microsoft.Scripting.Generation; +using IronRuby.Compiler; +using System.IO; namespace IronRuby.Builtins { @@ -97,15 +99,29 @@ [RubyMethod("Integer", RubyMethodAttributes.PrivateInstance)] [RubyMethod("Integer", RubyMethodAttributes.PublicSingleton)] - public static object/*!*/ ToInteger(RubyContext/*!*/ context, object self, object obj) { - // TODO: MRI converts strings with base prefix ("0x1", "0d1", "0o1") and octals "000" as well - // should the protocol do that or is is a specificity of this method? - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(context, obj, out fixnum, out bignum); - return (object)bignum ?? ScriptingRuntimeHelpers.Int32ToObject(fixnum); + public static object/*!*/ ToInteger(object self, [NotNull]MutableString/*!*/ value) { + var str = value.ConvertToString(); + int i = 0; + object result = Tokenizer.ParseInteger(str, 0, ref i).ToObject(); + + while (i < str.Length && Tokenizer.IsWhiteSpace(str[i])) { + i++; + } + + if (i < str.Length) { + throw RubyExceptions.CreateArgumentError(String.Format("invalid value for Integer: \"{0}\"", str)); + } + + return result; } + [RubyMethod("Integer", RubyMethodAttributes.PrivateInstance)] + [RubyMethod("Integer", RubyMethodAttributes.PublicSingleton)] + public static object/*!*/ ToInteger(ConversionStorage/*!*/ integerConversion, RubyContext/*!*/ context, object self, object value) { + var integer = Protocols.ConvertToInteger(integerConversion, context, value); + return integer.IsFixnum ? ScriptingRuntimeHelpers.Int32ToObject(integer.Fixnum) : integer.Bignum; + } + [RubyMethod("String", RubyMethodAttributes.PrivateInstance)] [RubyMethod("String", RubyMethodAttributes.PublicSingleton)] public static object/*!*/ ToString(ConversionStorage/*!*/ tosStorage, RubyContext/*!*/ context, object self, object obj) { @@ -548,16 +564,24 @@ // this overload is called only if the first parameter is string: [RubyMethod("printf", RubyMethodAttributes.PrivateInstance)] [RubyMethod("printf", RubyMethodAttributes.PublicSingleton)] - public static void PrintFormatted(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, + public static void PrintFormatted( + ConversionStorage/*!*/ integerConversion, + ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, + ConversionStorage/*!*/ stringCast, BinaryOpStorage/*!*/ writeStorage, RubyContext/*!*/ context, object self, [NotNull]MutableString/*!*/ format, [NotNull]params object[]/*!*/ args) { - PrintFormatted(fixnumCast, tosConversion, writeStorage, context, self, context.StandardOutput, format, args); + PrintFormatted(integerConversion, fixnumCast, tosConversion, stringCast, writeStorage, context, self, context.StandardOutput, format, args); } [RubyMethod("printf", RubyMethodAttributes.PrivateInstance)] [RubyMethod("printf", RubyMethodAttributes.PublicSingleton)] - public static void PrintFormatted(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, + public static void PrintFormatted( + ConversionStorage/*!*/ integerConversion, + ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, + ConversionStorage/*!*/ stringCast, BinaryOpStorage/*!*/ writeStorage, RubyContext/*!*/ context, object self, object io, [NotNull]object/*!*/ format, [NotNull]params object[]/*!*/ args) { @@ -566,7 +590,9 @@ // TODO: BindAsObject attribute on format? // format cannot be strongly typed to MutableString due to ambiguity between signatures (MS, object) vs (object, MS) var site = writeStorage.GetCallSite("write"); - site.Target(site, context, io, Sprintf(fixnumCast, tosConversion, context, self, Protocols.CastToString(context, format), args)); + site.Target(site, context, io, + Sprintf(integerConversion, fixnumCast, tosConversion, context, self, Protocols.CastToString(stringCast, context, format), args) + ); } [RubyMethod("putc", RubyMethodAttributes.PrivateInstance)] @@ -842,10 +868,11 @@ [RubyMethod("format", RubyMethodAttributes.PublicSingleton)] [RubyMethod("sprintf", RubyMethodAttributes.PrivateInstance)] [RubyMethod("sprintf", RubyMethodAttributes.PublicSingleton)] - public static MutableString/*!*/ Sprintf(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, + public static MutableString/*!*/ Sprintf(ConversionStorage/*!*/ integerCast, ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, RubyContext/*!*/ context, object self, [DefaultProtocol, NotNull]MutableString/*!*/ format, [NotNull]params object[] args) { - return new StringFormatter(fixnumCast, tosConversion, context, format.ConvertToString(), args).Format(); + return new StringFormatter(integerCast, fixnumCast, tosConversion, context, format.ConvertToString(), args).Format(); } //srand @@ -1211,9 +1238,9 @@ [RubyMethod("respond_to?")] public static bool RespondTo(RubyContext/*!*/ context, object self, - [DefaultProtocol]string/*!*/ methodName, [DefaultProtocol, Optional]bool includePrivate) { + [DefaultProtocol]string/*!*/ methodName, [DefaultParameterValue(null)]object includePrivate) { - return context.ResolveMethod(self, methodName, includePrivate) != null; + return context.ResolveMethod(self, methodName, Protocols.IsTrue(includePrivate)) != null; } #region __send__, send =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;C695629 File: Marshal.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;C695629 (server) 1/7/2009 1:25 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/Marshal.cs;CompositeConversions3 @@ -185,7 +185,7 @@ } else if (Double.IsNaN(value)) { WriteStringValue(_nanString); } else { - StringFormatter sf = new StringFormatter(null, null, _context, "%.15g", new object[] { value }); + StringFormatter sf = new StringFormatter(_context, "%.15g", new object[] { value }); sf.TrailingZeroAfterWholeFloat = false; WriteStringValue(sf.Format()); } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;C695629 File: ModuleOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;C695629 (server) 1/6/2009 4:10 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ModuleOps.cs;CompositeConversions3 @@ -24,6 +24,7 @@ using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; using Microsoft.Scripting.Generation; +using Microsoft.Scripting; namespace IronRuby.Builtins { @@ -656,8 +657,13 @@ internal static RubyArray/*!*/ GetMethods(RubyModule/*!*/ self, bool inherited, RubyMethodAttributes attributes) { var result = new RubyArray(); + var symbolicNames = self.Context.RubyOptions.Compatibility > RubyCompatibility.Ruby18; self.ForEachMember(inherited, attributes, delegate(string/*!*/ name, RubyMemberInfo/*!*/ member) { - result.Add(MutableString.Create(name)); + if (symbolicNames) { + result.Add(SymbolTable.StringToId(name)); + } else { + result.Add(MutableString.Create(name)); + } }); return result; } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C674241 File: MutableStringOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C674241 (server) 1/7/2009 2:26 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;CompositeConversions3 @@ -330,11 +330,14 @@ #region % [RubyMethod("%")] - public static MutableString/*!*/ Format(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, + public static MutableString/*!*/ Format( + ConversionStorage/*!*/ integerCast, + ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, RubyContext/*!*/ context, MutableString/*!*/ self, object arg) { IList args = arg as IList ?? new object[] { arg }; - StringFormatter formatter = new StringFormatter(fixnumCast, tosConversion, context, self.ConvertToString(), args); + StringFormatter formatter = new StringFormatter(integerCast, fixnumCast, tosConversion, context, self.ConvertToString(), args); return formatter.Format().TaintBy(self); } @@ -2311,94 +2314,22 @@ #region to_i, hex, oct - private static string/*!*/ StripWhitespace(MutableString/*!*/ str) { - int i = 0; - while (i < str.Length) { - char c = str.GetChar(i); - if (c == ' ' || c == '_' || c == '\t' || c == '\n' || c == '\r') { - i += 1; - } else { - return str.GetSlice(i).ConvertToString().Replace("_", ""); - } - } - return str.ConvertToString().Replace("_", ""); - } - - private static string/*!*/ ParseSign(string/*!*/ number, ref bool isNegative) { - if (number[0] == '-') { - isNegative = true; - number = number.Remove(0, 1); - } - return number; - } - - // This method only gets called if we are explicitly specifying base via argument to to_i - private static object ParseInteger(RubyContext/*!*/ context, string/*!*/ str, int @base) { - if (@base == 0) { - return ParseInteger(context, str); - } - - if (str.Length == 0) { - return ScriptingRuntimeHelpers.Int32ToObject(0); - } - - bool isNegative = false; - str = ParseSign(str, ref isNegative); - - Tokenizer.BignumParser parser = new Tokenizer.BignumParser(); - parser.Position = 0; - parser.Buffer = str.ToCharArray(); - BigInteger result = parser.Parse(str.Length, @base); - int intValue; - if (result.AsInt32(out intValue)) - return ScriptingRuntimeHelpers.Int32ToObject(isNegative ? -intValue : intValue); - else - return isNegative ? BigInteger.Negate(result) : result; - } - - // This method uses the tokenizer to auto-detect the base type -- happens when agument to to_i is 0 - private static object ParseInteger(RubyContext/*!*/ context, string/*!*/ str) { - bool isNegative = false; - if (str.Length == 0) { - return ScriptingRuntimeHelpers.Int32ToObject(0); - } - - str = ParseSign(str, ref isNegative); - - Tokenizer tokenizer = new Tokenizer(); - tokenizer.Initialize(new StringReader(str)); - Tokens token = tokenizer.GetNextToken(); - - TokenValue value = tokenizer.TokenValue; - if (token == Tokens.Integer) - return ScriptingRuntimeHelpers.Int32ToObject(isNegative ? -value.Integer1: value.Integer1); - else if (token == Tokens.BigInteger) - return isNegative ? BigInteger.Negate(value.BigInteger) : value.BigInteger; - else - return ScriptingRuntimeHelpers.Int32ToObject(0); - } - [RubyMethod("to_i")] - public static object ToInteger(RubyContext/*!*/ context, MutableString/*!*/ self) { - return ParseInteger(context, StripWhitespace(self)); - } - - [RubyMethod("to_i")] - public static object ToInteger(RubyContext/*!*/ context, MutableString/*!*/ self, [DefaultProtocol]int @base) { + public static object/*!*/ ToInteger(MutableString/*!*/ self, [DefaultProtocol, DefaultParameterValue(10)]int @base) { if (@base == 1 || @base < 0 || @base > 36) { throw RubyExceptions.CreateArgumentError(String.Format("illegal radix {0}", @base)); } - return ParseInteger(context, StripWhitespace(self), @base); + return Tokenizer.ParseInteger(self.ConvertToString(), @base).ToObject(); } [RubyMethod("hex")] - public static object ToIntegerHex(RubyContext/*!*/ context, MutableString/*!*/ self) { - return ParseInteger(context, StripWhitespace(self), 16); + public static object/*!*/ ToIntegerHex(MutableString/*!*/ self) { + return Tokenizer.ParseInteger(self.ConvertToString(), 16).ToObject(); } [RubyMethod("oct")] - public static object ToIntegerOctal(RubyContext/*!*/ context, MutableString/*!*/ self) { - return ParseInteger(context, StripWhitespace(self), 8); + public static object/*!*/ ToIntegerOctal(MutableString/*!*/ self) { + return Tokenizer.ParseInteger(self.ConvertToString(), 8).ToObject(); } #endregion =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs;C674241 File: StringFormatter.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs;C674241 (server) 1/7/2009 1:23 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/StringFormatter.cs;CompositeConversions3 @@ -23,6 +23,7 @@ using Microsoft.Scripting.Math; using IronRuby.Runtime; using SM = System.Math; +using IronRuby.Runtime.Calls; namespace IronRuby.Builtins { @@ -83,21 +84,33 @@ private StringBuilder _buf; - private readonly ConversionStorage/*!*/ _fixnumCast; - private readonly ConversionStorage/*!*/ _tosConversion; + private readonly ConversionStorage _fixnumCast; + private readonly ConversionStorage _tosConversion; + private readonly ConversionStorage _integerConversion; #region Constructors - internal StringFormatter(ConversionStorage/*!*/ fixnumCast, ConversionStorage/*!*/ tosConversion, - RubyContext/*!*/ context, string/*!*/ format, IList/*!*/ data) { + // TODO: remove + internal StringFormatter(RubyContext/*!*/ context, string/*!*/ format, IList/*!*/ data) { Assert.NotNull(context, format, data); - // TODO: Assert.NotNull(fixnumCast,tosConversion) + _context = context; + _format = format; + _data = data; + } + + internal StringFormatter( + ConversionStorage/*!*/ integerConversion, + ConversionStorage/*!*/ fixnumCast, + ConversionStorage/*!*/ tosConversion, + RubyContext/*!*/ context, string/*!*/ format, IList/*!*/ data) + : this(context, format, data) { + + Assert.NotNull(integerConversion, fixnumCast, tosConversion); + _fixnumCast = fixnumCast; _tosConversion = tosConversion; - _format = format; - _data = data; - _context = context; + _integerConversion = integerConversion; } #endregion @@ -314,18 +327,16 @@ } private void AppendInt(char format) { - int fixnum; - BigInteger bignum; - Protocols.ConvertToInteger(_context, _opts.Value, out fixnum, out bignum); + IntegerValue integer = (_opts.Value == null) ? 0 : Protocols.ConvertToInteger(_integerConversion, _context, _opts.Value); object val; bool isPositive; - if ((object)bignum != null) { - isPositive = bignum.IsPositive(); - val = bignum; + if (integer.IsFixnum) { + isPositive = integer.Fixnum > 0; + val = integer.Fixnum; } else { - isPositive = fixnum > 0; - val = fixnum; + isPositive = integer.Bignum.IsPositive(); + val = integer.Bignum; } if (_opts.LeftAdj) { @@ -766,12 +777,10 @@ /// for BigInteger below that should be kept in sync. /// private void AppendBase(char format, int radix) { - BigInteger bignum; - int fixnum; - Protocols.ConvertToInteger(_context, _opts.Value, out fixnum, out bignum); + IntegerValue integer = (_opts.Value == null) ? 0 : Protocols.ConvertToInteger(_integerConversion, _context, _opts.Value); // TODO: split paths for bignum and fixnum - object value = ((object)bignum) ?? fixnum; + object value = integer.IsFixnum ? (object)integer.Fixnum : (object)integer.Bignum; bool isNegative = IsNegative(value); if (isNegative) { =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj;C698276 File: Ruby.csproj =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj;C698276 (server) 1/7/2009 6:11 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Ruby.csproj;CompositeConversions3 @@ -188,6 +188,7 @@ + @@ -318,6 +319,7 @@ + @@ -361,4 +363,4 @@ - + \ No newline at end of file =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySites.cs;C674241 File: RubySites.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySites.cs;C674241 (server) 1/8/2009 4:21 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySites.cs;CompositeConversions3 @@ -53,8 +53,6 @@ return ModuleConstMissingSharedSite.Target(ModuleConstMissingSharedSite, context, self, SymbolTable.StringToId(name)); } - #region Helpers - public static RubyCallAction InstanceCallAction(string/*!*/ name) { return RubyCallAction.Make(name, 0); } @@ -66,7 +64,5 @@ public static RubyCallAction InstanceCallAction(string/*!*/ name, RubyCallSignature callSignature) { return RubyCallAction.Make(name, callSignature); } - - #endregion } } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.cs;C659171 File: ReflectionCache.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.cs;C659171 (server) 1/9/2009 3:20 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.cs;CompositeConversions3 @@ -35,8 +35,14 @@ namespace IronRuby.Compiler { internal static class Fields { private static FieldInfo _RubyOps_DefaultArgumentField, _RubyOps_MethodNotFound; - public static FieldInfo RubyOps_DefaultArgumentField { get { return _RubyOps_DefaultArgumentField ?? (_RubyOps_DefaultArgumentField = typeof(RubyOps).GetField("DefaultArgument")); } } - public static FieldInfo RubyOps_MethodNotFound { get { return _RubyOps_MethodNotFound ?? (_RubyOps_MethodNotFound = typeof(RubyOps).GetField("MethodNotFound")); } } + public static FieldInfo RubyOps_DefaultArgumentField { get { return _RubyOps_DefaultArgumentField ?? (_RubyOps_DefaultArgumentField = GetField(typeof(RubyOps), "DefaultArgument")); } } + public static FieldInfo RubyOps_MethodNotFound { get { return _RubyOps_MethodNotFound ?? (_RubyOps_MethodNotFound = GetField(typeof(RubyOps), "MethodNotFound")); } } + + internal static FieldInfo/*!*/ GetField(Type/*!*/ type, string/*!*/ name) { + var field = type.GetField(name); + Debug.Assert(field != null, type.Name + "::" + name); + return field; + } } internal static partial class Methods { @@ -44,20 +50,30 @@ private static MethodInfo _Stopwatch_GetTimestamp, _IEnumerable_Of_Object_GetEnumerator, _IEnumerator_MoveNext, _IEnumerator_get_Current; - public static ConstructorInfo RubyCallSignatureCtor { get { return _RubyCallSignatureCtor ?? (_RubyCallSignatureCtor = typeof(RubyCallSignature).GetConstructor(new[] { typeof(int) })); } } + public static ConstructorInfo RubyCallSignatureCtor { get { return _RubyCallSignatureCtor ?? (_RubyCallSignatureCtor = GetConstructor(typeof(RubyCallSignature), typeof(uint))); } } public static MethodInfo Stopwatch_GetTimestamp { get { return _Stopwatch_GetTimestamp ?? (_Stopwatch_GetTimestamp = GetMethod(typeof(Stopwatch), "GetTimestamp")); } } public static MethodInfo IEnumerable_Of_Object_GetEnumerator { get { return _IEnumerable_Of_Object_GetEnumerator ?? (_IEnumerable_Of_Object_GetEnumerator = GetMethod(typeof(IEnumerable), "GetEnumerator", BindingFlags.Instance, Type.EmptyTypes)); } } public static MethodInfo IEnumerator_get_Current { get { return _IEnumerator_get_Current ?? (_IEnumerator_get_Current = GetMethod(typeof(IEnumerator), "get_Current", BindingFlags.Instance, Type.EmptyTypes)); } } public static MethodInfo IEnumerator_MoveNext { get { return _IEnumerator_MoveNext ?? (_IEnumerator_MoveNext = GetMethod(typeof(IEnumerator), "MoveNext", BindingFlags.Instance, Type.EmptyTypes)); } } - private static MethodInfo/*!*/ GetMethod(Type/*!*/ type, string/*!*/ name) { + internal static ConstructorInfo/*!*/ GetConstructor(Type/*!*/ type, params Type/*!*/[]/*!*/ signature) { + var ctor = type.GetConstructor(signature); + Debug.Assert(ctor != null, type.Name + "::.ctor"); + return ctor; + } + + internal static MethodInfo/*!*/ GetMethod(Type/*!*/ type, string/*!*/ name) { var method = type.GetMethod(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); Debug.Assert(method != null, type.Name + "::" + name); return method; } - private static MethodInfo/*!*/ GetMethod(Type/*!*/ type, string/*!*/ name, BindingFlags flags, Type/*!*/[]/*!*/ signature) { + internal static MethodInfo/*!*/ GetMethod(Type/*!*/ type, string/*!*/ name, params Type/*!*/[]/*!*/ signature) { + return GetMethod(type, name, BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, signature); + } + + internal static MethodInfo/*!*/ GetMethod(Type/*!*/ type, string/*!*/ name, BindingFlags flags, params Type/*!*/[]/*!*/ signature) { var method = type.GetMethod(name, flags | BindingFlags.Public | BindingFlags.DeclaredOnly, null, signature, null); Debug.Assert(method != null, type.Name + "::" + name); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.Generated.cs;C695629 File: ReflectionCache.Generated.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.Generated.cs;C695629 (server) 1/7/2009 1:57 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/ReflectionCache.Generated.cs;CompositeConversions3 @@ -19,93 +19,58 @@ namespace IronRuby.Compiler { internal static partial class Methods { - private static MethodInfo _CreateRfcForMethod, _BlockRetry, _MethodRetry, _EvalRetry, _BlockBreak, _MethodBreak, _EvalBreak, _MethodNext, _EvalNext, _MethodRedo, _EvalRedo, _BlockReturn, _EvalReturn, _BlockYield, _MethodYield, _EvalYield, _MethodProcCall, _CanRescue, _IsRetrySingleton, - _PropagateRetrySingleton, _GetRetrySingleton, _UpdateProfileTicks, _CreateMainTopLevelScope, _CreateTopLevelHostedScope, _CreateTopLevelScope, _CreateWrappedTopLevelScope, _CreateModuleEvalScope, _CreateModuleScope, _CreateMethodScope, _CreateBlockScope, _TraceMethodCall, _TraceMethodReturn, _TraceBlockCall, _TraceBlockReturn, _PrintInteractiveResult, _GetLocalVariable, _SetLocalVariable, _GetContextFromScope, _GetContextFromMethod, - _GetContextFromBlockParam, _GetContextFromProc, _GetEmptyScope, _DefineBlock, _InitializeBlock, _Yield0, _Yield1, _Yield2, _Yield3, _Yield4, _YieldN, _YieldSplat0, _YieldSplat1, _YieldSplat2, _YieldSplat3, _YieldSplat4, _YieldSplatN, _YieldSplatNRhs, _DefineMethod, _MethodDefined, - _AliasMethod, _UndefineMethod, _IsDefinedMethod, _DefineGlobalModule, _DefineNestedModule, _DefineModule, _ConvertNamespaceToModule, _DefineSingletonClass, _DefineGlobalClass, _DefineNestedClass, _DefineClass, _GetGlobalConstant, _GetUnqualifiedConstant, _GetQualifiedConstant, _IsDefinedGlobalConstant, _IsDefinedUnqualifiedConstant, _IsDefinedQualifiedConstant, _SetGlobalConstant, _SetUnqualifiedConstant, _SetQualifiedConstant, - _MakeArray0, _MakeArray1, _MakeArray2, _MakeArray3, _MakeArray4, _MakeArray5, _MakeArrayN, _MakeHash0, _MakeHash, _SplatAppend, _Splat, _SplatPair, _Unsplat, _GetArrayItem, _GetArraySuffix, _GetGlobalVariable, _IsDefinedGlobalVariable, _SetGlobalVariable, _AliasGlobalVariable, _GetCurrentMatchGroup, - _GetCurrentMatchData, _GetCurrentMatchLastGroup, _GetCurrentMatchPrefix, _GetCurrentMatchSuffix, _MatchLastInputLine, _MatchString, _CreateRegexB, _CreateRegexU, _CreateRegexE, _CreateRegexM, _CreateRegexBM, _CreateRegexUM, _CreateRegexEM, _CreateRegexMB, _CreateRegexMU, _CreateRegexME, _CreateRegexMM, _CreateRegexN, _CreateMutableStringB, _CreateMutableStringU, - _CreateMutableStringE, _CreateMutableStringM, _CreateMutableStringBM, _CreateMutableStringUM, _CreateMutableStringEM, _CreateMutableStringMB, _CreateMutableStringMU, _CreateMutableStringME, _CreateMutableStringMM, _CreateMutableStringN, _CreateSymbolB, _CreateSymbolU, _CreateSymbolE, _CreateSymbolM, _CreateSymbolBM, _CreateSymbolUM, _CreateSymbolEM, _CreateSymbolMB, _CreateSymbolMU, _CreateSymbolME, - _CreateSymbolMM, _CreateSymbolN, _CreateEncoding, _IsTrue, _IsFalse, _GetCurrentException, _SetCurrentExceptionAndStackTrace, _SetCurrentException, _CompareException, _CompareSplattedExceptions, _CompareDefaultException, _GetDefaultExceptionMessage, _MakeWrongNumberOfArgumentsError, _MakeTopLevelSuperException, _MakeMissingSuperException, _MakeInvalidArgumentTypesError, _MakeAmbiguousMatchError, _IsSuperCallTarget, _CreateInclusiveRange, _CreateExclusiveRange, - _CreateInclusiveIntegerRange, _CreateExclusiveIntegerRange, _AllocateStructInstance, _CreateStructInstance, _GetMetaObject, _ToProcValidator, _ToStringValidator, _ToSymbolValidator, _ConvertSymbolIdToSymbol, _ConvertFixnumToSymbol, _ConvertMutableStringToSymbol, _ToRegexValidator, _ToArrayValidator, _ToHashValidator, _ToFixnumValidator, _CreateTypeConversionError, _ConvertBignumToFixnum, _ToSDefaultConversion, _GetInstanceVariable, _IsDefinedInstanceVariable, - _SetInstanceVariable, _GetObjectClassVariable, _GetClassVariable, _TryGetObjectClassVariable, _TryGetClassVariable, _IsDefinedObjectClassVariable, _IsDefinedClassVariable, _SetObjectClassVariable, _SetClassVariable, _GetInstanceData, _DeserializeObject, _SerializeObject, _HookupEvent, _CreateDelegateFromProc, _CreateDelegateFromMethod, _X, _IsProcConverterTarget, _CreateBfcForYield, _CreateBfcForMethodProcCall, _CreateBfcForProcCall, - _CreateBfcForLibraryMethod, _LeaveProcConverter; + private static MethodInfo _CreateInclusiveRange, _CreateExclusiveRange, _CreateInclusiveIntegerRange, _CreateExclusiveIntegerRange, _AllocateStructInstance, _CreateStructInstance, _GetMetaObject, _ToProcValidator, _ToStringValidator, _ToSymbolValidator, _ConvertSymbolIdToSymbol, _ConvertFixnumToSymbol, _ConvertMutableStringToSymbol, _ToRegexValidator, _ToArrayValidator, _ToHashValidator, _ToFixnumValidator, _ToIntegerValidator, _CreateTypeConversionError, + _ConvertBignumToFixnum, _ToSDefaultConversion, _GetInstanceVariable, _IsDefinedInstanceVariable, _SetInstanceVariable, _GetObjectClassVariable, _GetClassVariable, _TryGetObjectClassVariable, _TryGetClassVariable, _IsDefinedObjectClassVariable, _IsDefinedClassVariable, _SetObjectClassVariable, _SetClassVariable, _GetInstanceData, _DeserializeObject, _SerializeObject, _HookupEvent, _CreateDelegateFromProc, _CreateDelegateFromMethod, _X, + _UpdateProfileTicks, _IsDefinedQualifiedConstant, _SetGlobalConstant, _SetUnqualifiedConstant, _SetQualifiedConstant, _MakeArray0, _MakeArray1, _MakeArray2, _MakeArray3, _MakeArray4, _MakeArray5, _MakeArrayN, _MakeHash0, _MakeHash, _SplatAppend, _Splat, _SplatPair, _Unsplat, _GetArrayItem, _GetArraySuffix, + _GetGlobalVariable, _IsDefinedGlobalVariable, _SetGlobalVariable, _AliasGlobalVariable, _GetCurrentMatchGroup, _GetCurrentMatchData, _GetCurrentMatchLastGroup, _GetCurrentMatchPrefix, _GetCurrentMatchSuffix, _MatchLastInputLine, _MatchString, _CreateRegexB, _CreateRegexU, _CreateRegexE, _CreateRegexM, _CreateRegexBM, _CreateRegexUM, _CreateRegexEM, _CreateRegexMB, _CreateRegexMU, + _CreateRegexME, _CreateRegexMM, _CreateRegexN, _CreateMutableStringB, _CreateMutableStringU, _CreateMutableStringE, _CreateMutableStringM, _CreateMutableStringBM, _CreateMutableStringUM, _CreateMutableStringEM, _CreateMutableStringMB, _CreateMutableStringMU, _CreateMutableStringME, _CreateMutableStringMM, _CreateMutableStringN, _CreateSymbolB, _CreateSymbolU, _CreateSymbolE, _CreateSymbolM, _CreateSymbolBM, + _CreateSymbolUM, _CreateSymbolEM, _CreateSymbolMB, _CreateSymbolMU, _CreateSymbolME, _CreateSymbolMM, _CreateSymbolN, _CreateEncoding, _IsTrue, _IsFalse, _GetCurrentException, _SetCurrentExceptionAndStackTrace, _SetCurrentException, _CompareException, _CompareSplattedExceptions, _CompareDefaultException, _GetDefaultExceptionMessage, _MakeWrongNumberOfArgumentsError, _MakeTopLevelSuperException, _MakeMissingSuperException, + _MakeInvalidArgumentTypesError, _MakeAmbiguousMatchError, _IsSuperCallTarget, _IsProcConverterTarget, _CreateBfcForYield, _CreateBfcForMethodProcCall, _CreateBfcForProcCall, _CreateBfcForLibraryMethod, _LeaveProcConverter, _CreateRfcForMethod, _BlockRetry, _MethodRetry, _EvalRetry, _BlockBreak, _MethodBreak, _EvalBreak, _MethodNext, _EvalNext, _MethodRedo, _EvalRedo, + _BlockReturn, _EvalReturn, _BlockYield, _MethodYield, _EvalYield, _MethodProcCall, _CanRescue, _IsRetrySingleton, _PropagateRetrySingleton, _GetRetrySingleton, _CreateMainTopLevelScope, _CreateTopLevelHostedScope, _CreateTopLevelScope, _CreateWrappedTopLevelScope, _CreateModuleEvalScope, _CreateModuleScope, _CreateMethodScope, _CreateBlockScope, _TraceMethodCall, _TraceMethodReturn, + _TraceBlockCall, _TraceBlockReturn, _PrintInteractiveResult, _GetLocalVariable, _SetLocalVariable, _GetContextFromScope, _GetContextFromMethod, _GetContextFromBlockParam, _GetContextFromProc, _GetEmptyScope, _DefineBlock, _InitializeBlock, _Yield0, _Yield1, _Yield2, _Yield3, _Yield4, _YieldN, _YieldSplat0, _YieldSplat1, + _YieldSplat2, _YieldSplat3, _YieldSplat4, _YieldSplatN, _YieldSplatNRhs, _DefineMethod, _MethodDefined, _AliasMethod, _UndefineMethod, _IsDefinedMethod, _DefineGlobalModule, _DefineNestedModule, _DefineModule, _ConvertNamespaceToModule, _DefineSingletonClass, _DefineGlobalClass, _DefineNestedClass, _DefineClass, _GetGlobalConstant, _GetUnqualifiedConstant, + _GetQualifiedConstant, _IsDefinedGlobalConstant, _IsDefinedUnqualifiedConstant; - public static MethodInfo/*!*/ CreateRfcForMethod { get { return _CreateRfcForMethod ?? (_CreateRfcForMethod = GetMethod(typeof(RubyOps), "CreateRfcForMethod")); } } - public static MethodInfo/*!*/ BlockRetry { get { return _BlockRetry ?? (_BlockRetry = GetMethod(typeof(RubyOps), "BlockRetry")); } } - public static MethodInfo/*!*/ MethodRetry { get { return _MethodRetry ?? (_MethodRetry = GetMethod(typeof(RubyOps), "MethodRetry")); } } - public static MethodInfo/*!*/ EvalRetry { get { return _EvalRetry ?? (_EvalRetry = GetMethod(typeof(RubyOps), "EvalRetry")); } } - public static MethodInfo/*!*/ BlockBreak { get { return _BlockBreak ?? (_BlockBreak = GetMethod(typeof(RubyOps), "BlockBreak")); } } - public static MethodInfo/*!*/ MethodBreak { get { return _MethodBreak ?? (_MethodBreak = GetMethod(typeof(RubyOps), "MethodBreak")); } } - public static MethodInfo/*!*/ EvalBreak { get { return _EvalBreak ?? (_EvalBreak = GetMethod(typeof(RubyOps), "EvalBreak")); } } - public static MethodInfo/*!*/ MethodNext { get { return _MethodNext ?? (_MethodNext = GetMethod(typeof(RubyOps), "MethodNext")); } } - public static MethodInfo/*!*/ EvalNext { get { return _EvalNext ?? (_EvalNext = GetMethod(typeof(RubyOps), "EvalNext")); } } - public static MethodInfo/*!*/ MethodRedo { get { return _MethodRedo ?? (_MethodRedo = GetMethod(typeof(RubyOps), "MethodRedo")); } } - public static MethodInfo/*!*/ EvalRedo { get { return _EvalRedo ?? (_EvalRedo = GetMethod(typeof(RubyOps), "EvalRedo")); } } - public static MethodInfo/*!*/ BlockReturn { get { return _BlockReturn ?? (_BlockReturn = GetMethod(typeof(RubyOps), "BlockReturn")); } } - public static MethodInfo/*!*/ EvalReturn { get { return _EvalReturn ?? (_EvalReturn = GetMethod(typeof(RubyOps), "EvalReturn")); } } - public static MethodInfo/*!*/ BlockYield { get { return _BlockYield ?? (_BlockYield = GetMethod(typeof(RubyOps), "BlockYield")); } } - public static MethodInfo/*!*/ MethodYield { get { return _MethodYield ?? (_MethodYield = GetMethod(typeof(RubyOps), "MethodYield")); } } - public static MethodInfo/*!*/ EvalYield { get { return _EvalYield ?? (_EvalYield = GetMethod(typeof(RubyOps), "EvalYield")); } } - public static MethodInfo/*!*/ MethodProcCall { get { return _MethodProcCall ?? (_MethodProcCall = GetMethod(typeof(RubyOps), "MethodProcCall")); } } - public static MethodInfo/*!*/ CanRescue { get { return _CanRescue ?? (_CanRescue = GetMethod(typeof(RubyOps), "CanRescue")); } } - public static MethodInfo/*!*/ IsRetrySingleton { get { return _IsRetrySingleton ?? (_IsRetrySingleton = GetMethod(typeof(RubyOps), "IsRetrySingleton")); } } - public static MethodInfo/*!*/ PropagateRetrySingleton { get { return _PropagateRetrySingleton ?? (_PropagateRetrySingleton = GetMethod(typeof(RubyOps), "PropagateRetrySingleton")); } } - public static MethodInfo/*!*/ GetRetrySingleton { get { return _GetRetrySingleton ?? (_GetRetrySingleton = GetMethod(typeof(RubyOps), "GetRetrySingleton")); } } + public static MethodInfo/*!*/ CreateInclusiveRange { get { return _CreateInclusiveRange ?? (_CreateInclusiveRange = GetMethod(typeof(RubyOps), "CreateInclusiveRange")); } } + public static MethodInfo/*!*/ CreateExclusiveRange { get { return _CreateExclusiveRange ?? (_CreateExclusiveRange = GetMethod(typeof(RubyOps), "CreateExclusiveRange")); } } + public static MethodInfo/*!*/ CreateInclusiveIntegerRange { get { return _CreateInclusiveIntegerRange ?? (_CreateInclusiveIntegerRange = GetMethod(typeof(RubyOps), "CreateInclusiveIntegerRange")); } } + public static MethodInfo/*!*/ CreateExclusiveIntegerRange { get { return _CreateExclusiveIntegerRange ?? (_CreateExclusiveIntegerRange = GetMethod(typeof(RubyOps), "CreateExclusiveIntegerRange")); } } + public static MethodInfo/*!*/ AllocateStructInstance { get { return _AllocateStructInstance ?? (_AllocateStructInstance = GetMethod(typeof(RubyOps), "AllocateStructInstance")); } } + public static MethodInfo/*!*/ CreateStructInstance { get { return _CreateStructInstance ?? (_CreateStructInstance = GetMethod(typeof(RubyOps), "CreateStructInstance")); } } + public static MethodInfo/*!*/ GetMetaObject { get { return _GetMetaObject ?? (_GetMetaObject = GetMethod(typeof(RubyOps), "GetMetaObject")); } } + public static MethodInfo/*!*/ ToProcValidator { get { return _ToProcValidator ?? (_ToProcValidator = GetMethod(typeof(RubyOps), "ToProcValidator")); } } + public static MethodInfo/*!*/ ToStringValidator { get { return _ToStringValidator ?? (_ToStringValidator = GetMethod(typeof(RubyOps), "ToStringValidator")); } } + public static MethodInfo/*!*/ ToSymbolValidator { get { return _ToSymbolValidator ?? (_ToSymbolValidator = GetMethod(typeof(RubyOps), "ToSymbolValidator")); } } + public static MethodInfo/*!*/ ConvertSymbolIdToSymbol { get { return _ConvertSymbolIdToSymbol ?? (_ConvertSymbolIdToSymbol = GetMethod(typeof(RubyOps), "ConvertSymbolIdToSymbol")); } } + public static MethodInfo/*!*/ ConvertFixnumToSymbol { get { return _ConvertFixnumToSymbol ?? (_ConvertFixnumToSymbol = GetMethod(typeof(RubyOps), "ConvertFixnumToSymbol")); } } + public static MethodInfo/*!*/ ConvertMutableStringToSymbol { get { return _ConvertMutableStringToSymbol ?? (_ConvertMutableStringToSymbol = GetMethod(typeof(RubyOps), "ConvertMutableStringToSymbol")); } } + public static MethodInfo/*!*/ ToRegexValidator { get { return _ToRegexValidator ?? (_ToRegexValidator = GetMethod(typeof(RubyOps), "ToRegexValidator")); } } + public static MethodInfo/*!*/ ToArrayValidator { get { return _ToArrayValidator ?? (_ToArrayValidator = GetMethod(typeof(RubyOps), "ToArrayValidator")); } } + public static MethodInfo/*!*/ ToHashValidator { get { return _ToHashValidator ?? (_ToHashValidator = GetMethod(typeof(RubyOps), "ToHashValidator")); } } + public static MethodInfo/*!*/ ToFixnumValidator { get { return _ToFixnumValidator ?? (_ToFixnumValidator = GetMethod(typeof(RubyOps), "ToFixnumValidator")); } } + public static MethodInfo/*!*/ ToIntegerValidator { get { return _ToIntegerValidator ?? (_ToIntegerValidator = GetMethod(typeof(RubyOps), "ToIntegerValidator")); } } + public static MethodInfo/*!*/ CreateTypeConversionError { get { return _CreateTypeConversionError ?? (_CreateTypeConversionError = GetMethod(typeof(RubyOps), "CreateTypeConversionError")); } } + public static MethodInfo/*!*/ ConvertBignumToFixnum { get { return _ConvertBignumToFixnum ?? (_ConvertBignumToFixnum = GetMethod(typeof(RubyOps), "ConvertBignumToFixnum")); } } + public static MethodInfo/*!*/ ToSDefaultConversion { get { return _ToSDefaultConversion ?? (_ToSDefaultConversion = GetMethod(typeof(RubyOps), "ToSDefaultConversion")); } } + public static MethodInfo/*!*/ GetInstanceVariable { get { return _GetInstanceVariable ?? (_GetInstanceVariable = GetMethod(typeof(RubyOps), "GetInstanceVariable")); } } + public static MethodInfo/*!*/ IsDefinedInstanceVariable { get { return _IsDefinedInstanceVariable ?? (_IsDefinedInstanceVariable = GetMethod(typeof(RubyOps), "IsDefinedInstanceVariable")); } } + public static MethodInfo/*!*/ SetInstanceVariable { get { return _SetInstanceVariable ?? (_SetInstanceVariable = GetMethod(typeof(RubyOps), "SetInstanceVariable")); } } + public static MethodInfo/*!*/ GetObjectClassVariable { get { return _GetObjectClassVariable ?? (_GetObjectClassVariable = GetMethod(typeof(RubyOps), "GetObjectClassVariable")); } } + public static MethodInfo/*!*/ GetClassVariable { get { return _GetClassVariable ?? (_GetClassVariable = GetMethod(typeof(RubyOps), "GetClassVariable")); } } + public static MethodInfo/*!*/ TryGetObjectClassVariable { get { return _TryGetObjectClassVariable ?? (_TryGetObjectClassVariable = GetMethod(typeof(RubyOps), "TryGetObjectClassVariable")); } } + public static MethodInfo/*!*/ TryGetClassVariable { get { return _TryGetClassVariable ?? (_TryGetClassVariable = GetMethod(typeof(RubyOps), "TryGetClassVariable")); } } + public static MethodInfo/*!*/ IsDefinedObjectClassVariable { get { return _IsDefinedObjectClassVariable ?? (_IsDefinedObjectClassVariable = GetMethod(typeof(RubyOps), "IsDefinedObjectClassVariable")); } } + public static MethodInfo/*!*/ IsDefinedClassVariable { get { return _IsDefinedClassVariable ?? (_IsDefinedClassVariable = GetMethod(typeof(RubyOps), "IsDefinedClassVariable")); } } + public static MethodInfo/*!*/ SetObjectClassVariable { get { return _SetObjectClassVariable ?? (_SetObjectClassVariable = GetMethod(typeof(RubyOps), "SetObjectClassVariable")); } } + public static MethodInfo/*!*/ SetClassVariable { get { return _SetClassVariable ?? (_SetClassVariable = GetMethod(typeof(RubyOps), "SetClassVariable")); } } + public static MethodInfo/*!*/ GetInstanceData { get { return _GetInstanceData ?? (_GetInstanceData = GetMethod(typeof(RubyOps), "GetInstanceData")); } } + public static MethodInfo/*!*/ DeserializeObject { get { return _DeserializeObject ?? (_DeserializeObject = GetMethod(typeof(RubyOps), "DeserializeObject")); } } + public static MethodInfo/*!*/ SerializeObject { get { return _SerializeObject ?? (_SerializeObject = GetMethod(typeof(RubyOps), "SerializeObject")); } } + public static MethodInfo/*!*/ HookupEvent { get { return _HookupEvent ?? (_HookupEvent = GetMethod(typeof(RubyOps), "HookupEvent")); } } + public static MethodInfo/*!*/ CreateDelegateFromProc { get { return _CreateDelegateFromProc ?? (_CreateDelegateFromProc = GetMethod(typeof(RubyOps), "CreateDelegateFromProc")); } } + public static MethodInfo/*!*/ CreateDelegateFromMethod { get { return _CreateDelegateFromMethod ?? (_CreateDelegateFromMethod = GetMethod(typeof(RubyOps), "CreateDelegateFromMethod")); } } + public static MethodInfo/*!*/ X { get { return _X ?? (_X = GetMethod(typeof(RubyOps), "X")); } } public static MethodInfo/*!*/ UpdateProfileTicks { get { return _UpdateProfileTicks ?? (_UpdateProfileTicks = GetMethod(typeof(RubyOps), "UpdateProfileTicks")); } } - public static MethodInfo/*!*/ CreateMainTopLevelScope { get { return _CreateMainTopLevelScope ?? (_CreateMainTopLevelScope = GetMethod(typeof(RubyOps), "CreateMainTopLevelScope")); } } - public static MethodInfo/*!*/ CreateTopLevelHostedScope { get { return _CreateTopLevelHostedScope ?? (_CreateTopLevelHostedScope = GetMethod(typeof(RubyOps), "CreateTopLevelHostedScope")); } } - public static MethodInfo/*!*/ CreateTopLevelScope { get { return _CreateTopLevelScope ?? (_CreateTopLevelScope = GetMethod(typeof(RubyOps), "CreateTopLevelScope")); } } - public static MethodInfo/*!*/ CreateWrappedTopLevelScope { get { return _CreateWrappedTopLevelScope ?? (_CreateWrappedTopLevelScope = GetMethod(typeof(RubyOps), "CreateWrappedTopLevelScope")); } } - public static MethodInfo/*!*/ CreateModuleEvalScope { get { return _CreateModuleEvalScope ?? (_CreateModuleEvalScope = GetMethod(typeof(RubyOps), "CreateModuleEvalScope")); } } - public static MethodInfo/*!*/ CreateModuleScope { get { return _CreateModuleScope ?? (_CreateModuleScope = GetMethod(typeof(RubyOps), "CreateModuleScope")); } } - public static MethodInfo/*!*/ CreateMethodScope { get { return _CreateMethodScope ?? (_CreateMethodScope = GetMethod(typeof(RubyOps), "CreateMethodScope")); } } - public static MethodInfo/*!*/ CreateBlockScope { get { return _CreateBlockScope ?? (_CreateBlockScope = GetMethod(typeof(RubyOps), "CreateBlockScope")); } } - public static MethodInfo/*!*/ TraceMethodCall { get { return _TraceMethodCall ?? (_TraceMethodCall = GetMethod(typeof(RubyOps), "TraceMethodCall")); } } - public static MethodInfo/*!*/ TraceMethodReturn { get { return _TraceMethodReturn ?? (_TraceMethodReturn = GetMethod(typeof(RubyOps), "TraceMethodReturn")); } } - public static MethodInfo/*!*/ TraceBlockCall { get { return _TraceBlockCall ?? (_TraceBlockCall = GetMethod(typeof(RubyOps), "TraceBlockCall")); } } - public static MethodInfo/*!*/ TraceBlockReturn { get { return _TraceBlockReturn ?? (_TraceBlockReturn = GetMethod(typeof(RubyOps), "TraceBlockReturn")); } } - public static MethodInfo/*!*/ PrintInteractiveResult { get { return _PrintInteractiveResult ?? (_PrintInteractiveResult = GetMethod(typeof(RubyOps), "PrintInteractiveResult")); } } - public static MethodInfo/*!*/ GetLocalVariable { get { return _GetLocalVariable ?? (_GetLocalVariable = GetMethod(typeof(RubyOps), "GetLocalVariable")); } } - public static MethodInfo/*!*/ SetLocalVariable { get { return _SetLocalVariable ?? (_SetLocalVariable = GetMethod(typeof(RubyOps), "SetLocalVariable")); } } - public static MethodInfo/*!*/ GetContextFromScope { get { return _GetContextFromScope ?? (_GetContextFromScope = GetMethod(typeof(RubyOps), "GetContextFromScope")); } } - public static MethodInfo/*!*/ GetContextFromMethod { get { return _GetContextFromMethod ?? (_GetContextFromMethod = GetMethod(typeof(RubyOps), "GetContextFromMethod")); } } - public static MethodInfo/*!*/ GetContextFromBlockParam { get { return _GetContextFromBlockParam ?? (_GetContextFromBlockParam = GetMethod(typeof(RubyOps), "GetContextFromBlockParam")); } } - public static MethodInfo/*!*/ GetContextFromProc { get { return _GetContextFromProc ?? (_GetContextFromProc = GetMethod(typeof(RubyOps), "GetContextFromProc")); } } - public static MethodInfo/*!*/ GetEmptyScope { get { return _GetEmptyScope ?? (_GetEmptyScope = GetMethod(typeof(RubyOps), "GetEmptyScope")); } } - public static MethodInfo/*!*/ DefineBlock { get { return _DefineBlock ?? (_DefineBlock = GetMethod(typeof(RubyOps), "DefineBlock")); } } - public static MethodInfo/*!*/ InitializeBlock { get { return _InitializeBlock ?? (_InitializeBlock = GetMethod(typeof(RubyOps), "InitializeBlock")); } } - public static MethodInfo/*!*/ Yield0 { get { return _Yield0 ?? (_Yield0 = GetMethod(typeof(RubyOps), "Yield0")); } } - public static MethodInfo/*!*/ Yield1 { get { return _Yield1 ?? (_Yield1 = GetMethod(typeof(RubyOps), "Yield1")); } } - public static MethodInfo/*!*/ Yield2 { get { return _Yield2 ?? (_Yield2 = GetMethod(typeof(RubyOps), "Yield2")); } } - public static MethodInfo/*!*/ Yield3 { get { return _Yield3 ?? (_Yield3 = GetMethod(typeof(RubyOps), "Yield3")); } } - public static MethodInfo/*!*/ Yield4 { get { return _Yield4 ?? (_Yield4 = GetMethod(typeof(RubyOps), "Yield4")); } } - public static MethodInfo/*!*/ YieldN { get { return _YieldN ?? (_YieldN = GetMethod(typeof(RubyOps), "YieldN")); } } - public static MethodInfo/*!*/ YieldSplat0 { get { return _YieldSplat0 ?? (_YieldSplat0 = GetMethod(typeof(RubyOps), "YieldSplat0")); } } - public static MethodInfo/*!*/ YieldSplat1 { get { return _YieldSplat1 ?? (_YieldSplat1 = GetMethod(typeof(RubyOps), "YieldSplat1")); } } - public static MethodInfo/*!*/ YieldSplat2 { get { return _YieldSplat2 ?? (_YieldSplat2 = GetMethod(typeof(RubyOps), "YieldSplat2")); } } - public static MethodInfo/*!*/ YieldSplat3 { get { return _YieldSplat3 ?? (_YieldSplat3 = GetMethod(typeof(RubyOps), "YieldSplat3")); } } - public static MethodInfo/*!*/ YieldSplat4 { get { return _YieldSplat4 ?? (_YieldSplat4 = GetMethod(typeof(RubyOps), "YieldSplat4")); } } - public static MethodInfo/*!*/ YieldSplatN { get { return _YieldSplatN ?? (_YieldSplatN = GetMethod(typeof(RubyOps), "YieldSplatN")); } } - public static MethodInfo/*!*/ YieldSplatNRhs { get { return _YieldSplatNRhs ?? (_YieldSplatNRhs = GetMethod(typeof(RubyOps), "YieldSplatNRhs")); } } - public static MethodInfo/*!*/ DefineMethod { get { return _DefineMethod ?? (_DefineMethod = GetMethod(typeof(RubyOps), "DefineMethod")); } } - public static MethodInfo/*!*/ MethodDefined { get { return _MethodDefined ?? (_MethodDefined = GetMethod(typeof(RubyOps), "MethodDefined")); } } - public static MethodInfo/*!*/ AliasMethod { get { return _AliasMethod ?? (_AliasMethod = GetMethod(typeof(RubyOps), "AliasMethod")); } } - public static MethodInfo/*!*/ UndefineMethod { get { return _UndefineMethod ?? (_UndefineMethod = GetMethod(typeof(RubyOps), "UndefineMethod")); } } - public static MethodInfo/*!*/ IsDefinedMethod { get { return _IsDefinedMethod ?? (_IsDefinedMethod = GetMethod(typeof(RubyOps), "IsDefinedMethod")); } } - public static MethodInfo/*!*/ DefineGlobalModule { get { return _DefineGlobalModule ?? (_DefineGlobalModule = GetMethod(typeof(RubyOps), "DefineGlobalModule")); } } - public static MethodInfo/*!*/ DefineNestedModule { get { return _DefineNestedModule ?? (_DefineNestedModule = GetMethod(typeof(RubyOps), "DefineNestedModule")); } } - public static MethodInfo/*!*/ DefineModule { get { return _DefineModule ?? (_DefineModule = GetMethod(typeof(RubyOps), "DefineModule")); } } - public static MethodInfo/*!*/ ConvertNamespaceToModule { get { return _ConvertNamespaceToModule ?? (_ConvertNamespaceToModule = GetMethod(typeof(RubyOps), "ConvertNamespaceToModule")); } } - public static MethodInfo/*!*/ DefineSingletonClass { get { return _DefineSingletonClass ?? (_DefineSingletonClass = GetMethod(typeof(RubyOps), "DefineSingletonClass")); } } - public static MethodInfo/*!*/ DefineGlobalClass { get { return _DefineGlobalClass ?? (_DefineGlobalClass = GetMethod(typeof(RubyOps), "DefineGlobalClass")); } } - public static MethodInfo/*!*/ DefineNestedClass { get { return _DefineNestedClass ?? (_DefineNestedClass = GetMethod(typeof(RubyOps), "DefineNestedClass")); } } - public static MethodInfo/*!*/ DefineClass { get { return _DefineClass ?? (_DefineClass = GetMethod(typeof(RubyOps), "DefineClass")); } } - public static MethodInfo/*!*/ GetGlobalConstant { get { return _GetGlobalConstant ?? (_GetGlobalConstant = GetMethod(typeof(RubyOps), "GetGlobalConstant")); } } - public static MethodInfo/*!*/ GetUnqualifiedConstant { get { return _GetUnqualifiedConstant ?? (_GetUnqualifiedConstant = GetMethod(typeof(RubyOps), "GetUnqualifiedConstant")); } } - public static MethodInfo/*!*/ GetQualifiedConstant { get { return _GetQualifiedConstant ?? (_GetQualifiedConstant = GetMethod(typeof(RubyOps), "GetQualifiedConstant")); } } - public static MethodInfo/*!*/ IsDefinedGlobalConstant { get { return _IsDefinedGlobalConstant ?? (_IsDefinedGlobalConstant = GetMethod(typeof(RubyOps), "IsDefinedGlobalConstant")); } } - public static MethodInfo/*!*/ IsDefinedUnqualifiedConstant { get { return _IsDefinedUnqualifiedConstant ?? (_IsDefinedUnqualifiedConstant = GetMethod(typeof(RubyOps), "IsDefinedUnqualifiedConstant")); } } public static MethodInfo/*!*/ IsDefinedQualifiedConstant { get { return _IsDefinedQualifiedConstant ?? (_IsDefinedQualifiedConstant = GetMethod(typeof(RubyOps), "IsDefinedQualifiedConstant")); } } public static MethodInfo/*!*/ SetGlobalConstant { get { return _SetGlobalConstant ?? (_SetGlobalConstant = GetMethod(typeof(RubyOps), "SetGlobalConstant")); } } public static MethodInfo/*!*/ SetUnqualifiedConstant { get { return _SetUnqualifiedConstant ?? (_SetUnqualifiedConstant = GetMethod(typeof(RubyOps), "SetUnqualifiedConstant")); } } @@ -188,50 +153,86 @@ public static MethodInfo/*!*/ MakeInvalidArgumentTypesError { get { return _MakeInvalidArgumentTypesError ?? (_MakeInvalidArgumentTypesError = GetMethod(typeof(RubyOps), "MakeInvalidArgumentTypesError")); } } public static MethodInfo/*!*/ MakeAmbiguousMatchError { get { return _MakeAmbiguousMatchError ?? (_MakeAmbiguousMatchError = GetMethod(typeof(RubyOps), "MakeAmbiguousMatchError")); } } public static MethodInfo/*!*/ IsSuperCallTarget { get { return _IsSuperCallTarget ?? (_IsSuperCallTarget = GetMethod(typeof(RubyOps), "IsSuperCallTarget")); } } - public static MethodInfo/*!*/ CreateInclusiveRange { get { return _CreateInclusiveRange ?? (_CreateInclusiveRange = GetMethod(typeof(RubyOps), "CreateInclusiveRange")); } } - public static MethodInfo/*!*/ CreateExclusiveRange { get { return _CreateExclusiveRange ?? (_CreateExclusiveRange = GetMethod(typeof(RubyOps), "CreateExclusiveRange")); } } - public static MethodInfo/*!*/ CreateInclusiveIntegerRange { get { return _CreateInclusiveIntegerRange ?? (_CreateInclusiveIntegerRange = GetMethod(typeof(RubyOps), "CreateInclusiveIntegerRange")); } } - public static MethodInfo/*!*/ CreateExclusiveIntegerRange { get { return _CreateExclusiveIntegerRange ?? (_CreateExclusiveIntegerRange = GetMethod(typeof(RubyOps), "CreateExclusiveIntegerRange")); } } - public static MethodInfo/*!*/ AllocateStructInstance { get { return _AllocateStructInstance ?? (_AllocateStructInstance = GetMethod(typeof(RubyOps), "AllocateStructInstance")); } } - public static MethodInfo/*!*/ CreateStructInstance { get { return _CreateStructInstance ?? (_CreateStructInstance = GetMethod(typeof(RubyOps), "CreateStructInstance")); } } - public static MethodInfo/*!*/ GetMetaObject { get { return _GetMetaObject ?? (_GetMetaObject = GetMethod(typeof(RubyOps), "GetMetaObject")); } } - public static MethodInfo/*!*/ ToProcValidator { get { return _ToProcValidator ?? (_ToProcValidator = GetMethod(typeof(RubyOps), "ToProcValidator")); } } - public static MethodInfo/*!*/ ToStringValidator { get { return _ToStringValidator ?? (_ToStringValidator = GetMethod(typeof(RubyOps), "ToStringValidator")); } } - public static MethodInfo/*!*/ ToSymbolValidator { get { return _ToSymbolValidator ?? (_ToSymbolValidator = GetMethod(typeof(RubyOps), "ToSymbolValidator")); } } - public static MethodInfo/*!*/ ConvertSymbolIdToSymbol { get { return _ConvertSymbolIdToSymbol ?? (_ConvertSymbolIdToSymbol = GetMethod(typeof(RubyOps), "ConvertSymbolIdToSymbol")); } } - public static MethodInfo/*!*/ ConvertFixnumToSymbol { get { return _ConvertFixnumToSymbol ?? (_ConvertFixnumToSymbol = GetMethod(typeof(RubyOps), "ConvertFixnumToSymbol")); } } - public static MethodInfo/*!*/ ConvertMutableStringToSymbol { get { return _ConvertMutableStringToSymbol ?? (_ConvertMutableStringToSymbol = GetMethod(typeof(RubyOps), "ConvertMutableStringToSymbol")); } } - public static MethodInfo/*!*/ ToRegexValidator { get { return _ToRegexValidator ?? (_ToRegexValidator = GetMethod(typeof(RubyOps), "ToRegexValidator")); } } - public static MethodInfo/*!*/ ToArrayValidator { get { return _ToArrayValidator ?? (_ToArrayValidator = GetMethod(typeof(RubyOps), "ToArrayValidator")); } } - public static MethodInfo/*!*/ ToHashValidator { get { return _ToHashValidator ?? (_ToHashValidator = GetMethod(typeof(RubyOps), "ToHashValidator")); } } - public static MethodInfo/*!*/ ToFixnumValidator { get { return _ToFixnumValidator ?? (_ToFixnumValidator = GetMethod(typeof(RubyOps), "ToFixnumValidator")); } } - public static MethodInfo/*!*/ CreateTypeConversionError { get { return _CreateTypeConversionError ?? (_CreateTypeConversionError = GetMethod(typeof(RubyOps), "CreateTypeConversionError")); } } - public static MethodInfo/*!*/ ConvertBignumToFixnum { get { return _ConvertBignumToFixnum ?? (_ConvertBignumToFixnum = GetMethod(typeof(RubyOps), "ConvertBignumToFixnum")); } } - public static MethodInfo/*!*/ ToSDefaultConversion { get { return _ToSDefaultConversion ?? (_ToSDefaultConversion = GetMethod(typeof(RubyOps), "ToSDefaultConversion")); } } - public static MethodInfo/*!*/ GetInstanceVariable { get { return _GetInstanceVariable ?? (_GetInstanceVariable = GetMethod(typeof(RubyOps), "GetInstanceVariable")); } } - public static MethodInfo/*!*/ IsDefinedInstanceVariable { get { return _IsDefinedInstanceVariable ?? (_IsDefinedInstanceVariable = GetMethod(typeof(RubyOps), "IsDefinedInstanceVariable")); } } - public static MethodInfo/*!*/ SetInstanceVariable { get { return _SetInstanceVariable ?? (_SetInstanceVariable = GetMethod(typeof(RubyOps), "SetInstanceVariable")); } } - public static MethodInfo/*!*/ GetObjectClassVariable { get { return _GetObjectClassVariable ?? (_GetObjectClassVariable = GetMethod(typeof(RubyOps), "GetObjectClassVariable")); } } - public static MethodInfo/*!*/ GetClassVariable { get { return _GetClassVariable ?? (_GetClassVariable = GetMethod(typeof(RubyOps), "GetClassVariable")); } } - public static MethodInfo/*!*/ TryGetObjectClassVariable { get { return _TryGetObjectClassVariable ?? (_TryGetObjectClassVariable = GetMethod(typeof(RubyOps), "TryGetObjectClassVariable")); } } - public static MethodInfo/*!*/ TryGetClassVariable { get { return _TryGetClassVariable ?? (_TryGetClassVariable = GetMethod(typeof(RubyOps), "TryGetClassVariable")); } } - public static MethodInfo/*!*/ IsDefinedObjectClassVariable { get { return _IsDefinedObjectClassVariable ?? (_IsDefinedObjectClassVariable = GetMethod(typeof(RubyOps), "IsDefinedObjectClassVariable")); } } - public static MethodInfo/*!*/ IsDefinedClassVariable { get { return _IsDefinedClassVariable ?? (_IsDefinedClassVariable = GetMethod(typeof(RubyOps), "IsDefinedClassVariable")); } } - public static MethodInfo/*!*/ SetObjectClassVariable { get { return _SetObjectClassVariable ?? (_SetObjectClassVariable = GetMethod(typeof(RubyOps), "SetObjectClassVariable")); } } - public static MethodInfo/*!*/ SetClassVariable { get { return _SetClassVariable ?? (_SetClassVariable = GetMethod(typeof(RubyOps), "SetClassVariable")); } } - public static MethodInfo/*!*/ GetInstanceData { get { return _GetInstanceData ?? (_GetInstanceData = GetMethod(typeof(RubyOps), "GetInstanceData")); } } - public static MethodInfo/*!*/ DeserializeObject { get { return _DeserializeObject ?? (_DeserializeObject = GetMethod(typeof(RubyOps), "DeserializeObject")); } } - public static MethodInfo/*!*/ SerializeObject { get { return _SerializeObject ?? (_SerializeObject = GetMethod(typeof(RubyOps), "SerializeObject")); } } - public static MethodInfo/*!*/ HookupEvent { get { return _HookupEvent ?? (_HookupEvent = GetMethod(typeof(RubyOps), "HookupEvent")); } } - public static MethodInfo/*!*/ CreateDelegateFromProc { get { return _CreateDelegateFromProc ?? (_CreateDelegateFromProc = GetMethod(typeof(RubyOps), "CreateDelegateFromProc")); } } - public static MethodInfo/*!*/ CreateDelegateFromMethod { get { return _CreateDelegateFromMethod ?? (_CreateDelegateFromMethod = GetMethod(typeof(RubyOps), "CreateDelegateFromMethod")); } } - public static MethodInfo/*!*/ X { get { return _X ?? (_X = GetMethod(typeof(RubyOps), "X")); } } public static MethodInfo/*!*/ IsProcConverterTarget { get { return _IsProcConverterTarget ?? (_IsProcConverterTarget = GetMethod(typeof(RubyOps), "IsProcConverterTarget")); } } public static MethodInfo/*!*/ CreateBfcForYield { get { return _CreateBfcForYield ?? (_CreateBfcForYield = GetMethod(typeof(RubyOps), "CreateBfcForYield")); } } public static MethodInfo/*!*/ CreateBfcForMethodProcCall { get { return _CreateBfcForMethodProcCall ?? (_CreateBfcForMethodProcCall = GetMethod(typeof(RubyOps), "CreateBfcForMethodProcCall")); } } public static MethodInfo/*!*/ CreateBfcForProcCall { get { return _CreateBfcForProcCall ?? (_CreateBfcForProcCall = GetMethod(typeof(RubyOps), "CreateBfcForProcCall")); } } public static MethodInfo/*!*/ CreateBfcForLibraryMethod { get { return _CreateBfcForLibraryMethod ?? (_CreateBfcForLibraryMethod = GetMethod(typeof(RubyOps), "CreateBfcForLibraryMethod")); } } public static MethodInfo/*!*/ LeaveProcConverter { get { return _LeaveProcConverter ?? (_LeaveProcConverter = GetMethod(typeof(RubyOps), "LeaveProcConverter")); } } + public static MethodInfo/*!*/ CreateRfcForMethod { get { return _CreateRfcForMethod ?? (_CreateRfcForMethod = GetMethod(typeof(RubyOps), "CreateRfcForMethod")); } } + public static MethodInfo/*!*/ BlockRetry { get { return _BlockRetry ?? (_BlockRetry = GetMethod(typeof(RubyOps), "BlockRetry")); } } + public static MethodInfo/*!*/ MethodRetry { get { return _MethodRetry ?? (_MethodRetry = GetMethod(typeof(RubyOps), "MethodRetry")); } } + public static MethodInfo/*!*/ EvalRetry { get { return _EvalRetry ?? (_EvalRetry = GetMethod(typeof(RubyOps), "EvalRetry")); } } + public static MethodInfo/*!*/ BlockBreak { get { return _BlockBreak ?? (_BlockBreak = GetMethod(typeof(RubyOps), "BlockBreak")); } } + public static MethodInfo/*!*/ MethodBreak { get { return _MethodBreak ?? (_MethodBreak = GetMethod(typeof(RubyOps), "MethodBreak")); } } + public static MethodInfo/*!*/ EvalBreak { get { return _EvalBreak ?? (_EvalBreak = GetMethod(typeof(RubyOps), "EvalBreak")); } } + public static MethodInfo/*!*/ MethodNext { get { return _MethodNext ?? (_MethodNext = GetMethod(typeof(RubyOps), "MethodNext")); } } + public static MethodInfo/*!*/ EvalNext { get { return _EvalNext ?? (_EvalNext = GetMethod(typeof(RubyOps), "EvalNext")); } } + public static MethodInfo/*!*/ MethodRedo { get { return _MethodRedo ?? (_MethodRedo = GetMethod(typeof(RubyOps), "MethodRedo")); } } + public static MethodInfo/*!*/ EvalRedo { get { return _EvalRedo ?? (_EvalRedo = GetMethod(typeof(RubyOps), "EvalRedo")); } } + public static MethodInfo/*!*/ BlockReturn { get { return _BlockReturn ?? (_BlockReturn = GetMethod(typeof(RubyOps), "BlockReturn")); } } + public static MethodInfo/*!*/ EvalReturn { get { return _EvalReturn ?? (_EvalReturn = GetMethod(typeof(RubyOps), "EvalReturn")); } } + public static MethodInfo/*!*/ BlockYield { get { return _BlockYield ?? (_BlockYield = GetMethod(typeof(RubyOps), "BlockYield")); } } + public static MethodInfo/*!*/ MethodYield { get { return _MethodYield ?? (_MethodYield = GetMethod(typeof(RubyOps), "MethodYield")); } } + public static MethodInfo/*!*/ EvalYield { get { return _EvalYield ?? (_EvalYield = GetMethod(typeof(RubyOps), "EvalYield")); } } + public static MethodInfo/*!*/ MethodProcCall { get { return _MethodProcCall ?? (_MethodProcCall = GetMethod(typeof(RubyOps), "MethodProcCall")); } } + public static MethodInfo/*!*/ CanRescue { get { return _CanRescue ?? (_CanRescue = GetMethod(typeof(RubyOps), "CanRescue")); } } + public static MethodInfo/*!*/ IsRetrySingleton { get { return _IsRetrySingleton ?? (_IsRetrySingleton = GetMethod(typeof(RubyOps), "IsRetrySingleton")); } } + public static MethodInfo/*!*/ PropagateRetrySingleton { get { return _PropagateRetrySingleton ?? (_PropagateRetrySingleton = GetMethod(typeof(RubyOps), "PropagateRetrySingleton")); } } + public static MethodInfo/*!*/ GetRetrySingleton { get { return _GetRetrySingleton ?? (_GetRetrySingleton = GetMethod(typeof(RubyOps), "GetRetrySingleton")); } } + public static MethodInfo/*!*/ CreateMainTopLevelScope { get { return _CreateMainTopLevelScope ?? (_CreateMainTopLevelScope = GetMethod(typeof(RubyOps), "CreateMainTopLevelScope")); } } + public static MethodInfo/*!*/ CreateTopLevelHostedScope { get { return _CreateTopLevelHostedScope ?? (_CreateTopLevelHostedScope = GetMethod(typeof(RubyOps), "CreateTopLevelHostedScope")); } } + public static MethodInfo/*!*/ CreateTopLevelScope { get { return _CreateTopLevelScope ?? (_CreateTopLevelScope = GetMethod(typeof(RubyOps), "CreateTopLevelScope")); } } + public static MethodInfo/*!*/ CreateWrappedTopLevelScope { get { return _CreateWrappedTopLevelScope ?? (_CreateWrappedTopLevelScope = GetMethod(typeof(RubyOps), "CreateWrappedTopLevelScope")); } } + public static MethodInfo/*!*/ CreateModuleEvalScope { get { return _CreateModuleEvalScope ?? (_CreateModuleEvalScope = GetMethod(typeof(RubyOps), "CreateModuleEvalScope")); } } + public static MethodInfo/*!*/ CreateModuleScope { get { return _CreateModuleScope ?? (_CreateModuleScope = GetMethod(typeof(RubyOps), "CreateModuleScope")); } } + public static MethodInfo/*!*/ CreateMethodScope { get { return _CreateMethodScope ?? (_CreateMethodScope = GetMethod(typeof(RubyOps), "CreateMethodScope")); } } + public static MethodInfo/*!*/ CreateBlockScope { get { return _CreateBlockScope ?? (_CreateBlockScope = GetMethod(typeof(RubyOps), "CreateBlockScope")); } } + public static MethodInfo/*!*/ TraceMethodCall { get { return _TraceMethodCall ?? (_TraceMethodCall = GetMethod(typeof(RubyOps), "TraceMethodCall")); } } + public static MethodInfo/*!*/ TraceMethodReturn { get { return _TraceMethodReturn ?? (_TraceMethodReturn = GetMethod(typeof(RubyOps), "TraceMethodReturn")); } } + public static MethodInfo/*!*/ TraceBlockCall { get { return _TraceBlockCall ?? (_TraceBlockCall = GetMethod(typeof(RubyOps), "TraceBlockCall")); } } + public static MethodInfo/*!*/ TraceBlockReturn { get { return _TraceBlockReturn ?? (_TraceBlockReturn = GetMethod(typeof(RubyOps), "TraceBlockReturn")); } } + public static MethodInfo/*!*/ PrintInteractiveResult { get { return _PrintInteractiveResult ?? (_PrintInteractiveResult = GetMethod(typeof(RubyOps), "PrintInteractiveResult")); } } + public static MethodInfo/*!*/ GetLocalVariable { get { return _GetLocalVariable ?? (_GetLocalVariable = GetMethod(typeof(RubyOps), "GetLocalVariable")); } } + public static MethodInfo/*!*/ SetLocalVariable { get { return _SetLocalVariable ?? (_SetLocalVariable = GetMethod(typeof(RubyOps), "SetLocalVariable")); } } + public static MethodInfo/*!*/ GetContextFromScope { get { return _GetContextFromScope ?? (_GetContextFromScope = GetMethod(typeof(RubyOps), "GetContextFromScope")); } } + public static MethodInfo/*!*/ GetContextFromMethod { get { return _GetContextFromMethod ?? (_GetContextFromMethod = GetMethod(typeof(RubyOps), "GetContextFromMethod")); } } + public static MethodInfo/*!*/ GetContextFromBlockParam { get { return _GetContextFromBlockParam ?? (_GetContextFromBlockParam = GetMethod(typeof(RubyOps), "GetContextFromBlockParam")); } } + public static MethodInfo/*!*/ GetContextFromProc { get { return _GetContextFromProc ?? (_GetContextFromProc = GetMethod(typeof(RubyOps), "GetContextFromProc")); } } + public static MethodInfo/*!*/ GetEmptyScope { get { return _GetEmptyScope ?? (_GetEmptyScope = GetMethod(typeof(RubyOps), "GetEmptyScope")); } } + public static MethodInfo/*!*/ DefineBlock { get { return _DefineBlock ?? (_DefineBlock = GetMethod(typeof(RubyOps), "DefineBlock")); } } + public static MethodInfo/*!*/ InitializeBlock { get { return _InitializeBlock ?? (_InitializeBlock = GetMethod(typeof(RubyOps), "InitializeBlock")); } } + public static MethodInfo/*!*/ Yield0 { get { return _Yield0 ?? (_Yield0 = GetMethod(typeof(RubyOps), "Yield0")); } } + public static MethodInfo/*!*/ Yield1 { get { return _Yield1 ?? (_Yield1 = GetMethod(typeof(RubyOps), "Yield1")); } } + public static MethodInfo/*!*/ Yield2 { get { return _Yield2 ?? (_Yield2 = GetMethod(typeof(RubyOps), "Yield2")); } } + public static MethodInfo/*!*/ Yield3 { get { return _Yield3 ?? (_Yield3 = GetMethod(typeof(RubyOps), "Yield3")); } } + public static MethodInfo/*!*/ Yield4 { get { return _Yield4 ?? (_Yield4 = GetMethod(typeof(RubyOps), "Yield4")); } } + public static MethodInfo/*!*/ YieldN { get { return _YieldN ?? (_YieldN = GetMethod(typeof(RubyOps), "YieldN")); } } + public static MethodInfo/*!*/ YieldSplat0 { get { return _YieldSplat0 ?? (_YieldSplat0 = GetMethod(typeof(RubyOps), "YieldSplat0")); } } + public static MethodInfo/*!*/ YieldSplat1 { get { return _YieldSplat1 ?? (_YieldSplat1 = GetMethod(typeof(RubyOps), "YieldSplat1")); } } + public static MethodInfo/*!*/ YieldSplat2 { get { return _YieldSplat2 ?? (_YieldSplat2 = GetMethod(typeof(RubyOps), "YieldSplat2")); } } + public static MethodInfo/*!*/ YieldSplat3 { get { return _YieldSplat3 ?? (_YieldSplat3 = GetMethod(typeof(RubyOps), "YieldSplat3")); } } + public static MethodInfo/*!*/ YieldSplat4 { get { return _YieldSplat4 ?? (_YieldSplat4 = GetMethod(typeof(RubyOps), "YieldSplat4")); } } + public static MethodInfo/*!*/ YieldSplatN { get { return _YieldSplatN ?? (_YieldSplatN = GetMethod(typeof(RubyOps), "YieldSplatN")); } } + public static MethodInfo/*!*/ YieldSplatNRhs { get { return _YieldSplatNRhs ?? (_YieldSplatNRhs = GetMethod(typeof(RubyOps), "YieldSplatNRhs")); } } + public static MethodInfo/*!*/ DefineMethod { get { return _DefineMethod ?? (_DefineMethod = GetMethod(typeof(RubyOps), "DefineMethod")); } } + public static MethodInfo/*!*/ MethodDefined { get { return _MethodDefined ?? (_MethodDefined = GetMethod(typeof(RubyOps), "MethodDefined")); } } + public static MethodInfo/*!*/ AliasMethod { get { return _AliasMethod ?? (_AliasMethod = GetMethod(typeof(RubyOps), "AliasMethod")); } } + public static MethodInfo/*!*/ UndefineMethod { get { return _UndefineMethod ?? (_UndefineMethod = GetMethod(typeof(RubyOps), "UndefineMethod")); } } + public static MethodInfo/*!*/ IsDefinedMethod { get { return _IsDefinedMethod ?? (_IsDefinedMethod = GetMethod(typeof(RubyOps), "IsDefinedMethod")); } } + public static MethodInfo/*!*/ DefineGlobalModule { get { return _DefineGlobalModule ?? (_DefineGlobalModule = GetMethod(typeof(RubyOps), "DefineGlobalModule")); } } + public static MethodInfo/*!*/ DefineNestedModule { get { return _DefineNestedModule ?? (_DefineNestedModule = GetMethod(typeof(RubyOps), "DefineNestedModule")); } } + public static MethodInfo/*!*/ DefineModule { get { return _DefineModule ?? (_DefineModule = GetMethod(typeof(RubyOps), "DefineModule")); } } + public static MethodInfo/*!*/ ConvertNamespaceToModule { get { return _ConvertNamespaceToModule ?? (_ConvertNamespaceToModule = GetMethod(typeof(RubyOps), "ConvertNamespaceToModule")); } } + public static MethodInfo/*!*/ DefineSingletonClass { get { return _DefineSingletonClass ?? (_DefineSingletonClass = GetMethod(typeof(RubyOps), "DefineSingletonClass")); } } + public static MethodInfo/*!*/ DefineGlobalClass { get { return _DefineGlobalClass ?? (_DefineGlobalClass = GetMethod(typeof(RubyOps), "DefineGlobalClass")); } } + public static MethodInfo/*!*/ DefineNestedClass { get { return _DefineNestedClass ?? (_DefineNestedClass = GetMethod(typeof(RubyOps), "DefineNestedClass")); } } + public static MethodInfo/*!*/ DefineClass { get { return _DefineClass ?? (_DefineClass = GetMethod(typeof(RubyOps), "DefineClass")); } } + public static MethodInfo/*!*/ GetGlobalConstant { get { return _GetGlobalConstant ?? (_GetGlobalConstant = GetMethod(typeof(RubyOps), "GetGlobalConstant")); } } + public static MethodInfo/*!*/ GetUnqualifiedConstant { get { return _GetUnqualifiedConstant ?? (_GetUnqualifiedConstant = GetMethod(typeof(RubyOps), "GetUnqualifiedConstant")); } } + public static MethodInfo/*!*/ GetQualifiedConstant { get { return _GetQualifiedConstant ?? (_GetQualifiedConstant = GetMethod(typeof(RubyOps), "GetQualifiedConstant")); } } + public static MethodInfo/*!*/ IsDefinedGlobalConstant { get { return _IsDefinedGlobalConstant ?? (_IsDefinedGlobalConstant = GetMethod(typeof(RubyOps), "IsDefinedGlobalConstant")); } } + public static MethodInfo/*!*/ IsDefinedUnqualifiedConstant { get { return _IsDefinedUnqualifiedConstant ?? (_IsDefinedUnqualifiedConstant = GetMethod(typeof(RubyOps), "IsDefinedUnqualifiedConstant")); } } public static MethodInfo/*!*/ CreateRegex(string/*!*/ suffix) { switch (suffix) { =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C674241 File: Symbols.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;C674241 (server) 1/8/2009 11:26 AM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Symbols.cs;CompositeConversions3 @@ -40,6 +40,7 @@ public static readonly string ToAry = "to_ary"; public static readonly string ToHash = "to_hash"; public static readonly string ToInt = "to_int"; + public static readonly string ToI = "to_i"; public static readonly string Initialize = "initialize"; public static readonly string InitializeCopy = "initialize_copy"; public static readonly string Object = "Object"; =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Tokenizer.cs;C674241 File: Tokenizer.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Tokenizer.cs;C674241 (server) 1/8/2009 6:57 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Tokenizer.cs;CompositeConversions3 @@ -26,6 +26,7 @@ using IronRuby.Builtins; using IronRuby.Compiler.Ast; using System.Text.RegularExpressions; +using IronRuby.Runtime; namespace IronRuby.Compiler { internal enum LexicalState { @@ -624,25 +625,27 @@ switch (token) { case Tokens.MultiLineComment: case Tokens.SingleLineComment: - if (_verbatim) { - return token; - } - continue; + break; case Tokens.Whitespace: whitespaceSeen = true; - continue; + break; case Tokens.EndOfLine: // not considered whitespace case Tokens.InvalidCharacter: - continue; + break; case Tokens.EndOfFile: _eofReached = true; - break; + return token; + + default: + return token; } - return token; + if (_verbatim) { + return token; + } } } @@ -3396,6 +3399,114 @@ get { return _unterminatedToken; } } + #region ParseInteger + + private static int NextChar(string/*!*/ str, ref int i) { + return i == str.Length ? -1 : str[i++]; + } + + public static IntegerValue ParseInteger(string/*!*/ str, int @base) { + int i = 0; + return ParseInteger(str, @base, ref i); + } + + // @base == 0: + // [:whitespace:]*[+-]?(0x|0X|ob|0B|0d|0D|0o|0O)?([:base-digit:][_]?)*[:base-digit:].* + // otherwise: + // [:whitespace:]*[+-]?([:base-digit:][_]?)*[:base-digit:].* + public static IntegerValue ParseInteger(string/*!*/ str, int @base, ref int i) { + ContractUtils.RequiresNotNull(str, "str"); + + int c; + do { c = NextChar(str, ref i); } while (IsWhiteSpace(c)); + + int sign; + if (c == '+') { + sign = +1; + c = NextChar(str, ref i); + } else if (c == '-') { + sign = -1; + c = NextChar(str, ref i); + } else { + sign = +1; + } + + if (c == '0') { + c = NextChar(str, ref i); + int newBase = 0; + switch (c) { + case 'x': + case 'X': newBase = 16; break; + case 'b': + case 'B': newBase = 2; break; + case 'd': + case 'D': newBase = 10; break; + case 'o': + case 'O': newBase = 8; break; + } + + if (newBase != 0) { + // no base specified -> set the base + // base specified -> skip prefix of that base + if (@base == 0 || newBase == @base) { + @base = newBase; + c = NextChar(str, ref i); + } + } else if (@base == 0) { + @base = 8; + } + } else if (@base == 0) { + @base = 10; + } + + bool underAllowed = false; + long value = 0; + int digitCount = 0; + int start = i - 1; + while (true) { + if (c != '_') { + int digit = ToDigit(c); + if (digit < @base) { + if (value <= Int32.MaxValue) { + value = value * @base + digit; + } + digitCount++; + } else { + break; + } + underAllowed = true; + } else if (underAllowed) { + underAllowed = false; + } else { + break; + } + c = NextChar(str, ref i); + } + + if (digitCount == 0) { + return 0; + } + + if (value <= Int32.MaxValue) { + value *= sign; + if (value >= Int32.MinValue && value <= Int32.MaxValue) { + return (int)value; + } else { + return BigInteger.Create(value); + } + } else { + var parser = new BignumParser(); + parser.Position = 0; + parser.Buffer = str.ToCharArray(start, i - start); + + return parser.Parse(digitCount, @base) * sign; + } + } + + #endregion + + #region TryParseDouble + private static int Read(string/*!*/ str, ref int i) { i++; return (i < str.Length) ? str[i] : -1; @@ -3471,6 +3582,10 @@ return success; } + #endregion + + #region TryParseEncodingHeader + private const string EncodingHeaderPattern = @"^[#].*?coding\s*[:=]\s*(?[a-z0-9_-]+)"; // reads case insensitively, doesn't rewind the reader if the content doesn't match, doesn't read a line unless it starts with '#': @@ -3505,6 +3620,10 @@ return false; } + #endregion + + #region Names + public static bool IsConstantName(string name) { return !String.IsNullOrEmpty(name) && IsUpperLetter(name[0]) @@ -3550,6 +3669,8 @@ #endregion + #endregion + #region Tokenizer Service public override object CurrentState { =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/IntegerValue.cs File: IntegerValue.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/IntegerValue.cs;CompositeConversions3 @@ -1,0 +1,76 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using IronRuby.Compiler.Generation; +using Microsoft.Scripting.Math; +using IronRuby.Builtins; +using System.Diagnostics; +using Microsoft.Scripting.Runtime; + +namespace IronRuby.Runtime { + public struct IntegerValue : IEquatable { + private int _fixnum; + private BigInteger _bignum; + + public int Fixnum { + get { + Debug.Assert(IsFixnum); + return _fixnum; + } + } + + public BigInteger Bignum { + get { + Debug.Assert(!IsFixnum); + return _bignum; + } + } + + public bool IsFixnum { + get { return ReferenceEquals(_bignum, null); } + } + + public IntegerValue(int value) { + _fixnum = value; + _bignum = null; + } + + public IntegerValue(BigInteger/*!*/ value) { + _fixnum = 0; + _bignum = value; + } + + public static implicit operator IntegerValue(int value) { + return new IntegerValue(value); + } + + public static implicit operator IntegerValue(BigInteger value) { + return new IntegerValue(value); + } + + public object/*!*/ ToObject() { + return (object)_bignum ?? ScriptingRuntimeHelpers.Int32ToObject(_fixnum); + } + + public bool Equals(IntegerValue other) { + if (_fixnum != other.Fixnum) return false; + if (ReferenceEquals(_bignum, null)) return ReferenceEquals(other._bignum, null); + return _bignum.Equals(other._bignum); + } + } +} =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C695629 File: RubyOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;C695629 (server) 1/7/2009 1:54 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyOps.cs;CompositeConversions3 @@ -1515,6 +1515,20 @@ } [Emitted] // ProtocolConversionAction + public static IntegerValue ToIntegerValidator(string/*!*/ className, object obj) { + if (obj is int) { + return new IntegerValue((int)obj); + } + + var bignum = obj as BigInteger; + if ((object)bignum != null) { + return new IntegerValue(bignum); + } + + throw new InvalidOperationException(String.Format("{0}#to_int/to_i should return Integer", className)); + } + + [Emitted] // ProtocolConversionAction public static Exception/*!*/ CreateTypeConversionError(string/*!*/ fromType, string/*!*/ toType) { return RubyExceptions.CreateTypeConversionError(fromType, toType); } =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Union.cs File: Union.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Union.cs;CompositeConversions3 @@ -1,0 +1,74 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using IronRuby.Compiler.Generation; +using IronRuby.Builtins; +using System.Diagnostics; + +namespace IronRuby.Runtime { + public struct Union { + private TFirst _first; + private TSecond _second; + + public TFirst First { get { return _first; } } + public TSecond Second { get { return _second; } } + + public Union(TFirst first, TSecond second) { + _first = first; + _second = second; + } + + public static implicit operator Union(TFirst value) { + return new Union(value, default(TSecond)); + } + + public static implicit operator Union(TSecond value) { + return new Union(default(TFirst), value); + } + } + + public static class UnionSpecializations { + public static bool IsFixnum(this Union union) { + return ReferenceEquals(union.Second, null); + } + + public static int Fixnum(this Union union) { + Debug.Assert(union.IsFixnum()); + return union.First; + } + + public static MutableString/*!*/ String(this Union union) { + Debug.Assert(!union.IsFixnum()); + return union.Second; + } + + public static bool IsFixnum(this Union union) { + return ReferenceEquals(union.First, null); + } + + public static int Fixnum(this Union union) { + Debug.Assert(union.IsFixnum()); + return union.Second; + } + + public static MutableString/*!*/ String(this Union union) { + Debug.Assert(!union.IsFixnum()); + return union.First; + } + } +} =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Utils.cs;C633889 File: Utils.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Utils.cs;C633889 (server) 1/9/2009 3:23 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Utils.cs;CompositeConversions3 @@ -17,6 +17,7 @@ using Microsoft.Scripting.Utils; using System.Diagnostics; using System.Text; +using System.Reflection; namespace IronRuby.Runtime { public static class Utils { @@ -65,7 +66,7 @@ } } - public static class StringBuilderExtensions { + public static class BclExtensions { public static int IndexOf(this StringBuilder/*!*/ sb, char value) { ContractUtils.RequiresNotNull(sb, "sb"); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ArgsBuilder.cs;C656583 edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs;C674241 File: ConvertToSAction.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs;C674241 (server) 1/9/2009 2:22 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ConvertToSAction.cs;CompositeConversions3 @@ -18,6 +18,9 @@ using IronRuby.Compiler; using IronRuby.Compiler.Generation; using Microsoft.Scripting.Runtime; +using System.Linq.Expressions; +using Ast = System.Linq.Expressions.Expression; +using AstFactory = IronRuby.Compiler.Ast.AstFactory; using AstUtils = Microsoft.Scripting.Ast.Utils; namespace IronRuby.Runtime.Calls { @@ -39,7 +42,11 @@ return other != null; } - protected override void SetRule(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { + Expression/*!*/ IExpressionSerializable.CreateExpression() { + return Ast.Call(Methods.GetMethod(GetType(), "Make")); + } + + protected override void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { const string ToS = "to_s"; // no conversion for a subclass of string: =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;C674241 File: ProtocolConversionAction.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;C674241 (server) 1/7/2009 1:10 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/ProtocolConversionAction.cs;CompositeConversions3 @@ -33,7 +33,7 @@ using System.Collections.Generic; namespace IronRuby.Runtime.Calls { - public abstract class RubyConversionAction : DynamicMetaObjectBinder, IExpressionSerializable { + public abstract class RubyConversionAction : DynamicMetaObjectBinder { protected RubyConversionAction() { } @@ -48,33 +48,19 @@ public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, DynamicMetaObject/*!*/[]/*!*/ args) { var mo = new MetaObjectBuilder(); - SetRule(mo, new CallArguments(context, args, Signature)); + BuildConversion(mo, new CallArguments(context, args, Signature)); return mo.CreateMetaObject(this, context, args); } - Expression/*!*/ IExpressionSerializable.CreateExpression() { - return Ast.Call(GetType().GetMethod("Make")); - } + protected abstract void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args); - protected abstract void SetRule(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args); - } - - // Conversion operations: - // 1) tries implicit conversions - // 2) calls respond_to? :to_xxx - // 3) calls to_xxx - public abstract class ProtocolConversionAction : RubyConversionAction, IExpressionSerializable { - protected ProtocolConversionAction() { - } - - public static ProtocolConversionAction TryGetConversionAction(Type/*!*/ parameterType) { + public static RubyConversionAction TryGetDefaultConversionAction(Type/*!*/ parameterType) { if (parameterType == typeof(MutableString)) { return ConvertToStrAction.Instance; } - // TODO: combined to_str + to_int cast -> String/Fixnum (socket) - // TODO: combined to_int + to_i cast -> Fixnum/Bignum - + // TODO: combined to_str + to_int cast -> String/Fixnum (socket) + // TODO: nullable int (see Array#fill, Sockets:ConvertToSocketFlag) if (parameterType == typeof(int)) { return ConvertToFixnumAction.Instance; @@ -84,14 +70,22 @@ return ConvertToSymbolAction.Instance; } + if (parameterType == typeof(IntegerValue)) { + return ConvertToIntAction.Instance; + } + + if (parameterType == typeof(Union)) { + return CompositeConversionAction.ToFixnumToStr; + } + + if (parameterType == typeof(Union)) { + return CompositeConversionAction.ToStrToFixnum; + } + if (parameterType == typeof(RubyRegex)) { return ConvertToRegexAction.Instance; } - if (parameterType == typeof(bool)) { - return ConvertToBooleanAction.Instance; - } - if (parameterType == typeof(IList)) { return ConvertToArrayAction.Instance; } @@ -102,34 +96,53 @@ return null; } + } + // Conversion operations: + // 1) tries implicit conversions + // 2) calls respond_to? :to_xxx + // 3) calls to_xxx + public abstract class ProtocolConversionAction : RubyConversionAction { + protected ProtocolConversionAction() { + } + protected abstract string/*!*/ ToMethodName { get; } protected abstract MethodInfo ConversionResultValidator { get; } protected abstract string/*!*/ TargetTypeName { get; } protected abstract bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args); - protected override void SetRule(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { - Assert.NotNull(metaBuilder, args); + protected override void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { + BuildConversion(metaBuilder, args, ConversionResultValidator != null ? ConversionResultValidator.ReturnType : typeof(object), this); + } + + internal static void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, Type/*!*/ resultType, + params ProtocolConversionAction[]/*!*/ conversions) { + Assert.NotNull(metaBuilder, args, conversions); Debug.Assert(args.SimpleArgumentCount == 0 && !args.Signature.HasBlock && !args.Signature.HasSplattedArgument && !args.Signature.HasRhsArgument); Debug.Assert(!args.Signature.HasScope); var ec = args.RubyContext; - // implicit conversions should only depend on a static type: - if (TryImplicitConversion(metaBuilder, args)) { - if (args.Target == null) { - metaBuilder.AddRestriction(Ast.Equal(args.TargetExpression, Ast.Constant(null, args.TargetExpression.Type))); - } else { - metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression); + // implicit conversions should only depend on the static type: + foreach (var conversion in conversions) { + if (conversion.TryImplicitConversion(metaBuilder, args)) { + if (args.Target == null) { + metaBuilder.AddRestriction(Ast.Equal(args.TargetExpression, Ast.Constant(null, args.TargetExpression.Type))); + } else { + metaBuilder.AddTypeRestriction(args.Target.GetType(), args.TargetExpression); + } + + if (!metaBuilder.Error) { + metaBuilder.Result = AstUtils.Convert(metaBuilder.Result, resultType); + } + return; } - return; } // check for type version: metaBuilder.AddTargetTypeTest(args); - string toMethodName = ToMethodName; Expression targetClassNameConstant = Ast.Constant(ec.GetClassOf(args.Target).Name); // Kernel#respond_to? method is not overridden => we can optimize @@ -138,64 +151,82 @@ // the method is defined in library, hasn't been replaced by user defined method (TODO: maybe we should make this check better) (respondToMethod.DeclaringModule == ec.KernelModule && respondToMethod is RubyMethodGroupInfo)) { - RubyMemberInfo conversionMethod = ec.ResolveMethod(args.Target, toMethodName, false).InvalidateSitesOnOverride(); + ProtocolConversionAction selectedConversion = null; + RubyMemberInfo conversionMethod = null; + + foreach (var conversion in conversions) { + selectedConversion = conversion; + conversionMethod = ec.ResolveMethod(args.Target, conversion.ToMethodName, false).InvalidateSitesOnOverride(); + if (conversionMethod != null) { + break; + } + } + if (conversionMethod == null) { // error: - SetError(metaBuilder, targetClassNameConstant, args); + selectedConversion.SetError(metaBuilder, targetClassNameConstant, args); return; } else { // invoke target.to_xxx() and validate it; returns an instance of TTargetType: - conversionMethod.BuildCall(metaBuilder, args, toMethodName); + conversionMethod.BuildCall(metaBuilder, args, selectedConversion.ToMethodName); - if (!metaBuilder.Error && ConversionResultValidator != null) { - metaBuilder.Result = ConversionResultValidator.OpCall(targetClassNameConstant, AstFactory.Box(metaBuilder.Result)); + var validator = selectedConversion.ConversionResultValidator; + if (!metaBuilder.Error) { + if (validator != null) { + metaBuilder.Result = validator.OpCall(targetClassNameConstant, AstFactory.Box(metaBuilder.Result)); + } + metaBuilder.Result = AstUtils.Convert(metaBuilder.Result, resultType); } return; } } else if (!RubyModule.IsMethodVisible(respondToMethod, false)) { // respond_to? is private: - SetError(metaBuilder, targetClassNameConstant, args); + conversions[conversions.Length - 1].SetError(metaBuilder, targetClassNameConstant, args); return; } // slow path: invoke respond_to?, to_xxx and result validation: + for (int i = conversions.Length - 1; i >= 0; i--) { + string toMethodName = conversions[i].ToMethodName; + MethodInfo validator = conversions[i].ConversionResultValidator; + + var conversionCallSite = Ast.Dynamic( + RubyCallAction.Make(toMethodName, RubyCallSignature.WithImplicitSelf(0)), + typeof(object), + args.ContextExpression, args.TargetExpression + ); - var conversionCallSite = Ast.Dynamic( - RubyCallAction.Make(toMethodName, RubyCallSignature.WithImplicitSelf(0)), - typeof(object), - args.ContextExpression, args.TargetExpression - ); + metaBuilder.Result = Ast.Condition( + // If - Expression opCall; - metaBuilder.Result = Ast.Condition( - // If + // respond_to?() + Methods.IsTrue.OpCall( + Ast.Dynamic( + RubyCallAction.Make(Symbols.RespondTo, RubyCallSignature.WithImplicitSelf(1)), + typeof(object), + args.ContextExpression, args.TargetExpression, Ast.Constant(SymbolTable.StringToId(toMethodName)) + ) + ), - // respond_to?() - Methods.IsTrue.OpCall( - Ast.Dynamic( - RubyCallAction.Make(Symbols.RespondTo, RubyCallSignature.WithImplicitSelf(1)), - typeof(object), - args.ContextExpression, args.TargetExpression, Ast.Constant(SymbolTable.StringToId(toMethodName)) - ) - ), + // Then - // Then + // to_xxx(): + AstUtils.Convert( + (validator == null) ? conversionCallSite : + validator.OpCall(targetClassNameConstant, conversionCallSite), + resultType + ), - // to_xxx(): - opCall = (ConversionResultValidator == null) ? conversionCallSite : - ConversionResultValidator.OpCall(targetClassNameConstant, conversionCallSite), + // Else - // Else - - AstUtils.Convert( - (ConversionResultValidator == null) ? args.TargetExpression : - AstUtils.Convert( - Ast.Throw(Methods.CreateTypeConversionError.OpCall(targetClassNameConstant, Ast.Constant(TargetTypeName))), - typeof(object) - ), - opCall.Type - ) - ); + (i < conversions.Length - 1) ? metaBuilder.Result : + (validator == null) ? AstUtils.Convert(args.TargetExpression, resultType) : + Ast.Throw( + Methods.CreateTypeConversionError.OpCall(targetClassNameConstant, Ast.Constant(conversions[i].TargetTypeName)), + resultType + ) + ); + } } private void SetError(MetaObjectBuilder/*!*/ metaBuilder, Expression/*!*/ targetClassNameConstant, CallArguments/*!*/ args) { @@ -207,8 +238,38 @@ } } - public abstract class ConvertToReferenceTypeAction : ProtocolConversionAction where TTargetType : class { + public abstract class ProtocolConversionAction : ProtocolConversionAction, IEquatable, IExpressionSerializable + where TSelf : ProtocolConversionAction, new() { + + public static readonly TSelf Instance = new TSelf(); + + public bool Equals(TSelf other) { + return ReferenceEquals(this, other); + } + + [Emitted] + public static TSelf/*!*/ Make() { + return Instance; + } + + protected ProtocolConversionAction() { + Debug.Assert(GetType() == typeof(TSelf)); + } + + Expression/*!*/ IExpressionSerializable.CreateExpression() { + return Ast.Call(Methods.GetMethod(typeof(ProtocolConversionAction), "Make")); + } + } + + public abstract class ConvertToReferenceTypeAction : ProtocolConversionAction + where TSelf : ConvertToReferenceTypeAction, new() + where TTargetType : class { + protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { + return TryImplicitConversionInternal(metaBuilder, args); + } + + internal static bool TryImplicitConversionInternal(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { if (args.Target == null) { metaBuilder.Result = Ast.Constant(null); return true; @@ -223,151 +284,53 @@ } } - public sealed class ConvertToProcAction : ConvertToReferenceTypeAction, IEquatable { - public static readonly ConvertToProcAction Instance = new ConvertToProcAction(); - + public sealed class ConvertToProcAction : ConvertToReferenceTypeAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToProc; } } protected override string/*!*/ TargetTypeName { get { return "Proc"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToProcValidator; } } - - private ConvertToProcAction() { - } - - [Emitted] - public static ConvertToProcAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToProcAction other) { - return other != null; - } } - public sealed class ConvertToStrAction : ConvertToReferenceTypeAction, IEquatable { - public static readonly ConvertToStrAction Instance = new ConvertToStrAction(); - + public sealed class ConvertToStrAction : ConvertToReferenceTypeAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } } protected override string/*!*/ TargetTypeName { get { return "String"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToStringValidator; } } - - private ConvertToStrAction() { - } - - [Emitted] - public static ConvertToStrAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToStrAction other) { - return other != null; - } } // TODO: escaping vs. non-escaping? // This conversion escapes the regex. - public sealed class ConvertToRegexAction : ConvertToReferenceTypeAction, IEquatable { - public static readonly ConvertToRegexAction Instance = new ConvertToRegexAction(); - + public sealed class ConvertToRegexAction : ConvertToReferenceTypeAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } } protected override string/*!*/ TargetTypeName { get { return "Regexp"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToRegexValidator; } } - - private ConvertToRegexAction() { - } - - [Emitted] - public static ConvertToRegexAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToRegexAction other) { - return other != null; - } } - public sealed class ConvertToArrayAction : ConvertToReferenceTypeAction, IEquatable { - public static readonly ConvertToArrayAction Instance = new ConvertToArrayAction(); - + public sealed class ConvertToArrayAction : ConvertToReferenceTypeAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToAry; } } protected override string/*!*/ TargetTypeName { get { return "Array"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToArrayValidator; } } - - private ConvertToArrayAction() { - } - - [Emitted] - public static ConvertToArrayAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToArrayAction other) { - return other != null; - } } - public sealed class ConvertToHashAction : ConvertToReferenceTypeAction>, IEquatable { - public static readonly ConvertToHashAction Instance = new ConvertToHashAction(); - + public sealed class ConvertToHashAction : ConvertToReferenceTypeAction> { protected override string/*!*/ ToMethodName { get { return Symbols.ToHash; } } protected override string/*!*/ TargetTypeName { get { return "Hash"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToHashValidator; } } - - private ConvertToHashAction() { - } - - [Emitted] - public static ConvertToHashAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToHashAction other) { - return other != null; - } } - public sealed class TryConvertToArrayAction : ConvertToReferenceTypeAction, IEquatable { - public static readonly TryConvertToArrayAction Instance = new TryConvertToArrayAction(); - + public sealed class TryConvertToArrayAction : ConvertToReferenceTypeAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToAry; } } protected override string/*!*/ TargetTypeName { get { return "Array"; } } protected override MethodInfo ConversionResultValidator { get { return null; } } - - private TryConvertToArrayAction() { - } - - [Emitted] - public static TryConvertToArrayAction/*!*/ Make() { - return Instance; - } - - public bool Equals(TryConvertToArrayAction other) { - return other != null; - } } - public sealed class ConvertToFixnumAction : ProtocolConversionAction, IEquatable { - public static readonly ConvertToFixnumAction Instance = new ConvertToFixnumAction(); - + public sealed class ConvertToFixnumAction : ProtocolConversionAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToInt; } } protected override string/*!*/ TargetTypeName { get { return "Fixnum"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToFixnumValidator; } } - private ConvertToFixnumAction() { - } - - [Emitted] - public static ConvertToFixnumAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToFixnumAction other) { - return other != null; - } - protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { object target = args.Target; - - if (args.Target == null) { + + if (target == null) { metaBuilder.SetError(Methods.CreateTypeConversionError.OpCall(Ast.Constant("nil"), Ast.Constant(TargetTypeName))); return true; } @@ -388,62 +351,56 @@ } } - public sealed class ConvertToBooleanAction : ProtocolConversionAction, IEquatable { - public static readonly ConvertToBooleanAction Instance = new ConvertToBooleanAction(); + public abstract class ConvertToIntegerActionBase : ProtocolConversionAction + where TSelf : ConvertToIntegerActionBase, new() { - protected override string/*!*/ ToMethodName { get { return Symbols.ToInt; } } - protected override string/*!*/ TargetTypeName { get { return "Fixnum"; } } - protected override MethodInfo ConversionResultValidator { get { return Methods.ToFixnumValidator; } } + protected override string/*!*/ TargetTypeName { get { return "Integer"; } } - private ConvertToBooleanAction() { - } - - [Emitted] - public static ConvertToBooleanAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToBooleanAction other) { - return other != null; - } - protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { object target = args.Target; if (args.Target == null) { - metaBuilder.Result = Ast.Constant(false); + metaBuilder.SetError(Methods.CreateTypeConversionError.OpCall(Ast.Constant("nil"), Ast.Constant(TargetTypeName))); return true; - } - - if (target is bool) { - metaBuilder.Result = AstUtils.Convert(args.TargetExpression, typeof(bool)); + } + + // TODO: other .NET primitive integer types + if (target is int) { + metaBuilder.Result = AstUtils.Convert(args.TargetExpression, typeof(int)); return true; } - return true; + var bignum = target as BigInteger; + if ((object)bignum != null) { + metaBuilder.Result = AstUtils.Convert(args.TargetExpression, typeof(BigInteger)); + return true; + } + + return false; } } + /// + /// Calls to_int and wraps the result (Fixnum or Bignum) into IntegerValue. + /// + public sealed class ConvertToIntAction : ConvertToIntegerActionBase { + protected override string/*!*/ ToMethodName { get { return Symbols.ToInt; } } + protected override MethodInfo ConversionResultValidator { get { return Methods.ToIntegerValidator; } } + } - public sealed class ConvertToSymbolAction : ProtocolConversionAction, IEquatable { - public static readonly ConvertToSymbolAction Instance = new ConvertToSymbolAction(); - + /// + /// Calls to_i and wraps the result (Fixnum or Bignum) into IntegerValue. + /// + public sealed class ConvertToIAction : ConvertToIntegerActionBase { + protected override string/*!*/ ToMethodName { get { return Symbols.ToI; } } + protected override MethodInfo ConversionResultValidator { get { return Methods.ToIntegerValidator; } } + } + + public sealed class ConvertToSymbolAction : ProtocolConversionAction { protected override string/*!*/ ToMethodName { get { return Symbols.ToStr; } } protected override string/*!*/ TargetTypeName { get { return "Symbol"; } } protected override MethodInfo ConversionResultValidator { get { return Methods.ToSymbolValidator; } } - private ConvertToSymbolAction() { - } - - [Emitted] - public static ConvertToSymbolAction/*!*/ Make() { - return Instance; - } - - public bool Equals(ConvertToSymbolAction other) { - return other != null; - } - protected override bool TryImplicitConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { object target = args.Target; var targetExpression = args.TargetExpression; @@ -478,4 +435,61 @@ return false; } } + + public sealed class CompositeConversionAction : RubyConversionAction, IExpressionSerializable, IEquatable { + private readonly ProtocolConversionAction[]/*!*/ _conversions; + private readonly Type/*!*/ _resultType; + + public static readonly CompositeConversionAction ToFixnumToStr = + new CompositeConversionAction(typeof(Union), ConvertToFixnumAction.Instance, ConvertToStrAction.Instance); + + public static readonly CompositeConversionAction ToStrToFixnum = + new CompositeConversionAction(typeof(Union), ConvertToStrAction.Instance, ConvertToFixnumAction.Instance); + + public static readonly CompositeConversionAction ToIntToI = + new CompositeConversionAction(typeof(IntegerValue), ConvertToIntAction.Instance, ConvertToIAction.Instance); + + internal CompositeConversionAction(Type/*!*/ resultType, params ProtocolConversionAction[]/*!*/ conversions) { + Assert.NotNullItems(conversions); + Assert.NotEmpty(conversions); + _conversions = conversions; + _resultType = resultType; + } + + Expression/*!*/ IExpressionSerializable.CreateExpression() { + if (ReferenceEquals(this, ToFixnumToStr)) { + return Ast.Call(Methods.GetMethod(GetType(), "MakeToFixnumToStr")); + } + if (ReferenceEquals(this, ToStrToFixnum)) { + return Ast.Call(Methods.GetMethod(GetType(), "MakeToStrToFixnum")); + } + if (ReferenceEquals(this, ToIntToI)) { + return Ast.Call(Methods.GetMethod(GetType(), "MakeToIntToI")); + } + throw Assert.Unreachable; + } + + [Emitted] + public static CompositeConversionAction/*!*/ MakeToFixnumToStr() { + return ToFixnumToStr; + } + + [Emitted] + public static CompositeConversionAction/*!*/ MakeToStrToFixnum() { + return ToStrToFixnum; + } + + [Emitted] + public static CompositeConversionAction/*!*/ MakeToIntToI() { + return ToIntToI; + } + + public bool Equals(CompositeConversionAction other) { + return ReferenceEquals(other, this); + } + + protected override void BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) { + ProtocolConversionAction.BuildConversion(metaBuilder, args, _resultType, _conversions); + } + } } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyCallAction.cs;C669565 File: RubyCallAction.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyCallAction.cs;C669565 (server) 1/9/2009 3:32 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyCallAction.cs;CompositeConversions3 @@ -89,7 +89,7 @@ Expression/*!*/ IExpressionSerializable.CreateExpression() { return Expression.Call( - typeof(RubyCallAction).GetMethod("Make", new Type[] { typeof(string), typeof(RubyCallSignature) }), + Methods.GetMethod(typeof(RubyCallAction), "Make", typeof(string), typeof(RubyCallSignature)), Expression.Constant(_methodName), _signature.CreateExpression() ); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyParameterBinder.cs;C674241 File: RubyParameterBinder.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyParameterBinder.cs;C674241 (server) 1/8/2009 5:00 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/RubyParameterBinder.cs;CompositeConversions3 @@ -68,7 +68,7 @@ // protocol conversions: if (info != null && info.IsDefined(typeof(DefaultProtocolAttribute), false)) { - var action = ProtocolConversionAction.TryGetConversionAction(toType); + var action = RubyConversionAction.TryGetDefaultConversionAction(toType); if (action != null) { // TODO: once we work with MetaObjects, we could inline these dynamic sites: return Ast.Dynamic(action, toType, ContextExpression, expr); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/SuperCallAction.cs;C669565 File: SuperCallAction.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/SuperCallAction.cs;C669565 (server) 1/9/2009 3:33 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/SuperCallAction.cs;CompositeConversions3 @@ -28,6 +28,7 @@ using Ast = System.Linq.Expressions.Expression; using AstFactory = IronRuby.Compiler.Ast.AstFactory; using IronRuby.Compiler; +using IronRuby.Compiler.Generation; namespace IronRuby.Runtime.Calls { @@ -44,6 +45,7 @@ _lexicalScopeId = lexicalScopeId; } + [Emitted] public static SuperCallAction/*!*/ Make(RubyCallSignature signature, int lexicalScopeId) { return new SuperCallAction(signature, lexicalScopeId); } @@ -131,7 +133,7 @@ Expression/*!*/ IExpressionSerializable.CreateExpression() { return Expression.Call( - typeof(SuperCallAction).GetMethod("Make", new Type[] { typeof(RubyCallSignature), typeof(int) }), + Methods.GetMethod(typeof(SuperCallAction), "Make", typeof(RubyCallSignature), typeof(int)), _signature.CreateExpression(), Expression.Constant(_lexicalScopeId) ); ===================================================================