edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;C518603
File: Protocols.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;C518603 (server) 8/8/2008 7:52 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Protocols.cs;IntConv
@@ -48,6 +48,7 @@
#endregion
#region Bignum/Fixnum Normalization
+
///
/// Converts a BigInteger to int if it is small enough
///
@@ -56,15 +57,24 @@
///
/// Use this helper to downgrade BigIntegers as necessary.
///
+ public static object Normalize(BigInteger x) {
+ int result;
+ if (x.AsInt32(out result)) {
+ return RuntimeHelpers.Int32ToObject(result);
+ }
+ return x;
+ }
+
public static object Normalize(object x) {
int result;
if (x is BigInteger) {
if (((BigInteger)x).AsInt32(out result)) {
- return result;
+ return RuntimeHelpers.Int32ToObject(result);
}
}
return x;
}
+
#endregion
#region CastToString, AsString, TryConvertToString
@@ -181,21 +191,49 @@
#region TryConvertToInteger, ConvertToInteger, AsInteger, CastToInteger, CastToFixnum, IsInteger, IntegerAsFixnum
+ 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 object/*!*/ ConvertToInteger(CodeContext/*!*/ context, object obj) {
+ int fixnum;
+ BigInteger bignum;
+ ConvertToInteger(context, obj, out fixnum, out bignum);
+ return (object)bignum ?? RuntimeHelpers.Int32ToObject(fixnum);
+ }
+
///
/// 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, returns null
+ /// If neither is callable, throws a type error.
///
- public static object TryConvertToInteger(CodeContext/*!*/ context, object obj) {
- // Don't call to_int, to_i on types derived from Integer
- if (IsInteger(obj)) {
- return obj;
+ public static void ConvertToInteger(CodeContext/*!*/ 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 (IsInteger(result)) {
- return result;
+ if (AsPrimitiveInteger(result, out fixnum, out bignum)) {
+ return;
}
throw RubyExceptions.MethodShouldReturnType(context, obj, "to_int", "Integer");
@@ -203,27 +241,13 @@
if (RubySites.RespondTo(context, obj, "to_i")) {
object result = _ToI.Target(_ToI, context, obj);
- if (IsInteger(result)) {
- return result;
+ if (AsPrimitiveInteger(result, out fixnum, out bignum)) {
+ return;
}
throw RubyExceptions.MethodShouldReturnType(context, obj, "to_i", "Integer");
}
- return null;
- }
-
- ///
- /// 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 object/*!*/ ConvertToInteger(CodeContext/*!*/ context, object obj) {
- object value = TryConvertToInteger(context, obj);
- if (value != null) {
- return value;
- }
-
throw RubyExceptions.CannotConvertTypeToTargetType(context, obj, "Integer");
}
@@ -232,33 +256,58 @@
/// Returns null if the object doesn't implement to_int
/// Can return either Bignum or Fixnum
///
- public static object AsInteger(CodeContext/*!*/ context, object obj) {
+ public static bool AsInteger(CodeContext/*!*/ context, object obj, out int fixnum, out BigInteger bignum) {
// Don't call to_int on types derived from Integer
- if (IsInteger(obj)) {
- return obj;
+ if (AsPrimitiveInteger(obj, out fixnum, out bignum)) {
+ return true;
}
if (RubySites.RespondTo(context, obj, "to_int")) {
object result = _ToInt.Target(_ToInt, context, obj);
- if (IsInteger(result)) {
- return result;
+ if (AsPrimitiveInteger(result, out fixnum, out bignum)) {
+ return true;
}
throw RubyExceptions.InvalidValueForType(context, result, "Integer");
}
- return null;
+ return false;
}
///
+ /// Converts an Integer to a Fixnum.
+ /// Don't call any conversion methods--just handles Fixnum & Bignum
+ ///
+ ///
+ /// true if value is an Integer, false otherwise
+ /// Throws a RangeError if value is a
+ /// BigInteger but can't be converted to a Fixnum
+ public static bool IntegerAsFixnum(object value, out int result) {
+ if (value is int) {
+ result = (int)value;
+ return true;
+ }
+
+ var bignum = value as BigInteger;
+ if ((object)bignum != null) {
+ if (!bignum.AsInt32(out result)) {
+ throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
+ }
+ return true;
+ }
+
+ result = 0;
+ return false;
+ }
+
+ ///
/// Try to cast the object to an Integer using to_int
/// Throws if the cast fails
/// Can return either Bignum or Fixnum
///
- public static object/*!*/ CastToInteger(CodeContext/*!*/ context, object obj) {
- object value = AsInteger(context, obj);
- if (value != null) {
- return value;
+ public static void CastToInteger(CodeContext/*!*/ context, object obj, out int fixnum, out BigInteger bignum) {
+ if (AsInteger(context, obj, out fixnum, out bignum)) {
+ return;
}
throw RubyExceptions.CannotConvertTypeToTargetType(context, obj, "Integer");
@@ -272,22 +321,14 @@
throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer");
}
- if (obj is int) {
- return (int)obj;
+ int fixnum;
+ BigInteger bignum;
+ CastToInteger(context, obj, out fixnum, out bignum);
+ if ((object)bignum != null && !bignum.AsInt32(out fixnum)) {
+ throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
}
- object value = CastToInteger(context, obj);
- if (value is int) {
- return (int)value;
- }
-
- // CastToInteger can only return BigInteger or int
- BigInteger big = (BigInteger)value;
- int val;
- if (!big.AsInt32(out val)) {
- throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
- }
- return val;
+ return fixnum;
}
///
@@ -298,22 +339,18 @@
throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer");
}
- if (obj is int) {
- return unchecked((uint)(int)obj);
+ 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'");
}
- object value = CastToInteger(context, obj);
- if (value is int) {
- return unchecked((uint)(int)value);
- }
-
- // CastToInteger can only return BigInteger or int
- BigInteger big = (BigInteger)value;
- uint val;
- if (!big.AsUInt32(out val)) {
- throw RubyExceptions.CreateRangeError("bignum too big to convert into `unsigned long'");
- }
- return val;
+ return unchecked((uint)fixnum);
}
///
@@ -324,86 +361,20 @@
throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer");
}
- if (obj is int) {
- return unchecked((ulong)(int)obj);
+ 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'");
}
- object value = CastToInteger(context, obj);
- if (value is int) {
- return unchecked((ulong)(int)value);
- }
-
- // CastToInteger can only return BigInteger or int
- BigInteger big = (BigInteger)value;
- ulong val;
- if (!big.AsUInt64(out val)) {
- throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad int'");
- }
- return val;
+ return unchecked((ulong)fixnum);
}
- ///
- /// Like AsInteger, but converts the result to a Fixnum
- ///
- public static int? AsFixnum(CodeContext/*!*/ context, object obj) {
- if (obj is int) {
- return (int)obj;
- }
-
- object value = AsInteger(context, obj);
- if (value is int) {
- return (int)value;
- }
-
- if (value == null) {
- return null;
- }
-
- // AsInteger can only return BigInteger or int or null
- BigInteger big = (BigInteger)value;
- int val;
- if (!big.AsInt32(out val)) {
- throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
- }
- return val;
- }
-
- ///
- /// Check if the object is derived from Ruby's Integer type
- ///
- /// TODO: for now just check int (Fixnum) and BigInteger (Bignum)
- /// are there more types to check for?
- ///
- public static bool IsInteger(object value) {
- return value is int || value is BigInteger;
- }
-
- ///
- /// Converts an Integer to a Fixnum.
- /// Don't call any conversion methods--just handles Fixnum & Bignum
- ///
- ///
- /// true if value is an Integer, false otherwise
- /// Throws a RangeError if value is a
- /// BigInteger but can't be converted to a Fixnum
- public static bool IntegerAsFixnum(object value, out int result) {
- if (value is int) {
- result = (int)value;
- return true;
- }
-
- BigInteger big = value as BigInteger;
- // use ReferenceEquals because BigInteger overrides ==, !=
- if (!object.ReferenceEquals(big, null)) {
- if (!big.AsInt32(out result)) {
- throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
- }
- return true;
- }
-
- result = 0;
- return false;
- }
#endregion
#region TryConvertToArray, ConvertToArray, AsArray, CastToArray
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;C509767
File: BigNumOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;C509767 (server) 8/8/2008 7:54 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/BigNumOps.cs;IntConv
@@ -375,6 +375,7 @@
public static int Compare(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
return BigInteger.Compare(self, other);
}
+
///
/// Comparison operator, where other is Float. This is the basis for the tests in Comparable.
///
@@ -382,13 +383,14 @@
/// Returns -1, 0, or +1 depending on whether self is less than, equal to, or greater than other.
///
///
- /// Converts self to Float and then directly invokes <=>.
+ /// Converts self to Float and then directly invokes <=>.
/// Correctly copes if self is too big to fit into a Float, i.e. assumes self is +/-Infinity.
///
[RubyMethod("<=>")]
public static object Compare(CodeContext/*!*/ context, BigInteger/*!*/ self, double other) {
return FloatOps.Compare(ToFloat(context, self), other);
}
+
///
/// Comparison operator, where other is not Bignum, Fixnum or Float. This is the basis for the tests in Comparable.
///
@@ -396,7 +398,7 @@
/// Returns -1, 0, or +1 depending on whether self is less than, equal to, or greater than other.
///
///
- /// Dynamically invokes <=>.
+ /// Dynamically invokes <=>.
///
[RubyMethod("<=>")]
public static object Compare(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
@@ -440,6 +442,7 @@
#endregion
#region eql?
+
///
/// Returns true only if other is a Bignum with the same value as self.
/// Contrast this with Bignum#==, which performs type conversions.
@@ -449,6 +452,7 @@
public static bool Eql(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
return self == other;
}
+
///
/// Returns true only if other is a Bignum with the same value as self, where other is Fixnum.
/// Contrast this with Bignum#==, which performs type conversions.
@@ -463,6 +467,7 @@
public static bool Eql(BigInteger/*!*/ self, int other) {
return false;
}
+
///
/// Returns true only if other is a Bignum with the same value as self, where other is not Bignum or Fixnum.
/// Contrast this with Bignum#==, which performs type conversions.
@@ -473,6 +478,7 @@
public static bool Eql(BigInteger/*!*/ self, object other) {
return false;
}
+
#endregion
#endregion
@@ -480,6 +486,7 @@
#region Bitwise Operators <<, >>, |, &, ^, ~, []
#region <<
+
///
/// Shifts self to the left by other bits (or to the right if other is negative).
///
@@ -494,6 +501,13 @@
result = ShiftOverflowCheck(self, result);
return Protocols.Normalize(result);
}
+
+ [RubyMethod("<<")]
+ public static object LeftShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
+ // TODO:
+ throw new NotImplementedException();
+ }
+
///
/// Shifts self to the left by other bits (or to the right if other is negative).
///
@@ -501,15 +515,16 @@
/// other is converted to an Integer by dynamically invoking self.to_int
[RubyMethod("<<")]
public static object LeftShift(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
- // First convert the other object to an int via a site
- // TODO: Should we consider that we may get a BigInteger here?
- int otherInt = (int)Protocols.ConvertToInteger(context, other);
- // Then do the operation converting the int to a big on the way.
- return LeftShift(self, otherInt);
+ int fixnum;
+ BigInteger bignum;
+ Protocols.ConvertToInteger(context, self, out fixnum, out bignum);
+ return ((object)bignum != null) ? LeftShift(self, bignum) : LeftShift(self, fixnum);
}
+
#endregion
#region >>
+
///
/// Shifts self to the right by other bits (or to the left if other is negative).
///
@@ -524,6 +539,13 @@
result = ShiftOverflowCheck(self, result);
return Protocols.Normalize(result);
}
+
+ [RubyMethod(">>")]
+ public static object RightShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
+ // TODO:
+ throw new NotImplementedException();
+ }
+
///
/// Shifts self to the left by other bits (or to the right if other is negative).
///
@@ -531,68 +553,94 @@
/// other is converted to an Integer by dynamically invoking self.to_int
[RubyMethod(">>")]
public static object RightShift(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
- // First convert the other object to an int via a site
- int otherInt = (int)Protocols.ConvertToInteger(context, other);
- // Then do the operation converting the int to a big on the way.
- return RightShift(self, otherInt);
+ int fixnum;
+ BigInteger bignum;
+ Protocols.ConvertToInteger(context, self, out fixnum, out bignum);
+ return ((object)bignum != null) ? RightShift(self, bignum) : RightShift(self, fixnum);
}
+
#endregion
#region |
- ///
- /// Performs bitwise or between self and other, where other is Fixnum or Bignum.
- ///
+
[RubyMethod("|")]
+ public static object BitwiseOr(BigInteger/*!*/ self, int other) {
+ return Protocols.Normalize(self | other);
+ }
+
+ [RubyMethod("|")]
public static object BitwiseOr(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
return Protocols.Normalize(self | other);
}
+
///
/// Performs bitwise or between self and other, where other is not Fixnum or Bignum.
///
/// 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(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
- return ToIntAndCall(context, self, other, BigInteger.BitwiseOr);
+ int fixnum;
+ BigInteger bignum;
+ Protocols.ConvertToInteger(context, self, out fixnum, out bignum);
+ return ((object)bignum != null) ? BitwiseOr(self, bignum) : BitwiseOr(self, fixnum);
}
+
#endregion
#region &
- ///
- /// Performs bitwise and between self and other, where other is Fixnum or Bignum.
- ///
+
[RubyMethod("&")]
+ public static object And(BigInteger/*!*/ self, int other) {
+ return Protocols.Normalize(self & other);
+ }
+
+ [RubyMethod("&")]
public static object And(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
return Protocols.Normalize(self & other);
}
+
///
/// Performs bitwise and between self and other, where other is not Fixnum or Bignum.
///
/// 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(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
- return ToIntAndCall(context, self, other, BigInteger.BitwiseAnd);
+ int fixnum;
+ BigInteger bignum;
+ Protocols.ConvertToInteger(context, self, out fixnum, out bignum);
+ return ((object)bignum != null) ? And(self, bignum) : And(self, fixnum);
}
+
#endregion
#region ^
- ///
- /// Performs bitwise xor between self and other, where other is Fixnum or Bignum.
- ///
+
[RubyMethod("^")]
+ public static object Xor(BigInteger/*!*/ self, int other) {
+ return Protocols.Normalize(self ^ other);
+ }
+
+ [RubyMethod("^")]
public static object Xor(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) {
return Protocols.Normalize(self ^ other);
}
+
///
/// Performs bitwise xor between self and other, where other is not Fixnum or Bignum.
///
/// 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(CodeContext/*!*/ context, BigInteger/*!*/ self, object other) {
- return ToIntAndCall(context, self, other, BigInteger.Xor);
+ int fixnum;
+ BigInteger bignum;
+ Protocols.ConvertToInteger(context, self, out fixnum, out bignum);
+ return ((object)bignum != null) ? Xor(self, bignum) : Xor(self, fixnum);
}
+
#endregion
#region ~
+
///
/// Performs bitwise inversion on self.
///
@@ -600,9 +648,11 @@
public static object Invert(BigInteger/*!*/ self) {
return Protocols.Normalize(~self);
}
+
#endregion
#region []
+
///
/// Returns the Bit value at the reference index, where index is Fixnum
///
@@ -634,6 +684,7 @@
return (data[bytePos] & (1 << bitOffset)) != 0 ? 1 : 0;
}
+
///
/// Returns the Bit value at the reference index, where index is Bignum
///
@@ -650,6 +701,7 @@
if (index.IsNegative() || self.IsPositive()) return 0;
return 1;
}
+
///
/// Returns the Bit value at the reference index, where index is not Fixnum or Bignum
///
@@ -664,10 +716,11 @@
throw RubyExceptions.CreateRangeError("float " + x.Message + " out of range of Integer");
}
}
- #endregion
#endregion
+ #endregion
+
#region Conversion methods: coerce, to_f, to_s
#region coerce
@@ -693,6 +746,7 @@
#endregion
#region to_f
+
///
/// Converts self to a Float. If self doesn’t fit in a Float, the result is infinity.
///
@@ -707,6 +761,7 @@
return self.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity;
}
}
+
#endregion
#region to_s
@@ -738,6 +793,7 @@
#endregion
#region hash
+
///
/// Compute a hash based on the value of self.
///
@@ -745,9 +801,11 @@
public static int Hash(BigInteger/*!*/ self) {
return self.GetHashCode();
}
+
#endregion
#region size
+
///
/// Returns the number of bytes in the machine representation of self.
///
@@ -761,16 +819,10 @@
//TODO: Should we expose the number of bytes per word in a BitInteger?
return self.GetBits().Length * 4;
}
+
#endregion
#region Helpers
- private delegate object BinaryOperation(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other);
- private static object ToIntAndCall(CodeContext/*!*/ context, BigInteger/*!*/ self, object other, BinaryOperation/*!*/ operation) {
- // First convert the other object to an int via a site
- int otherInt = (int)Protocols.ConvertToInteger(context, other);
- // Then do the operation converting the int to a big on the way.
- return Protocols.Normalize(operation(self, otherInt));
- }
///
/// Test for shift overflow on negative BigIntegers
@@ -785,12 +837,13 @@
/// The test here checks whether we have overflowed into the infinite 1s.
/// [Arguably this should get factored into the BigInteger class.]
///
- private static BigInteger ShiftOverflowCheck(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ result) {
+ private static BigInteger/*!*/ ShiftOverflowCheck(BigInteger/*!*/ self, BigInteger/*!*/ result) {
if (self.IsNegative() && result.IsZero()) {
return -1;
}
return result;
}
+
#endregion
}
}
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;C509767
File: FixnumOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;C509767 (server) 8/8/2008 8:12 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/FixnumOps.cs;IntConv
@@ -40,6 +40,7 @@
#endregion
#region induced_from
+
///
/// Convert obj to a Fixnum, where obj is Fixnum
///
@@ -48,6 +49,7 @@
public static int InducedFrom(RubyClass klass, int obj) {
return obj;
}
+
///
/// Convert obj to a Fixnum, where obj is Float
///
@@ -60,6 +62,7 @@
}
throw RubyExceptions.CreateRangeError("Float " + obj.ToString() + " out of range of integer");
}
+
///
/// Convert obj to a Fixnum
///
@@ -69,6 +72,7 @@
public static int InducedFrom(CodeContext/*!*/ context, RubyClass/*!*/ klass, object obj) {
return Protocols.CastToFixnum(context, Protocols.ConvertToInteger(context, obj));
}
+
#endregion
#region size
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;C518603
File: IoOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;C518603 (server) 8/8/2008 8:28 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/IoOps.cs;IntConv
@@ -51,7 +51,7 @@
[RubyConstructor]
public static RubyIO/*!*/ CreateIO(CodeContext/*!*/ context, object fileDescriptor) {
- return RubyUtils.GetExecutionContext(context).GetDescriptor((int)Protocols.CastToInteger(context, fileDescriptor));
+ return RubyUtils.GetExecutionContext(context).GetDescriptor(Protocols.CastToFixnum(context, fileDescriptor));
}
[RubyConstructor]
@@ -601,7 +601,7 @@
[RubyMethod("putc")]
public static int Putc(CodeContext/*!*/ context, RubyIO/*!*/ self, object/*!*/ obj) {
- return Putc(context, self, (int)Protocols.CastToInteger(context, obj));
+ return Putc(context, self, Protocols.CastToFixnum(context, obj));
}
public static MutableString/*!*/ ToPrintedString(CodeContext/*!*/ context, object obj) {
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C520315
File: MutableStringOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C520315 (server) 8/8/2008 8:29 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;IntConv
@@ -1095,8 +1095,9 @@
[RubyMethod("center", RubyMethodAttributes.PublicInstance)]
public static MutableString/*!*/ Center(CodeContext/*!*/ context, MutableString/*!*/ self, object length, [Optional]object padding) {
- return Center(context, self, (int)Protocols.CastToInteger(context, length), Protocols.CastToString(context, padding));
+ return Center(context, self, Protocols.CastToFixnum(context, length), Protocols.CastToString(context, padding));
}
+
#endregion
@@ -2210,7 +2211,7 @@
[RubyMethod("insert")]
public static MutableString Insert(CodeContext/*!*/ context, MutableString/*!*/ self, object start, object value) {
- return Insert(context, self, (int)Protocols.CastToInteger(context, start), Protocols.CastToString(context, value));
+ return Insert(context, self, Protocols.CastToFixnum(context, start), Protocols.CastToString(context, value));
}
#endregion
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ProcOps.cs;C520315
File: ProcOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ProcOps.cs;C520315 (server) 8/8/2008 3:07 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ProcOps.cs;IntConv
@@ -19,6 +19,7 @@
using Ruby.Runtime.Calls;
using System.Diagnostics;
using System.Scripting.Actions;
+using Microsoft.Scripting.Utils;
namespace Ruby.Builtins {
@@ -65,7 +66,7 @@
[RubyMethod("new", RubyMethodAttributes.PublicSingleton)]
public static Proc/*!*/ CreateNew(CodeContext/*!*/ context, RubyClass/*!*/ self) {
RubyMethodScope methodScope = RubyUtils.GetScope(context).GetInnerMostMethodScope();
- if (methodScope == null) {
+ if (methodScope == null || methodScope.BlockParameter == null) {
throw RubyExceptions.CreateArgumentError("tried to create Proc object without a block");
}
@@ -82,7 +83,8 @@
}
public static Proc/*!*/ CreateNew(CodeContext/*!*/ context, RubyClass/*!*/ self, Proc/*!*/ proc) {
-
+ Assert.NotNull(context, self, proc);
+
// an instance of Proc class, the identity is preserved:
if (self.GetUnderlyingSystemType() == typeof(Proc)) {
return proc;
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;C509767
File: BasicSocket.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;C509767 (server) 8/8/2008 8:30 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;IntConv
@@ -87,6 +87,7 @@
}
#region Public Singleton Methods
+
///
/// Returns the value of the global reverse lookup flag.
///
@@ -95,6 +96,7 @@
// TODO : Are there threading issues?
return RubyBasicSocket.DoNotReverseLookup;
}
+
///
/// Sets the value of the global reverse lookup flag.
/// If set to true, queries on remote addresses will return the numeric address but not the host name.
@@ -106,14 +108,16 @@
// TODO : Are there threading issues?
RubyBasicSocket.DoNotReverseLookup = value;
}
+
///
/// Wraps an already open file descriptor into a socket object.
///
/// The corresponding socket
[RubyMethod("for_fd", RubyMethodAttributes.PublicSingleton)]
public static RubyBasicSocket/*!*/ ForFileDescriptor(CodeContext/*!*/ context, RubyClass/*!*/ klass, object fileDescriptor) {
- return (RubyBasicSocket)RubyUtils.GetExecutionContext(context).GetDescriptor((int)Protocols.CastToInteger(context, fileDescriptor));
+ return (RubyBasicSocket)RubyUtils.GetExecutionContext(context).GetDescriptor(Protocols.CastToFixnum(context, fileDescriptor));
}
+
#endregion
#region Public Instance Methods
===================================================================