2 insns.def
- YARV instruction definitions
5 created at
: 04/01/01 01:17:55 JST
7 Copyright (C
) 2004-2007 Koichi Sasada
8 Massive rewrite by @shyouhei in
2017.
11 /* Some comments about this file
's contents:
13 - The new format aims to be editable by C editor of your choice;
14 your mileage might vary of course.
16 - Each instructions are in following format:
20 (type operand, type operand, ..)
23 // attr type name contents..
28 - Unlike the old format which was line-oriented, you can now place
29 newlines and comments at liberal positions.
31 - `DEFINE_INSN` is a keyword.
33 - An instruction name must be a valid C identifier.
35 - Operands, pop values, return values are series of either variable
36 declarations, keyword `void`, or keyword `...`. They are much
37 like C function declarations.
39 - Attribute pragmas are optional, and can include arbitrary C
40 expressions. You can write anything there but as of writing,
41 supported attributes are:
43 * sp_inc: Used to dynamically calculate sp increase in
44 `insn_stack_increase`.
46 * handles_sp: If it is true, VM deals with sp in the insn.
47 Default is if the instruction takes ISEQ operand or not.
49 * leaf: indicates that the instruction is "leaf" i.e. it does
50 not introduce new stack frame on top of it.
51 If an instruction handles sp, that can never be a leaf.
53 - Attributes can access operands, but not stack (push/pop) variables.
55 - An instruction's body is a pure C block
, copied verbatimly into
56 the generated C source code.
69 /**********************************************************/
70 /* deal with variables
*/
71 /**********************************************************/
73 /* Get local
variable (pointed by `idx
' and `level').
74 'level' indicates the nesting depth from the current block.
78 (lindex_t idx
, rb_num_t level
)
82 val
= *(vm_get_ep(GET_EP(), level
) - idx
);
83 RB_DEBUG_COUNTER_INC(lvar_get
);
84 (void
)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic
, level
> 0);
87 /* Set a local
variable (pointed to by
'idx') as val.
88 'level' indicates the nesting depth from the current block.
92 (lindex_t idx
, rb_num_t level
)
96 vm_env_write(vm_get_ep(GET_EP(), level
), -(int
)idx
, val
);
97 RB_DEBUG_COUNTER_INC(lvar_set
);
98 (void
)RB_DEBUG_COUNTER_INC_IF(lvar_set_dynamic
, level
> 0);
101 /* Get a block parameter.
*/
104 (lindex_t idx
, rb_num_t level
)
108 const VALUE
*ep
= vm_get_ep(GET_EP(), level
);
109 VM_ASSERT(VM_ENV_LOCAL_P(ep
));
111 if (!VM_ENV_FLAGS(ep
, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM
)) {
112 val
= rb_vm_bh_to_procval(ec
, VM_ENV_BLOCK_HANDLER(ep
));
113 vm_env_write(ep
, -(int
)idx
, val
);
114 VM_ENV_FLAGS_SET(ep
, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM
);
118 RB_DEBUG_COUNTER_INC(lvar_get
);
119 (void
)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic
, level
> 0);
123 /* Set block parameter.
*/
126 (lindex_t idx
, rb_num_t level
)
130 const VALUE
*ep
= vm_get_ep(GET_EP(), level
);
131 VM_ASSERT(VM_ENV_LOCAL_P(ep
));
133 vm_env_write(ep
, -(int
)idx
, val
);
134 RB_DEBUG_COUNTER_INC(lvar_set
);
135 (void
)RB_DEBUG_COUNTER_INC_IF(lvar_set_dynamic
, level
> 0);
137 VM_ENV_FLAGS_SET(ep
, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM
);
140 /* Get special proxy object which only responds to `call` method if the block parameter
141 represents a iseq
/ifunc block. Otherwise
, same as `getblockparam`.
145 (lindex_t idx
, rb_num_t level
)
149 const VALUE
*ep
= vm_get_ep(GET_EP(), level
);
150 VM_ASSERT(VM_ENV_LOCAL_P(ep
));
152 if (!VM_ENV_FLAGS(ep
, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM
)) {
153 VALUE block_handler
= VM_ENV_BLOCK_HANDLER(ep
);
156 switch (vm_block_handler_type(block_handler
)) {
157 case block_handler_type_iseq
:
158 case block_handler_type_ifunc
:
159 val
= rb_block_param_proxy
;
161 case block_handler_type_symbol
:
162 val
= rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler
));
163 goto
INSN_LABEL(set
);
164 case block_handler_type_proc
:
165 val
= VM_BH_TO_PROC(block_handler
);
166 goto
INSN_LABEL(set
);
168 VM_UNREACHABLE(getblockparamproxy
);
174 vm_env_write(ep
, -(int
)idx
, val
);
175 VM_ENV_FLAGS_SET(ep
, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM
);
180 RB_DEBUG_COUNTER_INC(lvar_get
);
181 (void
)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic
, level
> 0);
185 /* Get value of special local
variable ($~
, $_
, ..
).
*/
188 (rb_num_t key
, rb_num_t type
)
191 /* `$~
= MatchData.allocate
; $
&` can raise.
*/
192 // attr bool leaf
= (type
== 0) ? true
: false
;
194 val
= vm_getspecial(ec
, GET_LEP(), key
, type
);
197 /* Set value of special local
variable ($~
, $_
, ...
) to obj.
*/
204 lep_svar_set(ec
, GET_LEP(), key
, obj
);
207 /* Get value of instance variable id of self.
*/
213 /* Ractor crashes when it accesses class
/module
-level instances variables.
*/
214 // attr bool leaf
= false
; /* has
IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR() */
216 val
= vm_getinstancevariable(GET_ISEQ(), GET_SELF(), id
, ic
);
219 /* Set value of instance variable id of self to val.
*/
225 // attr bool leaf
= false
; /* has
rb_check_frozen_internal() */
227 vm_setinstancevariable(GET_ISEQ(), GET_SELF(), id
, val
, ic
);
230 /* Get value of class variable id of klass as val.
*/
236 /* "class variable access from toplevel" warning can be hooked.
*/
237 // attr bool leaf
= false
; /* has
rb_warning() */
239 rb_control_frame_t
*cfp
= GET_CFP();
240 val
= vm_getclassvariable(GET_ISEQ(), cfp
, id
, (ICVARC
)ic
);
243 /* Set value of class variable id of klass as val.
*/
249 /* "class variable access from toplevel" warning can be hooked.
*/
250 // attr bool leaf
= false
; /* has
rb_warning() */
252 vm_ensure_not_refinement_module(GET_SELF());
253 vm_setclassvariable(GET_ISEQ(), GET_CFP(), id
, val
, (ICVARC
)ic
);
256 /* Get constant variable id. If klass is Qnil and allow_nil is Qtrue
, constants
257 are searched in the current scope. Otherwise
, get constant under klass
263 (VALUE klass
, VALUE allow_nil
)
265 /* getconstant can kick autoload
*/
266 // attr bool leaf
= false
; /* has
rb_autoload_load() */
268 val
= vm_get_ev_const(ec
, klass
, id
, allow_nil
== Qtrue
, 0);
271 /* Set constant variable id under cbase class or module.
276 (VALUE val
, VALUE cbase
)
278 /* Assigning an object to a constant is basically a leaf operation.
279 * The problem is
, assigning a Module instance to a constant _names_
280 * that module. Naming involves string manipulations
, which are
282 // attr bool leaf
= false
; /* has
StringValue() */
284 vm_check_if_namespace(cbase
);
285 vm_ensure_not_refinement_module(GET_SELF());
286 rb_const_set(cbase
, id
, val
);
289 /* get global variable id.
*/
295 // attr bool leaf
= false
;
297 val
= rb_gvar_get(gid
);
300 /* set global variable id as val.
*/
306 // attr bool leaf
= false
;
308 rb_gvar_set(gid
, val
);
311 /**********************************************************/
312 /* deal with values
*/
313 /**********************************************************/
315 /* put nil to stack.
*/
336 i.e. Fixnum
, true
, false
, nil
, and so on.
347 /* put special object.
"value_type" is for expansion.
*/
350 (rb_num_t value_type
)
353 // attr bool leaf
= (value_type
== VM_SPECIAL_OBJECT_VMCORE
); /* others may raise when allocating singleton
*/
355 enum vm_special_object_type type
;
357 type
= (enum vm_special_object_type
)value_type
;
358 val
= vm_get_special_object(GET_EP(), type
);
361 /* put string val. string will be copied.
*/
368 val
= rb_ec_str_resurrect(ec
, str
);
371 /* put concatenate strings
*/
377 /* This instruction can concat UTF
-8 and binary strings
, resulting in
378 * Encoding
::CompatibilityError.
*/
379 // attr bool leaf
= false
; /* has
rb_enc_cr_str_buf_cat() */
380 // attr rb_snum_t sp_inc
= 1 - (rb_snum_t
)num
;
382 val
= rb_str_concat_literals(num
, STACK_ADDR_FROM_TOP(num
));
385 /* Convert the result to string if not already a string.
386 This is used as a backup if to_s does not return a string.
*/
390 (VALUE val
, VALUE str
)
393 val
= rb_obj_as_string_result(str
, val
);
396 /* compile str to Regexp and push it.
397 opt is the option for the Regexp.
401 (rb_num_t opt
, rb_num_t cnt
)
404 /* This instruction can raise RegexpError
, thus can call
405 * RegexpError#initialize
*/
406 // attr bool leaf
= false
;
407 // attr rb_snum_t sp_inc
= 1 - (rb_snum_t
)cnt
;
409 const VALUE ary
= rb_ary_tmp_new_from_values(0, cnt
, STACK_ADDR_FROM_TOP(cnt
));
410 val
= rb_reg_new_ary(ary
, (int
)opt
);
414 /* intern str to Symbol and push it.
*/
421 sym
= rb_str_intern(str
);
424 /* put new array initialized with num values on the stack.
*/
430 // attr rb_snum_t sp_inc
= 1 - (rb_snum_t
)num
;
432 val
= rb_ec_ary_new_from_values(ec
, num
, STACK_ADDR_FROM_TOP(num
));
435 /* put new array initialized with num values on the stack. There
436 should be at least one element on the stack
, and the top element
437 should be a hash. If the top element is empty
, it is not
438 included in the array.
445 // attr rb_snum_t sp_inc
= 1 - (rb_snum_t
)num
;
447 if (RHASH_EMPTY_P(*STACK_ADDR_FROM_TOP(1))) {
448 val = rb_ary_new4(num-1, STACK_ADDR_FROM_TOP(num));
451 val = rb_ary_new4(num, STACK_ADDR_FROM_TOP(num));
462 RUBY_DTRACE_CREATE_HOOK(ARRAY, RARRAY_LEN(ary));
463 val = rb_ary_resurrect(ary);
473 RUBY_DTRACE_CREATE_HOOK(HASH, RHASH_SIZE(hash) << 1);
474 val = rb_hash_resurrect(hash);
477 /* if TOS is an array expand, expand it to num objects.
478 if the number of the array is less than num, push nils to fill.
479 if it is greater than num, exceeding elements are dropped.
480 unless TOS is an array, push num - 1 nils.
481 if flags is non-zero, push the array of the rest elements.
482 flag: 0x01 - rest args array
483 flag: 0x02 - for postarg
484 flag: 0x04 - reverse?
488 (rb_num_t num, rb_num_t flag)
491 // attr bool leaf = false; /* has rb_check_array_type() */
492 // attr rb_snum_t sp_inc = (rb_snum_t)num - 1 + (flag & 1 ? 1 : 0);
494 vm_expandarray(GET_SP(), ary, num, (int)flag);
497 /* concat two arrays */
501 (VALUE ary1, VALUE ary2)
503 // attr bool leaf = false; /* has rb_check_array_type() */
505 ary = vm_concat_array(ary1, ary2);
508 /* call to_a on array ary to splat */
514 // attr bool leaf = false; /* has rb_check_array_type() */
516 obj = vm_splat_array(flag, ary);
519 /* put new Hash from n elements. n must be an even number. */
525 // attr bool leaf = false; /* has rb_hash_key_str() */
526 // attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
528 RUBY_DTRACE_CREATE_HOOK(HASH, num);
531 val = rb_hash_new_with_size(num / 2);
532 rb_hash_bulk_insert(num, STACK_ADDR_FROM_TOP(num), val);
539 /* put new Range object.(Range.new(low, high, flag)) */
543 (VALUE low, VALUE high)
545 /* rb_range_new() exercises "bad value for range" check. */
546 // attr bool leaf = false; /* see also: range.c:range_init() */
548 val = rb_range_new(low, high, (int)flag);
551 /**********************************************************/
552 /* deal with stack operation */
553 /**********************************************************/
555 /* pop from stack. */
566 /* duplicate stack top. */
571 (VALUE val1, VALUE val2)
576 /* duplicate stack top n elements */
582 // attr rb_snum_t sp_inc = n;
584 void *dst = GET_SP();
585 void *src = STACK_ADDR_FROM_TOP(n);
587 MEMCPY(dst, src, VALUE, n);
590 /* swap top 2 vals */
594 (VALUE val, VALUE obj)
595 (VALUE obj, VALUE val)
600 /* for stack caching. */
601 DEFINE_INSN_IF(STACK_CACHING)
606 // attr rb_snum_t sp_inc = 0;
611 /* get nth stack value from stack top */
617 // attr rb_snum_t sp_inc = 1;
622 /* set Nth stack entry to stack top */
628 // attr rb_snum_t sp_inc = 0;
633 /* empty current stack */
639 // attr rb_snum_t sp_inc = -(rb_snum_t)n;
644 /**********************************************************/
645 /* deal with setting */
646 /**********************************************************/
651 (rb_num_t op_type, VALUE obj, VALUE pushval)
654 // attr bool leaf = leafness_of_defined(op_type);
657 if (vm_defined(ec, GET_CFP(), op_type, obj, v)) {
662 /* check `target' matches `pattern'.
663 `flag & VM_CHECKMATCH_TYPE_MASK' describe how to check pattern.
664 VM_CHECKMATCH_TYPE_WHEN: ignore target and check pattern is truthy.
665 VM_CHECKMATCH_TYPE_CASE: check `patten === target'.
666 VM_CHECKMATCH_TYPE_RESCUE: check `pattern.kind_of?(Module) && pattern === target'.
667 if `flag & VM_CHECKMATCH_ARRAY' is not 0, then `patten' is array of patterns.
672 (VALUE target, VALUE pattern)
674 // attr bool leaf = leafness_of_checkmatch(flag);
676 result = vm_check_match(ec, target, pattern, flag);
679 /* check keywords are specified or not. */
682 (lindex_t kw_bits_index, lindex_t keyword_index)
686 ret = vm_check_keyword(kw_bits_index, keyword_index, GET_EP());
689 /* check if val is type. */
696 ret = RBOOL(TYPE(val) == (int)type);
699 /**********************************************************/
700 /* deal with control flow 1: class/module */
701 /**********************************************************/
703 /* enter class definition scope. if super is Qfalse, and class
704 "klass" is defined, it's redefined. Otherwise, define "klass" class.
708 (ID id, ISEQ class_iseq, rb_num_t flags)
709 (VALUE cbase, VALUE super)
712 VALUE klass = vm_find_or_create_class_by_id(id, flags, cbase, super);
714 rb_iseq_check(class_iseq);
717 vm_push_frame(ec, class_iseq, VM_FRAME_MAGIC_CLASS | VM_ENV_FLAG_LOCAL, klass,
719 (VALUE)vm_cref_push(ec, klass, NULL, FALSE, FALSE),
720 class_iseq->body->iseq_encoded, GET_SP(),
721 class_iseq->body->local_table_size,
722 class_iseq->body->stack_max);
733 vm_define_method(ec, Qnil, id, (VALUE)iseq, FALSE);
742 vm_define_method(ec, obj, id, (VALUE)iseq, TRUE);
745 /**********************************************************/
746 /* deal with control flow 2: method/iterator */
747 /**********************************************************/
752 (CALL_DATA cd, ISEQ blockiseq)
755 // attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
756 // attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
758 VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, false);
759 val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
767 /* Invoke method without block */
769 opt_send_without_block
773 // attr bool handles_sp = true;
774 // attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
775 // attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
777 VALUE bh = VM_BLOCK_HANDLER_NONE;
778 val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
786 /* Convert object to string using to_s or equivalent. */
792 // attr bool leaf = false;
794 val = vm_objtostring(GET_ISEQ(), recv, cd);
797 CALL_SIMPLE_METHOD();
803 (VALUE str, CALL_DATA cd)
807 val = vm_opt_str_freeze(str, BOP_FREEZE, idFreeze);
810 PUSH(rb_str_resurrect(str));
811 CALL_SIMPLE_METHOD();
822 val = vm_opt_nil_p(GET_ISEQ(), cd, recv);
825 CALL_SIMPLE_METHOD();
831 (VALUE str, CALL_DATA cd)
835 val = vm_opt_str_freeze(str, BOP_UMINUS, idUMinus);
838 PUSH(rb_str_resurrect(str));
839 CALL_SIMPLE_METHOD();
848 /* This instruction typically has no funcalls. But it compares array
849 * contents each other by nature. That part could call methods when
850 * necessary. No way to detect such method calls beforehand. We
851 * cannot but mark it being not leaf. */
852 // attr bool leaf = false; /* has rb_funcall() */
853 // attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
855 val = vm_opt_newarray_max(ec, num, STACK_ADDR_FROM_TOP(num));
863 /* Same discussion as opt_newarray_max. */
864 // attr bool leaf = false; /* has rb_funcall() */
865 // attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
867 val = vm_opt_newarray_min(ec, num, STACK_ADDR_FROM_TOP(num));
870 /* super(args) # args.size => num */
873 (CALL_DATA cd, ISEQ blockiseq)
876 // attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
877 // attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
879 VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, true);
880 val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_super);
894 // attr bool handles_sp = true;
895 // attr rb_snum_t sp_inc = sp_inc_of_invokeblock(cd->ci);
896 // attr rb_snum_t comptime_sp_inc = sp_inc_of_invokeblock(ci);
898 VALUE bh = VM_BLOCK_HANDLER_NONE;
899 val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_invokeblock);
907 /* return from this scope. */
913 /* This is super surprising but when leaving from a frame, we check
914 * for interrupts. If any, that should be executed on top of the
915 * current execution context. This is a method call. */
916 // attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
917 // attr bool handles_sp = true;
919 if (OPT_CHECKED_RUN) {
920 const VALUE *const bp = vm_base_ptr(GET_CFP());
921 if (GET_SP() != bp) {
922 vm_stack_consistency_error(ec, GET_CFP(), bp);
926 if (vm_pop_frame(ec, GET_CFP(), GET_EP())) {
927 #if OPT_CALL_THREADED_CODE
928 rb_ec_thread_ptr(ec)->retval = val;
939 /**********************************************************/
940 /* deal with control flow 3: exception */
941 /**********************************************************/
946 (rb_num_t throw_state)
949 /* Same discussion as leave. */
950 // attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
952 val = vm_throw(ec, GET_CFP(), throw_state, throwobj);
953 THROW_EXCEPTION(val);
957 /**********************************************************/
958 /* deal with control flow 4: local jump */
959 /**********************************************************/
961 /* set PC to (PC + dst). */
967 /* Same discussion as leave. */
968 // attr bool leaf = leafness_of_check_ints; /* has rb_threadptr_execute_interrupts() */
970 RUBY_VM_CHECK_INTS(ec);
974 /* if val is not false or nil, set PC to (PC + dst). */
980 /* Same discussion as jump. */
981 // attr bool leaf = leafness_of_check_ints; /* has rb_threadptr_execute_interrupts() */
984 RUBY_VM_CHECK_INTS(ec);
989 /* if val is false or nil, set PC to (PC + dst). */
995 /* Same discussion as jump. */
996 // attr bool leaf = leafness_of_check_ints; /* has rb_threadptr_execute_interrupts() */
999 RUBY_VM_CHECK_INTS(ec);
1004 /* if val is nil, set PC to (PC + dst). */
1010 /* Same discussion as jump. */
1011 // attr bool leaf = leafness_of_check_ints; /* has rb_threadptr_execute_interrupts() */
1014 RUBY_VM_CHECK_INTS(ec);
1019 /**********************************************************/
1021 /**********************************************************/
1023 /* push inline-cached value and go to dst if it is valid */
1030 struct iseq_inline_constant_cache_entry *ice = ic->entry;
1031 if (ice && vm_ic_hit_p(ice, GET_EP())) {
1040 /* set inline cache */
1046 // attr bool leaf = false;
1048 vm_ic_update(GET_ISEQ(), ic, val, GET_EP());
1051 /* run iseq only once */
1054 (ISEQ iseq, ISE ise)
1058 val = vm_once_dispatch(ec, iseq, ise);
1061 /* case dispatcher, jump by table if possible */
1064 (CDHASH hash, OFFSET else_offset)
1067 // attr rb_snum_t sp_inc = -1;
1069 OFFSET dst = vm_case_dispatch(hash, else_offset, key);
1076 /** simple functions */
1078 /* optimized X+Y. */
1082 (VALUE recv, VALUE obj)
1085 val = vm_opt_plus(recv, obj);
1087 if (val == Qundef) {
1088 CALL_SIMPLE_METHOD();
1092 /* optimized X-Y. */
1096 (VALUE recv, VALUE obj)
1099 val = vm_opt_minus(recv, obj);
1101 if (val == Qundef) {
1102 CALL_SIMPLE_METHOD();
1106 /* optimized X*Y. */
1110 (VALUE recv, VALUE obj)
1113 val = vm_opt_mult(recv, obj);
1115 if (val == Qundef) {
1116 CALL_SIMPLE_METHOD();
1120 /* optimized X/Y. */
1124 (VALUE recv, VALUE obj)
1126 /* In case of division by zero, it raises. Thus
1127 * ZeroDivisionError#initialize is called. */
1128 // attr bool leaf = false;
1130 val = vm_opt_div(recv, obj);
1132 if (val == Qundef) {
1133 CALL_SIMPLE_METHOD();
1137 /* optimized X%Y. */
1141 (VALUE recv, VALUE obj)
1143 /* Same discussion as opt_div. */
1144 // attr bool leaf = false;
1146 val = vm_opt_mod(recv, obj);
1148 if (val == Qundef) {
1149 CALL_SIMPLE_METHOD();
1153 /* optimized X==Y. */
1157 (VALUE recv, VALUE obj)
1160 val = opt_equality(GET_ISEQ(), recv, obj, cd);
1162 if (val == Qundef) {
1163 CALL_SIMPLE_METHOD();
1167 /* optimized X!=Y. */
1170 (CALL_DATA cd_eq, CALL_DATA cd)
1171 (VALUE recv, VALUE obj)
1174 val = vm_opt_neq(GET_ISEQ(), cd, cd_eq, recv, obj);
1176 if (val == Qundef) {
1177 CALL_SIMPLE_METHOD();
1181 /* optimized X<Y. */
1185 (VALUE recv, VALUE obj)
1188 val = vm_opt_lt(recv, obj);
1190 if (val == Qundef) {
1191 CALL_SIMPLE_METHOD();
1195 /* optimized X<=Y. */
1199 (VALUE recv, VALUE obj)
1202 val = vm_opt_le(recv, obj);
1204 if (val == Qundef) {
1205 CALL_SIMPLE_METHOD();
1209 /* optimized X>Y. */
1213 (VALUE recv, VALUE obj)
1216 val = vm_opt_gt(recv, obj);
1218 if (val == Qundef) {
1219 CALL_SIMPLE_METHOD();
1223 /* optimized X>=Y. */
1227 (VALUE recv, VALUE obj)
1230 val = vm_opt_ge(recv, obj);
1232 if (val == Qundef) {
1233 CALL_SIMPLE_METHOD();
1241 (VALUE recv, VALUE obj)
1243 /* This instruction can append an integer, as a codepoint, into a
1244 * string. Then what happens if that codepoint does not exist in the
1245 * string's encoding? Of course an exception. That's not a leaf. */
1246 // attr bool leaf = false; /* has "invalid codepoint" exception */
1248 val = vm_opt_ltlt(recv, obj);
1250 if (val == Qundef) {
1251 CALL_SIMPLE_METHOD();
1255 /* optimized X&Y. */
1259 (VALUE recv, VALUE obj)
1262 val = vm_opt_and(recv, obj);
1264 if (val == Qundef) {
1265 CALL_SIMPLE_METHOD();
1269 /* optimized X|Y. */
1273 (VALUE recv, VALUE obj)
1276 val = vm_opt_or(recv, obj);
1278 if (val == Qundef) {
1279 CALL_SIMPLE_METHOD();
1287 (VALUE recv, VALUE obj)
1289 /* This is complicated. In case of hash, vm_opt_aref() resorts to
1290 * rb_hash_aref(). If `recv` has no `obj`, this function then yields
1291 * default_proc. This is a method call. So opt_aref is
1292 * (surprisingly) not leaf. */
1293 // attr bool leaf = false; /* has rb_funcall() */ /* calls #yield */
1295 val = vm_opt_aref(recv, obj);
1297 if (val == Qundef) {
1298 CALL_SIMPLE_METHOD();
1302 /* recv[obj] = set */
1306 (VALUE recv, VALUE obj, VALUE set)
1308 /* This is another story than opt_aref. When vm_opt_aset() resorts
1309 * to rb_hash_aset(), which should call #hash for `obj`. */
1310 // attr bool leaf = false; /* has rb_funcall() */ /* calls #hash */
1312 val = vm_opt_aset(recv, obj, set);
1314 if (val == Qundef) {
1315 CALL_SIMPLE_METHOD();
1319 /* recv[str] = set */
1322 (VALUE key, CALL_DATA cd)
1323 (VALUE recv, VALUE val)
1325 /* Same discussion as opt_aset. */
1326 // attr bool leaf = false; /* has rb_funcall() */ /* calls #hash */
1328 VALUE tmp = vm_opt_aset_with(recv, key, val);
1330 if (tmp != Qundef) {
1335 TOPN(0) = rb_str_resurrect(key);
1338 CALL_SIMPLE_METHOD();
1345 (VALUE key, CALL_DATA cd)
1348 /* Same discussion as opt_aref. */
1349 // attr bool leaf = false; /* has rb_funcall() */ /* calls #yield */
1351 val = vm_opt_aref_with(recv, key);
1353 if (val == Qundef) {
1355 PUSH(rb_str_resurrect(key));
1357 CALL_SIMPLE_METHOD();
1361 /* optimized length */
1368 val = vm_opt_length(recv, BOP_LENGTH);
1370 if (val == Qundef) {
1371 CALL_SIMPLE_METHOD();
1375 /* optimized size */
1382 val = vm_opt_length(recv, BOP_SIZE);
1384 if (val == Qundef) {
1385 CALL_SIMPLE_METHOD();
1389 /* optimized empty? */
1396 val = vm_opt_empty_p(recv);
1398 if (val == Qundef) {
1399 CALL_SIMPLE_METHOD();
1403 /* optimized succ */
1410 val = vm_opt_succ(recv);
1412 if (val == Qundef) {
1413 CALL_SIMPLE_METHOD();
1424 val = vm_opt_not(GET_ISEQ(), cd, recv);
1426 if (val == Qundef) {
1427 CALL_SIMPLE_METHOD();
1431 /* optimized regexp match 2 */
1435 (VALUE obj2, VALUE obj1)
1437 // attr bool leaf = false; /* match_at() has rb_thread_check_ints() */
1439 val = vm_opt_regexpmatch2(obj2, obj1);
1441 if (val == Qundef) {
1442 CALL_SIMPLE_METHOD();
1446 /* call native compiled method */
1447 DEFINE_INSN_IF(SUPPORT_CALL_C_FUNCTION)
1449 (rb_insn_func_t funcptr)
1452 // attr bool leaf = false; /* anything can happen inside */
1453 // attr bool handles_sp = true;
1455 reg_cfp = (funcptr)(ec, reg_cfp);
1458 VALUE err = ec->errinfo;
1460 THROW_EXCEPTION(err);
1467 /* call specific function with args */
1473 // attr bool leaf = false; /* anything can happen inside */
1474 // attr rb_snum_t sp_inc = 1 - bf->argc;
1476 val = vm_invoke_builtin(ec, reg_cfp, bf, STACK_ADDR_FROM_TOP(bf->argc));
1479 /* call specific function with args (same parameters) */
1481 opt_invokebuiltin_delegate
1482 (RB_BUILTIN bf, rb_num_t index)
1485 // attr bool leaf = false; /* anything can happen inside */
1487 val = vm_invoke_builtin_delegate(ec, reg_cfp, bf, (unsigned int)index);
1490 /* call specific function with args (same parameters) and leave */
1492 opt_invokebuiltin_delegate_leave
1493 (RB_BUILTIN bf, rb_num_t index)
1496 // attr bool leaf = false; /* anything can happen inside */
1498 val = vm_invoke_builtin_delegate(ec, reg_cfp, bf, (unsigned int)index);
1500 /* leave fastpath */
1501 /* TracePoint/return fallbacks this insn to opt_invokebuiltin_delegate */
1502 if (vm_pop_frame(ec, GET_CFP(), GET_EP())) {
1503 #if OPT_CALL_THREADED_CODE
1504 rb_ec_thread_ptr(ec)->retval = val;
1516 DEFINE_INSN_IF(SUPPORT_JOKE)
1522 ret = rb_str_new2("a bit of bacon, lettuce and tomato");
1525 /* The Answer to Life, the Universe, and Everything */
1526 DEFINE_INSN_IF(SUPPORT_JOKE)