Project

General

Profile

Feature #8693 » 0001-returning-from-lambda.patch

nobu (Nobuyoshi Nakada), 08/08/2013 10:13 PM

View differences:

NEWS
* Raises TypeError instead of ArgumentError if the receiver doesn't have
to_r method.
* Proc
* Returning from lambda proc now always exits from the Proc, not from the
method where the lambda is created. Returing from non-lambda proc exits
from the method, same as the former behavior.
=== Stdlib updates (outstanding ones only)
* Digest
test/ruby/test_lambda.rb
assert_send([e.backtrace.first, :start_with?, "#{__FILE__}:#{line}:"], bug6151)
assert_equal(0, called)
end
def return_in_current(val)
1.tap &->(*) {return 0}
val
end
def yield_block
yield
end
def return_in_callee(val)
yield_block &->(*) {return 0}
val
end
def test_return
feature8693 = '[ruby-core:56193] [Feature #8693]'
assert_equal(42, return_in_current(42), feature8693)
assert_equal(42, return_in_callee(42), feature8693)
end
end
vm_insnhelper.c
if (BUILTIN_TYPE(iseq) != T_NODE) {
int opt_pc;
const int arg_size = iseq->arg_size;
int is_lambda = block_proc_is_lambda(block->proc);
VALUE * const rsp = GET_SP() - ci->argc;
SET_SP(rsp);
CHECK_VM_STACK_OVERFLOW(GET_CFP(), iseq->stack_max);
opt_pc = vm_yield_setup_args(th, iseq, ci->argc, rsp, 0, block_proc_is_lambda(block->proc));
opt_pc = vm_yield_setup_args(th, iseq, ci->argc, rsp, 0, is_lambda);
vm_push_frame(th, iseq, VM_FRAME_MAGIC_BLOCK, block->self,
vm_push_frame(th, iseq,
is_lambda ? VM_FRAME_MAGIC_LAMBDA : VM_FRAME_MAGIC_BLOCK,
block->self,
block->klass,
VM_ENVVAL_PREV_EP_PTR(block->ep),
iseq->iseq_encoded + opt_pc,
(2-2/2)