Sha256: 5666f802a25e8724ecef2ea87cee0bc76d1d1ef5de066e3dab290156b9d711f5

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# Block = BlockEnvironment

class Block {
  forwards_unary_ruby_methods
  metaclass forwards_unary_ruby_methods

  # low level while_true: implementation
  # use direct bytecode generation for speed purposes
  # this gives us good speed in loops
  dynamic_method('while_true_impl:) |g| {
    start = g new_label()
    end = g new_label()
    g total_args=(1)

    start set!()
    g push_self()
    g send('call, 0)
    g set_local(1)
    g gif(end)
    g push_local(0)
    g push_local(1)
    g send('call, 1)
    g pop()
    g check_interrupts()
    g goto(start)

    end set!()
    g push_nil()
    g ret()
  }

  def receiver {
    """
    @return Receiver object of a @Block@.

    Returns the receiver of the @Block@ (value for @self)
    """
    @top_scope receiver
  }

  def receiver: recv {
    """
    @recv New receiver object for a @Block@.

    Sets the receiver (value for @self) of a @Block@.
    """
    @top_scope receiver: recv
  }

  # Ugh. HACK.
  # Use try/catch to deal with older and latest version of rbx (method got changed)
  def call_with_receiver: receiver {
    try {
      return call_under(receiver, method() scope())
    } catch {
      return call_on_instance(receiver)
    }
  }

  def call: args with_receiver: receiver {
    try {
      return call_under(receiver, method() scope(), *args)
    } catch {
      return call_on_instance(receiver, *args)
    }
  }

  def to_proc {
    """
    @return Ruby Proc representing @self.

    Turns a @Block@ into a Ruby Proc object.
    """

    Proc new(&self)
  }
}

class Rubinius VariableScope {
  forwards_unary_ruby_methods

  def receiver {
    @self
  }

  def receiver: recv {
    @self = recv
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.5.0 lib/rbx/block.fy