Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
|
Go to the documentation of this file.
27 static VALUE rb_eUncaughtThrow;
28 static ID id_result, id_tag, id_value;
29 #define id_mesg idMesg
85 vm_push_frame(ec, 0, frame_flags, recv,
105 return vm_call0_cfunc_with_frame(ec,
calling, cd,
argv);
117 calling->block_handler = vm_passed_block_handler(ec);
148 rb_warn(
"Passing the keyword argument as the last hash parameter is deprecated");
182 CC_SET_ME(
cc, refined_method_callable_without_refinement(
cc->
me));
200 CC_SET_ME(
cc, aliased_callable_method_entry(
cc->
me));
204 vm_passed_block_handler_set(ec,
calling->block_handler);
257 rb_warn(
"Keyword flag passed calling internal method, but last entry is not a hash, unsetting keyword flag");
282 if (VM_FRAME_RUBYFRAME_P(
cfp)) {
283 rb_bug(
"vm_call_super: should not be reached");
302 return vm_call_super(ec,
argc,
argv, kw_splat);
318 if (!ec || !(
cfp = ec->
cfp)) {
384 me = rb_search_method_entry(recv, mid);
409 check_funcall_exec(
VALUE v)
461 ret = basic_obj_respond_to_missing(
ec,
klass,
recv,
463 if (!
RTEST(ret))
return def;
486 args.
argv = new_args;
489 check_funcall_failed, (
VALUE)&args,
522 if (!check_funcall_callable(
ec,
me)) {
525 if (ret ==
Qundef) ret = def;
553 if (!check_funcall_callable(
ec,
me)) {
574 #define type_case(t) t: return #t
620 "method `%"PRIsVALUE"' called on unexpected immediate object (%p)",
621 mname, (
void *)
recv);
623 else if ((flags =
RBASIC(
recv)->flags) == 0) {
625 "method `%"PRIsVALUE"' called on terminated object (%p)",
626 mname, (
void *)
recv);
630 "method `%"PRIsVALUE"' called on broken T_?""?""?(0x%02x) object"
636 "method `%"PRIsVALUE"' called on hidden %s object"
638 mname, typestr, (
void *)
recv, flags);
642 "method `%"PRIsVALUE"' called on unexpected %s object"
644 mname, typestr, (
void *)
recv, flags);
813 format =
rb_fstring_lit(
"protected method `%s' called for %s%s%s");
816 format =
rb_fstring_lit(
"undefined local variable or method `%s' for %s%s%s");
820 format =
rb_fstring_lit(
"super: no superclass method `%s' for %s%s%s");
870 if (!
klass)
goto missing;
934 for (
i = 0;
i <
n;
i++) {
1010 vm_search_method(cd, recv);
1013 return vm_call0_body(
1052 if (!
NIL_P(passed_procval)) {
1053 vm_passed_block_handler_set(
GET_EC(), passed_procval);
1062 if (!
NIL_P(passed_procval)) {
1063 vm_passed_block_handler_set(
GET_EC(), passed_procval);
1076 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, prev_cfp))
return NULL;
1078 return prev_cfp->
sp + 1;
1087 VALUE ret, vargv = 0;
1113 VALUE *tmp_argv = current_vm_stack_arg(ec,
argv);
1118 else if (
argc > 1) {
1135 ret = rb_call0(ec, recv,
id,
argc,
argv, scope,
self);
1158 ret = send_internal(
argc,
argv, recv, scope);
1233 return rb_yield_0(1, &val);
1240 return rb_yield_0(0, 0);
1247 #undef rb_yield_values
1252 return rb_yield_0(0, 0);
1261 for (
i=0;
i<
n;
i++) {
1266 return rb_yield_0(
n,
argv);
1279 return rb_yield_0_kw(
argc,
argv, kw_splat);
1311 return vm_yield_force_blockarg(
GET_EC(), values);
1378 rb_f_loop(
VALUE self)
1391 const struct vm_ifunc *
const ifunc,
1415 retval = (*it_proc) (data1);
1421 if (
cfp == escape_cfp) {
1428 if (state ==
TAG_RETRY)
goto iter_retry;
1429 retval = THROW_DATA_VAL(
err);
1447 return rb_iterate0(it_proc, data1,
1448 bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (
void *)data2) : 0,
1515 return rb_iterate0(iterate_method, (
VALUE)&
arg, block,
GET_EC());
1553 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1567 fname = pathobj_path(bind->
pathobj);
1582 parent, ISEQ_TYPE_EVAL,
NULL);
1609 block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(
cfp);
1610 block.as.captured.self =
self;
1611 block.as.captured.code.iseq =
cfp->
iseq;
1614 iseq = eval_make_iseq(
src, file, line,
NULL, &block);
1620 if (!cref && block.as.captured.code.val) {
1621 rb_cref_t *orig_cref = vm_get_cref(vm_block_ep(&block));
1622 cref = vm_cref_dup(orig_cref);
1624 vm_set_eval_stack(ec,
iseq, cref, &block);
1644 vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->
cfp));
1689 return eval_string_with_cref(
self,
src,
NULL, file, line);
1691 return eval_string_with_scope(scope,
src, file, line);
1749 eval_string_wrap_protect(
VALUE data)
1826 rb_warn(
"rb_eval_cmd will be removed in Ruby 3.0");
1838 VALUE new_block_handler = 0;
1843 int is_lambda =
FALSE;
1853 new_captured = *captured;
1854 new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1858 new_captured = *captured;
1859 new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
1872 new_captured.self =
self;
1878 cref = vm_cref_push(ec, under,
ep,
TRUE);
1879 ret = vm_yield_with_cref(ec,
argc,
argv, kw_splat, cref, is_lambda);
1891 rb_bug(
"rb_yield_refine_block: an iseq block is required");
1896 VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1899 CREF_REFINEMENTS_SET(cref, refinements);
1901 new_captured.
self = refinement;
1912 return eval_string_with_cref(
self,
src, cref, file, line);
1920 return yield_under(
klass,
self, 1, &
self, kw_splat);
1936 return eval_under(
klass,
self,
code, file, line);
1941 singleton_class_for_eval(
VALUE self)
1992 VALUE klass = singleton_class_for_eval(
self);
1999 VALUE klass = singleton_class_for_eval(
self);
2024 VALUE klass = singleton_class_for_eval(
self);
2031 VALUE klass = singleton_class_for_eval(
self);
2168 VALUE tag = uncaught_throw_tag(
exc);
2228 return rb_yield_0(1, &
tag);
2328 return vm_catch_protect(t, func, data, stateptr,
GET_EC());
2390 rb_f_local_variables(
VALUE _)
2397 local_var_list_init(&
vars);
2404 if (!VM_ENV_LOCAL_P(
cfp->
ep)) {
2406 const VALUE *ep = VM_CF_PREV_EP(
cfp);
2408 if (vm_collect_local_variables_in_heap(ep, &
vars)) {
2412 while (
cfp->
ep != ep) {
2421 return local_var_list_finish(&
vars);
2447 rb_f_block_given_p(
VALUE _)
2505 rb_define_method(rb_eUncaughtThrow,
"initialize", uncaught_throw_init, -1);
VALUE rb_iseq_realpath(const rb_iseq_t *iseq)
VALUE rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2)
VALUE rb_parser_new(void)
VALUE rb_proc_lambda_p(VALUE)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
unsigned int respond_to_missing
VALUE rb_check_funcall_with_hook_kw(VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg, int kw_splat)
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
@ block_handler_type_iseq
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
VALUE rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2)
NORETURN(static void uncallable_object(VALUE recv, ID mid))
@ VM_METHOD_TYPE_REFINED
refinement
#define RB_PASS_CALLED_KEYWORDS
MJIT_FUNC_EXPORTED VALUE rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, int argc, const VALUE *argv, int kw_splat, VALUE passed_block_handler)
VALUE rb_ident_hash_new(void)
VALUE rb_iterate(VALUE(*it_proc)(VALUE), VALUE data1, rb_block_call_func_t bl_proc, VALUE data2)
VALUE(* invoker)(VALUE recv, int argc, const VALUE *argv, VALUE(*func)(ANYARGS))
@ VM_METHOD_TYPE_OPTIMIZED
Kernel::send, Proc::call, etc.
void rb_warn(const char *fmt,...)
@ VM_FRAME_FLAG_CFRAME_KW
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_current_receiver(void)
VALUE rb_iseq_disasm(const rb_iseq_t *iseq)
#define RBASIC_CLEAR_CLASS(obj)
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
VALUE rb_yield_values_kw(int argc, const VALUE *argv, int kw_splat)
void rb_ast_dispose(rb_ast_t *ast)
VALUE rb_hash_clear(VALUE hash)
const struct rb_callable_method_entry_struct * me
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
VALUE rb_yield_1(VALUE val)
int rb_empty_keyword_given_p(void)
VALUE rb_attr_get(VALUE, ID)
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
void rb_throw_obj(VALUE tag, VALUE value)
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
const char * rb_type_str(enum ruby_value_type type)
MJIT_FUNC_EXPORTED VALUE rb_adjust_argv_kw_splat(int *argc, const VALUE **argv, int *kw_splat)
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
VALUE rb_module_new(void)
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, VALUE data2)
#define RB_TYPE_P(obj, type)
#define rb_intern_const(str)
RUBY_EXTERN VALUE rb_cModule
@ block_handler_type_proc
VALUE rb_current_realfilepath(void)
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_call_super(int argc, const VALUE *argv)
#define EC_JUMP_TAG(ec, st)
VALUE rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
rb_iseq_location_t location
#define RB_PASS_EMPTY_KEYWORDS
#define VM_ENV_DATA_INDEX_SPECVAL
enum method_optimized_type optimize_type
rb_method_refined_t refined
#define vm_check_canary(ec, sp)
struct rb_method_entry_struct * orig_me
VALUE rb_catch_obj(VALUE t, rb_block_call_func_t func, VALUE data)
#define Check_TypedStruct(v, t)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RUBY_VM_CHECK_INTS(ec)
MJIT_FUNC_EXPORTED VALUE rb_hash_keys(VALUE hash)
IFUNC (Internal FUNCtion)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
int rb_method_boundp(VALUE, ID, int)
#define SPECIAL_CONST_P(x)
#define SafeStringValue(v)
VALUE rb_eval_string_wrap(const char *str, int *pstate)
Evaluates the given string under a module binding in an isolated binding.
int rb_ec_stack_check(rb_execution_context_t *ec)
VALUE rb_funcallv_public_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
@ VM_FRAME_FLAG_CFRAME_EMPTY_KW
void rb_parser_warn_location(VALUE, int)
@ OPTIMIZED_METHOD_TYPE_SEND
VALUE rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval, int kw_splat)
rb_execution_context_t * ec
void rb_free_tmp_buffer(volatile VALUE *store)
@ VM_METHOD_TYPE_IVAR
attr_reader or attr_accessor
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
#define VM_BLOCK_HANDLER_NONE
#define RARRAY_LENINT(ary)
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
#define UNLIMITED_ARGUMENTS
VALUE rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
VALUE rb_yield_force_blockarg(VALUE values)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
#define CHECK_CFP_CONSISTENCY(func)
int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func func, st_data_t arg)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_special_singleton_class(VALUE obj)
#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, klass, id)
VALUE rb_str_format(int, const VALUE *, VALUE)
@ OPTIMIZED_METHOD_TYPE_CALL
VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self)
MJIT_STATIC void rb_vm_pop_cfunc_frame(void)
RUBY_EXTERN VALUE rb_cBasicObject
const VALUE defined_class
VALUE rb_str_intern(VALUE)
VALUE rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat)
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
#define METHOD_ENTRY_VISI(me)
#define ALLOCV_N(type, v, n)
VALUE ruby_eval_string_from_file(const char *str, const char *filename)
unsigned int local_table_size
VALUE rb_vm_top_self(void)
VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc)
struct vm_ifunc * rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc)
VALUE rb_yield_splat(VALUE values)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
@ VM_METHOD_TYPE_CFUNC
C method.
MJIT_FUNC_EXPORTED VALUE rb_vm_call_kw(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat)
void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE)
@ VM_METHOD_TYPE_NOTIMPLEMENTED
VALUE rb_check_funcall_default(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def)
#define METHOD_ENTRY_BASIC(me)
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
const struct rb_block block
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr)
#define rb_ary_subseq(ary, beg, len)
@ block_handler_type_ifunc
#define ALLOCA_N(type, n)
VALUE rb_yield_splat_kw(VALUE values, int kw_splat)
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int _level)
#define StringValuePtr(v)
enum method_missing_reason method_missing_reason
rb_ast_t * rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(val, arg))
VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
#define rb_ec_raised_set(ec, f)
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
#define GetProcPtr(obj, ptr)
VALUE rb_check_array_type(VALUE ary)
const rb_data_type_t ruby_binding_data_type
VALUE rb_yield_values2(int argc, const VALUE *argv)
VALUE rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
#define va_init_list(a, b)
VALUE rb_apply(VALUE recv, ID mid, VALUE args)
Calls a method.
MJIT_STATIC const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
#define FL_TEST_RAW(x, f)
VALUE rb_eval_string(const char *str)
Evaluates the given string in an isolated binding.
void rb_throw(const char *tag, VALUE val)
RUBY_SYMBOL_EXPORT_END const rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
RUBY_EXTERN VALUE rb_cObject
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
unsigned char buf[MIME_BUF_SIZE]
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
@ VM_METHOD_TYPE_MISSING
wrapper for method_missing(id)
void rb_bug(const char *fmt,...)
#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, klass, id)
rb_block_call_func * rb_block_call_func_t
RUBY_EXTERN VALUE rb_mKernel
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp)
MJIT_FUNC_EXPORTED rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
@ VM_METHOD_TYPE_ATTRSET
attr_writer or attr_accessor
VALUE vm_exec(rb_execution_context_t *ec, int mjit_enable_p)
union rb_method_definition_struct::@0 body
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
char str[HTML_ESCAPE_MAX_LEN+1]
#define PASS_PASSED_BLOCK_HANDLER()
#define RARRAY_CONST_PTR(s)
#define MEMCPY(p1, p2, type, n)
VALUE rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main)
#define PASS_PASSED_BLOCK_HANDLER_EC(ec)
rb_execution_context_t * ec
VALUE rb_eval_string_protect(const char *str, int *pstate)
Evaluates the given string in an isolated binding.
MJIT_FUNC_EXPORTED const rb_callable_method_entry_t * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
@ block_handler_type_symbol
@ VM_METHOD_TYPE_ISEQ
Ruby method.
union rb_captured_block::@11 code
MJIT_STATIC void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
VALUE rb_catch(const char *tag, rb_block_call_func_t func, VALUE data)
int rb_is_local_id(ID id)
rb_iseq_t * rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type type, const rb_compile_option_t *option)
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
#define MJIT_FUNC_EXPORTED
#define RUBY_EVENT_C_RETURN
struct rb_method_definition_struct *const def
const rb_method_entry_t * me
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
int rb_keyword_given_p(void)
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
struct rb_iseq_constant_body * body
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_yield_values(int n,...)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define RUBY_EVENT_C_CALL
VALUE rb_yield(VALUE val)
VALUE rb_block_call_kw(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2, int kw_splat)
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg)
#define RARRAY_CONST_PTR_TRANSIENT(a)
#define rb_fstring_lit(str)
const struct vm_ifunc * ifunc
VALUE rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
rb_cref_t * rb_vm_cref_new_toplevel(void)
#define UNALIGNED_MEMBER_PTR(ptr, mem)
#define UNREACHABLE_RETURN(val)
#define rb_ec_raised_p(ec, f)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
MJIT_FUNC_EXPORTED VALUE rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj, int argc, const VALUE *argv, int priv)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
MJIT_FUNC_EXPORTED VALUE rb_vm_call0(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat)
unsigned short first_lineno
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
VALUE rb_obj_clone(VALUE)
Almost same as Object::clone.
#define UNDEFINED_METHOD_ENTRY_P(me)
VALUE rb_source_location(int *pline)