class CodeTools::AST::HashLiteral

Attributes

array[RW]

Public Class Methods

new(line, array) click to toggle source
# File lib/rubinius/code/ast/literals.rb, line 117
def initialize(line, array)
  @line = line
  @array = array
end

Public Instance Methods

bytecode(g) click to toggle source
# File lib/rubinius/code/ast/literals.rb, line 122
def bytecode(g)
  pos(g)

  count = @array.size
  i = 0

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

  while i < count
    key = @array[i]
    value = @array[i + 1]

    if key
      g.dup
      key.bytecode(g)
      value.bytecode(g)
      g.send :[]=, 2
      g.pop
    else
      case value
      when HashLiteral
        value.merge_entries_bytecode(g)
      else
        g.push_rubinius
        g.find_const :Runtime
        g.swap
        value.bytecode(g)
        g.send :splat_hash_value, 2
      end
    end

    i += 2
  end
end
defined(g) click to toggle source
# File lib/rubinius/code/ast/literals.rb, line 191
def defined(g)
  g.push_literal "expression"
end
merge_entries_bytecode(g) click to toggle source
# File lib/rubinius/code/ast/literals.rb, line 160
def merge_entries_bytecode(g)
  count = @array.size
  i = 0

  while i < count
    key = @array[i]
    value = @array[i + 1]
    if key
      g.push_rubinius
      g.find_const :Runtime
      g.swap
      key.bytecode(g)
      value.bytecode(g)
      g.send :splat_hash_entry, 3
    else
      case value
      when HashLiteral
        value.merge_entries_bytecode(g)
      else
        g.push_rubinius
        g.find_const :Runtime
        g.swap
        value.bytecode(g)
        g.send :splat_hash_value, 2
      end
    end

    i += 2
  end
end
to_sexp() click to toggle source
# File lib/rubinius/code/ast/literals.rb, line 195
def to_sexp
  @array.inject([:hash]) { |s, x| s << (x ? x.to_sexp : [:hash_splat]) }
end