Class: Rubinius::ToolSet.current::TS::AST::HashLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/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) ⇒ HashLiteral

Returns a new instance of HashLiteral.



118
119
120
121
# File 'lib/rubinius/ast/literals.rb', line 118

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

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



116
117
118
# File 'lib/rubinius/ast/literals.rb', line 116

def array
  @array
end

Instance Method Details

#bytecode(g) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/rubinius/ast/literals.rb', line 123

def bytecode(g)
  pos(g)

  count = @array.size
  i = 0

  g.push_cpath_top
  g.find_const :Hash
  g.push count / 2
  g.send :new_from_literal, 1

  while i < count
    k = @array[i]
    v = @array[i + 1]

    g.dup
    k.bytecode(g)
    v.bytecode(g)
    g.send :[]=, 2
    g.pop

    i += 2
  end
end

#defined(g) ⇒ Object



148
149
150
# File 'lib/rubinius/ast/literals.rb', line 148

def defined(g)
  g.push_literal "expression"
end

#to_sexpObject



152
153
154
# File 'lib/rubinius/ast/literals.rb', line 152

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