class CodeTools::AST::Define

Attributes

arguments[RW]
name[RW]

Public Class Methods

new(line, name, block) click to toggle source
# File lib/rubinius/code/ast/definitions.rb, line 241
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

Public Instance Methods

bytecode(g) click to toggle source
# File lib/rubinius/code/ast/definitions.rb, line 273
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) click to toggle source
# File lib/rubinius/code/ast/definitions.rb, line 249
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_sexp() click to toggle source
# File lib/rubinius/code/ast/definitions.rb, line 286
def to_sexp
  [:defn, @name, @arguments.to_sexp, [:scope, @body.to_sexp]]
end