diff options
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/10error.rb | 4 | ||||
| -rw-r--r-- | mrblib/init_mrblib.c | 11 | ||||
| -rw-r--r-- | mrblib/mrblib.rake | 17 | ||||
| -rw-r--r-- | mrblib/numeric.rb | 47 | ||||
| -rw-r--r-- | mrblib/range.rb | 2 |
5 files changed, 56 insertions, 25 deletions
diff --git a/mrblib/10error.rb b/mrblib/10error.rb index 0d9f38d58..054603514 100644 --- a/mrblib/10error.rb +++ b/mrblib/10error.rb @@ -21,6 +21,10 @@ end class TypeError < StandardError end +# ISO 15.2.30 +class ZeroDivisionError < StandardError +end + # ISO 15.2.31 class NameError < StandardError attr_accessor :name diff --git a/mrblib/init_mrblib.c b/mrblib/init_mrblib.c index 4d4bcd25a..e69de29bb 100644 --- a/mrblib/init_mrblib.c +++ b/mrblib/init_mrblib.c @@ -1,11 +0,0 @@ -#include <mruby.h> -#include <mruby/irep.h> - -extern const uint8_t mrblib_irep[]; - -void -mrb_init_mrblib(mrb_state *mrb) -{ - mrb_load_irep(mrb, mrblib_irep); -} - diff --git a/mrblib/mrblib.rake b/mrblib/mrblib.rake index 6fba0adc1..724d328fa 100644 --- a/mrblib/mrblib.rake +++ b/mrblib/mrblib.rake @@ -11,8 +11,21 @@ MRuby.each_target do mkdir_p File.dirname(t.name) open(t.name, 'w') do |f| _pp "GEN", "*.rb", "#{t.name.relative_path}" - f.puts File.read("#{current_dir}/init_mrblib.c") - mrbc.run f, rbfiles, 'mrblib_irep' + f.puts %Q[/*] + f.puts %Q[ * This file is loading the mrblib] + f.puts %Q[ *] + f.puts %Q[ * IMPORTANT:] + f.puts %Q[ * This file was generated!] + f.puts %Q[ * All manual changes will get lost.] + f.puts %Q[ */] + mrbc.run f, rbfiles, 'mrblib_proc' + f.puts <<INIT_END +void +mrb_init_mrblib(mrb_state *mrb) +{ + mrb_load_proc(mrb, mrblib_proc); +} +INIT_END end end end diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 5926518d5..e28d63324 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -34,11 +34,11 @@ class Numeric end ## -# Integral +# Integer # -# mruby special - module to share methods between Floats and Integers -# to make them compatible -module Integral +# ISO 15.2.8 +## +class Integer ## # Calls the given block once for each Integer # from +self+ downto +num+. @@ -125,14 +125,7 @@ module Integral end self end -end -## -# Integer -# -# ISO 15.2.8 -class Integer - include Integral ## # Returns the receiver simply. # @@ -161,3 +154,35 @@ class Integer # ISO 15.2.8.3.26 alias truncate floor end + +class Float + ## + # Calls the given block from +self+ to +num+ + # incremented by +step+ (default 1). + # + def step(num=nil, step=1, &block) + raise ArgumentError, "step can't be 0" if step == 0 + return to_enum(:step, num, step) unless block + + i = self + if num == self || step.infinite? + block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i) + elsif num == nil + while true + block.call(i) + i += step + end + elsif step > 0 + while i <= num + block.call(i) + i += step + end + else + while i >= num + block.call(i) + i += step + end + end + self + end +end diff --git a/mrblib/range.rb b/mrblib/range.rb index 392cc2274..9f94f35d1 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -15,7 +15,7 @@ class Range val = self.first last = self.last - if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special + if val.kind_of?(Integer) && last.kind_of?(Integer) # fixnums are special lim = last lim += 1 unless exclude_end? i = val |
