Class: CodeTools::AST::ElementAssignment

Inherits:
SendWithArguments show all
Defined in:
lib/rubinius/code/ast/sends.rb

Instance Attribute Summary

Attributes inherited from SendWithArguments

#arguments

Attributes inherited from Send

#block, #name, #privately, #receiver, #variable, #vcall_style

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from SendWithArguments

#arguments_sexp

Methods inherited from Send

#arguments_sexp, #check_local_reference, #defined, #receiver_sexp, #to_sexp, #value_defined

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, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, receiver, arguments) ⇒ ElementAssignment

Returns a new instance of ElementAssignment.



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/rubinius/code/ast/sends.rb', line 269

def initialize(line, receiver, arguments)
  @line = line

  @receiver = receiver
  @privately = receiver.kind_of?(Self) ? true : false

  @name = :[]=

  case arguments
  when PushArgs
    @arguments = PushArguments.new line, arguments
  else
    @arguments = Arguments.new line, arguments
  end
end

Instance Method Details

#bytecode(g) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/rubinius/code/ast/sends.rb', line 293

def bytecode(g)
  return masgn_bytecode(g) if g.state.masgn?

  @receiver.bytecode(g)
  @arguments.bytecode(g)

  g.dup

  if @arguments.splat?
    case @arguments
    when PushArguments
      g.move_down @arguments.size + 2
      g.swap
      flag = true
    when Arguments
      # TODO: Optimize bytecode for x[a, *b, c, d] = e
      g.send :last, 0, true
      g.move_down @arguments.size + 2
      flag = false
    end

    g.push_nil
    g.send_with_splat @name, @arguments.size, @privately, flag
  else
    g.move_down @arguments.size + 1
    g.send @name, @arguments.size, @privately
  end

  g.pop
end

#masgn_bytecode(g) ⇒ Object



285
286
287
288
289
290
291
# File 'lib/rubinius/code/ast/sends.rb', line 285

def masgn_bytecode(g)
  @receiver.bytecode(g)
  g.swap
  @arguments.masgn_bytecode(g)
  g.send @name, @arguments.size + 1, @privately
  # TODO: splat
end

#sexp_nameObject



324
325
326
# File 'lib/rubinius/code/ast/sends.rb', line 324

def sexp_name
  :attrasgn
end