Class: CodeTools::AST::Block

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

Overview

Is it weird that Block has the :arguments attribute? Yes. Is it weird that MRI parse tree puts arguments and block_arg in Block? Yes. So we make do and pull them out here rather than having something else reach inside of Block.

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

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) ⇒ Block

Returns a new instance of Block.



73
74
75
76
77
78
79
80
# File 'lib/rubinius/code/ast/definitions.rb', line 73

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

  # These are any local variable that are declared as explicit
  # locals for this scope. This is only used by the |a;b| syntax.
  @locals = nil
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



71
72
73
# File 'lib/rubinius/code/ast/definitions.rb', line 71

def array
  @array
end

#localsObject

Returns the value of attribute locals.



71
72
73
# File 'lib/rubinius/code/ast/definitions.rb', line 71

def locals
  @locals
end

Instance Method Details

#bytecode(g) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/rubinius/code/ast/definitions.rb', line 92

def bytecode(g)
  count = @array.size - 1
  @array.each_with_index do |x, i|
    start_ip = g.ip
    x.bytecode(g)
    g.pop unless start_ip == g.ip or i == count
  end
end

#extract_parametersObject



82
83
84
85
86
87
88
89
90
# File 'lib/rubinius/code/ast/definitions.rb', line 82

def extract_parameters
  if @array.first.kind_of? Parameters
    node = @array.shift
    if @array.first.kind_of? BlockArgument
      node.block_arg = @array.shift
    end
    return node
  end
end

#to_sexpObject



101
102
103
# File 'lib/rubinius/code/ast/definitions.rb', line 101

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