class CodeTools::AST::Send

Attributes

block[RW]
name[RW]
privately[RW]
receiver[RW]
variable[RW]
vcall_style[RW]

Public Class Methods

new(line, receiver, name, privately=false, vcall_style=false) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 7
def initialize(line, receiver, name, privately=false, vcall_style=false)
  @line = line
  @receiver = receiver
  @name = name
  @privately = privately
  @block = nil
  @vcall_style = vcall_style
end

Public Instance Methods

arguments_sexp() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 111
def arguments_sexp
  sexp = [:arglist]
  sexp << @block.to_sexp if @block
  sexp
end
bytecode(g, anddot=false) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 22
def bytecode(g, anddot=false)
  pos(g)

  if @vcall_style
    if reference = check_local_reference(g)
      return reference.get_bytecode(g)
    end
  elsif !anddot
    @receiver.bytecode(g)
  end

  if @block
    @block.bytecode(g)
    g.send_with_block @name, 0, @privately
  elsif @vcall_style
    g.send_vcall @name
  else
    g.send @name, 0, @privately
  end
end
check_local_reference(g) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 16
def check_local_reference(g)
  if @receiver.kind_of? Self and g.state.check_for_locals
    g.state.scope.search_local(@name)
  end
end
defined(g) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 68
def defined(g)
  if @block.kind_of? For
    @block.defined(g)
    return
  end

  if @vcall_style and check_local_reference(g)
    g.push_literal "local-variable"
    return
  end

  f = g.new_label
  done = g.new_label

  @receiver.value_defined(g, f)

  g.push_literal @name

  if @vcall_style or @privately
    g.push_true
    g.send :__respond_to_p__, 2
  else
    g.push_self
    g.invoke_primitive :vm_check_callable, 3
  end
  g.goto_if_false f
  g.push_literal "method"
  g.goto done

  f.set!
  g.push_tagged_nil 0

  done.set!
end
receiver_sexp() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 107
def receiver_sexp
  @privately ? nil : @receiver.to_sexp
end
sexp_name() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 103
def sexp_name
  :call
end
to_sexp() click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 117
def to_sexp
  case @block
  when For
    n, x, b = @block.to_sexp
    xs = @receiver.to_sexp
    [n, x, xs, b]
  else
    [sexp_name, receiver_sexp, @name, arguments_sexp]
  end
end
value_defined(g, f) click to toggle source
# File lib/rubinius/code/ast/sends.rb, line 43
def value_defined(g, f)
  # Save the current exception into a stack local
  g.push_exception_state
  outer_exc_state = g.new_stack_local
  g.set_stack_local outer_exc_state
  g.pop

  ok = g.new_label
  ex = g.new_label
  g.setup_unwind ex, RescueType

  bytecode(g)

  g.pop_unwind
  g.goto ok

  ex.set!
  g.clear_exception
  g.push_stack_local outer_exc_state
  g.restore_exception_state
  g.goto f

  ok.set!
end