mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_eval.c, eval.c (rb_f_block_given_p): move definition of
"iterator?" and "block_given?" to make static. * vm.c (vm_get_ruby_level_caller_cfp): make it static. * eval_intern.h, vm_insnhelper.c: move decl. of vm_get_ruby_level_caller_cfp() from eval_intern.h to vm_insnhelper.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cf23d0f0f0
commit
9b520ddcec
6 changed files with 55 additions and 44 deletions
41
vm_eval.c
41
vm_eval.c
|
@ -1377,11 +1377,52 @@ rb_f_local_variables(void)
|
|||
return ary;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* block_given? => true or false
|
||||
* iterator? => true or false
|
||||
*
|
||||
* Returns <code>true</code> if <code>yield</code> would execute a
|
||||
* block in the current context. The <code>iterator?</code> form
|
||||
* is mildly deprecated.
|
||||
*
|
||||
* def try
|
||||
* if block_given?
|
||||
* yield
|
||||
* else
|
||||
* "no block"
|
||||
* end
|
||||
* end
|
||||
* try #=> "no block"
|
||||
* try { "hello" } #=> "hello"
|
||||
* try do "hello" end #=> "hello"
|
||||
*/
|
||||
|
||||
|
||||
VALUE
|
||||
rb_f_block_given_p(void)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
rb_control_frame_t *cfp = th->cfp;
|
||||
cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
|
||||
|
||||
if (cfp != 0 &&
|
||||
(cfp->lfp[0] & 0x02) == 0 &&
|
||||
GC_GUARDED_PTR_REF(cfp->lfp[0])) {
|
||||
return Qtrue;
|
||||
}
|
||||
else {
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Init_vm_eval(void)
|
||||
{
|
||||
rb_define_global_function("eval", rb_f_eval, -1);
|
||||
rb_define_global_function("local_variables", rb_f_local_variables, 0);
|
||||
rb_define_global_function("iterator?", rb_f_block_given_p, 0);
|
||||
rb_define_global_function("block_given?", rb_f_block_given_p, 0);
|
||||
|
||||
rb_define_global_function("catch", rb_f_catch, -1);
|
||||
rb_define_global_function("throw", rb_f_throw, -1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue