Index: Integer.cs =================================================================== --- Integer.cs (revision 71) +++ Integer.cs (working copy) @@ -41,20 +41,68 @@ //ceil //chr - //downto //floor //integer? - //next //round - //succ [RubyMethod("succ")] public static int Succ(int/*!*/ instance) { return ((int)instance) + 1; } + [RubyMethod("next")] + public static int Next(int/*!*/ instance) { + return Succ(instance); + } + + private static DynamicSite UpToSharedSite = RuntimeHelpers.CreateSimpleCallSite(); + + [RubyMethod("upto")] + public static object UpTo(CodeContext/*!*/ context, int self, BlockParam block, int limit) { + Contract.RequiresNotNull(context, "context"); + + if (self < limit && block == null) { + throw RubyExceptions.CreateLocalJumpError("no block given"); + } + + for (int i = self; i <= limit; i++) { + object result = UpToSharedSite.Invoke(context, block, i); + if (block.BlockJumped(result)) return result; + } + + return self; + } + + [RubyMethod("upto")] + public static object UpTo(CodeContext/*!*/ context, BigInteger/*!*/ self, BlockParam block) { + throw new NotImplementedException(); + } + + private static DynamicSite DownToSharedSite = RuntimeHelpers.CreateSimpleCallSite(); + + [RubyMethod("downto")] + public static object DownTo(CodeContext/*!*/ context, int self, BlockParam block, int limit) { + Contract.RequiresNotNull(context, "context"); + + if (self > limit && block == null) { + throw RubyExceptions.CreateLocalJumpError("no block given"); + } + + for (int i = self; i >= limit; i--) { + object result = DownToSharedSite.Invoke(context, block, i); + if (block.BlockJumped(result)) return result; + } + + return self; + } + + [RubyMethod("downto")] + public static object DownTo(CodeContext/*!*/ context, BigInteger/*!*/ self, BlockParam block) { + throw new NotImplementedException(); + } + private static DynamicSite TimesSharedSite = RuntimeHelpers.CreateSimpleCallSite(); - + [RubyMethod("times")] public static object Times(CodeContext/*!*/ context, int self, BlockParam block) { Contract.RequiresNotNull(context, "context"); @@ -63,11 +111,9 @@ throw RubyExceptions.CreateLocalJumpError("no block given"); } - int i = 0; - while (i < self) { + for (int i = 0; i < self; i++) { object result = TimesSharedSite.Invoke(context, block, i); if (block.BlockJumped(result)) return result; - i++; } return self;