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