diff options
-rw-r--r-- | array.c | 2 | ||||
-rw-r--r-- | eval.c | 10 | ||||
-rw-r--r-- | numeric.c | 16 | ||||
-rw-r--r-- | range.c | 11 |
4 files changed, 31 insertions, 8 deletions
@@ -44,7 +44,7 @@ memfill(mem, size, val) #define ARY_TMPLOCK FL_USER1 -static void +static inline void rb_ary_modify_check(ary) VALUE ary; { @@ -917,14 +917,19 @@ static VALUE trace_func = 0; static int tracing = 0; static void call_trace_func _((char*,NODE*,VALUE,ID,VALUE)); +#if 0 #define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \ ruby_sourceline = nd_line(ruby_current_node)) +#else +#define SET_CURRENT_SOURCE() 0 +#endif void ruby_set_current_source() { if (ruby_current_node) { - SET_CURRENT_SOURCE(); + ruby_sourcefile = ruby_current_node->nd_file; + ruby_sourceline = nd_line(ruby_current_node); } } @@ -3390,7 +3395,6 @@ rb_eval(self, n) break; case NODE_NEWLINE: - ruby_sourcefile = node->nd_file; ruby_sourceline = node->nd_nth; if (trace_func) { call_trace_func("line", node, self, @@ -4443,7 +4447,7 @@ rb_undefined(obj, id, argc, argv, call_status) return rb_funcall2(obj, missing, argc+1, nargv); } -static VALUE +static inline VALUE call_cfunc(func, recv, len, argc, argv) VALUE (*func)(); VALUE recv; @@ -850,11 +850,21 @@ num_step(argc, argv, from) { VALUE to, step; - if (rb_scan_args(argc, argv, "11", &to, &step) == 1) { + if (argc == 1) { + to = argv[0]; step = INT2FIX(1); } - else if (rb_equal(step, INT2FIX(0))) { - rb_raise(rb_eArgError, "step cannot be 0"); + else { + if (argc == 2) { + to = argv[0]; + step = argv[1]; + } + else { + rb_raise(rb_eArgError, "wrong number of arguments"); + } + if (rb_equal(step, INT2FIX(0))) { + rb_raise(rb_eArgError, "step cannot be 0"); + } } if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) { @@ -306,7 +306,16 @@ range_each(range) rb_raise(rb_eTypeError, "cannot iterate from %s", rb_class2name(CLASS_OF(beg))); } - if (TYPE(beg) == T_STRING) { + if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */ + long lim = FIX2LONG(end); + long i; + + if (!EXCL(range)) lim += 1; + for (i=FIX2LONG(beg); i<lim; i++) { + rb_yield(LONG2NUM(i)); + } + } + else if (TYPE(beg) == T_STRING) { VALUE args[5]; long iter[2]; |