summaryrefslogtreecommitdiff
path: root/ext/rubyvm
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-20 02:12:48 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-20 02:12:48 (GMT)
commit2283d14cc9fefa278dfde02bdf8d84ce50cfe16f (patch)
tree30d2cbd4b62f9f61a83a9ef7e622351f630aa44a /ext/rubyvm
parentfb8628ecda28227d000f006cc17d4bddbc67f97e (diff)
forwardable/impl.rb
* lib/forwardable/impl.rb (_valid_method?, _compile_method): extract to separate implementation specific part. [ruby-core:78138] [Bug #12938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/rubyvm')
-rw-r--r--ext/rubyvm/extconf.rb1
-rw-r--r--ext/rubyvm/lib/forwardable/impl.rb19
2 files changed, 20 insertions, 0 deletions
diff --git a/ext/rubyvm/extconf.rb b/ext/rubyvm/extconf.rb
new file mode 100644
index 0000000..8c40f58
--- /dev/null
+++ b/ext/rubyvm/extconf.rb
@@ -0,0 +1 @@
+create_makefile("rubyvm")
diff --git a/ext/rubyvm/lib/forwardable/impl.rb b/ext/rubyvm/lib/forwardable/impl.rb
new file mode 100644
index 0000000..ddf7321
--- /dev/null
+++ b/ext/rubyvm/lib/forwardable/impl.rb
@@ -0,0 +1,19 @@
+# :stopdoc:
+module Forwardable
+ FILTER_EXCEPTION = ""
+
+ def self._valid_method?(method)
+ iseq = RubyVM::InstructionSequence.compile("().#{method}", nil, nil, 0, false)
+ rescue SyntaxError => e
+ false
+ else
+ iseq.to_a.dig(-1, 1, 1, :mid) == method.to_sym
+ end
+
+ def self._compile_method(src, file, line)
+ RubyVM::InstructionSequence.compile(src, file, file, line,
+ trace_instruction: false,
+ tailcall_optimization: true)
+ .eval
+ end
+end