Class: CodeTools::AST::ArrayLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/literals.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, 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) ⇒ ArrayLiteral

Returns a new instance of ArrayLiteral.



8
9
10
11
# File 'lib/rubinius/code/ast/literals.rb', line 8

def initialize(line, array)
  @line = line
  @body = array
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/rubinius/code/ast/literals.rb', line 6

def body
  @body
end

Instance Method Details

#bytecode(g) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/rubinius/code/ast/literals.rb', line 13

def bytecode(g)
  pos(g)

  @body.each do |x|
    x.bytecode(g)
  end

  g.make_array @body.size
end

#defined(g) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubinius/code/ast/literals.rb', line 23

def defined(g)
  not_found = g.new_label
  done = g.new_label
  @body.each do |x|
    x.defined(g)
    g.goto_if_false not_found
  end
  g.push_literal "expression"
  g.goto done
  not_found.set!
  g.push_nil
  g.goto done

  done.set!
end

#to_sexpObject



39
40
41
# File 'lib/rubinius/code/ast/literals.rb', line 39

def to_sexp
  @body.inject([:array]) { |s, x| s << x.to_sexp }
end