class CodeTools::AST::ConcatArgs
Attributes
array[RW]
rest[RW]
Public Class Methods
new(line, array, rest)
click to toggle source
# File lib/rubinius/code/ast/values.rb, line 103 def initialize(line, array, rest) @line = line @array = array @rest = rest end
Public Instance Methods
bytecode(g)
click to toggle source
# File lib/rubinius/code/ast/values.rb, line 109 def bytecode(g) @array.bytecode(g) if @array @rest.bytecode(g) convert_to_a(g) g.send :+, 1, true if @array end
convert_to_a(g)
click to toggle source
TODO: de-dup
# File lib/rubinius/code/ast/values.rb, line 119 def convert_to_a(g) done = g.new_label coerce = g.new_label make_array = g.new_label kind_of_array(g, done) g.dup g.push_literal :to_a g.push_true g.send :respond_to?, 2, true g.goto_if_true coerce make_array.set! g.make_array 1 g.goto done coerce.set! g.dup g.send :to_a, 0, true discard = g.new_label check_array = g.new_label g.dup g.goto_if_not_nil check_array g.pop g.goto make_array check_array.set! kind_of_array(g, discard) g.push_type g.move_down 2 g.push_literal :to_a g.push_cpath_top g.find_const :Array g.send :coerce_to_type_error, 4, true g.goto done discard.set! g.swap g.pop done.set! end
kind_of_array(g, label)
click to toggle source
# File lib/rubinius/code/ast/values.rb, line 167 def kind_of_array(g, label) g.dup g.push_cpath_top g.find_const :Array g.swap g.kind_of g.goto_if_true label end
peel_lhs()
click to toggle source
Dive down and try to find an array of regular values that could construct the left side of a concatination. This is used to minimize the splat doing a send.
# File lib/rubinius/code/ast/values.rb, line 179 def peel_lhs case @array when ConcatArgs @array.peel_lhs when ArrayLiteral ary = @array.body @array = nil ary else nil end end
splat?()
click to toggle source
# File lib/rubinius/code/ast/values.rb, line 196 def splat? true end
to_sexp()
click to toggle source
# File lib/rubinius/code/ast/values.rb, line 192 def to_sexp [:argscat, @array.to_sexp, @rest.to_sexp] end