Skip to content

Commit

Permalink
* Removed unused allocateStorage argument from IListOps.First and ILi…
Browse files Browse the repository at this point in the history
…stOps.Last; Removed the manual protocol conversion bits in IListOps.Fetch

* Fix IoOps.ToPrintedString to output a double converted to string using an invariant culture (Issue IronLanguages#597 NumericLiterals1 test fails under french culture)

* IListOps.ValuesAt adds a null value to the result if the begin value of the specified range instance(s) is <= the length of the array and the end value is >= the length of the array.

* Array#uniq! raises a TypeError on a frozen array if modification would take place.

* Fixed ArrayOps.ToArray to return a new RubyArray instance with the elements of self if self is a RubyArray.Subclass.

* Array#initialize with (size, object=nil) uses the block value instead of using the default value

* Fixed IListOps.Compare to work with recursive arrays.
  • Loading branch information
nrk committed Apr 18, 2009
1 parent b754ddc commit 4afc7f1
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 36 deletions.

This file was deleted.

@@ -1,2 +1 @@
fails:Array#initialize with (size, object=nil) raises an ArgumentError if size is too large
fails:Array#initialize with (size, object=nil) uses the block value instead of using the default value

This file was deleted.

@@ -1,3 +1,2 @@
critical:Array#uniq properly handles recursive arrays
critical:Array#uniq! properly handles recursive arrays
fails:Array#uniq! raises a TypeError on a frozen array if modification would take place

This file was deleted.

Expand Up @@ -16,7 +16,6 @@ core\argf\path_tags.txt:0:critical:ARGF.path it sets the $FILENAME global variab
core\argf\rewind_tags.txt:0:critical:ARGF.rewind goes back to beginning of current file
core\argf\to_i_tags.txt:0:critical:ARGF.to_i returns the current file number on each file
core\argf\to_io_tags.txt:0:critical:ARGF.to_io returns the IO of the current file
core\array\comparison_tags.txt:0:critical:Array#<=> properly handles recursive arrays
core\array\eql_tags.txt:0:critical:Array#eql? properly handles recursive arrays
core\array\equal_value_tags.txt:0:critical:Array#== properly handles recursive arrays
core\array\hash_tags.txt:0:critical:Array#hash properly handles recursive arrays
Expand Down
Expand Up @@ -106,6 +106,18 @@ public static class ArrayOps {
return Reinitialize(block, new RubyArray(), size);
}

[RubyConstructor]
public static RubyArray/*!*/ CreateArray(BlockParam/*!*/ block, RubyClass/*!*/ self, [DefaultProtocol]int size, object value) {
return Reinitialize(block, new RubyArray(), size, value);
}

[RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)]
public static RubyArray/*!*/ Reinitialize(BlockParam/*!*/ block, RubyArray/*!*/ self, int size, object value) {
block.RubyContext.ReportWarning("block supersedes default value argument");
Reinitialize(block, self, size);
return self;
}

private static object Reinitialize(BlockParam/*!*/ block, RubyArray/*!*/ self, int size) {
if (size < 0) {
throw RubyExceptions.CreateArgumentError("negative array size");
Expand Down Expand Up @@ -161,7 +173,7 @@ public static class ArrayOps {
[RubyMethod("to_a")]
[RubyMethod("to_ary")]
public static RubyArray/*!*/ ToArray(RubyArray/*!*/ self) {
return self;
return self is RubyArray.Subclass ? new RubyArray(self) : self;
}

#region class FormatDirective is used by Array.pack and String.unpack
Expand Down
Expand Up @@ -628,8 +628,9 @@ public class RubyIOOps {
} else if (obj is bool) {
return MutableString.Create((bool)obj ? "true" : "false");
} else if (obj is double) {
var result = MutableString.Create(obj.ToString());
if ((double)(int)(double)obj == (double)obj) {
double value = (double)obj;
var result = MutableString.Create(value.ToString(System.Globalization.CultureInfo.InvariantCulture));
if ((double)(int)value == value) {
result.Append(".0");
}
return result;
Expand Down
Expand Up @@ -273,20 +273,28 @@ public static class IListOps {
return true;
}

[MultiRuntimeAware]
private static RubyUtils.RecursionTracker _infiniteComparisonTracker = new RubyUtils.RecursionTracker();

[RubyMethod("<=>")]
public static object Compare(BinaryOpStorage/*!*/ comparisonStorage, IList/*!*/ self, [DefaultProtocol, NotNull]IList/*!*/ other) {
using (IDisposable handle = _infiniteComparisonTracker.TrackObject(self)) {
if (handle == null) {
return 0;
}

int limit = Math.Min(self.Count, other.Count);
var compare = comparisonStorage.GetCallSite("<=>");
int limit = Math.Min(self.Count, other.Count);
var compare = comparisonStorage.GetCallSite("<=>");

for (int i = 0; i < limit; i++) {
object result = compare.Target(compare, self[i], other[i]);
if (!(result is int) || (int)result != 0) {
return result;
for (int i = 0; i < limit; i++) {
object result = compare.Target(compare, self[i], other[i]);
if (!(result is int) || (int)result != 0) {
return result;
}
}
}

return ScriptingRuntimeHelpers.Int32ToObject(Math.Sign(self.Count - other.Count));
return ScriptingRuntimeHelpers.Int32ToObject(Math.Sign(self.Count - other.Count));
}
}

[RubyMethod("eql?")]
Expand Down Expand Up @@ -735,27 +743,21 @@ public static class IListOps {

[RubyMethod("fetch")]
public static object Fetch(
RespondToStorage/*!*/ respondToStorage,
CallSiteStorage<Func<CallSite, object, int>>/*!*/ toIntStorage,
ConversionStorage<int>/*!*/ fixnumCast,
BlockParam outOfRangeValueProvider,
IList/*!*/ list,
object/*!*/ index,
[Optional]object defaultValue) {

if (!Protocols.RespondTo(respondToStorage, index, "to_int")) {
throw RubyExceptions.CannotConvertTypeToTargetType(respondToStorage.Context, index, "Integer");
}

var toInt = toIntStorage.GetCallSite("to_int", 0);
int convertedIndex = toInt.Target(toInt, index);
int convertedIndex = Protocols.CastToFixnum(fixnumCast, index);

if (InRangeNormalized(list, ref convertedIndex)) {
return list[convertedIndex];
}

if (outOfRangeValueProvider != null) {
if (defaultValue != Missing.Value) {
respondToStorage.Context.ReportWarning("block supersedes default value argument");
fixnumCast.Context.ReportWarning("block supersedes default value argument");
}

object result;
Expand Down Expand Up @@ -887,8 +889,7 @@ public static class IListOps {
}

[RubyMethod("first")]
public static IList/*!*/ First(CallSiteStorage<Func<CallSite, RubyClass, object>>/*!*/ allocateStorage,
IList/*!*/ self, [DefaultProtocol]int count) {
public static IList/*!*/ First(IList/*!*/ self, [DefaultProtocol]int count) {
if (count < 0) {
throw RubyExceptions.CreateArgumentError("negative array size (or size too big)");
}
Expand All @@ -903,8 +904,7 @@ public static class IListOps {
}

[RubyMethod("last")]
public static IList/*!*/ Last(CallSiteStorage<Func<CallSite, RubyClass, object>>/*!*/ allocateStorage,
IList/*!*/ self, [DefaultProtocol]int count) {
public static IList/*!*/ Last(IList/*!*/ self, [DefaultProtocol]int count) {
if (count < 0) {
throw RubyExceptions.CreateArgumentError("negative array size (or size too big)");
}
Expand Down Expand Up @@ -1045,9 +1045,16 @@ public static class IListOps {
for (int i = 0; i < values.Length; i++) {
Range range = values[i] as Range;
if (range != null) {
IList fragment = GetElement(fixnumCast, allocateStorage, self, range);
if (fragment != null) {
result.AddRange(fragment);
int start, count;
if (!NormalizeRange(fixnumCast, self.Count, range, out start, out count)) {
continue;
}

if (count > 0) {
result.AddRange(GetElements(allocateStorage, self, start, count));
if (start + count >= self.Count) {
result.Add(null);
}
}
} else {
result.Add(GetElement(self, Protocols.CastToFixnum(fixnumCast, values[i])));
Expand Down Expand Up @@ -1393,6 +1400,7 @@ public static class IListOps {
[RubyMethod("uniq!")]
public static IList UniqueSelf(RubyContext/*!*/ context, IList/*!*/ self) {
var seen = new Dictionary<object, bool>(context.EqualityComparer);
bool frozen = context.IsObjectFrozen(self);
bool modified = false;
int i = 0;
while (i < self.Count) {
Expand All @@ -1401,6 +1409,9 @@ public static class IListOps {
seen.Add(key, true);
i++;
} else {
if (frozen) {
throw RubyExceptions.CreateTypeError("can't modify frozen array");
}
self.RemoveAt(i);
modified = true;
}
Expand Down
Expand Up @@ -99,6 +99,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia
DefineGlobalClass("Array", typeof(IronRuby.Builtins.RubyArray), false, Context.ObjectClass, LoadArray_Instance, LoadArray_Class, null, new IronRuby.Builtins.RubyModule[] {def29},
new System.Func<IronRuby.Builtins.RubyClass, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.CreateArray),
new System.Func<IronRuby.Runtime.ConversionStorage<IronRuby.Runtime.Union<System.Collections.IList, System.Int32>>, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Object, System.Object>(IronRuby.Builtins.ArrayOps.CreateArray),
new System.Func<IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyClass, System.Int32, System.Object, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.CreateArray),
new System.Func<IronRuby.Builtins.RubyClass, System.Int32, System.Object, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.CreateArray)
);
DefineGlobalClass("Binding", typeof(IronRuby.Builtins.Binding), false, Context.ObjectClass, null, null, null, IronRuby.Builtins.RubyModule.EmptyArray);
Expand Down Expand Up @@ -399,6 +400,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia
module.DefineLibraryMethod("initialize", 0x52,
new System.Func<IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyArray, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.Reinitialize),
new System.Func<IronRuby.Runtime.ConversionStorage<IronRuby.Runtime.Union<System.Collections.IList, System.Int32>>, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, System.Object, System.Object>(IronRuby.Builtins.ArrayOps.Reinitialize),
new System.Func<IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyArray, System.Int32, System.Object, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.Reinitialize),
new System.Func<IronRuby.Runtime.RubyContext, IronRuby.Builtins.RubyArray, System.Int32, System.Object, IronRuby.Builtins.RubyArray>(IronRuby.Builtins.ArrayOps.ReinitializeByRepeatedValue)
);

Expand Down Expand Up @@ -5071,7 +5073,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia
);

module.DefineLibraryMethod("fetch", 0x51,
new System.Func<IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.CallSiteStorage<System.Func<System.Runtime.CompilerServices.CallSite, System.Object, System.Int32>>, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Object, System.Object, System.Object>(IronRuby.Builtins.IListOps.Fetch)
new System.Func<IronRuby.Runtime.ConversionStorage<System.Int32>, IronRuby.Runtime.BlockParam, System.Collections.IList, System.Object, System.Object, System.Object>(IronRuby.Builtins.IListOps.Fetch)
);

module.DefineLibraryMethod("fill", 0x51,
Expand All @@ -5087,7 +5089,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia

module.DefineLibraryMethod("first", 0x51,
new System.Func<System.Collections.IList, System.Object>(IronRuby.Builtins.IListOps.First),
new System.Func<IronRuby.Runtime.CallSiteStorage<System.Func<System.Runtime.CompilerServices.CallSite, IronRuby.Builtins.RubyClass, System.Object>>, System.Collections.IList, System.Int32, System.Collections.IList>(IronRuby.Builtins.IListOps.First)
new System.Func<System.Collections.IList, System.Int32, System.Collections.IList>(IronRuby.Builtins.IListOps.First)
);

module.DefineLibraryMethod("flatten", 0x51,
Expand Down Expand Up @@ -5137,7 +5139,7 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia

module.DefineLibraryMethod("last", 0x51,
new System.Func<System.Collections.IList, System.Object>(IronRuby.Builtins.IListOps.Last),
new System.Func<IronRuby.Runtime.CallSiteStorage<System.Func<System.Runtime.CompilerServices.CallSite, IronRuby.Builtins.RubyClass, System.Object>>, System.Collections.IList, System.Int32, System.Collections.IList>(IronRuby.Builtins.IListOps.Last)
new System.Func<System.Collections.IList, System.Int32, System.Collections.IList>(IronRuby.Builtins.IListOps.Last)
);

module.DefineLibraryMethod("length", 0x51,
Expand Down

0 comments on commit 4afc7f1

Please sign in to comment.