class Opal::Rewriters::InlineArgs::Initializer
def args_to_keep
def args_to_keep @args.postargs.length end
def extract_args
def extract_args @args.args.each do |arg| if @type == :iter # block args are not required, # so we need to tell compiler that required args # must be initialized with nil-s @initialization << arg.updated(:initialize_iter_arg) else # required inline def argument like 'def m(req)' # no initialization is required end @inline << arg end end
def extract_blockarg
def extract_blockarg if (arg = @args.blockarg) @initialization << arg.updated(:extract_blockarg) end end
def extract_kwargs
def extract_kwargs @args.kwargs.each do |arg| @initialization << arg.updated(:extract_kwarg) end end
def extract_kwoptargs
def extract_kwoptargs @args.kwoptargs.each do |arg| @initialization << arg.updated(:extract_kwoptarg) end end
def extract_kwrestarg
def extract_kwrestarg if (arg = @args.kwrestarg) @initialization << arg.updated(:extract_kwrestarg) end end
def extract_optargs
def extract_optargs has_post_args = @args.has_post_args? @args.optargs.each do |arg| if has_post_args # optional post argument like 'def m(opt = 1, a)' arg_name, default_value = *arg @initialization << arg.updated(:extract_post_optarg, [arg_name, default_value, args_to_keep]) @inline << s(:fake_arg) else # optional inline argument like 'def m(a, opt = 1)' @inline << arg.updated(:arg) @initialization << arg.updated(:extract_optarg) end end end
def extract_post_args
def extract_post_args # post arguments must be extracted with an offset @args.postargs.each do |arg| @initialization << arg.updated(:extract_post_arg) @inline << s(:fake_arg) end end
def extract_restarg
def extract_restarg if (arg = @args.restarg) arg_name = arg.children[0] @initialization << arg.updated(:extract_restarg, [arg_name, args_to_keep]) @inline << s(:fake_arg) end end
def initialize(args, type:)
def initialize(args, type:) @args = Arguments.new(args.children) @inline = [] @initialization = [] @type = type STEPS.each do |step| send(step) end if @initialization.any? @initialization = s(:begin, *@initialization) else @initialization = nil end end
def initialize_shadowargs
def initialize_shadowargs @args.shadowargs.each do |arg| @initialization << arg.updated(:initialize_shadowarg) end end
def prepare_kwargs
def prepare_kwargs return unless @args.has_any_kwargs? if @args.can_inline_kwargs? @inline << s(:arg, :'$kwargs') else @initialization << s(:extract_kwargs) @inline << s(:fake_arg) end @initialization << s(:ensure_kwargs_are_kwargs) end
def prepare_post_args
def prepare_post_args if @args.has_post_args? @initialization << s(:prepare_post_args, @args.args.length) end end