[前][次][番号順一覧][スレッド一覧]

ruby-changes:58692

From: Takashi <ko1@a...>
Date: Sun, 10 Nov 2019 14:41:03 +0900 (JST)
Subject: [ruby-changes:58692] 5c168c7e7f (master): Support RB_BUILTIN in ISeq#to_a

https://git.ruby-lang.org/ruby.git/commit/?id=5c168c7e7f

From 5c168c7e7f73d400db45980115dedab4deefcda7 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sat, 9 Nov 2019 21:40:38 -0800
Subject: Support RB_BUILTIN in ISeq#to_a


diff --git a/iseq.c b/iseq.c
index 0b19056..48a4d4b 100644
--- a/iseq.c
+++ b/iseq.c
@@ -2802,6 +2802,21 @@ iseq_data_to_ary(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2802
 		    rb_ary_push(ary, val);
 		}
 		break;
+              case TS_BUILTIN:
+                {
+                    VALUE val = rb_hash_new();
+#if SIZEOF_VALUE <= SIZEOF_LONG
+                    VALUE func_ptr = LONG2NUM((SIGNED_VALUE)((RB_BUILTIN)*seq)->func_ptr);
+#else
+                    VALUE func_ptr = LL2NUM((SIGNED_VALUE)((RB_BUILTIN)*seq)->func_ptr);
+#endif
+                    rb_hash_aset(val, ID2SYM(rb_intern("func_ptr")), func_ptr);
+                    rb_hash_aset(val, ID2SYM(rb_intern("argc")), INT2NUM(((RB_BUILTIN)*seq)->argc));
+                    rb_hash_aset(val, ID2SYM(rb_intern("index")), INT2NUM(((RB_BUILTIN)*seq)->index));
+                    rb_hash_aset(val, ID2SYM(rb_intern("name")), rb_str_new_cstr(((RB_BUILTIN)*seq)->name));
+                    rb_ary_push(ary, val);
+                }
+                break;
 	      default:
 		rb_bug("unknown operand: %c", insn_op_type(insn, j));
 	    }
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 30c4c28..0120a50 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -559,4 +559,11 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L559
       assert_equal iseq1.object_id, iseq2.object_id
     }
   end
+
+  def test_iseq_builtin_to_a
+    insns = RubyVM::InstructionSequence.of([].method(:pack)).to_a.last
+    invokebuiltin = insns.find { |insn| insn.is_a?(Array) && insn[0] == :invokebuiltin }
+    assert_not_nil(invokebuiltin)
+    assert_equal([:func_ptr, :argc, :index, :name], invokebuiltin[1].keys)
+  end
 end
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index bb5727f..a4c3e32 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -601,8 +601,8 @@ class TestJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_jit.rb#L601
   end
 
   def test_compile_insn_invokebuiltin
-    # insns = collect_insns(RubyVM::InstructionSequence.of([0].method(:pack)).to_a)
-    # mark_tested_insn(:invokebuiltin, used_insns: insns)
+    insns = collect_insns(RubyVM::InstructionSequence.of([0].method(:pack)).to_a)
+    mark_tested_insn(:invokebuiltin, used_insns: insns)
     assert_eval_with_jit('print [0].pack("c")', stdout: "\x00", success_count: 1)
   end
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]