I have tidied up and completed the implementation of Range. Once Bignum tokenizing is working correctly and a bug #17448 <http://rubyforge.org/tracker/index.php?func=detail&aid=17448&group_id=4359& atid=16798> , regarding Kernel#respond_to?, Is fixed then all the specs will pass. The relevant specs that fail in these cases have been excluded. . Range#step and Range#each have a lot of common functionality so this has been factored out; both have a number of specialized algorithms depending on what kind of objects Range#begin and Range#end are. I have modified the specs for these accordingly and I will see if I can pass them on to the guys in Rubinius. . I have added Protocols.TryCompare because it was needed for Range#===. . There were some problems between creating literal Ranges (i.e. 2...4) and explicitly creating them (i.e. Range.new(2,4,true)). This is now solved, even for derived classes (i.e. class Range2 < Range ... end). The patch is run against r74 at the trunk level. Hope this all works, Pete -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080124/e1170da5/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: RangePatch.patch Type: application/octet-stream Size: 40266 bytes Desc: not available Url : http://rubyforge.org/pipermail/ironruby-core/attachments/20080124/e1170da5/attachment-0001.obj
Sorry, I introduced a small bug since I didn''t check all the other
specs
were still working (tut tut). The String#upto spec picked up a quirk of MRI
that I broke in rbx:
# This is weird but MRI behaves like that
it "upto calls block with self even if self is less than stop but stop
length is less than self length" do
a = []
"25".upto("5") { |s| a << s }
a.should == ["25"]
end
it "upto doesn''t call block if stop is less than self and stop
length is
less than self length" do
a = []
"25".upto("1") { |s| a << s }
a.should == []
end
This behaviour is also true for Range#each and Range#step too. The fix is
as follows. If it is a problem I can resubmit the whole patch with this fix
incorporated.
Inside the RangeOps.cs file, get rid of the CompareString method and change
StepString to:
private static Range StepString(CodeContext/*!*/ context, Range/*!*/
self, BlockParam block, MutableString begin, MutableString end, int step) {
CheckStep(step);
MutableString item = begin;
int comp;
while((comp = Protocols.Compare(context, item, end)) < 0) {
if (block.BlockJumped(_BlockSite.Invoke(context, block,
item))) {
return self;
}
for (int i = 0; i < step; ++i) {
item = (MutableString)RubySites.Successor(context,
item);
}
if (item.Length > end.Length) {
return self;
}
}
if (comp == 0 && !self.ExcludeEnd) {
_BlockSite.Invoke(context, block, item);
}
return self;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/ironruby-core/attachments/20080125/48ff02f9/attachment.html
Thanks for the catch. Will review and submit ASAP.
Thanks!
-John
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Peter Bacon Darwin
Sent: Friday, January 25, 2008 6:53 AM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] Range patch
Sorry, I introduced a small bug since I didn''t check all the other
specs were still working (tut tut). The String#upto spec picked up a quirk of
MRI that I broke in rbx:
# This is weird but MRI behaves like that
it "upto calls block with self even if self is less than stop but stop
length is less than self length" do
a = []
"25".upto("5") { |s| a << s }
a.should == ["25"]
end
it "upto doesn''t call block if stop is less than self and stop
length is less than self length" do
a = []
"25".upto("1") { |s| a << s }
a.should == []
end
This behaviour is also true for Range#each and Range#step too. The fix is as
follows. If it is a problem I can resubmit the whole patch with this fix
incorporated.
Inside the RangeOps.cs file, get rid of the CompareString method and change
StepString to:
private static Range StepString(CodeContext/*!*/ context, Range/*!*/
self, BlockParam block, MutableString begin, MutableString end, int step) {
CheckStep(step);
MutableString item = begin;
int comp;
while((comp = Protocols.Compare(context, item, end)) < 0) {
if (block.BlockJumped(_BlockSite.Invoke(context, block, item)))
{
return self;
}
for (int i = 0; i < step; ++i) {
item = (MutableString)RubySites.Successor(context, item);
}
if (item.Length > end.Length) {
return self;
}
}
if (comp == 0 && !self.ExcludeEnd) {
_BlockSite.Invoke(context, block, item);
}
return self;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/ironruby-core/attachments/20080125/e4663cb1/attachment-0001.html