Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

vm_eval.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 vm_eval.c -
4
5 $Author$
6 created at: Sat May 24 16:02:32 JST 2008
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9 Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10 Copyright (C) 2000 Information-technology Promotion Agency, Japan
11
12 **********************************************************************/
13
14 struct local_var_list {
15 VALUE tbl;
16 };
17
18 static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status, int kw_splat);
19 static inline VALUE vm_yield_with_cref(rb_execution_context_t *ec, int argc, const VALUE *argv, int kw_splat, const rb_cref_t *cref, int is_lambda);
20 static inline VALUE vm_yield(rb_execution_context_t *ec, int argc, const VALUE *argv, int kw_splat);
21 static inline VALUE vm_yield_with_block(rb_execution_context_t *ec, int argc, const VALUE *argv, VALUE block_handler, int kw_splat);
22 static inline VALUE vm_yield_force_blockarg(rb_execution_context_t *ec, VALUE args);
23 VALUE vm_exec(rb_execution_context_t *ec, int mjit_enable_p);
24 static void vm_set_eval_stack(rb_execution_context_t * th, const rb_iseq_t *iseq, const rb_cref_t *cref, const struct rb_block *base_block);
25 static int vm_collect_local_variables_in_heap(const VALUE *dfp, const struct local_var_list *vars);
26
27 static VALUE rb_eUncaughtThrow;
28 static ID id_result, id_tag, id_value;
29 #define id_mesg idMesg
30
31 typedef enum call_type {
32 CALL_PUBLIC,
33 CALL_FCALL,
34 CALL_VCALL,
35 CALL_PUBLIC_KW,
36 CALL_FCALL_KW,
37 CALL_TYPE_MAX
38 } call_type;
39
40 static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope);
41 static VALUE vm_call0_body(rb_execution_context_t* ec, struct rb_calling_info *calling, struct rb_call_data *cd, const VALUE *argv);
42
43 #ifndef MJIT_HEADER
44
45 MJIT_FUNC_EXPORTED VALUE
46 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)
47 {
48 struct rb_calling_info calling = { Qundef, recv, argc, kw_splat, };
49 struct rb_call_info ci = { id, (kw_splat ? VM_CALL_KW_SPLAT : 0), argc, };
50 struct rb_call_cache cc = { 0, { 0, }, me, me->def->method_serial, vm_call_general, { 0, }, };
51 struct rb_call_data cd = { cc, ci, };
52 return vm_call0_body(ec, &calling, &cd, argv);
53 }
54
55 static VALUE
56 vm_call0_cfunc_with_frame(rb_execution_context_t* ec, struct rb_calling_info *calling, struct rb_call_data *cd, const VALUE *argv)
57 {
58 const struct rb_call_info *ci = &cd->ci;
59 const struct rb_call_cache *cc = &cd->cc;
60 VALUE val;
61 const rb_callable_method_entry_t *me = cc->me;
62 const rb_method_cfunc_t *cfunc = UNALIGNED_MEMBER_PTR(me->def, body.cfunc);
63 int len = cfunc->argc;
64 VALUE recv = calling->recv;
65 int argc = calling->argc;
66 ID mid = ci->mid;
67 VALUE block_handler = calling->block_handler;
68 int frame_flags = VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL;
69
70 if (calling->kw_splat) {
71 if (argc > 0 && RB_TYPE_P(argv[argc-1], T_HASH) && RHASH_EMPTY_P(argv[argc-1])) {
72 frame_flags |= VM_FRAME_FLAG_CFRAME_EMPTY_KW;
73 argc--;
74 }
75 else {
76 frame_flags |= VM_FRAME_FLAG_CFRAME_KW;
77 }
78 }
79
80 RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, me->owner, me->def->original_id);
81 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil);
82 {
83 rb_control_frame_t *reg_cfp = ec->cfp;
84
85 vm_push_frame(ec, 0, frame_flags, recv,
86 block_handler, (VALUE)me,
87 0, reg_cfp->sp, 0, 0);
88
89 if (len >= 0) rb_check_arity(argc, len, len);
90
91 val = (*cfunc->invoker)(recv, argc, argv, cfunc->func);
92
93 CHECK_CFP_CONSISTENCY("vm_call0_cfunc_with_frame");
94 rb_vm_pop_frame(ec);
95 }
96 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, recv, me->def->original_id, mid, me->owner, val);
97 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
98
99 return val;
100 }
101
102 static VALUE
103 vm_call0_cfunc(rb_execution_context_t *ec, struct rb_calling_info *calling, struct rb_call_data *cd, const VALUE *argv)
104 {
105 return vm_call0_cfunc_with_frame(ec, calling, cd, argv);
106 }
107
108 /* `ci' should point temporal value (on stack value) */
109 static VALUE
110 vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, struct rb_call_data *cd, const VALUE *argv)
111 {
112 const struct rb_call_info *ci = &cd->ci;
113 struct rb_call_cache *cc = &cd->cc;
114
115 VALUE ret;
116
117 calling->block_handler = vm_passed_block_handler(ec);
118
119 again:
120 switch (cc->me->def->type) {
121 case VM_METHOD_TYPE_ISEQ:
122 {
123 rb_control_frame_t *reg_cfp = ec->cfp;
124 int i;
125
126 CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1);
127 vm_check_canary(ec, reg_cfp->sp);
128
129 *reg_cfp->sp++ = calling->recv;
130 for (i = 0; i < calling->argc; i++) {
131 *reg_cfp->sp++ = argv[i];
132 }
133
134 vm_call_iseq_setup(ec, reg_cfp, calling, cd);
135 VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);
136 return vm_exec(ec, TRUE); /* CHECK_INTS in this function */
137 }
138 case VM_METHOD_TYPE_NOTIMPLEMENTED:
139 case VM_METHOD_TYPE_CFUNC:
140 ret = vm_call0_cfunc(ec, calling, cd, argv);
141 goto success;
142 case VM_METHOD_TYPE_ATTRSET:
143 if (calling->kw_splat &&
144 calling->argc > 0 &&
145 RB_TYPE_P(argv[calling->argc-1], T_HASH) &&
146 RHASH_EMPTY_P(argv[calling->argc-1])) {
147 if (calling->argc == 1) {
148 rb_warn("Passing the keyword argument as the last hash parameter is deprecated");
149 }
150 else {
151 calling->argc--;
152 }
153 }
154
155 rb_check_arity(calling->argc, 1, 1);
156 ret = rb_ivar_set(calling->recv, cc->me->def->body.attr.id, argv[0]);
157 goto success;
158 case VM_METHOD_TYPE_IVAR:
159 if (calling->kw_splat &&
160 calling->argc > 0 &&
161 RB_TYPE_P(argv[calling->argc-1], T_HASH) &&
162 RHASH_EMPTY_P(argv[calling->argc-1])) {
163 calling->argc--;
164 }
165
166 rb_check_arity(calling->argc, 0, 0);
167 ret = rb_attr_get(calling->recv, cc->me->def->body.attr.id);
168 goto success;
169 case VM_METHOD_TYPE_BMETHOD:
170 ret = vm_call_bmethod_body(ec, calling, cd, argv);
171 goto success;
172 case VM_METHOD_TYPE_ZSUPER:
173 case VM_METHOD_TYPE_REFINED:
174 {
175 const rb_method_type_t type = cc->me->def->type;
176 VALUE super_class = cc->me->defined_class;
177
178 if (type == VM_METHOD_TYPE_ZSUPER) {
179 super_class = RCLASS_ORIGIN(super_class);
180 }
181 else if (cc->me->def->body.refined.orig_me) {
182 CC_SET_ME(cc, refined_method_callable_without_refinement(cc->me));
183 goto again;
184 }
185
186 super_class = RCLASS_SUPER(super_class);
187 if (super_class) {
188 CC_SET_ME(cc, rb_callable_method_entry(super_class, ci->mid));
189 if (cc->me) {
190 RUBY_VM_CHECK_INTS(ec);
191 goto again;
192 }
193 }
194
195 enum method_missing_reason ex = (type == VM_METHOD_TYPE_ZSUPER) ? MISSING_SUPER : 0;
196 ret = method_missing(calling->recv, ci->mid, calling->argc, argv, ex, calling->kw_splat);
197 goto success;
198 }
199 case VM_METHOD_TYPE_ALIAS:
200 CC_SET_ME(cc, aliased_callable_method_entry(cc->me));
201 goto again;
202 case VM_METHOD_TYPE_MISSING:
203 {
204 vm_passed_block_handler_set(ec, calling->block_handler);
205 return method_missing(calling->recv, ci->mid, calling->argc,
206 argv, MISSING_NOENTRY, calling->kw_splat);
207 }
208 case VM_METHOD_TYPE_OPTIMIZED:
209 switch (cc->me->def->body.optimize_type) {
210 case OPTIMIZED_METHOD_TYPE_SEND:
211 ret = send_internal(calling->argc, argv, calling->recv, calling->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
212 goto success;
213 case OPTIMIZED_METHOD_TYPE_CALL:
214 {
215 rb_proc_t *proc;
216 GetProcPtr(calling->recv, proc);
217 ret = rb_vm_invoke_proc(ec, proc, calling->argc, argv, calling->kw_splat, calling->block_handler);
218 goto success;
219 }
220 default:
221 rb_bug("vm_call0: unsupported optimized method type (%d)", cc->me->def->body.optimize_type);
222 }
223 break;
224 case VM_METHOD_TYPE_UNDEF:
225 break;
226 }
227 rb_bug("vm_call0: unsupported method type (%d)", cc->me->def->type);
228 return Qundef;
229
230 success:
231 RUBY_VM_CHECK_INTS(ec);
232 return ret;
233 }
234
235 /* Caller should keep the reference to the return value until argv becomes useless. */
236 MJIT_FUNC_EXPORTED VALUE
237 rb_adjust_argv_kw_splat(int *argc, const VALUE **argv, int *kw_splat)
238 {
239 if (*kw_splat == RB_PASS_CALLED_KEYWORDS || *kw_splat == RB_PASS_EMPTY_KEYWORDS) {
240 if (*kw_splat == RB_PASS_EMPTY_KEYWORDS || rb_empty_keyword_given_p()) {
241 int n = *argc;
242 VALUE v;
243 VALUE *ptr = rb_alloc_tmp_buffer2(&v, n+1, sizeof(VALUE));
244 if (n) memcpy(ptr, *argv, sizeof(VALUE)*n);
245 ptr[n] = rb_hash_new();
246 *argc = ++n;
247 *argv = ptr;
248 *kw_splat = 1;
249 return v;
250 }
251 else {
252 *kw_splat = rb_keyword_given_p();
253 }
254 }
255
256 if (*kw_splat && (*argc == 0 || !RB_TYPE_P((*argv)[(*argc)-1], T_HASH))) {
257 rb_warn("Keyword flag passed calling internal method, but last entry is not a hash, unsetting keyword flag");
258 *kw_splat = 0;
259 }
260
261 return 0;
262 }
263
264 MJIT_FUNC_EXPORTED VALUE
265 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)
266 {
267 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
268 VALUE ret = rb_vm_call0(ec, recv, id, argc, argv, me, kw_splat);
269 rb_free_tmp_buffer(&v);
270 return ret;
271 }
272
273 static inline VALUE
274 vm_call_super(rb_execution_context_t *ec, int argc, const VALUE *argv, int kw_splat)
275 {
276 VALUE recv = ec->cfp->self;
277 VALUE klass;
278 ID id;
279 rb_control_frame_t *cfp = ec->cfp;
280 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
281
282 if (VM_FRAME_RUBYFRAME_P(cfp)) {
283 rb_bug("vm_call_super: should not be reached");
284 }
285
286 klass = RCLASS_ORIGIN(me->defined_class);
287 klass = RCLASS_SUPER(klass);
288 id = me->def->original_id;
289 me = rb_callable_method_entry(klass, id);
290
291 if (!me) {
292 return method_missing(recv, id, argc, argv, MISSING_SUPER, kw_splat);
293 }
294 return rb_vm_call_kw(ec, recv, id, argc, argv, me, kw_splat);
295 }
296
297 VALUE
298 rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
299 {
300 rb_execution_context_t *ec = GET_EC();
301 PASS_PASSED_BLOCK_HANDLER_EC(ec);
302 return vm_call_super(ec, argc, argv, kw_splat);
303 }
304
305 VALUE
306 rb_call_super(int argc, const VALUE *argv)
307 {
308 rb_execution_context_t *ec = GET_EC();
309 PASS_PASSED_BLOCK_HANDLER_EC(ec);
310 return vm_call_super(ec, argc, argv, RB_NO_KEYWORDS);
311 }
312
313 VALUE
314 rb_current_receiver(void)
315 {
316 const rb_execution_context_t *ec = GET_EC();
317 rb_control_frame_t *cfp;
318 if (!ec || !(cfp = ec->cfp)) {
319 rb_raise(rb_eRuntimeError, "no self, no life");
320 }
321 return cfp->self;
322 }
323
324 #endif /* #ifndef MJIT_HEADER */
325
326 static inline void
327 stack_check(rb_execution_context_t *ec)
328 {
329 if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) &&
330 rb_ec_stack_check(ec)) {
331 rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
332 rb_ec_stack_overflow(ec, FALSE);
333 }
334 }
335
336 #ifndef MJIT_HEADER
337
338 static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
339 static inline enum method_missing_reason rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self);
340
357 static inline VALUE
358 rb_call0(rb_execution_context_t *ec,
359 VALUE recv, ID mid, int argc, const VALUE *argv,
360 call_type call_scope, VALUE self)
361 {
362 const rb_callable_method_entry_t *me;
363 enum method_missing_reason call_status;
364 call_type scope = call_scope;
365 int kw_splat = RB_NO_KEYWORDS;
366
367 switch(scope) {
368 case(CALL_PUBLIC_KW):
369 scope = CALL_PUBLIC;
370 kw_splat = 1;
371 break;
372 case(CALL_FCALL_KW):
373 scope = CALL_FCALL;
374 kw_splat = 1;
375 break;
376 default:
377 break;
378 }
379
380 if (scope == CALL_PUBLIC) {
381 me = rb_callable_method_entry_with_refinements(CLASS_OF(recv), mid, NULL);
382 }
383 else {
384 me = rb_search_method_entry(recv, mid);
385 }
386 call_status = rb_method_call_status(ec, me, scope, self);
387
388 if (call_status != MISSING_NONE) {
389 return method_missing(recv, mid, argc, argv, call_status, kw_splat);
390 }
391 stack_check(ec);
392 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
393 }
394
395 struct rescue_funcall_args {
396 VALUE defined_class;
397 VALUE recv;
398 ID mid;
399 rb_execution_context_t *ec;
400 const rb_method_entry_t *me;
401 unsigned int respond: 1;
402 unsigned int respond_to_missing: 1;
403 int argc;
404 const VALUE *argv;
405 int kw_splat;
406 };
407
408 static VALUE
409 check_funcall_exec(VALUE v)
410 {
411 struct rescue_funcall_args *args = (void *)v;
412 return call_method_entry(args->ec, args->defined_class,
413 args->recv, idMethodMissing,
414 args->me, args->argc, args->argv, args->kw_splat);
415 }
416
417 static VALUE
418 check_funcall_failed(VALUE v, VALUE e)
419 {
420 struct rescue_funcall_args *args = (void *)v;
421 int ret = args->respond;
422 if (!ret) {
423 switch (rb_method_boundp(args->defined_class, args->mid,
424 BOUND_PRIVATE|BOUND_RESPONDS)) {
425 case 2:
426 ret = TRUE;
427 break;
428 case 0:
429 ret = args->respond_to_missing;
430 break;
431 default:
432 ret = FALSE;
433 break;
434 }
435 }
436 if (ret) {
437 rb_exc_raise(e);
438 }
439 return Qundef;
440 }
441
442 static int
443 check_funcall_respond_to(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mid)
444 {
445 return vm_respond_to(ec, klass, recv, mid, TRUE);
446 }
447
448 static int
449 check_funcall_callable(rb_execution_context_t *ec, const rb_callable_method_entry_t *me)
450 {
451 return rb_method_call_status(ec, me, CALL_FCALL, ec->cfp->self) == MISSING_NONE;
452 }
453
454 static VALUE
455 check_funcall_missing(rb_execution_context_t *ec, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int respond, VALUE def, int kw_splat)
456 {
457 struct rescue_funcall_args args;
458 const rb_method_entry_t *me;
459 VALUE ret = Qundef;
460
461 ret = basic_obj_respond_to_missing(ec, klass, recv,
462 ID2SYM(mid), Qtrue);
463 if (!RTEST(ret)) return def;
464 args.respond = respond > 0;
465 args.respond_to_missing = (ret != Qundef);
466 ret = def;
467 me = method_entry_get(klass, idMethodMissing, &args.defined_class);
468 if (me && !METHOD_ENTRY_BASIC(me)) {
469 VALUE argbuf, *new_args = ALLOCV_N(VALUE, argbuf, argc+1);
470
471 new_args[0] = ID2SYM(mid);
472 #ifdef __GLIBC__
473 if (!argv) {
474 static const VALUE buf = Qfalse;
475 VM_ASSERT(argc == 0);
476 argv = &buf;
477 }
478 #endif
479 MEMCPY(new_args+1, argv, VALUE, argc);
480 ec->method_missing_reason = MISSING_NOENTRY;
481 args.ec = ec;
482 args.recv = recv;
483 args.me = me;
484 args.mid = mid;
485 args.argc = argc + 1;
486 args.argv = new_args;
487 args.kw_splat = kw_splat;
488 ret = rb_rescue2(check_funcall_exec, (VALUE)&args,
489 check_funcall_failed, (VALUE)&args,
490 rb_eNoMethodError, (VALUE)0);
491 ALLOCV_END(argbuf);
492 }
493 return ret;
494 }
495
496 static VALUE rb_check_funcall_default_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def, int kw_splat);
497
498 VALUE
499 rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
500 {
501 return rb_check_funcall_default_kw(recv, mid, argc, argv, Qundef, kw_splat);
502 }
503
504 VALUE
505 rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
506 {
507 return rb_check_funcall_default_kw(recv, mid, argc, argv, Qundef, RB_NO_KEYWORDS);
508 }
509
510 static VALUE
511 rb_check_funcall_default_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def, int kw_splat)
512 {
513 VALUE klass = CLASS_OF(recv);
514 const rb_callable_method_entry_t *me;
515 rb_execution_context_t *ec = GET_EC();
516 int respond = check_funcall_respond_to(ec, klass, recv, mid);
517
518 if (!respond)
519 return def;
520
521 me = rb_search_method_entry(recv, mid);
522 if (!check_funcall_callable(ec, me)) {
523 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
524 respond, def, kw_splat);
525 if (ret == Qundef) ret = def;
526 return ret;
527 }
528 stack_check(ec);
529 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
530 }
531
532 VALUE
533 rb_check_funcall_default(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def)
534 {
535 return rb_check_funcall_default_kw(recv, mid, argc, argv, def, RB_NO_KEYWORDS);
536 }
537
538 VALUE
539 rb_check_funcall_with_hook_kw(VALUE recv, ID mid, int argc, const VALUE *argv,
540 rb_check_funcall_hook *hook, VALUE arg, int kw_splat)
541 {
542 VALUE klass = CLASS_OF(recv);
543 const rb_callable_method_entry_t *me;
544 rb_execution_context_t *ec = GET_EC();
545 int respond = check_funcall_respond_to(ec, klass, recv, mid);
546
547 if (!respond) {
548 (*hook)(FALSE, recv, mid, argc, argv, arg);
549 return Qundef;
550 }
551
552 me = rb_search_method_entry(recv, mid);
553 if (!check_funcall_callable(ec, me)) {
554 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
555 respond, Qundef, kw_splat);
556 (*hook)(ret != Qundef, recv, mid, argc, argv, arg);
557 return ret;
558 }
559 stack_check(ec);
560 (*hook)(TRUE, recv, mid, argc, argv, arg);
561 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
562 }
563
564 VALUE
565 rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
566 rb_check_funcall_hook *hook, VALUE arg)
567 {
568 return rb_check_funcall_with_hook_kw(recv, mid, argc, argv, hook, arg, RB_NO_KEYWORDS);
569 }
570
571 const char *
572 rb_type_str(enum ruby_value_type type)
573 {
574 #define type_case(t) t: return #t
575 switch (type) {
576 case type_case(T_NONE);
577 case type_case(T_OBJECT);
578 case type_case(T_CLASS);
579 case type_case(T_MODULE);
580 case type_case(T_FLOAT);
581 case type_case(T_STRING);
582 case type_case(T_REGEXP);
583 case type_case(T_ARRAY);
584 case type_case(T_HASH);
585 case type_case(T_STRUCT);
586 case type_case(T_BIGNUM);
587 case type_case(T_FILE);
588 case type_case(T_DATA);
589 case type_case(T_MATCH);
590 case type_case(T_COMPLEX);
591 case type_case(T_RATIONAL);
592 case type_case(T_NIL);
593 case type_case(T_TRUE);
594 case type_case(T_FALSE);
595 case type_case(T_SYMBOL);
596 case type_case(T_FIXNUM);
597 case type_case(T_IMEMO);
598 case type_case(T_UNDEF);
599 case type_case(T_NODE);
600 case type_case(T_ICLASS);
601 case type_case(T_ZOMBIE);
602 case type_case(T_MOVED);
603 case T_MASK: break;
604 }
605 #undef type_case
606 return NULL;
607 }
608
609 NORETURN(static void uncallable_object(VALUE recv, ID mid));
610 static void
611 uncallable_object(VALUE recv, ID mid)
612 {
613 VALUE flags;
614 int type;
615 const char *typestr;
616 VALUE mname = rb_id2str(mid);
617
618 if (SPECIAL_CONST_P(recv)) {
619 rb_raise(rb_eNotImpError,
620 "method `%"PRIsVALUE"' called on unexpected immediate object (%p)",
621 mname, (void *)recv);
622 }
623 else if ((flags = RBASIC(recv)->flags) == 0) {
624 rb_raise(rb_eNotImpError,
625 "method `%"PRIsVALUE"' called on terminated object (%p)",
626 mname, (void *)recv);
627 }
628 else if (!(typestr = rb_type_str(type = BUILTIN_TYPE(recv)))) {
629 rb_raise(rb_eNotImpError,
630 "method `%"PRIsVALUE"' called on broken T_?""?""?(0x%02x) object"
631 " (%p flags=0x%"PRIxVALUE")",
632 mname, type, (void *)recv, flags);
633 }
634 else if (T_OBJECT <= type && type < T_NIL) {
635 rb_raise(rb_eNotImpError,
636 "method `%"PRIsVALUE"' called on hidden %s object"
637 " (%p flags=0x%"PRIxVALUE")",
638 mname, typestr, (void *)recv, flags);
639 }
640 else {
641 rb_raise(rb_eNotImpError,
642 "method `%"PRIsVALUE"' called on unexpected %s object"
643 " (%p flags=0x%"PRIxVALUE")",
644 mname, typestr, (void *)recv, flags);
645 }
646 }
647
648 static inline const rb_callable_method_entry_t *
649 rb_search_method_entry(VALUE recv, ID mid)
650 {
651 VALUE klass = CLASS_OF(recv);
652
653 if (!klass) uncallable_object(recv, mid);
654 return rb_callable_method_entry(klass, mid);
655 }
656
657 static inline enum method_missing_reason
658 rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self)
659 {
660 VALUE klass;
661 ID oid;
662 rb_method_visibility_t visi;
663
664 if (UNDEFINED_METHOD_ENTRY_P(me)) {
665 undefined:
666 return scope == CALL_VCALL ? MISSING_VCALL : MISSING_NOENTRY;
667 }
668 if (me->def->type == VM_METHOD_TYPE_REFINED) {
669 me = rb_resolve_refined_method_callable(Qnil, me);
670 if (UNDEFINED_METHOD_ENTRY_P(me)) goto undefined;
671 }
672
673 klass = me->owner;
674 oid = me->def->original_id;
675 visi = METHOD_ENTRY_VISI(me);
676
677 if (oid != idMethodMissing) {
678 /* receiver specified form for private method */
679 if (UNLIKELY(visi != METHOD_VISI_PUBLIC)) {
680 if (visi == METHOD_VISI_PRIVATE && scope == CALL_PUBLIC) {
681 return MISSING_PRIVATE;
682 }
683
684 /* self must be kind of a specified form for protected method */
685 if (visi == METHOD_VISI_PROTECTED && scope == CALL_PUBLIC) {
686 VALUE defined_class = klass;
687
688 if (RB_TYPE_P(defined_class, T_ICLASS)) {
689 defined_class = RBASIC(defined_class)->klass;
690 }
691
692 if (self == Qundef || !rb_obj_is_kind_of(self, defined_class)) {
693 return MISSING_PROTECTED;
694 }
695 }
696 }
697 }
698
699 return MISSING_NONE;
700 }
701
702
714 static inline VALUE
715 rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
716 {
717 rb_execution_context_t *ec = GET_EC();
718 return rb_call0(ec, recv, mid, argc, argv, scope, ec->cfp->self);
719 }
720
721 NORETURN(static void raise_method_missing(rb_execution_context_t *ec, int argc, const VALUE *argv,
722 VALUE obj, enum method_missing_reason call_status));
723
724 /*
725 * call-seq:
726 * obj.method_missing(symbol [, *args] ) -> result
727 *
728 * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
729 * <i>symbol</i> is the symbol for the method called, and <i>args</i>
730 * are any arguments that were passed to it. By default, the interpreter
731 * raises an error when this method is called. However, it is possible
732 * to override the method to provide more dynamic behavior.
733 * If it is decided that a particular method should not be handled, then
734 * <i>super</i> should be called, so that ancestors can pick up the
735 * missing method.
736 * The example below creates
737 * a class <code>Roman</code>, which responds to methods with names
738 * consisting of roman numerals, returning the corresponding integer
739 * values.
740 *
741 * class Roman
742 * def roman_to_int(str)
743 * # ...
744 * end
745 *
746 * def method_missing(symbol, *args)
747 * str = symbol.id2name
748 * begin
749 * roman_to_int(str)
750 * rescue
751 * super(symbol, *args)
752 * end
753 * end
754 * end
755 *
756 * r = Roman.new
757 * r.iv #=> 4
758 * r.xxiii #=> 23
759 * r.mm #=> 2000
760 * r.foo #=> NoMethodError
761 */
762
763 static VALUE
764 rb_method_missing(int argc, const VALUE *argv, VALUE obj)
765 {
766 rb_execution_context_t *ec = GET_EC();
767 raise_method_missing(ec, argc, argv, obj, ec->method_missing_reason);
768 UNREACHABLE_RETURN(Qnil);
769 }
770
771 MJIT_FUNC_EXPORTED VALUE
772 rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj,
773 int argc, const VALUE *argv, int priv)
774 {
775 VALUE name = argv[0];
776
777 if (!format) {
778 format = rb_fstring_lit("undefined method `%s' for %s%s%s");
779 }
780 if (exc == rb_eNoMethodError) {
781 VALUE args = rb_ary_new4(argc - 1, argv + 1);
782 return rb_nomethod_err_new(format, obj, name, args, priv);
783 }
784 else {
785 return rb_name_err_new(format, obj, name);
786 }
787 }
788
789 #endif /* #ifndef MJIT_HEADER */
790
791 static void
792 raise_method_missing(rb_execution_context_t *ec, int argc, const VALUE *argv, VALUE obj,
793 enum method_missing_reason last_call_status)
794 {
795 VALUE exc = rb_eNoMethodError;
796 VALUE format = 0;
797
798 if (UNLIKELY(argc == 0)) {
799 rb_raise(rb_eArgError, "no method name given");
800 }
801 else if (UNLIKELY(!SYMBOL_P(argv[0]))) {
802 const VALUE e = rb_eArgError; /* TODO: TypeError? */
803 rb_raise(e, "method name must be a Symbol but %"PRIsVALUE" is given",
804 rb_obj_class(argv[0]));
805 }
806
807 stack_check(ec);
808
809 if (last_call_status & MISSING_PRIVATE) {
810 format = rb_fstring_lit("private method `%s' called for %s%s%s");
811 }
812 else if (last_call_status & MISSING_PROTECTED) {
813 format = rb_fstring_lit("protected method `%s' called for %s%s%s");
814 }
815 else if (last_call_status & MISSING_VCALL) {
816 format = rb_fstring_lit("undefined local variable or method `%s' for %s%s%s");
817 exc = rb_eNameError;
818 }
819 else if (last_call_status & MISSING_SUPER) {
820 format = rb_fstring_lit("super: no superclass method `%s' for %s%s%s");
821 }
822
823 {
824 exc = rb_make_no_method_exception(exc, format, obj, argc, argv,
825 last_call_status & (MISSING_FCALL|MISSING_VCALL));
826 if (!(last_call_status & MISSING_MISSING)) {
827 rb_vm_pop_cfunc_frame();
828 }
829 rb_exc_raise(exc);
830 }
831 }
832
833 static void
834 vm_raise_method_missing(rb_execution_context_t *ec, int argc, const VALUE *argv,
835 VALUE obj, int call_status)
836 {
837 vm_passed_block_handler_set(ec, VM_BLOCK_HANDLER_NONE);
838 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
839 }
840
841 static inline VALUE
842 method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status, int kw_splat)
843 {
844 VALUE *nargv, result, work, klass;
845 rb_execution_context_t *ec = GET_EC();
846 VALUE block_handler = vm_passed_block_handler(ec);
847 const rb_callable_method_entry_t *me;
848
849 ec->method_missing_reason = call_status;
850
851 if (id == idMethodMissing) {
852 missing:
853 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
854 }
855
856 nargv = ALLOCV_N(VALUE, work, argc + 1);
857 nargv[0] = ID2SYM(id);
858 #ifdef __GLIBC__
859 if (!argv) {
860 static const VALUE buf = Qfalse;
861 VM_ASSERT(argc == 0);
862 argv = &buf;
863 }
864 #endif
865 MEMCPY(nargv + 1, argv, VALUE, argc);
866 ++argc;
867 argv = nargv;
868
869 klass = CLASS_OF(obj);
870 if (!klass) goto missing;
871 me = rb_callable_method_entry(klass, idMethodMissing);
872 if (!me || METHOD_ENTRY_BASIC(me)) goto missing;
873 vm_passed_block_handler_set(ec, block_handler);
874 result = rb_vm_call_kw(ec, obj, idMethodMissing, argc, argv, me, kw_splat);
875 if (work) ALLOCV_END(work);
876 return result;
877 }
878
879 #ifndef MJIT_HEADER
880
889 VALUE
890 rb_apply(VALUE recv, ID mid, VALUE args)
891 {
892 int argc;
893 VALUE *argv, ret;
894
895 argc = RARRAY_LENINT(args);
896 if (argc >= 0x100) {
897 args = rb_ary_subseq(args, 0, argc);
898 RBASIC_CLEAR_CLASS(args);
899 OBJ_FREEZE(args);
900 ret = rb_call(recv, mid, argc, RARRAY_CONST_PTR(args), CALL_FCALL);
901 RB_GC_GUARD(args);
902 return ret;
903 }
904 argv = ALLOCA_N(VALUE, argc);
905 MEMCPY(argv, RARRAY_CONST_PTR_TRANSIENT(args), VALUE, argc);
906 return rb_call(recv, mid, argc, argv, CALL_FCALL);
907 }
908
909 #ifdef rb_funcall
910 #undef rb_funcall
911 #endif
912
921 VALUE
922 rb_funcall(VALUE recv, ID mid, int n, ...)
923 {
924 VALUE *argv;
925 va_list ar;
926
927 if (n > 0) {
928 long i;
929
930 va_init_list(ar, n);
931
932 argv = ALLOCA_N(VALUE, n);
933
934 for (i = 0; i < n; i++) {
935 argv[i] = va_arg(ar, VALUE);
936 }
937 va_end(ar);
938 }
939 else {
940 argv = 0;
941 }
942 return rb_call(recv, mid, n, argv, CALL_FCALL);
943 }
944
945 #ifdef rb_funcallv
946 #undef rb_funcallv
947 #endif
948
955 VALUE
956 rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
957 {
958 return rb_call(recv, mid, argc, argv, CALL_FCALL);
959 }
960
961 VALUE
962 rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
963 {
964 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
965 VALUE ret = rb_call(recv, mid, argc, argv, kw_splat ? CALL_FCALL_KW : CALL_FCALL);
966 rb_free_tmp_buffer(&v);
967 return ret;
968 }
969
979 VALUE
980 rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv)
981 {
982 return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
983 }
984
985 VALUE
986 rb_funcallv_public_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
987 {
988 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
989 VALUE ret = rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
990 rb_free_tmp_buffer(&v);
991 return ret;
992 }
993
1003 VALUE
1004 rb_funcallv_with_cc(struct rb_call_data *cd, VALUE recv, ID mid, int argc, const VALUE *argv)
1005 {
1006 const struct rb_call_info *ci = &cd->ci;
1007 struct rb_call_cache *cc = &cd->cc;
1008
1009 if (LIKELY(ci->mid == mid)) {
1010 vm_search_method(cd, recv);
1011
1012 if (LIKELY(! UNDEFINED_METHOD_ENTRY_P(cc->me))) {
1013 return vm_call0_body(
1014 GET_EC(),
1015 &(struct rb_calling_info) {
1016 Qundef,
1017 recv,
1018 argc,
1019 RB_NO_KEYWORDS,
1020 },
1021 cd,
1022 argv
1023 );
1024 }
1025 }
1026
1027 *cd = (struct rb_call_data) /* reset */ { { 0, }, { mid, }, };
1028 return rb_funcallv(recv, mid, argc, argv);
1029 }
1030
1031 VALUE
1032 rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
1033 {
1034 PASS_PASSED_BLOCK_HANDLER();
1035 return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
1036 }
1037
1038 VALUE
1039 rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
1040 {
1041 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1042 VALUE ret;
1043 PASS_PASSED_BLOCK_HANDLER();
1044 ret = rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1045 rb_free_tmp_buffer(&v);
1046 return ret;
1047 }
1048
1049 VALUE
1050 rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
1051 {
1052 if (!NIL_P(passed_procval)) {
1053 vm_passed_block_handler_set(GET_EC(), passed_procval);
1054 }
1055
1056 return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
1057 }
1058
1059 VALUE
1060 rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval, int kw_splat)
1061 {
1062 if (!NIL_P(passed_procval)) {
1063 vm_passed_block_handler_set(GET_EC(), passed_procval);
1064 }
1065
1066 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1067 VALUE ret = rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1068 rb_free_tmp_buffer(&v);
1069 return ret;
1070 }
1071
1072 static VALUE *
1073 current_vm_stack_arg(const rb_execution_context_t *ec, const VALUE *argv)
1074 {
1075 rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp);
1076 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, prev_cfp)) return NULL;
1077 if (prev_cfp->sp + 1 != argv) return NULL;
1078 return prev_cfp->sp + 1;
1079 }
1080
1081 static VALUE
1082 send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
1083 {
1084 ID id;
1085 VALUE vid;
1086 VALUE self;
1087 VALUE ret, vargv = 0;
1088 rb_execution_context_t *ec = GET_EC();
1089 int public = scope == CALL_PUBLIC || scope == CALL_PUBLIC_KW;
1090
1091 if (public) {
1092 self = Qundef;
1093 }
1094 else {
1095 self = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)->self;
1096 }
1097
1098 if (argc == 0) {
1099 rb_raise(rb_eArgError, "no method name given");
1100 }
1101
1102 vid = *argv;
1103
1104 id = rb_check_id(&vid);
1105 if (!id) {
1106 if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) {
1107 VALUE exc = rb_make_no_method_exception(rb_eNoMethodError, 0,
1108 recv, argc, argv,
1109 !public);
1110 rb_exc_raise(exc);
1111 }
1112 if (!SYMBOL_P(*argv)) {
1113 VALUE *tmp_argv = current_vm_stack_arg(ec, argv);
1114 vid = rb_str_intern(vid);
1115 if (tmp_argv) {
1116 tmp_argv[0] = vid;
1117 }
1118 else if (argc > 1) {
1119 tmp_argv = ALLOCV_N(VALUE, vargv, argc);
1120 tmp_argv[0] = vid;
1121 MEMCPY(tmp_argv+1, argv+1, VALUE, argc-1);
1122 argv = tmp_argv;
1123 }
1124 else {
1125 argv = &vid;
1126 }
1127 }
1128 id = idMethodMissing;
1129 ec->method_missing_reason = MISSING_NOENTRY;
1130 }
1131 else {
1132 argv++; argc--;
1133 }
1134 PASS_PASSED_BLOCK_HANDLER_EC(ec);
1135 ret = rb_call0(ec, recv, id, argc, argv, scope, self);
1136 ALLOCV_END(vargv);
1137 return ret;
1138 }
1139
1140 static VALUE
1141 send_internal_kw(int argc, const VALUE *argv, VALUE recv, call_type scope)
1142 {
1143 VALUE v=0, ret;
1144 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1145 v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1146 if (kw_splat) {
1147 switch (scope) {
1148 case CALL_PUBLIC:
1149 scope = CALL_PUBLIC_KW;
1150 break;
1151 case CALL_FCALL:
1152 scope = CALL_FCALL_KW;
1153 break;
1154 default:
1155 break;
1156 }
1157 }
1158 ret = send_internal(argc, argv, recv, scope);
1159 rb_free_tmp_buffer(&v);
1160 return ret;
1161 }
1162
1163 /*
1164 * call-seq:
1165 * foo.send(symbol [, args...]) -> obj
1166 * foo.__send__(symbol [, args...]) -> obj
1167 * foo.send(string [, args...]) -> obj
1168 * foo.__send__(string [, args...]) -> obj
1169 *
1170 * Invokes the method identified by _symbol_, passing it any
1171 * arguments specified. You can use <code>__send__</code> if the name
1172 * +send+ clashes with an existing method in _obj_.
1173 * When the method is identified by a string, the string is converted
1174 * to a symbol.
1175 *
1176 * BasicObject implements +__send__+, Kernel implements +send+.
1177 *
1178 * class Klass
1179 * def hello(*args)
1180 * "Hello " + args.join(' ')
1181 * end
1182 * end
1183 * k = Klass.new
1184 * k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
1185 */
1186
1187 VALUE
1188 rb_f_send(int argc, VALUE *argv, VALUE recv)
1189 {
1190 return send_internal_kw(argc, argv, recv, CALL_FCALL);
1191 }
1192
1193 /*
1194 * call-seq:
1195 * obj.public_send(symbol [, args...]) -> obj
1196 * obj.public_send(string [, args...]) -> obj
1197 *
1198 * Invokes the method identified by _symbol_, passing it any
1199 * arguments specified. Unlike send, public_send calls public
1200 * methods only.
1201 * When the method is identified by a string, the string is converted
1202 * to a symbol.
1203 *
1204 * 1.public_send(:puts, "hello") # causes NoMethodError
1205 */
1206
1207 static VALUE
1208 rb_f_public_send(int argc, VALUE *argv, VALUE recv)
1209 {
1210 return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
1211 }
1212
1213 /* yield */
1214
1215 static inline VALUE
1216 rb_yield_0_kw(int argc, const VALUE * argv, int kw_splat)
1217 {
1218 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1219 VALUE ret = vm_yield(GET_EC(), argc, argv, kw_splat);
1220 rb_free_tmp_buffer(&v);
1221 return ret;
1222 }
1223
1224 static inline VALUE
1225 rb_yield_0(int argc, const VALUE * argv)
1226 {
1227 return vm_yield(GET_EC(), argc, argv, RB_NO_KEYWORDS);
1228 }
1229
1230 VALUE
1231 rb_yield_1(VALUE val)
1232 {
1233 return rb_yield_0(1, &val);
1234 }
1235
1236 VALUE
1237 rb_yield(VALUE val)
1238 {
1239 if (val == Qundef) {
1240 return rb_yield_0(0, 0);
1241 }
1242 else {
1243 return rb_yield_1(val);
1244 }
1245 }
1246
1247 #undef rb_yield_values
1248 VALUE
1249 rb_yield_values(int n, ...)
1250 {
1251 if (n == 0) {
1252 return rb_yield_0(0, 0);
1253 }
1254 else {
1255 int i;
1256 VALUE *argv;
1257 va_list args;
1258 argv = ALLOCA_N(VALUE, n);
1259
1260 va_init_list(args, n);
1261 for (i=0; i<n; i++) {
1262 argv[i] = va_arg(args, VALUE);
1263 }
1264 va_end(args);
1265
1266 return rb_yield_0(n, argv);
1267 }
1268 }
1269
1270 VALUE
1271 rb_yield_values2(int argc, const VALUE *argv)
1272 {
1273 return rb_yield_0(argc, argv);
1274 }
1275
1276 VALUE
1277 rb_yield_values_kw(int argc, const VALUE *argv, int kw_splat)
1278 {
1279 return rb_yield_0_kw(argc, argv, kw_splat);
1280 }
1281
1282 VALUE
1283 rb_yield_splat(VALUE values)
1284 {
1285 VALUE tmp = rb_check_array_type(values);
1286 VALUE v;
1287 if (NIL_P(tmp)) {
1288 rb_raise(rb_eArgError, "not an array");
1289 }
1290 v = rb_yield_0(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp));
1291 RB_GC_GUARD(tmp);
1292 return v;
1293 }
1294
1295 VALUE
1296 rb_yield_splat_kw(VALUE values, int kw_splat)
1297 {
1298 VALUE tmp = rb_check_array_type(values);
1299 VALUE v;
1300 if (NIL_P(tmp)) {
1301 rb_raise(rb_eArgError, "not an array");
1302 }
1303 v = rb_yield_0_kw(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), kw_splat);
1304 RB_GC_GUARD(tmp);
1305 return v;
1306 }
1307
1308 VALUE
1309 rb_yield_force_blockarg(VALUE values)
1310 {
1311 return vm_yield_force_blockarg(GET_EC(), values);
1312 }
1313
1314 VALUE
1315 rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(val, arg))
1316 {
1317 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1318 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1319 VALUE ret = vm_yield_with_block(GET_EC(), argc, argv,
1320 NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg,
1321 kw_splat);
1322 rb_free_tmp_buffer(&v);
1323 return ret;
1324 }
1325
1326 static VALUE
1327 loop_i(VALUE _)
1328 {
1329 for (;;) {
1330 rb_yield_0(0, 0);
1331 }
1332 return Qnil;
1333 }
1334
1335 static VALUE
1336 loop_stop(VALUE dummy, VALUE exc)
1337 {
1338 return rb_attr_get(exc, id_result);
1339 }
1340
1341 static VALUE
1342 rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
1343 {
1344 return DBL2NUM(HUGE_VAL);
1345 }
1346
1347 /*
1348 * call-seq:
1349 * loop { block }
1350 * loop -> an_enumerator
1351 *
1352 * Repeatedly executes the block.
1353 *
1354 * If no block is given, an enumerator is returned instead.
1355 *
1356 * loop do
1357 * print "Input: "
1358 * line = gets
1359 * break if !line or line =~ /^qQ/
1360 * # ...
1361 * end
1362 *
1363 * StopIteration raised in the block breaks the loop. In this case,
1364 * loop returns the "result" value stored in the exception.
1365 *
1366 * enum = Enumerator.new { |y|
1367 * y << "one"
1368 * y << "two"
1369 * :ok
1370 * }
1371 *
1372 * result = loop {
1373 * puts enum.next
1374 * } #=> :ok
1375 */
1376
1377 static VALUE
1378 rb_f_loop(VALUE self)
1379 {
1380 RETURN_SIZED_ENUMERATOR(self, 0, 0, rb_f_loop_size);
1381 return rb_rescue2(loop_i, (VALUE)0, loop_stop, (VALUE)0, rb_eStopIteration, (VALUE)0);
1382 }
1383
1384 #if VMDEBUG
1385 static const char *
1386 vm_frametype_name(const rb_control_frame_t *cfp);
1387 #endif
1388
1389 static VALUE
1390 rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
1391 const struct vm_ifunc *const ifunc,
1392 rb_execution_context_t *ec)
1393 {
1394 enum ruby_tag_type state;
1395 volatile VALUE retval = Qnil;
1396 rb_control_frame_t *const cfp = ec->cfp;
1397
1398 EC_PUSH_TAG(ec);
1399 state = EC_EXEC_TAG();
1400 if (state == 0) {
1401 iter_retry:
1402 {
1403 VALUE block_handler;
1404
1405 if (ifunc) {
1406 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(cfp);
1407 captured->code.ifunc = ifunc;
1408 block_handler = VM_BH_FROM_IFUNC_BLOCK(captured);
1409 }
1410 else {
1411 block_handler = VM_CF_BLOCK_HANDLER(cfp);
1412 }
1413 vm_passed_block_handler_set(ec, block_handler);
1414 }
1415 retval = (*it_proc) (data1);
1416 }
1417 else if (state == TAG_BREAK || state == TAG_RETRY) {
1418 const struct vm_throw_data *const err = (struct vm_throw_data *)ec->errinfo;
1419 const rb_control_frame_t *const escape_cfp = THROW_DATA_CATCH_FRAME(err);
1420
1421 if (cfp == escape_cfp) {
1422 rb_vm_rewind_cfp(ec, cfp);
1423
1424 state = 0;
1425 ec->tag->state = TAG_NONE;
1426 ec->errinfo = Qnil;
1427
1428 if (state == TAG_RETRY) goto iter_retry;
1429 retval = THROW_DATA_VAL(err);
1430 }
1431 else if (0) {
1432 SDR(); fprintf(stderr, "%p, %p\n", (void *)cfp, (void *)escape_cfp);
1433 }
1434 }
1435 EC_POP_TAG();
1436
1437 if (state) {
1438 EC_JUMP_TAG(ec, state);
1439 }
1440 return retval;
1441 }
1442
1443 VALUE
1444 rb_iterate(VALUE (* it_proc)(VALUE), VALUE data1,
1445 rb_block_call_func_t bl_proc, VALUE data2)
1446 {
1447 return rb_iterate0(it_proc, data1,
1448 bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (void *)data2) : 0,
1449 GET_EC());
1450 }
1451
1452 struct iter_method_arg {
1453 VALUE obj;
1454 ID mid;
1455 int argc;
1456 const VALUE *argv;
1457 int kw_splat;
1458 };
1459
1460 static VALUE
1461 iterate_method(VALUE obj)
1462 {
1463 const struct iter_method_arg * arg =
1464 (struct iter_method_arg *) obj;
1465
1466 return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, arg->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1467 }
1468
1469 VALUE
1470 rb_block_call(VALUE obj, ID mid, int argc, const VALUE * argv,
1471 rb_block_call_func_t bl_proc, VALUE data2)
1472 {
1473 struct iter_method_arg arg;
1474
1475 arg.obj = obj;
1476 arg.mid = mid;
1477 arg.argc = argc;
1478 arg.argv = argv;
1479 arg.kw_splat = 0;
1480 return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
1481 }
1482
1483 VALUE
1484 rb_block_call_kw(VALUE obj, ID mid, int argc, const VALUE * argv,
1485 rb_block_call_func_t bl_proc, VALUE data2, int kw_splat)
1486 {
1487 struct iter_method_arg arg;
1488
1489 VALUE v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1490 arg.obj = obj;
1491 arg.mid = mid;
1492 arg.argc = argc;
1493 arg.argv = argv;
1494 arg.kw_splat = kw_splat;
1495 VALUE ret = rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
1496 rb_free_tmp_buffer(&v);
1497 return ret;
1498 }
1499
1500 VALUE
1501 rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
1502 rb_block_call_func_t bl_proc, int min_argc, int max_argc,
1503 VALUE data2)
1504 {
1505 struct iter_method_arg arg;
1506 struct vm_ifunc *block;
1507
1508 if (!bl_proc) rb_raise(rb_eArgError, "NULL lambda function");
1509 arg.obj = obj;
1510 arg.mid = mid;
1511 arg.argc = argc;
1512 arg.argv = argv;
1513 arg.kw_splat = 0;
1514 block = rb_vm_ifunc_new(bl_proc, (void *)data2, min_argc, max_argc);
1515 return rb_iterate0(iterate_method, (VALUE)&arg, block, GET_EC());
1516 }
1517
1518 static VALUE
1519 iterate_check_method(VALUE obj)
1520 {
1521 const struct iter_method_arg * arg =
1522 (struct iter_method_arg *) obj;
1523
1524 return rb_check_funcall(arg->obj, arg->mid, arg->argc, arg->argv);
1525 }
1526
1527 VALUE
1528 rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv,
1529 rb_block_call_func_t bl_proc, VALUE data2)
1530 {
1531 struct iter_method_arg arg;
1532
1533 arg.obj = obj;
1534 arg.mid = mid;
1535 arg.argc = argc;
1536 arg.argv = argv;
1537 arg.kw_splat = 0;
1538 return rb_iterate(iterate_check_method, (VALUE)&arg, bl_proc, data2);
1539 }
1540
1541 VALUE
1542 rb_each(VALUE obj)
1543 {
1544 return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1545 }
1546
1547 void rb_parser_warn_location(VALUE, int);
1548 static const rb_iseq_t *
1549 eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind,
1550 const struct rb_block *base_block)
1551 {
1552 const VALUE parser = rb_parser_new();
1553 const rb_iseq_t *const parent = vm_block_iseq(base_block);
1554 VALUE realpath = Qnil;
1555 rb_iseq_t *iseq = 0;
1556 rb_ast_t *ast;
1557
1558 if (!fname) {
1559 fname = rb_source_location(&line);
1560 }
1561
1562 if (fname != Qundef) {
1563 if (!NIL_P(fname)) fname = rb_fstring(fname);
1564 realpath = fname;
1565 }
1566 else if (bind) {
1567 fname = pathobj_path(bind->pathobj);
1568 realpath = pathobj_realpath(bind->pathobj);
1569 line = bind->first_lineno;
1570 rb_parser_warn_location(parser, TRUE);
1571 }
1572 else {
1573 fname = rb_fstring_lit("(eval)");
1574 }
1575
1576 rb_parser_set_context(parser, parent, FALSE);
1577 ast = rb_parser_compile_string_path(parser, fname, src, line);
1578 if (ast->body.root) {
1579 iseq = rb_iseq_new_with_opt(&ast->body,
1580 parent->body->location.label,
1581 fname, realpath, INT2FIX(line),
1582 parent, ISEQ_TYPE_EVAL, NULL);
1583 }
1584 rb_ast_dispose(ast);
1585
1586 if (0 && iseq) { /* for debug */
1587 VALUE disasm = rb_iseq_disasm(iseq);
1588 printf("%s\n", StringValuePtr(disasm));
1589 }
1590
1591 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1592
1593 return iseq;
1594 }
1595
1596 static VALUE
1597 eval_string_with_cref(VALUE self, VALUE src, rb_cref_t *cref, VALUE file, int line)
1598 {
1599 rb_execution_context_t *ec = GET_EC();
1600 struct rb_block block;
1601 const rb_iseq_t *iseq;
1602 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
1603 if (!cfp) {
1604 rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
1605 }
1606
1607 block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
1608 block.as.captured.self = self;
1609 block.as.captured.code.iseq = cfp->iseq;
1610 block.type = block_type_iseq;
1611
1612 iseq = eval_make_iseq(src, file, line, NULL, &block);
1613 if (!iseq) {
1614 rb_exc_raise(ec->errinfo);
1615 }
1616
1617 /* TODO: what the code checking? */
1618 if (!cref && block.as.captured.code.val) {
1619 rb_cref_t *orig_cref = vm_get_cref(vm_block_ep(&block));
1620 cref = vm_cref_dup(orig_cref);
1621 }
1622 vm_set_eval_stack(ec, iseq, cref, &block);
1623
1624 /* kick */
1625 return vm_exec(ec, TRUE);
1626 }
1627
1628 static VALUE
1629 eval_string_with_scope(VALUE scope, VALUE src, VALUE file, int line)
1630 {
1631 rb_execution_context_t *ec = GET_EC();
1632 rb_binding_t *bind = Check_TypedStruct(scope, &ruby_binding_data_type);
1633 const rb_iseq_t *iseq = eval_make_iseq(src, file, line, bind, &bind->block);
1634 if (!iseq) {
1635 rb_exc_raise(ec->errinfo);
1636 }
1637
1638 vm_set_eval_stack(ec, iseq, NULL, &bind->block);
1639
1640 /* save new env */
1641 if (iseq->body->local_table_size > 0) {
1642 vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
1643 }
1644
1645 /* kick */
1646 return vm_exec(ec, TRUE);
1647 }
1648
1649 /*
1650 * call-seq:
1651 * eval(string [, binding [, filename [,lineno]]]) -> obj
1652 *
1653 * Evaluates the Ruby expression(s) in <em>string</em>. If
1654 * <em>binding</em> is given, which must be a Binding object, the
1655 * evaluation is performed in its context. If the optional
1656 * <em>filename</em> and <em>lineno</em> parameters are present, they
1657 * will be used when reporting syntax errors.
1658 *
1659 * def get_binding(str)
1660 * return binding
1661 * end
1662 * str = "hello"
1663 * eval "str + ' Fred'" #=> "hello Fred"
1664 * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
1665 */
1666
1667 VALUE
1668 rb_f_eval(int argc, const VALUE *argv, VALUE self)
1669 {
1670 VALUE src, scope, vfile, vline;
1671 VALUE file = Qundef;
1672 int line = 1;
1673
1674 rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1675 SafeStringValue(src);
1676 if (argc >= 3) {
1677 StringValue(vfile);
1678 }
1679 if (argc >= 4) {
1680 line = NUM2INT(vline);
1681 }
1682
1683 if (!NIL_P(vfile))
1684 file = vfile;
1685
1686 if (NIL_P(scope))
1687 return eval_string_with_cref(self, src, NULL, file, line);
1688 else
1689 return eval_string_with_scope(scope, src, file, line);
1690 }
1691
1693 VALUE
1694 ruby_eval_string_from_file(const char *str, const char *filename)
1695 {
1696 VALUE file = filename ? rb_str_new_cstr(filename) : 0;
1697 return eval_string_with_cref(rb_vm_top_self(), rb_str_new2(str), NULL, file, 1);
1698 }
1699
1712 VALUE
1713 rb_eval_string(const char *str)
1714 {
1715 return ruby_eval_string_from_file(str, "eval");
1716 }
1717
1718 static VALUE
1719 eval_string_protect(VALUE str)
1720 {
1721 return rb_eval_string((char *)str);
1722 }
1723
1734 VALUE
1735 rb_eval_string_protect(const char *str, int *pstate)
1736 {
1737 return rb_protect(eval_string_protect, (VALUE)str, pstate);
1738 }
1739
1740 struct eval_string_wrap_arg {
1741 VALUE top_self;
1742 VALUE klass;
1743 const char *str;
1744 };
1745
1746 static VALUE
1747 eval_string_wrap_protect(VALUE data)
1748 {
1749 const struct eval_string_wrap_arg *const arg = (struct eval_string_wrap_arg*)data;
1750 rb_cref_t *cref = rb_vm_cref_new_toplevel();
1751 cref->klass = arg->klass;
1752 return eval_string_with_cref(arg->top_self, rb_str_new_cstr(arg->str), cref, rb_str_new_cstr("eval"), 1);
1753 }
1754
1766 VALUE
1767 rb_eval_string_wrap(const char *str, int *pstate)
1768 {
1769 int state;
1770 rb_thread_t *th = GET_THREAD();
1771 VALUE self = th->top_self;
1772 VALUE wrapper = th->top_wrapper;
1773 VALUE val;
1774 struct eval_string_wrap_arg data;
1775
1776 th->top_wrapper = rb_module_new();
1777 th->top_self = rb_obj_clone(rb_vm_top_self());
1778 rb_extend_object(th->top_self, th->top_wrapper);
1779
1780 data.top_self = th->top_self;
1781 data.klass = th->top_wrapper;
1782 data.str = str;
1783
1784 val = rb_protect(eval_string_wrap_protect, (VALUE)&data, &state);
1785
1786 th->top_self = self;
1787 th->top_wrapper = wrapper;
1788
1789 if (pstate) {
1790 *pstate = state;
1791 }
1792 else if (state != TAG_NONE) {
1793 EC_JUMP_TAG(th->ec, state);
1794 }
1795 return val;
1796 }
1797
1798 VALUE
1799 rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat)
1800 {
1801 enum ruby_tag_type state;
1802 volatile VALUE val = Qnil; /* OK */
1803 rb_execution_context_t * volatile ec = GET_EC();
1804
1805 EC_PUSH_TAG(ec);
1806 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1807 if (!RB_TYPE_P(cmd, T_STRING)) {
1808 val = rb_funcallv_kw(cmd, idCall, RARRAY_LENINT(arg),
1809 RARRAY_CONST_PTR(arg), kw_splat);
1810 }
1811 else {
1812 val = eval_string_with_cref(rb_vm_top_self(), cmd, NULL, 0, 0);
1813 }
1814 }
1815 EC_POP_TAG();
1816
1817 if (state) EC_JUMP_TAG(ec, state);
1818 return val;
1819 }
1820
1821 VALUE
1822 rb_eval_cmd(VALUE cmd, VALUE arg, int _level)
1823 {
1824 rb_warn("rb_eval_cmd will be removed in Ruby 3.0");
1825 return rb_eval_cmd_kw(cmd, arg, RB_NO_KEYWORDS);
1826 }
1827
1828 /* block eval under the class/module context */
1829
1830 static VALUE
1831 yield_under(VALUE under, VALUE self, int argc, const VALUE *argv, int kw_splat)
1832 {
1833 rb_execution_context_t *ec = GET_EC();
1834 rb_control_frame_t *cfp = ec->cfp;
1835 VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
1836 VALUE new_block_handler = 0;
1837 const struct rb_captured_block *captured = NULL;
1838 struct rb_captured_block new_captured;
1839 const VALUE *ep = NULL;
1840 rb_cref_t *cref;
1841 int is_lambda = FALSE;
1842 VALUE v = 0, ret;
1843
1844 v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1845
1846 if (block_handler != VM_BLOCK_HANDLER_NONE) {
1847 again:
1848 switch (vm_block_handler_type(block_handler)) {
1849 case block_handler_type_iseq:
1850 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1851 new_captured = *captured;
1852 new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1853 break;
1854 case block_handler_type_ifunc:
1855 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1856 new_captured = *captured;
1857 new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
1858 break;
1859 case block_handler_type_proc:
1860 is_lambda = rb_proc_lambda_p(block_handler) != Qfalse;
1861 block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
1862 goto again;
1863 case block_handler_type_symbol:
1864 ret = rb_sym_proc_call(SYM2ID(VM_BH_TO_SYMBOL(block_handler)),
1865 argc, argv, kw_splat, VM_BLOCK_HANDLER_NONE);
1866 rb_free_tmp_buffer(&v);
1867 return ret;
1868 }
1869
1870 new_captured.self = self;
1871 ep = captured->ep;
1872
1873 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
1874 }
1875
1876 cref = vm_cref_push(ec, under, ep, TRUE);
1877 ret = vm_yield_with_cref(ec, argc, argv, kw_splat, cref, is_lambda);
1878 rb_free_tmp_buffer(&v);
1879 return ret;
1880 }
1881
1882 VALUE
1883 rb_yield_refine_block(VALUE refinement, VALUE refinements)
1884 {
1885 rb_execution_context_t *ec = GET_EC();
1886 VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
1887
1888 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1889 rb_bug("rb_yield_refine_block: an iseq block is required");
1890 }
1891 else {
1892 const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
1893 struct rb_captured_block new_captured = *captured;
1894 VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1895 const VALUE *ep = captured->ep;
1896 rb_cref_t *cref = vm_cref_push(ec, refinement, ep, TRUE);
1897 CREF_REFINEMENTS_SET(cref, refinements);
1898 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
1899 new_captured.self = refinement;
1900 return vm_yield_with_cref(ec, 0, NULL, RB_NO_KEYWORDS, cref, FALSE);
1901 }
1902 }
1903
1904 /* string eval under the class/module context */
1905 static VALUE
1906 eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
1907 {
1908 rb_cref_t *cref = vm_cref_push(GET_EC(), under, NULL, SPECIAL_CONST_P(self) && !NIL_P(under));
1909 SafeStringValue(src);
1910 return eval_string_with_cref(self, src, cref, file, line);
1911 }
1912
1913 static VALUE
1914 specific_eval(int argc, const VALUE *argv, VALUE klass, VALUE self, int kw_splat)
1915 {
1916 if (rb_block_given_p()) {
1917 rb_check_arity(argc, 0, 0);
1918 return yield_under(klass, self, 1, &self, kw_splat);
1919 }
1920 else {
1921 VALUE file = Qundef;
1922 int line = 1;
1923 VALUE code;
1924
1925 rb_check_arity(argc, 1, 3);
1926 code = argv[0];
1927 SafeStringValue(code);
1928 if (argc > 2)
1929 line = NUM2INT(argv[2]);
1930 if (argc > 1) {
1931 file = argv[1];
1932 if (!NIL_P(file)) StringValue(file);
1933 }
1934 return eval_under(klass, self, code, file, line);
1935 }
1936 }
1937
1938 static VALUE
1939 singleton_class_for_eval(VALUE self)
1940 {
1941 if (SPECIAL_CONST_P(self)) {
1942 return rb_special_singleton_class(self);
1943 }
1944 switch (BUILTIN_TYPE(self)) {
1945 case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
1946 return Qnil;
1947 case T_STRING:
1948 if (FL_TEST_RAW(self, RSTRING_FSTR)) return Qnil;
1949 default:
1950 return rb_singleton_class(self);
1951 }
1952 }
1953
1954 /*
1955 * call-seq:
1956 * obj.instance_eval(string [, filename [, lineno]] ) -> obj
1957 * obj.instance_eval {|obj| block } -> obj
1958 *
1959 * Evaluates a string containing Ruby source code, or the given block,
1960 * within the context of the receiver (_obj_). In order to set the
1961 * context, the variable +self+ is set to _obj_ while
1962 * the code is executing, giving the code access to _obj_'s
1963 * instance variables and private methods.
1964 *
1965 * When <code>instance_eval</code> is given a block, _obj_ is also
1966 * passed in as the block's only argument.
1967 *
1968 * When <code>instance_eval</code> is given a +String+, the optional
1969 * second and third parameters supply a filename and starting line number
1970 * that are used when reporting compilation errors.
1971 *
1972 * class KlassWithSecret
1973 * def initialize
1974 * @secret = 99
1975 * end
1976 * private
1977 * def the_secret
1978 * "Ssssh! The secret is #{@secret}."
1979 * end
1980 * end
1981 * k = KlassWithSecret.new
1982 * k.instance_eval { @secret } #=> 99
1983 * k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
1984 * k.instance_eval {|obj| obj == self } #=> true
1985 */
1986
1987 static VALUE
1988 rb_obj_instance_eval_internal(int argc, const VALUE *argv, VALUE self)
1989 {
1990 VALUE klass = singleton_class_for_eval(self);
1991 return specific_eval(argc, argv, klass, self, RB_PASS_CALLED_KEYWORDS);
1992 }
1993
1994 VALUE
1995 rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
1996 {
1997 VALUE klass = singleton_class_for_eval(self);
1998 return specific_eval(argc, argv, klass, self, RB_NO_KEYWORDS);
1999 }
2000
2001 /*
2002 * call-seq:
2003 * obj.instance_exec(arg...) {|var...| block } -> obj
2004 *
2005 * Executes the given block within the context of the receiver
2006 * (_obj_). In order to set the context, the variable +self+ is set
2007 * to _obj_ while the code is executing, giving the code access to
2008 * _obj_'s instance variables. Arguments are passed as block parameters.
2009 *
2010 * class KlassWithSecret
2011 * def initialize
2012 * @secret = 99
2013 * end
2014 * end
2015 * k = KlassWithSecret.new
2016 * k.instance_exec(5) {|x| @secret+x } #=> 104
2017 */
2018
2019 static VALUE
2020 rb_obj_instance_exec_internal(int argc, const VALUE *argv, VALUE self)
2021 {
2022 VALUE klass = singleton_class_for_eval(self);
2023 return yield_under(klass, self, argc, argv, RB_PASS_CALLED_KEYWORDS);
2024 }
2025
2026 VALUE
2027 rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
2028 {
2029 VALUE klass = singleton_class_for_eval(self);
2030 return yield_under(klass, self, argc, argv, RB_NO_KEYWORDS);
2031 }
2032
2033 /*
2034 * call-seq:
2035 * mod.class_eval(string [, filename [, lineno]]) -> obj
2036 * mod.class_eval {|mod| block } -> obj
2037 * mod.module_eval(string [, filename [, lineno]]) -> obj
2038 * mod.module_eval {|mod| block } -> obj
2039 *
2040 * Evaluates the string or block in the context of _mod_, except that when
2041 * a block is given, constant/class variable lookup is not affected. This
2042 * can be used to add methods to a class. <code>module_eval</code> returns
2043 * the result of evaluating its argument. The optional _filename_ and
2044 * _lineno_ parameters set the text for error messages.
2045 *
2046 * class Thing
2047 * end
2048 * a = %q{def hello() "Hello there!" end}
2049 * Thing.module_eval(a)
2050 * puts Thing.new.hello()
2051 * Thing.module_eval("invalid code", "dummy", 123)
2052 *
2053 * <em>produces:</em>
2054 *
2055 * Hello there!
2056 * dummy:123:in `module_eval': undefined local variable
2057 * or method `code' for Thing:Class
2058 */
2059
2060 static VALUE
2061 rb_mod_module_eval_internal(int argc, const VALUE *argv, VALUE mod)
2062 {
2063 return specific_eval(argc, argv, mod, mod, RB_PASS_CALLED_KEYWORDS);
2064 }
2065
2066 VALUE
2067 rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
2068 {
2069 return specific_eval(argc, argv, mod, mod, RB_NO_KEYWORDS);
2070 }
2071
2072 /*
2073 * call-seq:
2074 * mod.module_exec(arg...) {|var...| block } -> obj
2075 * mod.class_exec(arg...) {|var...| block } -> obj
2076 *
2077 * Evaluates the given block in the context of the class/module.
2078 * The method defined in the block will belong to the receiver.
2079 * Any arguments passed to the method will be passed to the block.
2080 * This can be used if the block needs to access instance variables.
2081 *
2082 * class Thing
2083 * end
2084 * Thing.class_exec{
2085 * def hello() "Hello there!" end
2086 * }
2087 * puts Thing.new.hello()
2088 *
2089 * <em>produces:</em>
2090 *
2091 * Hello there!
2092 */
2093
2094 static VALUE
2095 rb_mod_module_exec_internal(int argc, const VALUE *argv, VALUE mod)
2096 {
2097 return yield_under(mod, mod, argc, argv, RB_PASS_CALLED_KEYWORDS);
2098 }
2099
2100 VALUE
2101 rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
2102 {
2103 return yield_under(mod, mod, argc, argv, RB_NO_KEYWORDS);
2104 }
2105
2106 /*
2107 * Document-class: UncaughtThrowError
2108 *
2109 * Raised when +throw+ is called with a _tag_ which does not have
2110 * corresponding +catch+ block.
2111 *
2112 * throw "foo", "bar"
2113 *
2114 * <em>raises the exception:</em>
2115 *
2116 * UncaughtThrowError: uncaught throw "foo"
2117 */
2118
2119 static VALUE
2120 uncaught_throw_init(int argc, const VALUE *argv, VALUE exc)
2121 {
2122 rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
2123 rb_call_super(argc - 2, argv + 2);
2124 rb_ivar_set(exc, id_tag, argv[0]);
2125 rb_ivar_set(exc, id_value, argv[1]);
2126 return exc;
2127 }
2128
2129 /*
2130 * call-seq:
2131 * uncaught_throw.tag -> obj
2132 *
2133 * Return the tag object which was called for.
2134 */
2135
2136 static VALUE
2137 uncaught_throw_tag(VALUE exc)
2138 {
2139 return rb_ivar_get(exc, id_tag);
2140 }
2141
2142 /*
2143 * call-seq:
2144 * uncaught_throw.value -> obj
2145 *
2146 * Return the return value which was called for.
2147 */
2148
2149 static VALUE
2150 uncaught_throw_value(VALUE exc)
2151 {
2152 return rb_ivar_get(exc, id_value);
2153 }
2154
2155 /*
2156 * call-seq:
2157 * uncaught_throw.to_s -> string
2158 *
2159 * Returns formatted message with the inspected tag.
2160 */
2161
2162 static VALUE
2163 uncaught_throw_to_s(VALUE exc)
2164 {
2165 VALUE mesg = rb_attr_get(exc, id_mesg);
2166 VALUE tag = uncaught_throw_tag(exc);
2167 return rb_str_format(1, &tag, mesg);
2168 }
2169
2170 /*
2171 * call-seq:
2172 * throw(tag [, obj])
2173 *
2174 * Transfers control to the end of the active +catch+ block
2175 * waiting for _tag_. Raises +UncaughtThrowError+ if there
2176 * is no +catch+ block for the _tag_. The optional second
2177 * parameter supplies a return value for the +catch+ block,
2178 * which otherwise defaults to +nil+. For examples, see
2179 * Kernel::catch.
2180 */
2181
2182 static VALUE
2183 rb_f_throw(int argc, VALUE *argv, VALUE _)
2184 {
2185 VALUE tag, value;
2186
2187 rb_scan_args(argc, argv, "11", &tag, &value);
2188 rb_throw_obj(tag, value);
2189 UNREACHABLE_RETURN(Qnil);
2190 }
2191
2192 void
2193 rb_throw_obj(VALUE tag, VALUE value)
2194 {
2195 rb_execution_context_t *ec = GET_EC();
2196 struct rb_vm_tag *tt = ec->tag;
2197
2198 while (tt) {
2199 if (tt->tag == tag) {
2200 tt->retval = value;
2201 break;
2202 }
2203 tt = tt->prev;
2204 }
2205 if (!tt) {
2206 VALUE desc[3];
2207 desc[0] = tag;
2208 desc[1] = value;
2209 desc[2] = rb_str_new_cstr("uncaught throw %p");
2210 rb_exc_raise(rb_class_new_instance(numberof(desc), desc, rb_eUncaughtThrow));
2211 }
2212
2213 ec->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
2214 EC_JUMP_TAG(ec, TAG_THROW);
2215 }
2216
2217 void
2218 rb_throw(const char *tag, VALUE val)
2219 {
2220 rb_throw_obj(rb_sym_intern_ascii_cstr(tag), val);
2221 }
2222
2223 static VALUE
2224 catch_i(RB_BLOCK_CALL_FUNC_ARGLIST(tag, _))
2225 {
2226 return rb_yield_0(1, &tag);
2227 }
2228
2229 /*
2230 * call-seq:
2231 * catch([tag]) {|tag| block } -> obj
2232 *
2233 * +catch+ executes its block. If +throw+ is not called, the block executes
2234 * normally, and +catch+ returns the value of the last expression evaluated.
2235 *
2236 * catch(1) { 123 } # => 123
2237 *
2238 * If <code>throw(tag2, val)</code> is called, Ruby searches up its stack for
2239 * a +catch+ block whose +tag+ has the same +object_id+ as _tag2_. When found,
2240 * the block stops executing and returns _val_ (or +nil+ if no second argument
2241 * was given to +throw+).
2242 *
2243 * catch(1) { throw(1, 456) } # => 456
2244 * catch(1) { throw(1) } # => nil
2245 *
2246 * When +tag+ is passed as the first argument, +catch+ yields it as the
2247 * parameter of the block.
2248 *
2249 * catch(1) {|x| x + 2 } # => 3
2250 *
2251 * When no +tag+ is given, +catch+ yields a new unique object (as from
2252 * +Object.new+) as the block parameter. This object can then be used as the
2253 * argument to +throw+, and will match the correct +catch+ block.
2254 *
2255 * catch do |obj_A|
2256 * catch do |obj_B|
2257 * throw(obj_B, 123)
2258 * puts "This puts is not reached"
2259 * end
2260 *
2261 * puts "This puts is displayed"
2262 * 456
2263 * end
2264 *
2265 * # => 456
2266 *
2267 * catch do |obj_A|
2268 * catch do |obj_B|
2269 * throw(obj_A, 123)
2270 * puts "This puts is still not reached"
2271 * end
2272 *
2273 * puts "Now this puts is also not reached"
2274 * 456
2275 * end
2276 *
2277 * # => 123
2278 */
2279
2280 static VALUE
2281 rb_f_catch(int argc, VALUE *argv, VALUE self)
2282 {
2283 VALUE tag = rb_check_arity(argc, 0, 1) ? argv[0] : rb_obj_alloc(rb_cObject);
2284 return rb_catch_obj(tag, catch_i, 0);
2285 }
2286
2287 VALUE
2288 rb_catch(const char *tag, rb_block_call_func_t func, VALUE data)
2289 {
2290 VALUE vtag = tag ? rb_sym_intern_ascii_cstr(tag) : rb_obj_alloc(rb_cObject);
2291 return rb_catch_obj(vtag, func, data);
2292 }
2293
2294 static VALUE
2295 vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data,
2296 enum ruby_tag_type *stateptr, rb_execution_context_t *volatile ec)
2297 {
2298 enum ruby_tag_type state;
2299 VALUE val = Qnil; /* OK */
2300 rb_control_frame_t *volatile saved_cfp = ec->cfp;
2301
2302 EC_PUSH_TAG(ec);
2303
2304 _tag.tag = tag;
2305
2306 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2307 /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
2308 val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil);
2309 }
2310 else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)ec->errinfo) == tag) {
2311 rb_vm_rewind_cfp(ec, saved_cfp);
2312 val = ec->tag->retval;
2313 ec->errinfo = Qnil;
2314 state = 0;
2315 }
2316 EC_POP_TAG();
2317 if (stateptr)
2318 *stateptr = state;
2319
2320 return val;
2321 }
2322
2323 VALUE
2324 rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr)
2325 {
2326 return vm_catch_protect(t, func, data, stateptr, GET_EC());
2327 }
2328
2329 VALUE
2330 rb_catch_obj(VALUE t, rb_block_call_func_t func, VALUE data)
2331 {
2332 enum ruby_tag_type state;
2333 rb_execution_context_t *ec = GET_EC();
2334 VALUE val = vm_catch_protect(t, (rb_block_call_func *)func, data, &state, ec);
2335 if (state) EC_JUMP_TAG(ec, state);
2336 return val;
2337 }
2338
2339 static void
2340 local_var_list_init(struct local_var_list *vars)
2341 {
2342 vars->tbl = rb_ident_hash_new();
2343 RBASIC_CLEAR_CLASS(vars->tbl);
2344 }
2345
2346 static VALUE
2347 local_var_list_finish(struct local_var_list *vars)
2348 {
2349 /* TODO: not to depend on the order of st_table */
2350 VALUE ary = rb_hash_keys(vars->tbl);
2351 rb_hash_clear(vars->tbl);
2352 vars->tbl = 0;
2353 return ary;
2354 }
2355
2356 static int
2357 local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
2358 {
2359 if (existing) return ST_STOP;
2360 *value = (st_data_t)Qtrue; /* INT2FIX(arg) */
2361 return ST_CONTINUE;
2362 }
2363
2364 static void
2365 local_var_list_add(const struct local_var_list *vars, ID lid)
2366 {
2367 if (lid && rb_is_local_id(lid)) {
2368 /* should skip temporary variable */
2369 st_data_t idx = 0; /* tbl->num_entries */
2370 rb_hash_stlike_update(vars->tbl, ID2SYM(lid), local_var_list_update, idx);
2371 }
2372 }
2373
2374 /*
2375 * call-seq:
2376 * local_variables -> array
2377 *
2378 * Returns the names of the current local variables.
2379 *
2380 * fred = 1
2381 * for i in 1..10
2382 * # ...
2383 * end
2384 * local_variables #=> [:fred, :i]
2385 */
2386
2387 static VALUE
2388 rb_f_local_variables(VALUE _)
2389 {
2390 struct local_var_list vars;
2391 rb_execution_context_t *ec = GET_EC();
2392 rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp));
2393 unsigned int i;
2394
2395 local_var_list_init(&vars);
2396 while (cfp) {
2397 if (cfp->iseq) {
2398 for (i = 0; i < cfp->iseq->body->local_table_size; i++) {
2399 local_var_list_add(&vars, cfp->iseq->body->local_table[i]);
2400 }
2401 }
2402 if (!VM_ENV_LOCAL_P(cfp->ep)) {
2403 /* block */
2404 const VALUE *ep = VM_CF_PREV_EP(cfp);
2405
2406 if (vm_collect_local_variables_in_heap(ep, &vars)) {
2407 break;
2408 }
2409 else {
2410 while (cfp->ep != ep) {
2411 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2412 }
2413 }
2414 }
2415 else {
2416 break;
2417 }
2418 }
2419 return local_var_list_finish(&vars);
2420 }
2421
2422 /*
2423 * call-seq:
2424 * block_given? -> true or false
2425 * iterator? -> true or false
2426 *
2427 * Returns <code>true</code> if <code>yield</code> would execute a
2428 * block in the current context. The <code>iterator?</code> form
2429 * is mildly deprecated.
2430 *
2431 * def try
2432 * if block_given?
2433 * yield
2434 * else
2435 * "no block"
2436 * end
2437 * end
2438 * try #=> "no block"
2439 * try { "hello" } #=> "hello"
2440 * try do "hello" end #=> "hello"
2441 */
2442
2443
2444 static VALUE
2445 rb_f_block_given_p(VALUE _)
2446 {
2447 rb_execution_context_t *ec = GET_EC();
2448 rb_control_frame_t *cfp = ec->cfp;
2449 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2450
2451 if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) {
2452 return Qtrue;
2453 }
2454 else {
2455 return Qfalse;
2456 }
2457 }
2458
2459 VALUE
2460 rb_current_realfilepath(void)
2461 {
2462 const rb_execution_context_t *ec = GET_EC();
2463 rb_control_frame_t *cfp = ec->cfp;
2464 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2465 if (cfp != 0) return rb_iseq_realpath(cfp->iseq);
2466 return Qnil;
2467 }
2468
2469 void
2470 Init_vm_eval(void)
2471 {
2472 rb_define_global_function("eval", rb_f_eval, -1);
2473 rb_define_global_function("local_variables", rb_f_local_variables, 0);
2474 rb_define_global_function("iterator?", rb_f_block_given_p, 0);
2475 rb_define_global_function("block_given?", rb_f_block_given_p, 0);
2476
2477 rb_define_global_function("catch", rb_f_catch, -1);
2478 rb_define_global_function("throw", rb_f_throw, -1);
2479
2480 rb_define_global_function("loop", rb_f_loop, 0);
2481
2482 rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval_internal, -1);
2483 rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec_internal, -1);
2484 rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1);
2485
2486 #if 1
2487 rb_add_method(rb_cBasicObject, id__send__,
2488 VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2489 rb_add_method(rb_mKernel, idSend,
2490 VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2491 #else
2492 rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
2493 rb_define_method(rb_mKernel, "send", rb_f_send, -1);
2494 #endif
2495 rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
2496
2497 rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec_internal, -1);
2498 rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec_internal, -1);
2499 rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval_internal, -1);
2500 rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval_internal, -1);
2501
2502 rb_eUncaughtThrow = rb_define_class("UncaughtThrowError", rb_eArgError);
2503 rb_define_method(rb_eUncaughtThrow, "initialize", uncaught_throw_init, -1);
2504 rb_define_method(rb_eUncaughtThrow, "tag", uncaught_throw_tag, 0);
2505 rb_define_method(rb_eUncaughtThrow, "value", uncaught_throw_value, 0);
2506 rb_define_method(rb_eUncaughtThrow, "to_s", uncaught_throw_to_s, 0);
2507
2508 id_result = rb_intern_const("result");
2509 id_tag = rb_intern_const("tag");
2510 id_value = rb_intern_const("value");
2511 }
2512
2513 #endif /* #ifndef MJIT_HEADER */
rb_iseq_realpath
VALUE rb_iseq_realpath(const rb_iseq_t *iseq)
Definition: iseq.c:1033
METHOD_VISI_PRIVATE
@ METHOD_VISI_PRIVATE
Definition: method.h:29
rb_check_block_call
VALUE rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2)
Definition: vm_eval.c:1528
rb_parser_new
VALUE rb_parser_new(void)
Definition: ripper.c:19224
rb_proc_lambda_p
VALUE rb_proc_lambda_p(VALUE)
Definition: proc.c:275
UNLIKELY
#define UNLIKELY(x)
Definition: ffi_common.h:126
ID
unsigned long ID
Definition: ruby.h:103
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:649
T_FALSE
#define T_FALSE
Definition: ruby.h:537
rescue_funcall_args::respond_to_missing
unsigned int respond_to_missing
Definition: vm_eval.c:402
rb_fstring
VALUE rb_fstring(VALUE)
Definition: string.c:312
rb_check_funcall_with_hook_kw
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)
Definition: vm_eval.c:539
rb_method_basic_definition_p
#define rb_method_basic_definition_p(klass, mid)
Definition: rb_mjit_min_header-2.7.0.h:7900
iter_method_arg::obj
VALUE obj
Definition: vm_eval.c:1453
MISSING_SUPER
@ MISSING_SUPER
Definition: internal.h:2335
TRUE
#define TRUE
Definition: nkf.h:175
rb_f_send
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:1188
rb_callable_method_entry_with_refinements
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:917
block_handler_type_iseq
@ block_handler_type_iseq
Definition: vm_core.h:738
rb_check_id
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:919
T_FLOAT
#define T_FLOAT
Definition: ruby.h:527
rb_str_new2
#define rb_str_new2
Definition: intern.h:903
vars
const VALUE int int int int int int VALUE * vars[]
Definition: rb_mjit_min_header-2.7.0.h:6462
reg_cfp
rb_control_frame_t * reg_cfp
Definition: rb_mjit_min_header-2.7.0.h:15146
rb_thread_struct::top_self
VALUE top_self
Definition: vm_core.h:923
rb_obj_instance_eval
VALUE rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:1995
rb_ast_struct::body
rb_ast_body_t body
Definition: node.h:402
eval_string_wrap_arg::klass
VALUE klass
Definition: vm_eval.c:1742
VM_FRAME_FLAG_FINISH
@ VM_FRAME_FLAG_FINISH
Definition: vm_core.h:1177
rb_block_call
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, VALUE data2)
Definition: vm_eval.c:1470
id
const int id
Definition: nkf.c:209
idEach
@ idEach
Definition: rb_mjit_min_header-2.7.0.h:8703
NORETURN
NORETURN(static void uncallable_object(VALUE recv, ID mid))
VM_METHOD_TYPE_REFINED
@ VM_METHOD_TYPE_REFINED
refinement
Definition: method.h:113
RB_PASS_CALLED_KEYWORDS
#define RB_PASS_CALLED_KEYWORDS
Definition: ruby.h:1980
rb_iseq_struct
Definition: vm_core.h:456
ruby_value_type
ruby_value_type
Definition: ruby.h:486
iter_method_arg::argc
int argc
Definition: vm_eval.c:1455
rb_method_definition_struct::method_serial
uintptr_t method_serial
Definition: method.h:180
va_arg
#define va_arg(v, l)
Definition: rb_mjit_min_header-2.7.0.h:3980
rb_vm_invoke_proc
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)
Definition: vm.c:1249
rb_ident_hash_new
VALUE rb_ident_hash_new(void)
Definition: hash.c:4203
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:1501
rb_iterate
VALUE rb_iterate(VALUE(*it_proc)(VALUE), VALUE data1, rb_block_call_func_t bl_proc, VALUE data2)
Definition: vm_eval.c:1444
rb_method_cfunc_struct::invoker
VALUE(* invoker)(VALUE recv, int argc, const VALUE *argv, VALUE(*func)(ANYARGS))
Definition: method.h:133
VM_METHOD_TYPE_OPTIMIZED
@ VM_METHOD_TYPE_OPTIMIZED
Kernel::send, Proc::call, etc.
Definition: method.h:111
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:313
rb_block_given_p
int rb_block_given_p(void)
Determines if the current method is given a block.
Definition: eval.c:897
rb_current_receiver
VALUE rb_current_receiver(void)
Definition: vm_eval.c:314
rb_method_definition_struct::attr
rb_method_attr_t attr
Definition: method.h:171
rb_iseq_disasm
VALUE rb_iseq_disasm(const rb_iseq_t *iseq)
Definition: iseq.c:2278
RBASIC_CLEAR_CLASS
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:1981
rb_funcallv_kw
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:962
rb_yield_values_kw
VALUE rb_yield_values_kw(int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:1277
ST_STOP
@ ST_STOP
Definition: st.h:99
rb_ast_dispose
void rb_ast_dispose(rb_ast_t *ast)
Definition: node.c:1389
rb_scan_args
#define rb_scan_args(argc, argvp, fmt,...)
Definition: rb_mjit_min_header-2.7.0.h:6372
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
rb_hash_clear
VALUE rb_hash_clear(VALUE hash)
Definition: hash.c:2696
T_MASK
#define T_MASK
Definition: md5.c:131
VM_FRAME_FLAG_CFRAME_EMPTY_KW
@ VM_FRAME_FLAG_CFRAME_EMPTY_KW
Definition: vm_core.h:1183
rb_call_cache::me
const struct rb_callable_method_entry_struct * me
Definition: internal.h:2373
rb_funcallv
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:956
PRIxVALUE
#define PRIxVALUE
Definition: ruby.h:164
rb_binding_t::pathobj
const VALUE pathobj
Definition: vm_core.h:1070
rb_yield_1
VALUE rb_yield_1(VALUE val)
Definition: vm_eval.c:1231
id_mesg
#define id_mesg
Definition: vm_eval.c:29
rb_empty_keyword_given_p
int rb_empty_keyword_given_p(void)
Definition: eval.c:918
rb_thread_struct::top_wrapper
VALUE top_wrapper
Definition: vm_core.h:924
rb_callable_method_entry_struct::owner
const VALUE owner
Definition: method.h:64
rb_attr_get
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1084
EXEC_EVENT_HOOK
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:1935
rb_throw_obj
void rb_throw_obj(VALUE tag, VALUE value)
Definition: vm_eval.c:2193
rb_method_attr_struct::id
ID id
Definition: method.h:138
rb_yield_refine_block
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1883
rb_type_str
const char * rb_type_str(enum ruby_value_type type)
Definition: vm_eval.c:572
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_adjust_argv_kw_splat
MJIT_FUNC_EXPORTED VALUE rb_adjust_argv_kw_splat(int *argc, const VALUE **argv, int *kw_splat)
Definition: vm_eval.c:237
rb_funcallv_public
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:980
rb_module_new
VALUE rb_module_new(void)
Definition: class.c:758
rb_eArgError
VALUE rb_eArgError
Definition: error.c:923
rb_lambda_call
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)
Definition: vm_eval.c:1501
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
VM_FRAME_MAGIC_CFUNC
@ VM_FRAME_MAGIC_CFUNC
Definition: vm_core.h:1167
rb_intern_const
#define rb_intern_const(str)
Definition: ruby.h:1879
rb_callable_method_entry_struct
Definition: method.h:59
rb_cModule
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:2034
VM_FRAME_FLAG_CFRAME
@ VM_FRAME_FLAG_CFRAME
Definition: vm_core.h:1179
block_handler_type_proc
@ block_handler_type_proc
Definition: vm_core.h:741
rb_current_realfilepath
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:2460
rb_name_err_new
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1592
rb_method_definition_struct::type
rb_method_type_t type
Definition: rb_mjit_min_header-2.7.0.h:8877
rescue_funcall_args
Definition: vm_eval.c:395
rb_define_global_function
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1787
rb_call_super
VALUE rb_call_super(int argc, const VALUE *argv)
Definition: vm_eval.c:306
EC_JUMP_TAG
#define EC_JUMP_TAG(ec, st)
Definition: eval_intern.h:184
rb_funcall_passing_block_kw
VALUE rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:1039
rb_iseq_constant_body::location
rb_iseq_location_t location
Definition: vm_core.h:399
RB_PASS_EMPTY_KEYWORDS
#define RB_PASS_EMPTY_KEYWORDS
Definition: ruby.h:1979
StringValue
use StringValue() instead")))
rb_execution_context_struct::tag
struct rb_vm_tag * tag
Definition: vm_core.h:849
VM_ENV_DATA_INDEX_SPECVAL
#define VM_ENV_DATA_INDEX_SPECVAL
Definition: vm_core.h:1194
rb_method_definition_struct::optimize_type
enum method_optimized_type optimize_type
Definition: method.h:176
rb_method_definition_struct::refined
rb_method_refined_t refined
Definition: method.h:173
rb_method_visibility_t
rb_method_visibility_t
Definition: method.h:26
vm_check_canary
#define vm_check_canary(ec, sp)
Definition: vm_insnhelper.c:257
ci
rb_control_frame_t struct rb_calling_info const struct rb_call_info * ci
Definition: rb_mjit_min_header-2.7.0.h:15146
rb_vm_tag::prev
struct rb_vm_tag * prev
Definition: vm_core.h:803
rb_method_refined_struct::orig_me
struct rb_method_entry_struct * orig_me
Definition: method.h:147
Qundef
#define Qundef
Definition: ruby.h:470
T_RATIONAL
#define T_RATIONAL
Definition: ruby.h:541
rb_catch_obj
VALUE rb_catch_obj(VALUE t, rb_block_call_func_t func, VALUE data)
Definition: vm_eval.c:2330
Check_TypedStruct
#define Check_TypedStruct(v, t)
Definition: ruby.h:1200
rb_captured_block::self
VALUE self
Definition: vm_core.h:728
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1551
GET_EC
#define GET_EC()
Definition: vm_core.h:1766
RUBY_VM_CHECK_INTS
#define RUBY_VM_CHECK_INTS(ec)
Definition: vm_core.h:1862
rb_eNameError
VALUE rb_eNameError
Definition: error.c:927
eval_string_wrap_arg::str
const char * str
Definition: vm_eval.c:1743
rb_hash_keys
MJIT_FUNC_EXPORTED VALUE rb_hash_keys(VALUE hash)
Definition: hash.c:3334
rb_calling_info
Definition: vm_core.h:250
ptr
struct RIMemo * ptr
Definition: debug.c:74
vm_ifunc
IFUNC (Internal FUNCtion)
Definition: internal.h:1215
iter_method_arg::kw_splat
int kw_splat
Definition: vm_eval.c:1457
T_DATA
#define T_DATA
Definition: ruby.h:538
Qfalse
#define Qfalse
Definition: ruby.h:467
idCall
@ idCall
Definition: rb_mjit_min_header-2.7.0.h:8727
RETURN_SIZED_ENUMERATOR
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
Definition: intern.h:271
DBL2NUM
#define DBL2NUM(dbl)
Definition: ruby.h:967
iter_method_arg::mid
ID mid
Definition: vm_eval.c:1454
rb_method_boundp
int rb_method_boundp(VALUE, ID, int)
Definition: vm_method.c:1102
rb_id2str
#define rb_id2str(id)
Definition: vm_backtrace.c:30
T_NODE
#define T_NODE
Definition: ruby.h:545
SPECIAL_CONST_P
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1313
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
T_COMPLEX
#define T_COMPLEX
Definition: ruby.h:542
SafeStringValue
#define SafeStringValue(v)
Definition: ruby.h:607
rb_eval_string_wrap
VALUE rb_eval_string_wrap(const char *str, int *pstate)
Evaluates the given string under a module binding in an isolated binding.
Definition: vm_eval.c:1767
rb_ec_stack_check
int rb_ec_stack_check(rb_execution_context_t *ec)
Definition: gc.c:4665
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
idSend
@ idSend
Definition: rb_mjit_min_header-2.7.0.h:8706
MISSING_NONE
@ MISSING_NONE
Definition: internal.h:2337
rb_funcallv_public_kw
VALUE rb_funcallv_public_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:986
rb_parser_warn_location
void rb_parser_warn_location(VALUE, int)
Definition: ripper.c:19047
rb_callable_method_entry
const RUBY_SYMBOL_EXPORT_END rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
Definition: vm_method.c:878
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:414
OPTIMIZED_METHOD_TYPE_SEND
@ OPTIMIZED_METHOD_TYPE_SEND
Definition: method.h:157
rb_funcall_with_block_kw
VALUE rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval, int kw_splat)
Definition: vm_eval.c:1060
OBJ_FREEZE
#define OBJ_FREEZE(x)
Definition: ruby.h:1377
rb_thread_struct::ec
rb_execution_context_t * ec
Definition: vm_core.h:915
T_SYMBOL
#define T_SYMBOL
Definition: ruby.h:540
T_OBJECT
#define T_OBJECT
Definition: ruby.h:523
rb_free_tmp_buffer
void rb_free_tmp_buffer(volatile VALUE *store)
Definition: gc.c:10257
VM_METHOD_TYPE_IVAR
@ VM_METHOD_TYPE_IVAR
attr_reader or attr_accessor
Definition: method.h:105
VM_ASSERT
#define VM_ASSERT(expr)
Definition: vm_core.h:56
block_handler
rb_control_frame_t struct rb_calling_info const struct rb_call_info VALUE block_handler
Definition: rb_mjit_min_header-2.7.0.h:15146
RB_BLOCK_CALL_FUNC_ARGLIST
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Definition: ruby.h:1964
iter_method_arg
Definition: vm_eval.c:1452
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
Definition: eval.c:1071
rb_check_arity
#define rb_check_arity
Definition: intern.h:347
CALL_VCALL
@ CALL_VCALL
Definition: vm_eval.c:34
MISSING_MISSING
@ MISSING_MISSING
Definition: internal.h:2336
VM_BLOCK_HANDLER_NONE
#define VM_BLOCK_HANDLER_NONE
Definition: vm_core.h:1291
RARRAY_LENINT
#define RARRAY_LENINT(ary)
Definition: ruby.h:1071
VM_METHOD_TYPE_UNDEF
@ VM_METHOD_TYPE_UNDEF
Definition: method.h:109
v
int VALUE v
Definition: rb_mjit_min_header-2.7.0.h:12332
rb_funcall_passing_block
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
Definition: vm_eval.c:1032
rb_control_frame_struct::sp
VALUE * sp
Definition: vm_core.h:762
cc
const struct rb_call_cache * cc
Definition: rb_mjit_min_header-2.7.0.h:13228
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
Definition: intern.h:57
rb_obj_instance_exec
VALUE rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:2027
rb_yield_force_blockarg
VALUE rb_yield_force_blockarg(VALUE values)
Definition: vm_eval.c:1309
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
RCLASS_ORIGIN
#define RCLASS_ORIGIN(c)
Definition: internal.h:1075
rb_method_definition_struct::cfunc
rb_method_cfunc_t cfunc
Definition: method.h:170
rb_call_cache
Definition: internal.h:2355
rb_ivar_get
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1070
T_FILE
#define T_FILE
Definition: ruby.h:534
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:847
rb_iseq_constant_body::local_table
const ID * local_table
Definition: vm_core.h:411
rb_each
VALUE rb_each(VALUE obj)
Definition: vm_eval.c:1542
CHECK_CFP_CONSISTENCY
#define CHECK_CFP_CONSISTENCY(func)
Definition: vm_insnhelper.c:2448
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
rb_hash_stlike_update
int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func func, st_data_t arg)
Definition: hash.c:1624
rb_obj_class
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
rb_method_definition_struct::body
union rb_method_definition_struct::@118 body
MISSING_PROTECTED
@ MISSING_PROTECTED
Definition: internal.h:2332
rb_special_singleton_class
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1621
RUBY_DTRACE_CMETHOD_ENTRY_HOOK
#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, klass, id)
Definition: probes_helper.h:36
rb_str_format
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:204
OPTIMIZED_METHOD_TYPE_CALL
@ OPTIMIZED_METHOD_TYPE_CALL
Definition: method.h:158
rb_vm_tag::retval
VALUE retval
Definition: vm_core.h:801
T_ICLASS
#define T_ICLASS
Definition: ruby.h:525
memcpy
void * memcpy(void *__restrict, const void *__restrict, size_t)
rb_ast_struct
Definition: node.h:399
HUGE_VAL
#define HUGE_VAL
Definition: missing.h:161
rb_f_eval
VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:1668
rb_vm_pop_cfunc_frame
MJIT_STATIC void rb_vm_pop_cfunc_frame(void)
Definition: rb_mjit_min_header-2.7.0.h:17268
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__
LIKELY
#define LIKELY(x)
Definition: ffi_common.h:125
EC_POP_TAG
#define EC_POP_TAG()
Definition: eval_intern.h:137
undefined
#define undefined
Definition: vm_method.c:36
rb_calling_info::kw_splat
int kw_splat
Definition: vm_core.h:254
rb_cBasicObject
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:2009
ALLOCV_END
#define ALLOCV_END(v)
Definition: ruby.h:1750
rb_captured_block::ep
const VALUE * ep
Definition: vm_core.h:729
rb_callable_method_entry_struct::defined_class
const VALUE defined_class
Definition: method.h:61
rb_str_intern
VALUE rb_str_intern(VALUE)
Definition: symbol.c:710
SDR
#define SDR()
Definition: vm_core.h:1639
rb_eval_cmd_kw
VALUE rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat)
Definition: vm_eval.c:1799
MISSING_VCALL
@ MISSING_VCALL
Definition: internal.h:2334
rb_nomethod_err_new
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
Definition: error.c:1673
METHOD_ENTRY_VISI
#define METHOD_ENTRY_VISI(me)
Definition: method.h:67
VM_CALL_KW_SPLAT
#define VM_CALL_KW_SPLAT
Definition: vm_core.h:1108
rb_iseq_location_struct::label
VALUE label
Definition: vm_core.h:275
ALLOCV_N
#define ALLOCV_N(type, v, n)
Definition: ruby.h:1749
ruby_eval_string_from_file
VALUE ruby_eval_string_from_file(const char *str, const char *filename)
Definition: vm_eval.c:1694
rb_iseq_constant_body::local_table_size
unsigned int local_table_size
Definition: vm_core.h:435
T_FIXNUM
#define T_FIXNUM
Definition: ruby.h:535
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
rb_vm_top_self
VALUE rb_vm_top_self(void)
Definition: vm.c:3345
rb_sym_proc_call
VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc)
Definition: string.c:10816
RHASH_EMPTY_P
#define RHASH_EMPTY_P(h)
Definition: ruby.h:1131
rb_vm_ifunc_new
struct vm_ifunc * rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc)
Definition: proc.c:699
rb_yield_splat
VALUE rb_yield_splat(VALUE values)
Definition: vm_eval.c:1283
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
VM_METHOD_TYPE_CFUNC
@ VM_METHOD_TYPE_CFUNC
C method.
Definition: method.h:103
rb_vm_call_kw
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)
Definition: vm_eval.c:265
rb_execution_context_struct::errinfo
VALUE errinfo
Definition: vm_core.h:875
rb_method_cfunc_struct::func
VALUE(* func)(ANYARGS)
Definition: method.h:132
rb_check_funcall_hook
void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE)
Definition: internal.h:2308
T_REGEXP
#define T_REGEXP
Definition: ruby.h:529
VM_METHOD_TYPE_NOTIMPLEMENTED
@ VM_METHOD_TYPE_NOTIMPLEMENTED
Definition: method.h:110
rb_cref_struct
CREF (Class REFerence)
Definition: method.h:41
call_type
call_type
Definition: vm_eval.c:31
id__send__
@ id__send__
Definition: rb_mjit_min_header-2.7.0.h:8707
rb_resolve_refined_method_callable
const MJIT_FUNC_EXPORTED rb_callable_method_entry_t * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
Definition: vm_method.c:979
rb_check_funcall_default
VALUE rb_check_funcall_default(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def)
Definition: vm_eval.c:533
VM_ENV_FLAG_LOCAL
@ VM_ENV_FLAG_LOCAL
Definition: vm_core.h:1186
MISSING_FCALL
@ MISSING_FCALL
Definition: internal.h:2333
type_case
#define type_case(t)
vm_throw_data
THROW_DATA.
Definition: internal.h:1193
VM_METHOD_TYPE_BMETHOD
@ VM_METHOD_TYPE_BMETHOD
Definition: method.h:106
EC_EXEC_TAG
#define EC_EXEC_TAG()
Definition: eval_intern.h:181
METHOD_ENTRY_BASIC
#define METHOD_ENTRY_BASIC(me)
Definition: method.h:68
va_end
#define va_end(v)
Definition: rb_mjit_min_header-2.7.0.h:3979
rb_block_call_func
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
Definition: ruby.h:1966
rb_binding_t::block
const struct rb_block block
Definition: vm_core.h:1069
stderr
#define stderr
Definition: rb_mjit_min_header-2.7.0.h:1485
min_argc
const rb_iseq_t const int const int min_argc
Definition: rb_mjit_min_header-2.7.0.h:13505
rb_call_data::cc
struct rb_call_cache cc
Definition: internal.h:2394
eval_string_wrap_arg
Definition: vm_eval.c:1740
rescue_funcall_args::respond
unsigned int respond
Definition: vm_eval.c:401
T_CLASS
#define T_CLASS
Definition: ruby.h:524
rb_catch_protect
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr)
Definition: vm_eval.c:2324
T_MATCH
#define T_MATCH
Definition: ruby.h:539
RAISED_STACKOVERFLOW
@ RAISED_STACKOVERFLOW
Definition: eval_intern.h:255
rb_ary_subseq
#define rb_ary_subseq(ary, beg, len)
Definition: cparse.c:76
block_handler_type_ifunc
@ block_handler_type_ifunc
Definition: vm_core.h:739
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:920
ALLOCA_N
#define ALLOCA_N(type, n)
Definition: ruby.h:1684
METHOD_VISI_PROTECTED
@ METHOD_VISI_PROTECTED
Definition: method.h:30
rb_yield_splat_kw
VALUE rb_yield_splat_kw(VALUE values, int kw_splat)
Definition: vm_eval.c:1296
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_control_frame_struct
Definition: vm_core.h:760
rb_eval_cmd
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int _level)
Definition: vm_eval.c:1822
iter_method_arg::argv
const VALUE * argv
Definition: vm_eval.c:1456
StringValuePtr
#define StringValuePtr(v)
Definition: ruby.h:603
rb_vm_tag::tag
VALUE tag
Definition: vm_core.h:800
rescue_funcall_args::defined_class
VALUE defined_class
Definition: vm_eval.c:396
rb_execution_context_struct::method_missing_reason
enum method_missing_reason method_missing_reason
Definition: rb_mjit_min_header-2.7.0.h:9869
rescue_funcall_args::argc
int argc
Definition: vm_eval.c:403
FALSE
#define FALSE
Definition: nkf.h:174
RCLASS_SUPER
#define RCLASS_SUPER(c)
Definition: classext.h:16
VM_FRAME_FLAG_CFRAME_KW
@ VM_FRAME_FLAG_CFRAME_KW
Definition: vm_core.h:1182
RSTRING_FSTR
@ RSTRING_FSTR
Definition: ruby.h:983
TAG_RETRY
#define TAG_RETRY
Definition: vm_core.h:201
VM_METHOD_TYPE_ZSUPER
@ VM_METHOD_TYPE_ZSUPER
Definition: method.h:107
METHOD_VISI_PUBLIC
@ METHOD_VISI_PUBLIC
Definition: method.h:28
rb_parser_compile_string_path
rb_ast_t * rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
Definition: ripper.c:12897
CALL_TYPE_MAX
@ CALL_TYPE_MAX
Definition: vm_eval.c:37
rb_yield_block
VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(val, arg))
Definition: vm_eval.c:1315
rb_check_funcall_kw
VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:499
rb_vm_tag::state
enum ruby_tag_type state
Definition: vm_core.h:804
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: rb_mjit_min_header-2.7.0.h:6117
local_var_list::tbl
VALUE tbl
Definition: vm_eval.c:26
calling
rb_control_frame_t struct rb_calling_info * calling
Definition: rb_mjit_min_header-2.7.0.h:14544
T_NONE
#define T_NONE
Definition: ruby.h:521
rescue_funcall_args::kw_splat
int kw_splat
Definition: vm_eval.c:405
rb_ec_raised_set
#define rb_ec_raised_set(ec, f)
Definition: eval_intern.h:258
me
const rb_callable_method_entry_t * me
Definition: rb_mjit_min_header-2.7.0.h:13226
rb_extend_object
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
Definition: eval.c:1700
call_status
int const VALUE VALUE int call_status
Definition: rb_mjit_min_header-2.7.0.h:15420
GetProcPtr
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:1046
rb_check_array_type
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:909
key
key
Definition: openssl_missing.h:181
T_HASH
#define T_HASH
Definition: ruby.h:531
ruby_binding_data_type
const rb_data_type_t ruby_binding_data_type
Definition: proc.c:319
rb_yield_values2
VALUE rb_yield_values2(int argc, const VALUE *argv)
Definition: vm_eval.c:1271
RARRAY_CONST_PTR
#define RARRAY_CONST_PTR(a)
Definition: ruby.h:1072
rb_eNotImpError
VALUE rb_eNotImpError
Definition: error.c:932
CLASS_OF
#define CLASS_OF(v)
Definition: ruby.h:484
rb_vm_tag
Definition: vm_core.h:799
src
__inline__ const void *__restrict src
Definition: rb_mjit_min_header-2.7.0.h:2836
rb_mod_module_eval
VALUE rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
Definition: vm_eval.c:2067
va_init_list
#define va_init_list(a, b)
Definition: win32ole.h:34
rb_apply
VALUE rb_apply(VALUE recv, ID mid, VALUE args)
Calls a method.
Definition: vm_eval.c:890
rb_eNoMethodError
VALUE rb_eNoMethodError
Definition: error.c:930
T_MODULE
#define T_MODULE
Definition: ruby.h:526
rb_cref_struct::klass
VALUE klass
Definition: method.h:44
rb_vm_frame_method_entry
const MJIT_STATIC rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
Definition: rb_mjit_min_header-2.7.0.h:12521
rb_check_funcall
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Definition: vm_eval.c:505
rb_sym_intern_ascii_cstr
#define rb_sym_intern_ascii_cstr(ptr)
Definition: rb_mjit_min_header-2.7.0.h:7758
rb_ary_new4
#define rb_ary_new4
Definition: intern.h:105
rb_method_type_t
rb_method_type_t
Definition: method.h:101
FL_TEST_RAW
#define FL_TEST_RAW(x, f)
Definition: ruby.h:1352
rb_eval_string
VALUE rb_eval_string(const char *str)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1713
rb_throw
void rb_throw(const char *tag, VALUE val)
Definition: vm_eval.c:2218
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:2010
rb_add_method
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
Definition: vm_method.c:674
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:667
T_BIGNUM
#define T_BIGNUM
Definition: ruby.h:533
local_var_list
Definition: vm_eval.c:14
rescue_funcall_args::mid
ID mid
Definition: vm_eval.c:398
VM_METHOD_TYPE_MISSING
@ VM_METHOD_TYPE_MISSING
wrapper for method_missing(id)
Definition: method.h:112
rb_method_cfunc_struct::argc
int argc
Definition: method.h:134
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:634
rb_control_frame_struct::self
VALUE self
Definition: vm_core.h:764
RUBY_DTRACE_CMETHOD_RETURN_HOOK
#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, klass, id)
Definition: probes_helper.h:39
rb_block_call_func_t
rb_block_call_func * rb_block_call_func_t
Definition: ruby.h:1967
T_ARRAY
#define T_ARRAY
Definition: ruby.h:530
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.0.h:5601
rb_mKernel
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1998
argv
char ** argv
Definition: ruby.c:223
rb_funcall
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
Definition: vm_eval.c:922
ST_CONTINUE
@ ST_CONTINUE
Definition: st.h:99
rb_vm_rewind_cfp
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp)
Definition: vm.c:604
rb_vm_get_ruby_level_next_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)
Definition: vm.c:553
VM_METHOD_TYPE_ATTRSET
@ VM_METHOD_TYPE_ATTRSET
attr_writer or attr_accessor
Definition: method.h:104
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
eval_string_wrap_arg::top_self
VALUE top_self
Definition: vm_eval.c:1741
st_data_t
unsigned long st_data_t
Definition: rb_mjit_min_header-2.7.0.h:5363
vm_exec
VALUE vm_exec(rb_execution_context_t *ec, int mjit_enable_p)
Definition: vm.c:1909
rb_calling_info::recv
VALUE recv
Definition: vm_core.h:252
T_NIL
#define T_NIL
Definition: ruby.h:522
rb_obj_alloc
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
Definition: object.c:1895
T_MOVED
#define T_MOVED
Definition: ruby.h:547
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
GET_THREAD
#define GET_THREAD()
Definition: vm_core.h:1765
BOUND_RESPONDS
#define BOUND_RESPONDS
Definition: vm_method.c:1099
PASS_PASSED_BLOCK_HANDLER
#define PASS_PASSED_BLOCK_HANDLER()
Definition: eval_intern.h:23
rb_control_frame_struct::iseq
const rb_iseq_t * iseq
Definition: vm_core.h:763
rb_captured_block::code
union rb_captured_block::@186 code
rb_captured_block
Definition: vm_core.h:727
T_ZOMBIE
#define T_ZOMBIE
Definition: ruby.h:546
MEMCPY
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1753
rb_parser_set_context
VALUE rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main)
Definition: ripper.c:19234
PASS_PASSED_BLOCK_HANDLER_EC
#define PASS_PASSED_BLOCK_HANDLER_EC(ec)
Definition: eval_intern.h:22
rescue_funcall_args::ec
rb_execution_context_t * ec
Definition: vm_eval.c:399
rb_eval_string_protect
VALUE rb_eval_string_protect(const char *str, int *pstate)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1735
rescue_funcall_args::recv
VALUE recv
Definition: vm_eval.c:397
idMethodMissing
@ idMethodMissing
Definition: rb_mjit_min_header-2.7.0.h:8692
Init_vm_eval
void Init_vm_eval(void)
Definition: vm_eval.c:2470
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
TAG_NONE
#define TAG_NONE
Definition: vm_core.h:197
block_handler_type_symbol
@ block_handler_type_symbol
Definition: vm_core.h:740
rb_binding_t
Definition: vm_core.h:1068
BOUND_PRIVATE
#define BOUND_PRIVATE
Definition: vm_method.c:1098
argc
int argc
Definition: ruby.c:222
VM_METHOD_TYPE_ISEQ
@ VM_METHOD_TYPE_ISEQ
Ruby method.
Definition: method.h:102
T_IMEMO
#define T_IMEMO
Definition: ruby.h:543
rb_ec_stack_overflow
MJIT_STATIC void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit)
Definition: vm_insnhelper.c:67
rb_singleton_class
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1725
RB_NO_KEYWORDS
#define RB_NO_KEYWORDS
Definition: ruby.h:1977
rb_catch
VALUE rb_catch(const char *tag, rb_block_call_func_t func, VALUE data)
Definition: vm_eval.c:2288
CALL_FCALL
@ CALL_FCALL
Definition: vm_eval.c:33
err
int err
Definition: win32.c:135
rb_is_local_id
int rb_is_local_id(ID id)
Definition: symbol.c:884
BUILTIN_TYPE
#define BUILTIN_TYPE(x)
Definition: ruby.h:551
rb_iseq_new_with_opt
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)
Definition: iseq.c:807
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:179
rb_call_data::ci
struct rb_call_info ci
Definition: internal.h:2395
rb_vm_pop_frame
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
Definition: rb_mjit_min_header-2.7.0.h:12308
RBASIC
#define RBASIC(obj)
Definition: ruby.h:1267
MISSING_NOENTRY
@ MISSING_NOENTRY
Definition: internal.h:2330
MJIT_FUNC_EXPORTED
#define MJIT_FUNC_EXPORTED
Definition: defines.h:396
_
#define _(args)
Definition: dln.h:28
EC_PUSH_TAG
#define EC_PUSH_TAG(ec)
Definition: eval_intern.h:130
RUBY_EVENT_C_RETURN
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:2248
rb_callable_method_entry_struct::def
struct rb_method_definition_struct *const def
Definition: method.h:62
rescue_funcall_args::me
const rb_method_entry_t * me
Definition: vm_eval.c:400
Qtrue
#define Qtrue
Definition: ruby.h:468
rb_eStopIteration
VALUE rb_eStopIteration
Definition: enumerator.c:124
rb_rescue2
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
Definition: eval.c:961
rb_control_frame_struct::ep
const VALUE * ep
Definition: vm_core.h:765
len
uint8_t len
Definition: escape.c:17
rb_call_super_kw
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
Definition: vm_eval.c:298
SYMBOL_P
#define SYMBOL_P(x)
Definition: ruby.h:413
rb_keyword_given_p
int rb_keyword_given_p(void)
Definition: eval.c:910
rb_funcall_with_block
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
Definition: vm_eval.c:1050
rb_method_entry_struct
Definition: method.h:51
rb_iseq_struct::body
struct rb_iseq_constant_body * body
Definition: vm_core.h:460
rb_class_new_instance
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
Definition: object.c:1955
rb_yield_values
VALUE rb_yield_values(int n,...)
Definition: vm_eval.c:1249
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1300
T_STRING
#define T_STRING
Definition: ruby.h:528
rb_block
Definition: vm_core.h:751
RUBY_EVENT_C_CALL
#define RUBY_EVENT_C_CALL
Definition: ruby.h:2247
TAG_BREAK
#define TAG_BREAK
Definition: vm_core.h:199
va_list
__gnuc_va_list va_list
Definition: rb_mjit_min_header-2.7.0.h:836
iseq
const rb_iseq_t * iseq
Definition: rb_mjit_min_header-2.7.0.h:13504
rb_yield
VALUE rb_yield(VALUE val)
Definition: vm_eval.c:1237
rb_block_call_kw
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)
Definition: vm_eval.c:1484
rb_method_cfunc_struct
Definition: method.h:131
rb_call_info
Definition: internal.h:2387
rb_check_funcall_with_hook
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg)
Definition: vm_eval.c:565
RARRAY_CONST_PTR_TRANSIENT
#define RARRAY_CONST_PTR_TRANSIENT(a)
Definition: ruby.h:1073
rb_ast_body_struct::root
const NODE * root
Definition: node.h:395
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
T_STRUCT
#define T_STRUCT
Definition: ruby.h:532
Qnil
#define Qnil
Definition: ruby.h:469
realpath
char * realpath(const char *__restrict path, char *__restrict resolved_path)
rb_fstring_lit
#define rb_fstring_lit(str)
Definition: internal.h:2123
rb_captured_block::ifunc
const struct vm_ifunc * ifunc
Definition: vm_core.h:732
exc
const rb_iseq_t const VALUE exc
Definition: rb_mjit_min_header-2.7.0.h:13504
method_missing_reason
method_missing_reason
Definition: internal.h:2329
rb_mod_module_exec
VALUE rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
Definition: vm_eval.c:2101
rb_vm_cref_new_toplevel
rb_cref_t * rb_vm_cref_new_toplevel(void)
Definition: vm.c:298
UNALIGNED_MEMBER_PTR
#define UNALIGNED_MEMBER_PTR(ptr, mem)
Definition: internal.h:2685
RB_GC_GUARD
#define RB_GC_GUARD(v)
Definition: ruby.h:585
numberof
#define numberof(array)
Definition: etc.c:618
rb_thread_struct
Definition: vm_core.h:910
UNREACHABLE_RETURN
#define UNREACHABLE_RETURN(val)
Definition: ruby.h:59
rb_call_data
Definition: internal.h:2393
rb_proc_t
Definition: vm_core.h:1049
block_type_iseq
@ block_type_iseq
Definition: vm_core.h:745
rb_ec_raised_p
#define rb_ec_raised_p(ec, f)
Definition: eval_intern.h:260
rb_define_private_method
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1569
RUBY_VM_PREVIOUS_CONTROL_FRAME
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1384
TAG_THROW
#define TAG_THROW
Definition: vm_core.h:204
CALL_PUBLIC_KW
@ CALL_PUBLIC_KW
Definition: vm_eval.c:35
rb_make_no_method_exception
MJIT_FUNC_EXPORTED VALUE rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj, int argc, const VALUE *argv, int priv)
Definition: vm_eval.c:772
T_TRUE
#define T_TRUE
Definition: ruby.h:536
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:692
ruby_tag_type
ruby_tag_type
Definition: vm_core.h:184
rb_vm_call0
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)
Definition: vm_eval.c:46
rb_binding_t::first_lineno
unsigned short first_lineno
Definition: vm_core.h:1071
max_argc
const rb_iseq_t const int const int const int max_argc
Definition: rb_mjit_min_header-2.7.0.h:13505
RTEST
#define RTEST(v)
Definition: ruby.h:481
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
VM_METHOD_TYPE_ALIAS
@ VM_METHOD_TYPE_ALIAS
Definition: method.h:108
SYM2ID
#define SYM2ID(x)
Definition: ruby.h:415
rescue_funcall_args::argv
const VALUE * argv
Definition: vm_eval.c:404
CHECK_VM_STACK_OVERFLOW
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
Definition: vm_core.h:1746
T_UNDEF
#define T_UNDEF
Definition: ruby.h:544
CALL_PUBLIC
@ CALL_PUBLIC
Definition: vm_eval.c:32
rb_obj_clone
VALUE rb_obj_clone(VALUE)
Almost same as Object::clone.
Definition: object.c:410
CALL_FCALL_KW
@ CALL_FCALL_KW
Definition: vm_eval.c:36
UNDEFINED_METHOD_ENTRY_P
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:186
cfp
rb_control_frame_t * cfp
Definition: rb_mjit_min_header-2.7.0.h:14544
MISSING_PRIVATE
@ MISSING_PRIVATE
Definition: internal.h:2331
rb_source_location
VALUE rb_source_location(int *pline)
Definition: vm.c:1360
name
const char * name
Definition: nkf.c:208
rb_execution_context_struct
Definition: vm_core.h:843