Class: CodeTools::AST::ConcatArgs
- Defined in:
- lib/rubinius/ast/values.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#rest ⇒ Object
Returns the value of attribute rest.
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
-
#convert_to_a(g) ⇒ Object
TODO: de-dup.
-
#initialize(line, array, rest) ⇒ ConcatArgs
constructor
A new instance of ConcatArgs.
- #kind_of_array(g, label) ⇒ Object
-
#peel_lhs ⇒ Object
Dive down and try to find an array of regular values that could construct the left side of a concatination.
- #splat? ⇒ Boolean
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, array, rest) ⇒ ConcatArgs
85 86 87 88 89 |
# File 'lib/rubinius/ast/values.rb', line 85 def initialize(line, array, rest) @line = line @array = array @rest = rest end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
83 84 85 |
# File 'lib/rubinius/ast/values.rb', line 83 def array @array end |
#rest ⇒ Object
Returns the value of attribute rest.
83 84 85 |
# File 'lib/rubinius/ast/values.rb', line 83 def rest @rest end |
Instance Method Details
#bytecode(g) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/rubinius/ast/values.rb', line 91 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) ⇒ Object
TODO: de-dup
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rubinius/ast/values.rb', line 101 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.git 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.push :nil g.send :equal?, 1, true g.gif 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) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/rubinius/ast/values.rb', line 151 def kind_of_array(g, label) g.dup g.push_cpath_top g.find_const :Array g.swap g.kind_of g.git label end |
#peel_lhs ⇒ Object
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.
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rubinius/ast/values.rb', line 163 def peel_lhs case @array when ConcatArgs @array.peel_lhs when ArrayLiteral ary = @array.body @array = nil ary else nil end end |
#splat? ⇒ Boolean
180 181 182 |
# File 'lib/rubinius/ast/values.rb', line 180 def splat? true end |
#to_sexp ⇒ Object
176 177 178 |
# File 'lib/rubinius/ast/values.rb', line 176 def to_sexp [:argscat, @array.to_sexp, @rest.to_sexp] end |