Class: CodeTools::AST::Define

Inherits:
ClosedScope show all
Defined in:
lib/rubinius/code/ast/definitions.rb

Direct Known Subclasses

DefineSingletonScope

Instance Attribute Summary collapse

Attributes inherited from ClosedScope

#body

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from ClosedScope

#assign_local_reference, #attach_and_call, #module?, #nest_scope, #new_local, #new_nested_local, #search_local

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, name, block) ⇒ Define

Returns a new instance of Define.



191
192
193
194
195
196
197
# File 'lib/rubinius/code/ast/definitions.rb', line 191

def initialize(line, name, block)
  @line = line
  @name = name
  @arguments = block.extract_parameters
  block.array << NilLiteral.new(line) if block.array.empty?
  @body = block
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



189
190
191
# File 'lib/rubinius/code/ast/definitions.rb', line 189

def arguments
  @arguments
end

#nameObject

Returns the value of attribute name.



189
190
191
# File 'lib/rubinius/code/ast/definitions.rb', line 189

def name
  @name
end

Instance Method Details

#bytecode(g) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/rubinius/code/ast/definitions.rb', line 223

def bytecode(g)
  pos(g)

  g.push_rubinius
  g.push_literal @name
  g.push_generator compile_body(g)
  g.push_scope
  g.push_variables
  g.send :method_visibility, 0

  g.send :add_defn_method, 4
end

#compile_body(g) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/rubinius/code/ast/definitions.rb', line 199

def compile_body(g)
  meth = new_generator(g, @name, @arguments)

  meth.push_state self
  meth.state.push_super self
  meth.definition_line(@line)

  meth.state.push_name @name

  @arguments.bytecode(meth)
  @body.bytecode(meth)

  meth.state.pop_name

  meth.local_count = local_count
  meth.local_names = local_names

  meth.ret
  meth.close
  meth.pop_state

  return meth
end

#to_sexpObject



236
237
238
# File 'lib/rubinius/code/ast/definitions.rb', line 236

def to_sexp
  [:defn, @name, @arguments.to_sexp, [:scope, @body.to_sexp]]
end