static VALUE int_dotimes(VALUE num) { RETURN_ENUMERATOR(num, 0, 0); if (FIXNUM_P(num)) { long i, end; end = FIX2LONG(num); for (i=0; i<end; i++) { rb_yield(LONG2FIX(i)); } } else { VALUE i = INT2FIX(0); for (;;) { if (!RTEST(rb_funcall(i, '<', 1, num))) break; rb_yield(i); i = rb_funcall(i, '+', 1, INT2FIX(1)); } } return num; }
def times return to_enum(:times) unless block_given? i = 0 while i < self yield i i += 1 end self end
def hello Rubinius.asm do push_literal "hello " push_literal "world" send :+, 1 end end
irb> hello
=> "hello world"
"1 + 2".to_ast SendWithArguments @line: 1 @name: :+ @privately: false @check_for_local: false @vcall_style: false @block: nil @arguments: \ ActualArguments @line: 1 @splat: nil @array: [ FixnumLiteral [0] line: 1 value: 2 ] @receiver: \ FixnumLiteral @line: 1 @value: 1
============= :__script__ ============== Arguments: 0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 2 Lines to IP: 1: 0..6 0000: meta_push_1 0001: meta_push_2 0002: meta_send_op_plus :+ 0004: pop 0005: push_true 0006: ret ----------------------------------------
./bin/rbx -Xjit.show=true def simple 1 end 1_000_000.times { simple }
[[[ JIT finished background compiling (block) ]]] [[[ JIT finished background compiling (method) ]]]
1_000_000.times { 1 }
i = 0 while i < self 1 # THIS WAS yield i i += 1 end
push_int 3 push_int 4 send :+, 1
/
#