summaryrefslogtreecommitdiff
path: root/insns.def
diff options
context:
space:
mode:
Diffstat (limited to 'insns.def')
-rw-r--r--insns.def1761
1 files changed, 913 insertions, 848 deletions
diff --git a/insns.def b/insns.def
index 4ecdd64026..3ad378081a 100644
--- a/insns.def
+++ b/insns.def
@@ -1,36 +1,62 @@
-/** ##skip -*- mode:c; style:ruby; coding: utf-8 -*-
+/* -*- C -*-
insns.def - YARV instruction definitions
$Author: $
created at: 04/01/01 01:17:55 JST
Copyright (C) 2004-2007 Koichi Sasada
-*/
-
-/** ##skip
- instruction comment
- @c: category
- @e: english description
- @j: japanese description
-
- instruction form:
- DEFINE_INSN
- instruction_name
- (instruction_operands, ..)
- (pop_values, ..)
- (return value)
- {
+ Massive rewrite by @shyouhei in 2017.
+ */
+
+/* Some comments about this file's contents:
+
+ - The new format aims to be editable by C editor of your choice;
+ your mileage might vary of course.
+
+ - Each instructions are in following format:
+
+ DEFINE_INSN
+ instruction_name
+ (type operand, type operand, ..)
+ (pop_values, ..)
+ (return values ..)
+ // attr type name contents..
+ {
.. // insn body
- }
+ }
- */
+ - Unlike the old format which was line-oriented, you can now place
+ newlines and comments at liberal positions.
+
+ - `DEFINE_INSN` is a keyword.
+
+ - An instruction name must be a valid C identifier.
+
+ - Operands, pop values, return values are series of either variable
+ declarations, keyword `void`, or keyword `...`. They are much
+ like C function declarations.
+
+ - Attribute pragmas are optional, and can include arbitrary C
+ expressions. You can write anything there but as of writing,
+ supported attributes are:
+
+ * sp_inc: Used to dynamically calculate sp increase in
+ `insn_stack_increase`.
+
+ * handles_sp: If it is true, VM deals with sp in the insn.
+ Default is if the instruction takes ISEQ operand or not.
+ * leaf: indicates that the instruction is "leaf" i.e. it does
+ not introduce new stack frame on top of it.
+ If an instruction handles sp, that can never be a leaf.
-/**
- @c nop
- @e nop
- @j nop
+ - Attributes can access operands, but not stack (push/pop) variables.
+
+ - An instruction's body is a pure C block, copied verbatimly into
+ the generated C source code.
*/
+
+/* nop */
DEFINE_INSN
nop
()
@@ -44,12 +70,8 @@ nop
/* deal with variables */
/**********************************************************/
-/**
- @c variable
- @e Get local variable (pointed by `idx' and `level').
+/* Get local variable (pointed by `idx' and `level').
'level' indicates the nesting depth from the current block.
- @j level, idx で指定されたローカル変数の値をスタックに置く。
- level はブロックのネストレベルで、何段上かを示す。
*/
DEFINE_INSN
getlocal
@@ -62,12 +84,8 @@ getlocal
(void)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic, level > 0);
}
-/**
- @c variable
- @e Set a local variable (pointed to by 'idx') as val.
+/* Set a local variable (pointed to by 'idx') as val.
'level' indicates the nesting depth from the current block.
- @j level, idx で指定されたローカル変数の値を val にする。
- level はブロックのネストレベルで、何段上かを示す。
*/
DEFINE_INSN
setlocal
@@ -80,11 +98,7 @@ setlocal
(void)RB_DEBUG_COUNTER_INC_IF(lvar_set_dynamic, level > 0);
}
-/**
- @c variable
- @e Get a block parameter.
- @j ブロックパラメータを取得する。
- */
+/* Get a block parameter. */
DEFINE_INSN
getblockparam
(lindex_t idx, rb_num_t level)
@@ -95,22 +109,18 @@ getblockparam
VM_ASSERT(VM_ENV_LOCAL_P(ep));
if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
- val = rb_vm_bh_to_procval(ec, VM_ENV_BLOCK_HANDLER(ep));
- vm_env_write(ep, -(int)idx, val);
- VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
+ val = rb_vm_bh_to_procval(ec, VM_ENV_BLOCK_HANDLER(ep));
+ vm_env_write(ep, -(int)idx, val);
+ VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
}
else {
- val = *(ep - idx);
- RB_DEBUG_COUNTER_INC(lvar_get);
- (void)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic, level > 0);
+ val = *(ep - idx);
+ RB_DEBUG_COUNTER_INC(lvar_get);
+ (void)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic, level > 0);
}
}
-/**
- @c variable
- @e Set block parameter.
- @j ブロックパラメータを設定する。
- */
+/* Set block parameter. */
DEFINE_INSN
setblockparam
(lindex_t idx, rb_num_t level)
@@ -127,25 +137,65 @@ setblockparam
VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
}
-/**
- @c variable
- @e Get value of special local variable ($~, $_, ..).
- @j 特殊なローカル変数($~, $_, ...)の値を得る。
+/* Get special proxy object which only responds to `call` method if the block parameter
+ represents a iseq/ifunc block. Otherwise, same as `getblockparam`.
*/
DEFINE_INSN
+getblockparamproxy
+(lindex_t idx, rb_num_t level)
+()
+(VALUE val)
+// attr bool zjit_profile = true;
+{
+ const VALUE *ep = vm_get_ep(GET_EP(), level);
+ VM_ASSERT(VM_ENV_LOCAL_P(ep));
+
+ if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
+ VALUE block_handler = VM_ENV_BLOCK_HANDLER(ep);
+
+ if (block_handler) {
+ switch (vm_block_handler_type(block_handler)) {
+ case block_handler_type_iseq:
+ case block_handler_type_ifunc:
+ val = rb_block_param_proxy;
+ break;
+ case block_handler_type_symbol:
+ val = rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
+ goto INSN_LABEL(set);
+ case block_handler_type_proc:
+ val = VM_BH_TO_PROC(block_handler);
+ goto INSN_LABEL(set);
+ default:
+ VM_UNREACHABLE(getblockparamproxy);
+ }
+ }
+ else {
+ val = Qnil;
+ INSN_LABEL(set):
+ vm_env_write(ep, -(int)idx, val);
+ VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
+ }
+ }
+ else {
+ val = *(ep - idx);
+ RB_DEBUG_COUNTER_INC(lvar_get);
+ (void)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic, level > 0);
+ }
+}
+
+/* Get value of special local variable ($~, $_, ..). */
+DEFINE_INSN
getspecial
(rb_num_t key, rb_num_t type)
()
(VALUE val)
+/* `$~ = MatchData.allocate; $&` can raise. */
+// attr bool leaf = (type == 0) ? true : false;
{
val = vm_getspecial(ec, GET_LEP(), key, type);
}
-/**
- @c variable
- @e Set value of special local variable ($~, $_, ...) to obj.
- @j 特別なローカル変数($~, $_, ...)の値を設定する。
- */
+/* Set value of special local variable ($~, $_, ...) to obj. */
DEFINE_INSN
setspecial
(rb_num_t key)
@@ -155,146 +205,127 @@ setspecial
lep_svar_set(ec, GET_LEP(), key, obj);
}
-/**
- @c variable
- @e Get value of instance variable id of self.
- @j self のインスタンス変数 id の値を得る。
- */
+/* Get value of instance variable id of self. */
DEFINE_INSN
getinstancevariable
-(ID id, IC ic)
+(ID id, IVC ic)
()
(VALUE val)
+/* Ractor crashes when it accesses class/module-level instances variables. */
+// attr bool leaf = false; /* has IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR() */
+// attr bool zjit_profile = true;
{
- val = vm_getinstancevariable(GET_SELF(), id, ic);
+ val = vm_getinstancevariable(GET_ISEQ(), GET_SELF(), id, ic);
}
-/**
- @c variable
- @e Set value of instance variable id of self to val.
- @j self のインスタンス変数 id を val にする。
- */
+/* Set value of instance variable id of self to val. */
DEFINE_INSN
setinstancevariable
-(ID id, IC ic)
+(ID id, IVC ic)
(VALUE val)
()
+// attr bool leaf = false; /* has rb_check_frozen() */
+// attr bool zjit_profile = true;
{
- vm_setinstancevariable(GET_SELF(), id, val, ic);
+ vm_setinstancevariable(GET_ISEQ(), GET_SELF(), id, val, ic);
}
-/**
- @c variable
- @e Get value of class variable id of klass as val.
- @j 現在のスコープのクラス変数 id の値を得る。
- */
+/* Get value of class variable id of klass as val. */
DEFINE_INSN
getclassvariable
-(ID id)
+(ID id, ICVARC ic)
()
(VALUE val)
+/* "class variable access from toplevel" warning can be hooked. */
+// attr bool leaf = false; /* has rb_warning() */
{
- val = rb_cvar_get(vm_get_cvar_base(rb_vm_get_cref(GET_EP()), GET_CFP()), id);
+ rb_control_frame_t *cfp = GET_CFP();
+ val = vm_getclassvariable(GET_ISEQ(), cfp, id, ic);
}
-/**
- @c variable
- @e Set value of class variable id of klass as val.
- @j klass のクラス変数 id を val にする。
- */
+/* Set value of class variable id of klass as val. */
DEFINE_INSN
setclassvariable
-(ID id)
+(ID id, ICVARC ic)
(VALUE val)
()
+/* "class variable access from toplevel" warning can be hooked. */
+// attr bool leaf = false; /* has rb_warning() */
{
vm_ensure_not_refinement_module(GET_SELF());
- rb_cvar_set(vm_get_cvar_base(rb_vm_get_cref(GET_EP()), GET_CFP()), id, val);
+ vm_setclassvariable(GET_ISEQ(), GET_CFP(), id, val, ic);
+}
+
+DEFINE_INSN
+opt_getconstant_path
+(IC ic)
+()
+(VALUE val)
+// attr bool leaf = false; /* may autoload or raise */
+{
+ val = rb_vm_opt_getconstant_path(ec, GET_CFP(), ic);
}
-/**
- @c variable
- @e
- Get constant variable id. If klass is Qnil, constants
- are searched in the current scope. If klass is Qfalse, constants
- are searched as top level constants. Otherwise, get constant under klass
+/* Get constant variable id. If klass is Qnil and allow_nil is Qtrue, constants
+ are searched in the current scope. Otherwise, get constant under klass
class or module.
- @j 定数 id の値を得る。
- klass が Qnil なら、そのスコープで得られる定数の値を得る。
- Qfalse なら、トップレベルスコープを得る。
- それ以外なら、klass クラスの下の定数を得る。
*/
DEFINE_INSN
getconstant
(ID id)
-(VALUE klass)
+(VALUE klass, VALUE allow_nil)
(VALUE val)
+/* getconstant can kick autoload */
+// attr bool leaf = false; /* has rb_autoload_load() */
{
- val = vm_get_ev_const(ec, klass, id, 0);
+ val = vm_get_ev_const(ec, klass, id, allow_nil == Qtrue, 0);
}
-/**
- @c variable
- @e
- Set constant variable id. If klass is Qfalse, constant
- is able to access in this scope. if klass is Qnil, set
- top level constant. otherwise, set constant under klass
- class or module.
-
- @j 定数 id の値を val にする。
- klass が Qfalse なら、そのスコープで得られる定数 id の値を設定する。
- Qnil なら、トップレベルスコープの値を設定する。
- それ以外なら、klass クラスの下の定数を設定する。
+/* Set constant variable id under cbase class or module.
*/
DEFINE_INSN
setconstant
(ID id)
(VALUE val, VALUE cbase)
()
+/* Assigning an object to a constant is basically a leaf operation.
+ * The problem is, assigning a Module instance to a constant _names_
+ * that module. Naming involves string manipulations, which are
+ * method calls. */
+// attr bool leaf = false; /* has StringValue() */
{
vm_check_if_namespace(cbase);
vm_ensure_not_refinement_module(GET_SELF());
rb_const_set(cbase, id, val);
}
-/**
- @c variable
- @e get global variable id.
- @j グローバル変数 id の値を得る。
- */
+/* get global variable id. */
DEFINE_INSN
getglobal
-(GENTRY entry)
+(ID gid)
()
(VALUE val)
+// attr bool leaf = false;
{
- val = GET_GLOBAL((VALUE)entry);
+ val = rb_gvar_get(gid);
}
-/**
- @c variable
- @e set global variable id as val.
- @j グローバル変数 id の値を設定する。
- */
+/* set global variable id as val. */
DEFINE_INSN
setglobal
-(GENTRY entry)
+(ID gid)
(VALUE val)
()
+// attr bool leaf = false;
{
- SET_GLOBAL((VALUE)entry, val);
+ rb_gvar_set(gid, val);
}
-
/**********************************************************/
/* deal with values */
/**********************************************************/
-/**
- @c put
- @e put nil to stack.
- @j スタックに nil をプッシュする。
- */
+/* put nil to stack. */
DEFINE_INSN
putnil
()
@@ -304,11 +335,7 @@ putnil
val = Qnil;
}
-/**
- @c put
- @e put self.
- @j スタックに self をプッシュする。
- */
+/* put self. */
DEFINE_INSN
putself
()
@@ -318,11 +345,7 @@ putself
val = GET_SELF();
}
-/**
- @c put
- @e put some object.
- i.e. Fixnum, true, false, nil, and so on.
- @j オブジェクト val をスタックにプッシュする。
+/* put some object.
i.e. Fixnum, true, false, nil, and so on.
*/
DEFINE_INSN
@@ -334,17 +357,13 @@ putobject
/* */
}
-/**
- @c put
- @e put special object. "value_type" is for expansion.
- @j 特別なオブジェクト val をスタックにプッシュする。
- オブジェクトの種類は value_type による.
- */
+/* put special object. "value_type" is for expansion. */
DEFINE_INSN
putspecialobject
(rb_num_t value_type)
()
(VALUE val)
+// attr bool leaf = (value_type == VM_SPECIAL_OBJECT_VMCORE); /* others may raise when allocating singleton */
{
enum vm_special_object_type type;
@@ -352,104 +371,68 @@ putspecialobject
val = vm_get_special_object(GET_EP(), type);
}
-/**
- @c put
- @e put iseq value.
- @j iseq をスタックにプッシュする。
- */
+/* put string val. string will be copied. */
DEFINE_INSN
-putiseq
-(ISEQ iseq)
+dupstring
+(VALUE str)
()
-(VALUE ret)
+(VALUE val)
{
- ret = (VALUE)iseq;
+ val = rb_ec_str_resurrect(ec, str, false);
}
-/**
- @c put
- @e put string val. string will be copied.
- @j 文字列をコピーしてスタックにプッシュする。
- */
+/* put chilled string val. string will be copied but frozen in the future. */
DEFINE_INSN
-putstring
+dupchilledstring
(VALUE str)
()
(VALUE val)
{
- val = rb_str_resurrect(str);
+ val = rb_ec_str_resurrect(ec, str, true);
}
-/**
- @c put
- @e put concatenate strings
- @j スタックトップの文字列を n 個連結し,結果をスタックにプッシュする。
- */
+/* put concatenate strings */
DEFINE_INSN
concatstrings
(rb_num_t num)
(...)
-(VALUE val) // inc += 1 - num;
+(VALUE val)
+/* This instruction can concat UTF-8 and binary strings, resulting in
+ * Encoding::CompatibilityError. */
+// attr bool leaf = false; /* has rb_enc_cr_str_buf_cat() */
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
{
val = rb_str_concat_literals(num, STACK_ADDR_FROM_TOP(num));
- POPN(num);
}
-/**
- @c put
- @e push the result of to_s.
- @j to_s の結果をスタックにプッシュする。
- */
+/* Convert the result to string if not already a string.
+ This is used as a backup if to_s does not return a string. */
DEFINE_INSN
-tostring
+anytostring
()
(VALUE val, VALUE str)
(VALUE val)
{
- VALUE rb_obj_as_string_result(VALUE str, VALUE obj);
val = rb_obj_as_string_result(str, val);
}
-/**
- @c put
- @e Freeze (dynamically) created strings. if debug_info is given, set it.
- @j (埋め込み)文字列を freeze する。もし、debug_info が与えられていれば、それを設定する。
- */
-DEFINE_INSN
-freezestring
-(VALUE debug_info)
-(VALUE str)
-(VALUE str)
-{
- vm_freezestring(str, debug_info);
-}
-
-/**
- @c put
- @e compile str to Regexp and push it.
+/* compile str to Regexp and push it.
opt is the option for the Regexp.
- @j 文字列 str を正規表現にコンパイルしてスタックにプッシュする。
- コンパイル時,opt を正規表現のオプションとする。
*/
DEFINE_INSN
toregexp
(rb_num_t opt, rb_num_t cnt)
(...)
-(VALUE val) // inc += 1 - cnt;
+(VALUE val)
+/* This instruction can raise RegexpError, thus can call
+ * RegexpError#initialize */
+// attr bool leaf = false;
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)cnt;
{
- VALUE rb_reg_new_ary(VALUE ary, int options);
- VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
- const VALUE ary = rb_ary_tmp_new_from_values(0, cnt, STACK_ADDR_FROM_TOP(cnt));
- POPN(cnt);
- val = rb_reg_new_ary(ary, (int)opt);
- rb_ary_clear(ary);
+ val = rb_reg_new_from_values(cnt, STACK_ADDR_FROM_TOP(cnt), (int)opt);
}
-/**
- @c put
- @e intern str to Symbol and push it.
- @j 文字列 str をシンボルに変換してスタックにプッシュする。
- */
+/* intern str to Symbol and push it. */
DEFINE_INSN
intern
()
@@ -459,38 +442,54 @@ intern
sym = rb_str_intern(str);
}
-/**
- @c put
- @e put new array initialized with num values on the stack.
- @j 新しい配列をスタック上の num 個の値で初期化して生成しプッシュする。
- */
+/* put new array initialized with num values on the stack. */
DEFINE_INSN
newarray
(rb_num_t num)
(...)
-(VALUE val) // inc += 1 - num;
+(VALUE val)
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
{
- val = rb_ary_new4(num, STACK_ADDR_FROM_TOP(num));
- POPN(num);
+ val = rb_ec_ary_new_from_values(ec, num, STACK_ADDR_FROM_TOP(num));
}
-/**
- @c put
- @e dup array
- @j 配列 ary を dup してスタックにプッシュする。
+/* push hash onto array unless the hash is empty (as empty keyword
+ splats should be ignored).
*/
DEFINE_INSN
+pushtoarraykwsplat
+()
+(VALUE ary, VALUE hash)
+(VALUE ary)
+{
+ if (!RHASH_EMPTY_P(hash)) {
+ rb_ary_push(ary, hash);
+ }
+}
+
+/* dup array */
+DEFINE_INSN
duparray
(VALUE ary)
()
(VALUE val)
{
+ RUBY_DTRACE_CREATE_HOOK(ARRAY, RARRAY_LEN(ary));
val = rb_ary_resurrect(ary);
}
-/**
- @c put
- @e if TOS is an array expand, expand it to num objects.
+/* dup hash */
+DEFINE_INSN
+duphash
+(VALUE hash)
+()
+(VALUE val)
+{
+ RUBY_DTRACE_CREATE_HOOK(HASH, RHASH_SIZE(hash) << 1);
+ val = rb_hash_resurrect(hash);
+}
+
+/* if TOS is an array expand, expand it to num objects.
if the number of the array is less than num, push nils to fill.
if it is greater than num, exceeding elements are dropped.
unless TOS is an array, push num - 1 nils.
@@ -498,84 +497,113 @@ duparray
flag: 0x01 - rest args array
flag: 0x02 - for postarg
flag: 0x04 - reverse?
- @j スタックトップのオブジェクトが配列であれば、それを展開する。
- 配列オブジェクトの要素数が num以下ならば、代わりに nil を積む。num以上なら、
- num以上の要素は切り捨てる。
- 配列オブジェクトでなければ、num - 1 個の nil を積む。
- もし flag が真なら、残り要素の配列を積む
- flag: 0x01 - 最後を配列に
- flag: 0x02 - postarg 用
- flag: 0x04 - reverse?
*/
DEFINE_INSN
expandarray
(rb_num_t num, rb_num_t flag)
(..., VALUE ary)
-(...) // inc += num - 1 + (flag & 1 ? 1 : 0);
+(...)
+// attr bool handles_sp = true;
+// attr bool leaf = false; /* has rb_check_array_type() */
+// attr rb_snum_t sp_inc = (rb_snum_t)num - 1 + (flag & 1 ? 1 : 0);
{
vm_expandarray(GET_CFP(), ary, num, (int)flag);
}
-/**
- @c put
- @e concat two arrays
- @j 二つの配列 ary1, ary2 を連結しスタックへプッシュする。
+/* concat two arrays, without modifying first array.
+ * attempts to convert both objects to arrays using to_a.
*/
DEFINE_INSN
concatarray
()
(VALUE ary1, VALUE ary2)
(VALUE ary)
+// attr bool leaf = false; /* has rb_check_array_type() */
{
ary = vm_concat_array(ary1, ary2);
}
-/**
- @c put
- @e call to_a on array ary to splat
- @j splat のために配列 ary に対して to_a を呼び出す。
+/* concat second array to first array.
+ * first argument must already be an array.
+ * attempts to convert second object to array using to_a.
*/
DEFINE_INSN
+concattoarray
+()
+(VALUE ary1, VALUE ary2)
+(VALUE ary)
+// attr bool leaf = false; /* has rb_check_array_type() */
+{
+ ary = vm_concat_to_array(ary1, ary2);
+}
+
+/* push given number of objects to array directly before. */
+DEFINE_INSN
+pushtoarray
+(rb_num_t num)
+(...)
+(VALUE val)
+// attr rb_snum_t sp_inc = -(rb_snum_t)num;
+{
+ const VALUE *objp = STACK_ADDR_FROM_TOP(num);
+ val = rb_ary_cat(*(objp-1), objp, num);
+}
+
+/* call to_a on array ary to splat */
+DEFINE_INSN
splatarray
(VALUE flag)
(VALUE ary)
(VALUE obj)
+// attr bool leaf = false; /* has rb_check_array_type() */
{
obj = vm_splat_array(flag, ary);
}
-/**
- @c put
- @e put new Hash from n elements. n must be an even number.
- @j 新しいハッシュをスタックトップの n 個を初期値として生成する。
- n はキーと値のペアなので 2 の倍数でなければならない。
- */
+/* call to_hash on hash to keyword splat before converting block */
+DEFINE_INSN
+splatkw
+()
+(VALUE hash, VALUE block)
+(VALUE obj, VALUE block)
+// attr bool leaf = false; /* has rb_to_hash_type() */
+// attr bool zjit_profile = true;
+{
+ if (NIL_P(hash)) {
+ obj = Qnil;
+ }
+ else {
+ obj = rb_to_hash_type(hash);
+ }
+}
+
+/* put new Hash from n elements. n must be an even number. */
DEFINE_INSN
newhash
(rb_num_t num)
(...)
-(VALUE val) // inc += 1 - num;
+(VALUE val)
+// attr bool leaf = false; /* has rb_hash_key_str() */
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
{
RUBY_DTRACE_CREATE_HOOK(HASH, num);
- val = rb_hash_new_with_size(num / 2);
-
if (num) {
- rb_hash_bulk_insert(num, STACK_ADDR_FROM_TOP(num), val);
+ val = rb_hash_new_with_bulk_insert(num, STACK_ADDR_FROM_TOP(num));
+ }
+ else {
+ val = rb_hash_new();
}
- POPN(num);
}
-/**
- @c put
- @e put new Range object.(Range.new(low, high, flag))
- @j Range.new(low, high, flag) のようなオブジェクトを生成しスタックにプッシュする。
- */
+/* put new Range object.(Range.new(low, high, flag)) */
DEFINE_INSN
newrange
(rb_num_t flag)
(VALUE low, VALUE high)
(VALUE val)
+/* rb_range_new() exercises "bad value for range" check. */
+// attr bool leaf = false; /* see also: range.c:range_init() */
{
val = rb_range_new(low, high, (int)flag);
}
@@ -584,11 +612,7 @@ newrange
/* deal with stack operation */
/**********************************************************/
-/**
- @c stack
- @e pop from stack.
- @j スタックから一つポップする。
- */
+/* pop from stack. */
DEFINE_INSN
pop
()
@@ -599,11 +623,7 @@ pop
/* none */
}
-/**
- @c stack
- @e duplicate stack top.
- @j スタックトップをコピーしてスタックにプッシュする。
- */
+/* duplicate stack top. */
DEFINE_INSN
dup
()
@@ -613,30 +633,21 @@ dup
val1 = val2 = val;
}
-/**
- @c stack
- @e duplicate stack top n elements
- @j スタックトップの n 個をコピーしてスタックにプッシュする。
- */
+/* duplicate stack top n elements */
DEFINE_INSN
dupn
(rb_num_t n)
(...)
-(...) // inc += n;
+(...)
+// attr rb_snum_t sp_inc = n;
{
void *dst = GET_SP();
void *src = STACK_ADDR_FROM_TOP(n);
- INC_SP(n); /* alloca */
MEMCPY(dst, src, VALUE, n);
}
-
-/**
- @c stack
- @e swap top 2 vals
- @j スタックトップの 2 つの値を交換する。
- */
+/* swap top 2 vals */
DEFINE_INSN
swap
()
@@ -646,16 +657,13 @@ swap
/* none */
}
-/**
- @c stack
- @e reverse stack top N order.
- @j スタックトップの n 個の値を逆転する。
- */
+/* reverse stack top N order. */
DEFINE_INSN
-reverse
+opt_reverse
(rb_num_t n)
(...)
-(...) // inc += 0;
+(...)
+// attr rb_snum_t sp_inc = 0;
{
rb_num_t i;
VALUE *sp = STACK_ADDR_FROM_TOP(n);
@@ -668,161 +676,126 @@ reverse
}
}
-/**
- @c stack
- @e for stack caching.
- @j スタックキャッシングの状態を調整するために必要な命令。
- */
-DEFINE_INSN
+/* for stack caching. */
+DEFINE_INSN_IF(STACK_CACHING)
reput
()
(..., VALUE val)
-(VALUE val) // inc += 0;
+(VALUE val)
+// attr rb_snum_t sp_inc = 0;
{
/* none */
}
-/**
- @c stack
- @e get nth stack value from stack top
- @j スタックトップから n 個目をスタックにプッシュする。
- */
+/* get nth stack value from stack top */
DEFINE_INSN
topn
(rb_num_t n)
(...)
-(VALUE val) // inc += 1;
+(VALUE val)
+// attr rb_snum_t sp_inc = 1;
{
val = TOPN(n);
}
-/**
- @c stack
- @e set Nth stack entry to stack top
- @j スタックトップの値を n 個目のスタックにコピー
- */
+/* set Nth stack entry to stack top */
DEFINE_INSN
setn
(rb_num_t n)
(..., VALUE val)
-(VALUE val) // inc += 0
+(VALUE val)
+// attr rb_snum_t sp_inc = 0;
{
- TOPN(n-1) = val;
+ TOPN(n) = val;
}
-/**
- @c stack
- @e empty current stack
- @j current stack を空にする。
- */
+/* empty current stack */
DEFINE_INSN
adjuststack
(rb_num_t n)
(...)
-(...) // inc -= n
+(...)
+// attr rb_snum_t sp_inc = -(rb_snum_t)n;
{
- DEC_SP(n);
+ /* none */
}
-
/**********************************************************/
/* deal with setting */
/**********************************************************/
-/**
- @c setting
- @e defined?
- @j defined? を行う。
- */
+/* defined? */
DEFINE_INSN
defined
-(rb_num_t op_type, VALUE obj, VALUE needstr)
+(rb_num_t op_type, VALUE obj, VALUE pushval)
(VALUE v)
(VALUE val)
+// attr bool leaf = leafness_of_defined(op_type);
+{
+ val = Qnil;
+ if (vm_defined(ec, GET_CFP(), op_type, obj, v)) {
+ val = pushval;
+ }
+}
+
+/* defined?(@foo) */
+DEFINE_INSN
+definedivar
+(ID id, IVC ic, VALUE pushval)
+()
+(VALUE val)
+// attr bool leaf = false;
+// attr bool zjit_profile = true;
{
- val = vm_defined(ec, GET_CFP(), op_type, obj, needstr, v);
+ val = Qnil;
+ if (!UNDEF_P(vm_getivar(GET_SELF(), id, GET_ISEQ(), ic, NULL, FALSE, Qundef))) {
+ val = pushval;
+ }
}
-/**
- @c setting
- @e check `target' matches `pattern'.
+/* check `target' matches `pattern'.
`flag & VM_CHECKMATCH_TYPE_MASK' describe how to check pattern.
VM_CHECKMATCH_TYPE_WHEN: ignore target and check pattern is truthy.
VM_CHECKMATCH_TYPE_CASE: check `patten === target'.
- VM_CHECKMATCH_TYPE_RESCUE: check `pattern.kind_op?(Module) && pattern == target'.
+ VM_CHECKMATCH_TYPE_RESCUE: check `pattern.kind_of?(Module) && pattern === target'.
if `flag & VM_CHECKMATCH_ARRAY' is not 0, then `patten' is array of patterns.
- @j see above comments.
*/
DEFINE_INSN
checkmatch
(rb_num_t flag)
(VALUE target, VALUE pattern)
(VALUE result)
+// attr bool leaf = leafness_of_checkmatch(flag);
{
- result = vm_check_match(target, pattern, flag);
+ result = vm_check_match(ec, target, pattern, flag);
}
-/**
- @c setting
- @e check keywords are specified or not.
- @j キーワードが指定されているかどうかチェックする
- */
+/* check keywords are specified or not. */
DEFINE_INSN
checkkeyword
-(lindex_t kw_bits_index, rb_num_t keyword_index)
+(lindex_t kw_bits_index, lindex_t keyword_index)
()
(VALUE ret)
{
ret = vm_check_keyword(kw_bits_index, keyword_index, GET_EP());
}
-/**
- @c setting
- @e trace
- @j trace 用の命令。
- */
+/* check if val is type. */
DEFINE_INSN
-trace
-(rb_num_t nf)
-()
-()
+checktype
+(rb_num_t type)
+(VALUE val)
+(VALUE ret)
{
- rb_event_flag_t flag = (rb_event_flag_t)nf;
-
- vm_dtrace(flag, ec);
- EXEC_EVENT_HOOK(ec, flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */,
- (flag & (RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN)) ? TOPN(0) : Qundef);
-}
-
-/**
- @c setting
- @e trace
- @j trace 用の命令。
- */
-DEFINE_INSN
-trace2
-(rb_num_t nf, VALUE data)
-()
-()
-{
- rb_event_flag_t flag = (rb_event_flag_t)nf;
-
- vm_dtrace(flag, ec);
- EXEC_EVENT_HOOK(ec, flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, data);
+ ret = RBOOL(TYPE(val) == (int)type);
}
/**********************************************************/
/* deal with control flow 1: class/module */
/**********************************************************/
-/**
- @c class/module
- @e
- enter class definition scope. if super is Qfalse, and class
- "klass" is defined, it's redefine. otherwise, define "klass" class.
- @j クラス定義スコープへ移行する。
- もし super が Qfalse で klassクラスが定義されていれば再定義である。
- そうでなければ、klass クラスを定義する。
+/* enter class definition scope. if super is Qfalse, and class
+ "klass" is defined, it's redefined. Otherwise, define "klass" class.
*/
DEFINE_INSN
defineclass
@@ -831,181 +804,403 @@ defineclass
(VALUE val)
{
VALUE klass = vm_find_or_create_class_by_id(id, flags, cbase, super);
+ const rb_box_t *box = rb_current_box();
rb_iseq_check(class_iseq);
+ rb_cref_t *cref = vm_cref_push(ec, klass, NULL, FALSE, FALSE);
+
+ if (VM_DEFINECLASS_DYNAMIC_CREF_P(flags)) {
+ CREF_DYNAMIC_SET(cref);
+ }
+
/* enter scope */
vm_push_frame(ec, class_iseq, VM_FRAME_MAGIC_CLASS | VM_ENV_FLAG_LOCAL, klass,
- GET_BLOCK_HANDLER(),
- (VALUE)vm_cref_push(ec, klass, NULL, FALSE),
- class_iseq->body->iseq_encoded, GET_SP(),
- class_iseq->body->local_table_size,
- class_iseq->body->stack_max);
+ GC_GUARDED_PTR(box),
+ (VALUE)cref,
+ ISEQ_BODY(class_iseq)->iseq_encoded, GET_SP(),
+ ISEQ_BODY(class_iseq)->local_table_size,
+ ISEQ_BODY(class_iseq)->stack_max);
RESTORE_REGS();
NEXT_INSN();
}
+DEFINE_INSN
+definemethod
+(ID id, ISEQ iseq)
+()
+()
+{
+ vm_define_method(ec, Qnil, id, (VALUE)iseq, FALSE);
+}
+
+DEFINE_INSN
+definesmethod
+(ID id, ISEQ iseq)
+(VALUE obj)
+()
+{
+ vm_define_method(ec, obj, id, (VALUE)iseq, TRUE);
+}
/**********************************************************/
/* deal with control flow 2: method/iterator */
/**********************************************************/
-/**
- @c method/iterator
- @e invoke method.
- @j メソッド呼び出しを行う。ci に必要な情報が格納されている。
- */
+/* invoke method. */
DEFINE_INSN
send
-(CALL_INFO ci, CALL_CACHE cc, ISEQ blockiseq)
+(CALL_DATA cd, ISEQ blockiseq)
(...)
-(VALUE val) // inc += - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0));
+(VALUE val)
+// attr bool zjit_profile = true;
+// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
{
- struct rb_calling_info calling;
+ VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, false);
+ val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
+ JIT_EXEC(ec, val);
- vm_caller_setup_arg_block(ec, reg_cfp, &calling, ci, blockiseq, FALSE);
- vm_search_method(ci, cc, calling.recv = TOPN(calling.argc = ci->orig_argc));
- CALL_METHOD(&calling, ci, cc);
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
+ }
}
+/* invoke forward method. */
DEFINE_INSN
-opt_str_freeze
-(VALUE str)
-()
+sendforward
+(CALL_DATA cd, ISEQ blockiseq)
+(...)
(VALUE val)
+// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
{
- if (BASIC_OP_UNREDEFINED_P(BOP_FREEZE, STRING_REDEFINED_OP_FLAG)) {
- val = str;
+ struct rb_forwarding_call_data adjusted_cd;
+ struct rb_callinfo adjusted_ci;
+
+ VALUE bh = vm_caller_setup_fwd_args(ec, GET_CFP(), cd, blockiseq, 0, &adjusted_cd, &adjusted_ci);
+
+ val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_method);
+ JIT_EXEC(ec, val);
+
+ if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
+ RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
+ }
+
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
+ }
+}
+
+/* Invoke method without block */
+DEFINE_INSN
+opt_send_without_block
+(CALL_DATA cd)
+(...)
+(VALUE val)
+// attr bool zjit_profile = true;
+// attr bool handles_sp = true;
+// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
+{
+ VALUE bh = VM_BLOCK_HANDLER_NONE;
+ val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
+ JIT_EXEC(ec, val);
+
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
+ }
+}
+
+/* Jump if "new" method has been defined by user */
+DEFINE_INSN
+opt_new
+(CALL_DATA cd, OFFSET dst)
+()
+()
+// attr bool leaf = false;
+{
+ VALUE argc = vm_ci_argc(cd->ci);
+ VALUE val = TOPN(argc);
+
+ // The bookkeeping slot should be empty.
+ RUBY_ASSERT(TOPN(argc + 1) == Qnil);
+
+ if (vm_method_cfunc_is(GET_CFP(), cd, val, rb_class_new_instance_pass_kw)) {
+ RB_DEBUG_COUNTER_INC(opt_new_hit);
+ val = rb_obj_alloc(val);
+ TOPN(argc) = val;
+ TOPN(argc + 1) = val;
}
else {
- val = rb_funcall(rb_str_resurrect(str), idFreeze, 0);
+ RB_DEBUG_COUNTER_INC(opt_new_miss);
+ JUMP(dst);
}
}
+/* Convert object to string using to_s or equivalent. */
DEFINE_INSN
-opt_str_uminus
-(VALUE str)
+objtostring
+(CALL_DATA cd)
+(VALUE recv)
+(VALUE val)
+// attr bool leaf = false;
+// attr bool zjit_profile = true;
+{
+ val = vm_objtostring(GET_CFP(), recv, cd);
+
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
+ }
+}
+
+DEFINE_INSN
+opt_ary_freeze
+(VALUE ary, CALL_DATA cd)
()
(VALUE val)
{
- if (BASIC_OP_UNREDEFINED_P(BOP_UMINUS, STRING_REDEFINED_OP_FLAG)) {
- val = str;
+ val = vm_opt_ary_freeze(ary, BOP_FREEZE, idFreeze);
+
+ if (UNDEF_P(val)) {
+ RUBY_DTRACE_CREATE_HOOK(ARRAY, RARRAY_LEN(ary));
+ PUSH(rb_ary_resurrect(ary));
+ CALL_SIMPLE_METHOD();
}
- else {
- val = rb_funcall(rb_str_resurrect(str), idUMinus, 0);
+}
+
+DEFINE_INSN
+opt_hash_freeze
+(VALUE hash, CALL_DATA cd)
+()
+(VALUE val)
+{
+ val = vm_opt_hash_freeze(hash, BOP_FREEZE, idFreeze);
+
+ if (UNDEF_P(val)) {
+ RUBY_DTRACE_CREATE_HOOK(HASH, RHASH_SIZE(hash) << 1);
+ PUSH(rb_hash_resurrect(hash));
+ CALL_SIMPLE_METHOD();
}
}
DEFINE_INSN
-opt_newarray_max
-(rb_num_t num)
-(...)
-(VALUE val) // inc += 1 - num;
+opt_str_freeze
+(VALUE str, CALL_DATA cd)
+()
+(VALUE val)
{
- val = vm_opt_newarray_max(num, STACK_ADDR_FROM_TOP(num));
- POPN(num);
+ val = vm_opt_str_freeze(str, BOP_FREEZE, idFreeze);
+
+ if (UNDEF_P(val)) {
+ PUSH(rb_str_resurrect(str));
+ CALL_SIMPLE_METHOD();
+ }
}
+/* optimized nil? */
DEFINE_INSN
-opt_newarray_min
-(rb_num_t num)
-(...)
-(VALUE val) // inc += 1 - num;
+opt_nil_p
+(CALL_DATA cd)
+(VALUE recv)
+(VALUE val)
+// attr bool zjit_profile = true;
{
- val = vm_opt_newarray_min(num, STACK_ADDR_FROM_TOP(num));
- POPN(num);
+ val = vm_opt_nil_p(GET_CFP(), cd, recv);
+
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
+ }
}
-/**
- @c optimize
- @e Invoke method without block
- @j ブロックなしでメソッド呼び出しを行う。
- */
DEFINE_INSN
-opt_send_without_block
-(CALL_INFO ci, CALL_CACHE cc)
-(...)
-(VALUE val) // inc += -ci->orig_argc;
+opt_str_uminus
+(VALUE str, CALL_DATA cd)
+()
+(VALUE val)
{
- struct rb_calling_info calling;
- calling.block_handler = VM_BLOCK_HANDLER_NONE;
- vm_search_method(ci, cc, calling.recv = TOPN(calling.argc = ci->orig_argc));
- CALL_METHOD(&calling, ci, cc);
+ val = vm_opt_str_freeze(str, BOP_UMINUS, idUMinus);
+
+ if (UNDEF_P(val)) {
+ PUSH(rb_str_resurrect(str));
+ CALL_SIMPLE_METHOD();
+ }
+}
+
+DEFINE_INSN
+opt_duparray_send
+(VALUE ary, ID method, rb_num_t argc)
+(...)
+(VALUE val)
+/* This instruction typically has no funcalls. But it may compare array
+ * contents to each other which may call methods when necessary.
+ * No way to detect such method calls beforehand.
+ * We must mark it as not leaf. */
+// attr bool leaf = false; /* has rb_funcall() */
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)argc;
+// attr rb_snum_t comptime_sp_inc = 1 - (rb_snum_t)argc;
+{
+ switch (method) {
+ case idIncludeP:
+ val = vm_opt_duparray_include_p(ec, ary, TOPN(0));
+ break;
+ default:
+ rb_bug("unreachable");
+ }
}
-/**
- @c method/iterator
- @e super(args) # args.size => num
- @j super を実行する。ci に必要な情報が格納されている。
- */
+DEFINE_INSN
+opt_newarray_send
+(rb_num_t num, rb_num_t method)
+(...)
+(VALUE val)
+/* This instruction typically has no funcalls. But it compares array
+ * contents each other by nature. That part could call methods when
+ * necessary. No way to detect such method calls beforehand. We
+ * cannot but mark it being not leaf. */
+// attr bool leaf = false; /* has rb_funcall() */
+// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
+// attr rb_snum_t comptime_sp_inc = 1 - (rb_snum_t)num;
+{
+ switch (method) {
+ case VM_OPT_NEWARRAY_SEND_HASH:
+ val = vm_opt_newarray_hash(ec, num, STACK_ADDR_FROM_TOP(num));
+ break;
+ case VM_OPT_NEWARRAY_SEND_MIN:
+ val = vm_opt_newarray_min(ec, num, STACK_ADDR_FROM_TOP(num));
+ break;
+ case VM_OPT_NEWARRAY_SEND_MAX:
+ val = vm_opt_newarray_max(ec, num, STACK_ADDR_FROM_TOP(num));
+ break;
+ case VM_OPT_NEWARRAY_SEND_INCLUDE_P:
+ val = vm_opt_newarray_include_p(ec, (long)num-1, STACK_ADDR_FROM_TOP(num), TOPN(0));
+ break;
+ case VM_OPT_NEWARRAY_SEND_PACK:
+ val = vm_opt_newarray_pack_buffer(ec, (long)num-1, STACK_ADDR_FROM_TOP(num), TOPN(0), Qundef);
+ break;
+ case VM_OPT_NEWARRAY_SEND_PACK_BUFFER:
+ val = vm_opt_newarray_pack_buffer(ec, (long)num-2, STACK_ADDR_FROM_TOP(num), TOPN(1), TOPN(0));
+ break;
+ default:
+ rb_bug("unreachable");
+ }
+}
+
+/* super(args) # args.size => num */
DEFINE_INSN
invokesuper
-(CALL_INFO ci, CALL_CACHE cc, ISEQ blockiseq)
+(CALL_DATA cd, ISEQ blockiseq)
(...)
-(VALUE val) // inc += - (int)(ci->orig_argc + ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0));
-{
- struct rb_calling_info calling;
- calling.argc = ci->orig_argc;
+(VALUE val)
+// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
+// attr bool zjit_profile = true;
+{
+ struct rb_callinfo adjusted_ci = VM_CI_ON_STACK(vm_ci_mid(cd->ci),
+ vm_ci_flag(cd->ci),
+ vm_ci_argc(cd->ci),
+ vm_ci_kwarg(cd->ci));
+ const struct rb_callcache *original_cc = rbimpl_atomic_ptr_load((void **)&cd->cc, RBIMPL_ATOMIC_ACQUIRE);
+ struct rb_call_data adjusted_cd = {
+ .ci = &adjusted_ci,
+ .cc = original_cc,
+ };
+
+ VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), adjusted_cd.ci, blockiseq, true);
+ val = vm_sendish(ec, GET_CFP(), &adjusted_cd, bh, mexp_search_super);
+ JIT_EXEC(ec, val);
+
+ if (original_cc != adjusted_cd.cc && vm_cc_markable(adjusted_cd.cc)) {
+ rbimpl_atomic_ptr_store((volatile void **)&cd->cc, (void *)adjusted_cd.cc, RBIMPL_ATOMIC_RELEASE);
+ RB_OBJ_WRITTEN(GET_ISEQ(), Qundef, adjusted_cd.cc);
+ }
- vm_caller_setup_arg_block(ec, reg_cfp, &calling, ci, blockiseq, TRUE);
- calling.recv = GET_SELF();
- vm_search_super_method(ec, GET_CFP(), &calling, ci, cc);
- CALL_METHOD(&calling, ci, cc);
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
+ }
}
-/**
- @c method/iterator
- @e yield(args)
- @j yield を実行する。
- */
+/* super(args) # args.size => num */
DEFINE_INSN
-invokeblock
-(CALL_INFO ci)
+invokesuperforward
+(CALL_DATA cd, ISEQ blockiseq)
(...)
-(VALUE val) // inc += 1 - ci->orig_argc;
+(VALUE val)
+// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
{
- struct rb_calling_info calling;
- calling.argc = ci->orig_argc;
- calling.block_handler = VM_BLOCK_HANDLER_NONE;
- calling.recv = GET_SELF();
+ struct rb_forwarding_call_data adjusted_cd;
+ struct rb_callinfo adjusted_ci;
+
+ VALUE bh = vm_caller_setup_fwd_args(ec, GET_CFP(), cd, blockiseq, 1, &adjusted_cd, &adjusted_ci);
- val = vm_invoke_block(ec, GET_CFP(), &calling, ci);
- if (val == Qundef) {
- RESTORE_REGS();
- NEXT_INSN();
+ val = vm_sendish(ec, GET_CFP(), &adjusted_cd.cd, bh, mexp_search_super);
+ JIT_EXEC(ec, val);
+
+ if (cd->cc != adjusted_cd.cd.cc && vm_cc_markable(adjusted_cd.cd.cc)) {
+ RB_OBJ_WRITE(GET_ISEQ(), &cd->cc, adjusted_cd.cd.cc);
+ }
+
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
}
}
-/**
- @c method/iterator
- @e return from this scope.
- @j このスコープから抜ける。
- */
+/* yield(args) */
+DEFINE_INSN
+invokeblock
+(CALL_DATA cd)
+(...)
+(VALUE val)
+// attr bool handles_sp = true;
+// attr rb_snum_t sp_inc = sp_inc_of_invokeblock(cd->ci);
+// attr rb_snum_t comptime_sp_inc = sp_inc_of_invokeblock(ci);
+// attr bool zjit_profile = true;
+{
+ VALUE bh = VM_BLOCK_HANDLER_NONE;
+ val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_invokeblock);
+ JIT_EXEC(ec, val);
+
+ if (UNDEF_P(val)) {
+ RESTORE_REGS();
+ NEXT_INSN();
+ }
+}
+
+/* return from this scope. */
DEFINE_INSN
leave
()
(VALUE val)
(VALUE val)
+/* This is super surprising but when leaving from a frame, we check
+ * for interrupts. If any, that should be executed on top of the
+ * current execution context. This is a method call. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
+// attr bool handles_sp = true;
{
if (OPT_CHECKED_RUN) {
- const VALUE *const bp = vm_base_ptr(reg_cfp);
- if (reg_cfp->sp != bp) {
- vm_stack_consistency_error(ec, reg_cfp, bp);
- }
+ const VALUE *const bp = vm_base_ptr(GET_CFP());
+ if (GET_SP() != bp) {
+ vm_stack_consistency_error(ec, GET_CFP(), bp);
+ }
}
- RUBY_VM_CHECK_INTS(ec);
-
if (vm_pop_frame(ec, GET_CFP(), GET_EP())) {
#if OPT_CALL_THREADED_CODE
- rb_ec_thread_ptr(ec)->retval = val;
- return 0;
+ rb_ec_thread_ptr(ec)->retval = val;
+ return 0;
#else
- return val;
+ return val;
#endif
}
else {
- RESTORE_REGS();
+ RESTORE_REGS();
}
}
@@ -1013,18 +1208,15 @@ leave
/* deal with control flow 3: exception */
/**********************************************************/
-/**
- @c exception
- @e longjump
- @j 大域ジャンプを行う。
- */
+/* longjump */
DEFINE_INSN
throw
(rb_num_t throw_state)
(VALUE throwobj)
(VALUE val)
+/* Same discussion as leave. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
{
- RUBY_VM_CHECK_INTS(ec);
val = vm_throw(ec, GET_CFP(), throw_state, throwobj);
THROW_EXCEPTION(val);
/* unreachable */
@@ -1034,665 +1226,543 @@ throw
/* deal with control flow 4: local jump */
/**********************************************************/
-/**
- @c jump
- @e set PC to (PC + dst).
- @j PC を (PC + dst) にする。
- */
+/* set PC to (PC + dst). */
DEFINE_INSN
jump
(OFFSET dst)
()
()
+/* Same discussion as leave. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
{
RUBY_VM_CHECK_INTS(ec);
JUMP(dst);
}
-/**
- @c jump
- @e if val is not false or nil, set PC to (PC + dst).
- @j もし val が false か nil でなければ、PC を (PC + dst) にする。
- */
+/* if val is not false or nil, set PC to (PC + dst). */
DEFINE_INSN
branchif
(OFFSET dst)
(VALUE val)
()
+/* Same discussion as jump. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
{
if (RTEST(val)) {
- RUBY_VM_CHECK_INTS(ec);
- JUMP(dst);
+ RUBY_VM_CHECK_INTS(ec);
+ JUMP(dst);
}
}
-/**
- @c jump
- @e if val is false or nil, set PC to (PC + dst).
- @j もし val が false か nil ならば、PC を (PC + dst) にする。
- */
+/* if val is false or nil, set PC to (PC + dst). */
DEFINE_INSN
branchunless
(OFFSET dst)
(VALUE val)
()
+/* Same discussion as jump. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
{
if (!RTEST(val)) {
- RUBY_VM_CHECK_INTS(ec);
- JUMP(dst);
+ RUBY_VM_CHECK_INTS(ec);
+ JUMP(dst);
}
}
-/**
- @c jump
- @e if val is nil, set PC to (PC + dst).
- @j もし val が nil ならば、PC を (PC + dst) にする。
- */
+/* if val is nil, set PC to (PC + dst). */
DEFINE_INSN
branchnil
(OFFSET dst)
(VALUE val)
()
+/* Same discussion as jump. */
+// attr bool leaf = false; /* has rb_threadptr_execute_interrupts() */
{
if (NIL_P(val)) {
- RUBY_VM_CHECK_INTS(ec);
- JUMP(dst);
+ RUBY_VM_CHECK_INTS(ec);
+ JUMP(dst);
}
}
-/**
- @c jump
- @e if val is type, set PC to (PC + dst).
- @j もし val が type ならば、PC を (PC + dst) にする。
- */
+/* same as jump, but without interrupt check */
+DEFINE_INSN
+jump_without_ints
+(OFFSET dst)
+()
+()
+// attr bool leaf = true;
+{
+ JUMP(dst);
+}
+
+/* same as branchif, but without interrupt check */
DEFINE_INSN
-branchiftype
-(rb_num_t type, OFFSET dst)
+branchif_without_ints
+(OFFSET dst)
(VALUE val)
()
+// attr bool leaf = true;
{
- if (TYPE(val) == (int)type) {
- RUBY_VM_CHECK_INTS(ec);
- JUMP(dst);
+ if (RTEST(val)) {
+ JUMP(dst);
}
}
-
-/**********************************************************/
-/* for optimize */
-/**********************************************************/
-
-/**
- @c optimize
- @e push inline-cached value and go to dst if it is valid
- @j インラインキャッシュが有効なら、値をスタックにプッシュして dst へジャンプする。
- */
+/* same as branchunless, but without interrupt check */
DEFINE_INSN
-getinlinecache
-(OFFSET dst, IC ic)
-()
+branchunless_without_ints
+(OFFSET dst)
(VALUE val)
+()
+// attr bool leaf = true;
{
- val = vm_ic_hit_p(ic, GET_EP());
- if (val != Qnil) {
- JUMP(dst);
+ if (!RTEST(val)) {
+ JUMP(dst);
}
}
-/**
- @c optimize
- @e set inline cache
- @j インラインキャッシュの値を設定する。
- */
+/* same as branchnil, but without interrupt check */
DEFINE_INSN
-setinlinecache
-(IC ic)
-(VALUE val)
+branchnil_without_ints
+(OFFSET dst)
(VALUE val)
+()
+// attr bool leaf = true;
{
- vm_ic_update(ic, val, GET_EP());
+ if (NIL_P(val)) {
+ JUMP(dst);
+ }
}
-/**
- @c optimize
- @e run iseq only once
- @j once を実現する。
- */
+/**********************************************************/
+/* for optimize */
+/**********************************************************/
+
+/* run iseq only once */
DEFINE_INSN
once
-(ISEQ iseq, IC ic)
+(ISEQ iseq, ISE ise)
()
(VALUE val)
{
- val = vm_once_dispatch(ec, iseq, ic);
+ val = vm_once_dispatch(ec, iseq, ise);
}
-/**
- @c optimize
- @e case dispatcher, jump by table if possible
- @j case 文で、可能なら表引きでジャンプする。
- */
+/* case dispatcher, jump by table if possible */
DEFINE_INSN
opt_case_dispatch
(CDHASH hash, OFFSET else_offset)
(..., VALUE key)
-() // inc += -1;
+()
+// attr rb_snum_t sp_inc = -1;
{
OFFSET dst = vm_case_dispatch(hash, else_offset, key);
if (dst) {
- JUMP(dst);
+ JUMP(dst);
}
}
/** simple functions */
-/**
- @c optimize
- @e optimized X+Y.
- @j 最適化された X+Y。
- */
+/* optimized X+Y. */
DEFINE_INSN
opt_plus
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_plus(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X-Y.
- @j 最適化された X-Y。
- */
+/* optimized X-Y. */
DEFINE_INSN
opt_minus
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_minus(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X*Y.
- @j 最適化された X*Y。
- */
+/* optimized X*Y. */
DEFINE_INSN
opt_mult
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_mult(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X/Y.
- @j 最適化された X/Y。
- */
+/* optimized X/Y. */
DEFINE_INSN
opt_div
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+/* In case of division by zero, it raises. Thus
+ * ZeroDivisionError#initialize is called. */
+// attr bool leaf = false;
+// attr bool zjit_profile = true;
{
val = vm_opt_div(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X%Y.
- @j 最適化された X%Y。
- */
+/* optimized X%Y. */
DEFINE_INSN
opt_mod
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+/* Same discussion as opt_div. */
+// attr bool leaf = false;
+// attr bool zjit_profile = true;
{
val = vm_opt_mod(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X==Y.
- @j 最適化された X==Y。
- */
+/* optimized X==Y. */
DEFINE_INSN
opt_eq
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
- val = opt_eq_func(recv, obj, ci, cc);
+ val = opt_equality(GET_CFP(), recv, obj, cd);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X!=Y.
- @j 最適化された X!=Y。
- */
+/* optimized X!=Y. */
DEFINE_INSN
opt_neq
-(CALL_INFO ci, CALL_CACHE cc, CALL_INFO ci_eq, CALL_CACHE cc_eq)
+(CALL_DATA cd_eq, CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
- val = vm_opt_neq(ci, cc, ci_eq, cc_eq, recv, obj);
+ val = vm_opt_neq(GET_CFP(), cd, cd_eq, recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X<Y.
- @j 最適化された X<Y。
- */
+/* optimized X<Y. */
DEFINE_INSN
opt_lt
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_lt(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X<=Y.
- @j 最適化された X<=Y。
- */
+/* optimized X<=Y. */
DEFINE_INSN
opt_le
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_le(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X>Y.
- @j 最適化された X>Y。
- */
+/* optimized X>Y. */
DEFINE_INSN
opt_gt
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_gt(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized X>=Y.
- @j 最適化された X>=Y。
- */
+/* optimized X>=Y. */
DEFINE_INSN
opt_ge
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_ge(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e <<
- @j 最適化された X<<Y。
- */
+/* << */
DEFINE_INSN
opt_ltlt
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+/* This instruction can append an integer, as a codepoint, into a
+ * string. Then what happens if that codepoint does not exist in the
+ * string's encoding? Of course an exception. That's not a leaf. */
+// attr bool leaf = false; /* has "invalid codepoint" exception */
+// attr bool zjit_profile = true;
{
val = vm_opt_ltlt(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e []
- @j 最適化された recv[obj]。
- */
+/* optimized X&Y. */
DEFINE_INSN
-opt_aref
-(CALL_INFO ci, CALL_CACHE cc)
+opt_and
+(CALL_DATA cd)
(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
- val = vm_opt_aref(recv, obj);
+ val = vm_opt_and(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e recv[obj] = set
- @j 最適化された recv[obj] = set。
- */
+/* optimized X|Y. */
DEFINE_INSN
-opt_aset
-(CALL_INFO ci, CALL_CACHE cc)
-(VALUE recv, VALUE obj, VALUE set)
+opt_or
+(CALL_DATA cd)
+(VALUE recv, VALUE obj)
(VALUE val)
+// attr bool zjit_profile = true;
{
- val = vm_opt_aset(recv, obj, set);
+ val = vm_opt_or(recv, obj);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(obj);
- PUSH(set);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e recv[str] = set
- @j 最適化された recv[str] = set。
- */
+/* [] */
DEFINE_INSN
-opt_aset_with
-(CALL_INFO ci, CALL_CACHE cc, VALUE key)
-(VALUE recv, VALUE val)
+opt_aref
+(CALL_DATA cd)
+(VALUE recv, VALUE obj)
(VALUE val)
+/* This is complicated. In case of hash, vm_opt_aref() resorts to
+ * rb_hash_aref(). If `recv` has no `obj`, this function then yields
+ * default_proc. This is a method call. So opt_aref is
+ * (surprisingly) not leaf. */
+// attr bool leaf = false; /* has rb_funcall() */ /* calls #yield */
+// attr bool zjit_profile = true;
{
- VALUE tmp = vm_opt_aset_with(recv, key, val);
+ val = vm_opt_aref(recv, obj);
- if (tmp != Qundef) {
- val = tmp;
- }
- else {
- /* other */
- PUSH(recv);
- PUSH(rb_str_resurrect(key));
- PUSH(val);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e recv[str]
- @j 最適化された recv[str]。
- */
+/* recv[obj] = set */
DEFINE_INSN
-opt_aref_with
-(CALL_INFO ci, CALL_CACHE cc, VALUE key)
-(VALUE recv)
+opt_aset
+(CALL_DATA cd)
+(VALUE recv, VALUE obj, VALUE set)
(VALUE val)
+/* This is another story than opt_aref. When vm_opt_aset() resorts
+ * to rb_hash_aset(), which should call #hash for `obj`. */
+// attr bool leaf = false; /* has rb_funcall() */ /* calls #hash */
+// attr bool zjit_profile = true;
{
- val = vm_opt_aref_with(recv, key);
+ val = vm_opt_aset(recv, obj, set);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- PUSH(rb_str_resurrect(key));
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized length
- @j 最適化された recv.length()。
- */
+/* optimized length */
DEFINE_INSN
opt_length
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_length(recv, BOP_LENGTH);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized size
- @j 最適化された recv.size()。
- */
+/* optimized size */
DEFINE_INSN
opt_size
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_length(recv, BOP_SIZE);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized empty?
- @j 最適化された recv.empty?()。
- */
+/* optimized empty? */
DEFINE_INSN
opt_empty_p
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_empty_p(recv);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized succ
- @j 最適化された recv.succ()。
- */
+/* optimized succ */
DEFINE_INSN
opt_succ
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv)
(VALUE val)
+// attr bool zjit_profile = true;
{
val = vm_opt_succ(recv);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e optimized not
- @j 最適化された recv.!()。
- */
+/* optimized not */
DEFINE_INSN
opt_not
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE recv)
(VALUE val)
+// attr bool zjit_profile = true;
{
- val = vm_opt_not(ci, cc, recv);
+ val = vm_opt_not(GET_CFP(), cd, recv);
- if (val == Qundef) {
- /* other */
- PUSH(recv);
- CALL_SIMPLE_METHOD(recv);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-
-/**
- @c optimize
- @e optimized regexp match
- @j 最適化された正規表現マッチ。
- */
-DEFINE_INSN
-opt_regexpmatch1
-(VALUE recv)
-(VALUE obj)
-(VALUE val)
-{
- val = vm_opt_regexpmatch1(recv, obj);
-}
-
-/**
- @c optimize
- @e optimized regexp match 2
- @j 最適化された正規表現マッチ 2
- */
+/* optimized regexp match 2 */
DEFINE_INSN
opt_regexpmatch2
-(CALL_INFO ci, CALL_CACHE cc)
+(CALL_DATA cd)
(VALUE obj2, VALUE obj1)
(VALUE val)
+// attr bool leaf = false; /* match_at() has rb_thread_check_ints() */
+// attr bool zjit_profile = true;
{
val = vm_opt_regexpmatch2(obj2, obj1);
- if (val == Qundef) {
- /* other */
- PUSH(obj2);
- PUSH(obj1);
- CALL_SIMPLE_METHOD(obj2);
+ if (UNDEF_P(val)) {
+ CALL_SIMPLE_METHOD();
}
}
-/**
- @c optimize
- @e call native compiled method
- @j ネイティブコンパイルしたメソッドを起動。
- */
+/* call specific function with args */
+DEFINE_INSN
+invokebuiltin
+(RB_BUILTIN bf)
+(...)
+(VALUE val)
+// attr bool leaf = false; /* anything can happen inside */
+// attr rb_snum_t sp_inc = 1 - bf->argc;
+{
+ val = vm_invoke_builtin(ec, reg_cfp, bf, STACK_ADDR_FROM_TOP(bf->argc));
+}
+
+/* call specific function with args (same parameters) */
DEFINE_INSN
-opt_call_c_function
-(rb_insn_func_t funcptr)
+opt_invokebuiltin_delegate
+(RB_BUILTIN bf, rb_num_t index)
()
+(VALUE val)
+// attr bool leaf = false; /* anything can happen inside */
+{
+ val = vm_invoke_builtin_delegate(ec, reg_cfp, bf, (unsigned int)index);
+}
+
+/* call specific function with args (same parameters) and leave */
+DEFINE_INSN
+opt_invokebuiltin_delegate_leave
+(RB_BUILTIN bf, rb_num_t index)
()
+(VALUE val)
+// attr bool leaf = false; /* anything can happen inside */
{
- reg_cfp = (funcptr)(ec, reg_cfp);
+ val = vm_invoke_builtin_delegate(ec, reg_cfp, bf, (unsigned int)index);
- if (reg_cfp == 0) {
- VALUE err = ec->errinfo;
- ec->errinfo = Qnil;
- THROW_EXCEPTION(err);
+ /* leave fastpath */
+ /* TracePoint/return fallbacks this insn to opt_invokebuiltin_delegate */
+ if (vm_pop_frame(ec, GET_CFP(), GET_EP())) {
+#if OPT_CALL_THREADED_CODE
+ rb_ec_thread_ptr(ec)->retval = val;
+ return 0;
+#else
+ return val;
+#endif
+ }
+ else {
+ RESTORE_REGS();
}
-
- RESTORE_REGS();
- NEXT_INSN();
}
-/**
- @c joke
- @e BLT
- @j BLT
- */
-DEFINE_INSN
+/* BLT */
+DEFINE_INSN_IF(SUPPORT_JOKE)
bitblt
()
()
@@ -1701,12 +1771,8 @@ bitblt
ret = rb_str_new2("a bit of bacon, lettuce and tomato");
}
-/**
- @c joke
- @e The Answer to Life, the Universe, and Everything
- @j 人生、宇宙、すべての答え。
- */
-DEFINE_INSN
+/* The Answer to Life, the Universe, and Everything */
+DEFINE_INSN_IF(SUPPORT_JOKE)
answer
()
()
@@ -1714,4 +1780,3 @@ answer
{
ret = INT2FIX(42);
}
-