Class: Ruby2CExtension::Plugins::DirectSelfCall
- Inherits:
-
Ruby2CExtension::Plugin
- Object
- Ruby2CExtension::Plugin
- Ruby2CExtension::Plugins::DirectSelfCall
- Includes:
- Util
- Defined in:
- lib/ruby2cext/plugins/direct_self_call.rb
Constant Summary collapse
- @@only_private =
true
Instance Attribute Summary
Attributes inherited from Ruby2CExtension::Plugin
Class Method Summary collapse
Instance Method Summary collapse
- #call(cfun, node) ⇒ Object
-
#initialize(compiler) ⇒ DirectSelfCall
constructor
A new instance of DirectSelfCall.
Methods included from Util
#args_arity, #deduce_type, #split_args, #values
Methods inherited from Ruby2CExtension::Plugin
Constructor Details
#initialize(compiler) ⇒ DirectSelfCall
Returns a new instance of DirectSelfCall.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby2cext/plugins/direct_self_call.rb', line 33 def initialize(compiler) super @ruby2c_method = {} @scope = nil compiler.add_preprocessor(:defn) { |cfun, node| scope0 = @scope hash = node.last mid = hash[:mid] @scope = cfun name0 = "\0#{cfun.__id__}\0#{mid}\0" name = name0.clone @ruby2c_method[[cfun,mid]] = name _add_fun = compiler.method(:add_fun) klass = (class << compiler;self;end) klass.send(:define_method, :add_fun) { |code, base_name| name.replace(_add_fun[code, base_name]) code.gsub!(name0, name) name.clone } ret = cfun.comp_defn(hash) if @@only_private unless cfun.scope.vmode.equal?(:private) @ruby2c_method.delete([cfun,mid]) # pretend we never even saw this method... end end @scope = scope0 klass.send(:define_method, :add_fun, _add_fun.unbind) ret } compiler.add_preprocessor(:call, &method(:call)) compiler.add_preprocessor(:vcall, &method(:call)) compiler.add_preprocessor(:fcall, &method(:call)) end |
Class Method Details
.allow_public_methods ⇒ Object
11 12 13 |
# File 'lib/ruby2cext/plugins/direct_self_call.rb', line 11 def DirectSelfCall.allow_public_methods @@only_private = false end |
Instance Method Details
#call(cfun, node) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby2cext/plugins/direct_self_call.rb', line 15 def call(cfun, node) hash = node.last recv = hash[:recv] return node if recv && (!(Array === recv) || !recv.first.equal?(:self)) mid = hash[:mid] name = @ruby2c_method[[@scope,mid]] return node unless name args = hash[:args] || [:array, []] if Array == args and args.first.equal?(:array) and args.last.empty? "#{name}(0, 0, #{cfun.get_self})" else cfun.c_scope_res { cfun.build_args(args) "#{name}(argc, argv, #{cfun.get_self})" } end end |