Class: Ruby2CExtension::CFunction::Method

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby2cext/c_function.rb

Constant Summary

Constants included from Ruby2CExtension::CommonNodeComp

Ruby2CExtension::CommonNodeComp::NON_ITER_PROC

Instance Attribute Summary collapse

Attributes inherited from Base

#closure_tbl, #compiler, #need_class, #need_cref, #need_res, #need_self, #need_wrap, #scope

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_closure_need, #add_helper, #assign_res, #break_allowed?, #closure_buid_c_code, #comp_break, #comp_next, #comp_redo, #comp_retry, #get_cbase, #get_class, #get_closure_ary_var, #get_cref, #get_cvar_cbase, #get_lines, #get_self, #get_wrap_ptr, #global_const, #global_var, #in_while?, #init_c_code, #initialize, #l, #need_closure_ptr, #next_allowed?, #pop_while, #push_while, #redo_allowed?, #sym, #un, #wrap_buid_c_code

Methods included from Tools::EnsureNodeTypeMixin

#ensure_node_type

Methods included from Ruby2CExtension::CommonNodeComp

#build_args, #build_c_arr, #c_else, #c_for, #c_if, #c_scope, #c_scope_res, #c_static_once, #comp, #comp_alias, #comp_and, #comp_argscat, #comp_argspush, #comp_array, #comp_attrasgn, #comp_back_ref, #comp_begin, #comp_block, #comp_block_pass, #comp_break, #comp_call, #comp_case, #comp_cdecl, #comp_class, #comp_colon2, #comp_colon3, #comp_const, #comp_cvar, #comp_cvasgn, #comp_cvdecl, #comp_dasgn, #comp_dasgn_curr, #comp_defined, #comp_defn, #comp_defs, #comp_dot2, #comp_dot3, #comp_dregx, #comp_dregx_once, #comp_dstr, #comp_dsym, #comp_dvar, #comp_dxstr, #comp_ensure, #comp_evstr, #comp_false, #comp_fcall, #comp_flip2, #comp_flip3, #comp_for, #comp_gasgn, #comp_gvar, #comp_hash, #comp_iasgn, #comp_if, #comp_iter, #comp_ivar, #comp_lasgn, #comp_lit, #comp_lvar, #comp_masgn, #comp_match, #comp_match2, #comp_match3, #comp_module, #comp_next, #comp_nil, #comp_not, #comp_nth_ref, #comp_op_asgn1, #comp_op_asgn2, #comp_op_asgn_and, #comp_op_asgn_or, #comp_or, #comp_postexe, #comp_redo, #comp_rescue, #comp_retry, #comp_sclass, #comp_self, #comp_splat, #comp_str, #comp_super, #comp_svalue, #comp_to_ary, #comp_true, #comp_undef, #comp_until, #comp_valias, #comp_vcall, #comp_when, #comp_while, #comp_xstr, #comp_yield, #comp_zarray, #comp_zsuper, #do_funcall, #get_global_entry, #handle_assign, #handle_dot, #handle_dyn_str, #handle_flip, #handle_iter, #handle_method_args, #handle_when, #helper_class_module_check, #helper_super_allowed_check, #make_block, #make_class_prefix

Constructor Details

This class inherits a constructor from Ruby2CExtension::CFunction::Base

Instance Attribute Details

#cref_global_varObject (readonly)

Returns the value of attribute cref_global_var.



326
327
328
# File 'lib/ruby2cext/c_function.rb', line 326

def cref_global_var
  @cref_global_var
end

Class Method Details

.compile(outer, scope_node, def_fun, class_var, mid) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/ruby2cext/c_function.rb', line 283

def self.compile(outer, scope_node, def_fun, class_var, mid)
	ensure_node_type(scope_node, :scope)
	cf = self.new(outer.compiler, Scopes::Scope.new(scope_node.last[:tbl], []))
	cf.instance_eval {
		block_array = make_block(scope_node.last[:next]).last.dup # dup the block_array to allow modification
		arg = block_array.shift
		ba = nil
		unless block_array.empty? || block_array.first.first != :block_arg
			ba = block_array.shift
		end
		handle_method_args(arg, ba)
		l "return #{comp([:block, block_array])};"
	}
	body = "#{cf.init_c_code}\n#{cf.get_lines}"
	sig = "static VALUE FUNNAME(int meth_argc, VALUE *meth_argv, VALUE self) {"
	fname = cf.compiler.add_fun("#{sig}\n#{body}\n}", "method")
	if cf.need_cref
		outer.instance_eval {
			add_helper <<-EOC
				static void def_only_once(ID mid) {
					rb_raise(rb_eTypeError, "def for \\"%s\\" can only be used once", rb_id2name(mid));
				}
			EOC
			l "if (#{cf.cref_global_var}) def_only_once(#{sym(mid)});"
			l "#{cf.cref_global_var} = (VALUE)(#{get_cref});"
		}
	end
	outer.l "#{def_fun}(#{class_var}, #{mid.to_s.to_c_strlit}, #{fname}, -1);"
	"Qnil"
end

Instance Method Details

#comp_return(hash) ⇒ Object



317
318
319
320
# File 'lib/ruby2cext/c_function.rb', line 317

def comp_return(hash)
	l "return #{comp(hash[:stts])};"
	"Qnil"
end

#get_cref_implObject



322
323
324
325
# File 'lib/ruby2cext/c_function.rb', line 322

def get_cref_impl
	@cref_global_var ||= global_var("Qfalse")
	"(RNODE(#{@cref_global_var}))"
end

#return_allowed?Boolean

Returns:

  • (Boolean)


314
315
316
# File 'lib/ruby2cext/c_function.rb', line 314

def return_allowed?
	true
end